ubermag / help

Repository for raising issues and requesting help on Ubermag
BSD 2-Clause "Simplified" License
11 stars 3 forks source link

how to convert omf files to vtk files #229

Closed yejinhong10 closed 1 year ago

yejinhong10 commented 2 years ago

I am trying the command shown on https://ubermag.github.io/documentation/notebooks/discretisedfield/ovf2vtk.html to convert omf to vtk, but it says the command is not found. Am I supposed to install ovf2vtk following https://fangohr.github.io/software/ovf2vtk/index.html ? However the link for the source file to install ovf2vtk seems to be broken. Thanks so much

lang-m commented 2 years ago

Hi @yejinhong10 I have transferred your question to or help repository in which we collect all questions.

Thank you for bringing this up. We have recently changed some of the internal code structure in discretisedfield and the documentation for ovf2vtk unfortunately is outdated. For discretisedfield version >= 0.65.0 please use ovf2vtk as follows:

python3 -m discretisedfield.io.ovf2vtk ...

You do not have to install anything else separately.

yejinhong10 commented 2 years ago

Thank you! Now trying the new command, Error while finding module specification for 'discretisedfield.io.ovf2vtk' (ModuleNotFoundError: No module named 'discretisedfield.io') I get this error message, any suggestion or help??

lang-m commented 2 years ago

Which version of discretisedfield do you have (python3 -c "import discretisedfield; print(discretisedfield.__version__)")?

yejinhong10 commented 2 years ago

It is version 0.64.0. Hmm, now I tried (python3 -m discretisedfield.ovf2vtk -i _10ns_test1-Oxs_TimeDriver-Magnetization-0000000-0000079.omf —o my-ovf-file.vtk )

File "/Users/yejinhong/opt/anaconda3/envs/ubermag/lib/python3.9/runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "/Users/yejinhong/opt/anaconda3/envs/ubermag/lib/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals) File "/Users/yejinhong/opt/anaconda3/envs/ubermag/lib/python3.9/site-packages/discretisedfield/ovf2vtk.py", line 42, in ovf2vtk() File "/Users/yejinhong/opt/anaconda3/envs/ubermag/lib/python3.9/site-packages/discretisedfield/ovf2vtk.py", line 37, in ovf2vtk field = df.Field.fromfile(input_file) File "/Users/yejinhong/opt/anaconda3/envs/ubermag/lib/python3.9/site-packages/discretisedfield/field.py", line 3224, in fromfile raise ValueError(msg) ValueError: Reading file with extension —o not supported.

I got this error message. Do you have any idea of what '-o not supported' would mean? Thank you.

yejinhong10 commented 2 years ago

Now it works with python3 -m discretisedfield.ovf2vtk -i filename.omf command.

I was wondering if this allows running all omf files given a directory? I am trying with

cd directory
for filename in *.omf; do python3 -m discretisedfield.ovf2vtk --add all $filename ${filename%.omf}.vtk; done

but this does not seem to work.

fangohr commented 2 years ago

This or something similar should work. Which shell are you using (try echo $SHELL). What exactly is the error message?

yejinhong10 commented 2 years ago

I am using /bin/zsh shell, and the error message is

usage: ovf2vtk [-h] --input INPUT [INPUT ...] [--output OUTPUT [OUTPUT ...]] ovf2vtk: error: the following arguments are required: --input/-i

Thanks !!

lang-m commented 2 years ago

ovf2vtk must be called with -i (or --input). It does not support an argument --all When you omit -o (the output file name) input file names are used and .omf is replaced with .vtk.

Multiple inputs are supported and you should be able to use wildcards and shell expansion as follows:

python3 -m discretisedfield.ovf2vtk -i *.omf

If this does not work try replacing --add all with -i and remove ${filename%.omf}.vtk in your for loop.

Additionally, could you please try if replacing python3 -m discretisedfield.ovf2vtk with ovf2vtk works. If not, could you please post your error message? Thank you.

yejinhong10 commented 2 years ago

Thanks so much! Adding

-i *.omf

solved the problem.

When I was using ovf2vtk instead of python3 -m discretisedfield.ovf2vtk, the error message is as follows:

Traceback (most recent call last): File "/Users/yejinhong/opt/miniconda3/bin/ovf2vtk", line 5, in from discretisedfield.ovf2vtk import main ImportError: cannot import name 'main' from 'discretisedfield.ovf2vtk' (/Users/yejinhong/opt/miniconda3/lib/python3.9/site-packages/discretisedfield/ovf2vtk.py)

Thank you again!