nschloe / meshio

:spider_web: input/output for many mesh formats
MIT License
1.96k stars 405 forks source link

Cannot detect ugrid #713

Closed jbakosi closed 4 years ago

jbakosi commented 4 years ago

I'm having trouble detecting ugrid for the file attached. Here is what I'm doing:

$ meshio-convert sphere_tetra.1.ugrid sphere.exo
Traceback (most recent call last):
  File "/usr/bin/meshio-convert", line 11, in <module>
    load_entry_point('meshio==2.3.3', 'console_scripts', 'meshio-convert')()
  File "/usr/lib/python3/dist-packages/meshio/cli.py", line 22, in main
    mesh = read(args.infile, file_format=args.input_format)
  File "/usr/lib/python3/dist-packages/meshio/helpers.py", line 128, in read
    file_format = _filetype_from_filename(filename)
  File "/usr/lib/python3/dist-packages/meshio/helpers.py", line 109, in _filetype_from_filename
    ext
AssertionError: Could not deduce file format from extension '.1.ugrid'.

I also tried renaming the file to sphere_tetra.ugrid, but that produces the same problem.

meshio-convert --version
meshio-convert 2.3.3, Python 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0]

sphere_tetra.1.ugrid.txt Rename to sphere_tetra.1.ugrid

Please let me know what I'm doing wrong. Thanks.

nschloe commented 4 years ago

Please let me know what I'm doing wrong.

You're using the same meshio version as Galileo Galilei. Just upgrade and it'll work.

jbakosi commented 4 years ago

Okay, I'll install a custom one and try that one. This is what I pulled in from debian stable: https://packages.debian.org/search?keywords=meshio&searchon=names&suite=stable&section=all

nschloe commented 4 years ago

I'd use pip install meshio.

jbakosi commented 4 years ago

On debian stable pip install meshio still gives me

meshio 2.3.10 [Python 2.7.16]
Copyright (c) 2015-2019 Nico Schlömer <nico.schloemer@gmail.com>

which still does not detect ugrid correctly. I'm no python guru, how else should I install it?

keurfonluu commented 4 years ago

Probably pip3 install meshio. Python 2.7 has not been supported by meshio for quite a while now.

jbakosi commented 4 years ago

Thanks @keurfonluu . Now I get:

$ pip3 install meshio
Collecting meshio
  Downloading https://files.pythonhosted.org/packages/12/0e/44d6af1480791676d375f3c3e8ef5d40521a2529fddb180fef401ff414d0/meshio-4.0.2-py3-none-any.whl (125kB)
    100% |████████████████████████████████| 133kB 1.1MB/s 
Collecting numpy (from meshio)
  Downloading https://files.pythonhosted.org/packages/63/0c/0261693cc3ad8e2b66e66dc2d2676a2cc17d3efb1c58a70db73754320e47/numpy-1.18.1-cp37-cp37m-manylinux1_x86_64.whl (20.1MB)
    100% |████████████████████████████████| 20.1MB 97kB/s 
Installing collected packages: numpy, meshio
Successfully installed meshio-4.0.2 numpy-1.18.1
$ meshio-convert
Traceback (most recent call last):
  File "/usr/local/bin/meshio-convert", line 6, in <module>
    from meshio._cli import convert
ModuleNotFoundError: No module named 'meshio._cli'

Did it not pull some dependency?

keurfonluu commented 4 years ago

Well, my guess is that your previous Python 2 installation is messing with meshio-convert.

Try pip uninstall meshio and then reinstall with pip3.

nschloe commented 4 years ago

It's also weird that it installs in /usr/local/. It should really be $HOME/.local. What's your pip version? You might want to update this to pip 20 first (pip install pip --user should do).

jbakosi commented 4 years ago

Okay, thanks for the help. I think this is progress, but not quite there yet.

$ pip3 install meshio
Collecting meshio
  Downloading https://files.pythonhosted.org/packages/12/0e/44d6af1480791676d375f3c3e8ef5d40521a2529fddb180fef401ff414d0/meshio-4.0.2-py3-none-any.whl (125kB)
    100% |████████████████████████████████| 133kB 1.2MB/s
Collecting numpy (from meshio)
  Downloading https://files.pythonhosted.org/packages/63/0c/0261693cc3ad8e2b66e66dc2d2676a2cc17d3efb1c58a70db73754320e47/numpy-1.18.1-cp37-cp37m-manylinux1_x86_64.whl (20.1MB)
    100% |████████████████████████████████| 20.1MB 94kB/s
Installing collected packages: numpy, meshio
  The scripts f2py, f2py3 and f2py3.7 are installed in '/home/jbakosi/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  The scripts meshio-ascii, meshio-binary, meshio-compress, meshio-convert, meshio-decompress and meshio-info are installed in '/home/jbakosi/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed meshio-4.0.2 numpy-1.18.1
$ ~/.local/bin/meshio-convert sphere_tetra.1.ugrid sphere_tetra.1.exo
Traceback (most recent call last):
  File "/home/jbakosi/.local/bin/meshio-convert", line 10, in <module>
    sys.exit(convert())
  File "/home/jbakosi/.local/lib/python3.7/site-packages/meshio/_cli/_convert.py", line 35, in convert
    write(args.outfile, mesh, **kwargs)
  File "/home/jbakosi/.local/lib/python3.7/site-packages/meshio/_helpers.py", line 117, in write
    file_format = _filetype_from_path(path)
  File "/home/jbakosi/.local/lib/python3.7/site-packages/meshio/_helpers.py", line 33, in _filetype_from_path
    raise ReadError("Could not deduce file format from extension '{}'.".format(ext))
meshio._exceptions.ReadError: Could not deduce file format from extension '.1.exo'.
jbakosi@euler:~/code/etc/ugrid$ ~/.local/bin/meshio-convert sphere_tetra.1.ugrid sphere_tetra.exo
Traceback (most recent call last):
  File "/home/jbakosi/.local/bin/meshio-convert", line 10, in <module>
    sys.exit(convert())
  File "/home/jbakosi/.local/lib/python3.7/site-packages/meshio/_cli/_convert.py", line 35, in convert
    write(args.outfile, mesh, **kwargs)
  File "/home/jbakosi/.local/lib/python3.7/site-packages/meshio/_helpers.py", line 117, in write
    file_format = _filetype_from_path(path)
  File "/home/jbakosi/.local/lib/python3.7/site-packages/meshio/_helpers.py", line 33, in _filetype_from_path
    raise ReadError("Could not deduce file format from extension '{}'.".format(ext))
meshio._exceptions.ReadError: Could not deduce file format from extension '.exo'.

How do I tell meshio that I want exodus output?

nschloe commented 4 years ago

Aha! Use .e, but .exo should actually work as well.

jbakosi commented 4 years ago
$ ~/.local/bin/meshio-convert sphere_tetra.1.ugrid sphere_tetra.e
Traceback (most recent call last):
  File "/home/jbakosi/.local/bin/meshio-convert", line 10, in <module>
    sys.exit(convert())
  File "/home/jbakosi/.local/lib/python3.7/site-packages/meshio/_cli/_convert.py", line 35, in convert
    write(args.outfile, mesh, **kwargs)
  File "/home/jbakosi/.local/lib/python3.7/site-packages/meshio/_helpers.py", line 117, in write
    file_format = _filetype_from_path(path)
  File "/home/jbakosi/.local/lib/python3.7/site-packages/meshio/_helpers.py", line 33, in _filetype_from_path
    raise ReadError("Could not deduce file format from extension '{}'.".format(ext))
meshio._exceptions.ReadError: Could not deduce file format from extension '.e'.
nschloe commented 4 years ago

Ah, right. You need netCDF4 installed, otherwise meshio can't do nothing.

jbakosi commented 4 years ago

Cool. Should I just pull it in using apt-get or pip or some other recommended way so meshio finds it?

nschloe commented 4 years ago

netCDF4 itself has more dependencies, so I usually use apt.

jbakosi commented 4 years ago

Uh! Success! Thanks a lot for the help. I did apt-get install python3-netcdf4 to make netcdf4 available in python3.

One minor note: The ugrid -> exodus conversion took over the node coordinates, and the triangle and tetrahedron connectivities, but did not create side sets.

nschloe commented 4 years ago

Yeah, node sets aren't supported yet; I think there's an open issue for it. If not, feel free to open a new one.

jbakosi commented 4 years ago

Yeah, I figured. This is already very useful, though, since side sets and node sets to exo files can be added with another tool, e.g., cubit.