ubermag / help

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

Converting df to numpy array/ reading multiple file from the same directory #138

Closed zkhodzhaev closed 3 years ago

zkhodzhaev commented 3 years ago

I have 2 questions:

  1. How can we read multiple files and save them as, e.g., "file_name"?

The website does not have this info: https://discretisedfield.readthedocs.io/en/latest/ipynb/field-read-write.html i tried this, but didn't work: image

  1. I noticed discretisedfield array is not a NumPy array. Can I convert it to NumPy array? so that, I can do the usual operations on the final array.

Thanks

code-whale commented 3 years ago

@zkhodzhaev ,Hi, I'm also a beginner of ubermag. I have some suggestions for your question. First of all, I think you can use the for loop to read multiple files (on the premise that your read files should be named by regular numbers), but I haven't tried that before, so I'm not sure it works. For the second point, you can check whether d in your figure has been successfully defined as a field object. A field object should be similar to the one in the figure below. image If your d returns this type, then I think you just need to enter d.array to return a numpy array. Hope to help you! image

zkhodzhaev commented 3 years ago

Thanks, I'll let you if it works.

marijanbeg commented 3 years ago

Hi @zkhodzhaev, thank you for your question and for using Ubermag.

  1. As @code-whale suggested, you can use a loop. However, a package micromagneticdata can help you if you obtained the ovf files using Ubermag. For instance:
import micromagneticdata as md
import discretisedfiels as df

data = md.Data(system.name)
drive = data[drive_number]
for field in drive:
    field.write(filename)

However, if the files you want to read/write are not obtained by Ubermag, I would suggest looking at glob (https://docs.python.org/3/library/glob.html). If you provide us with more details, I can give you more specific advice.

  1. NumPy array from a field object can be obtained as field.array. Please note that the Field object provides many common operations and convenience functions already. If you let me know what you want to calculate, I can provide further details.
zkhodzhaev commented 3 years ago

Thank you for your response @marijanbeg

I am trying to track skyrmion motion:

Is there a way to track a skyrmion using the Field object? to see the trajectory of the motion, separately and multiple skyrmions at the time?

marijanbeg commented 3 years ago

Thank @zkhodzhaev for the clarification. If you used mumax3 for generating files, then glob seems to be the best way forward.

In order to track the position of a skyrmion, you can have a look at our discussion with @code-whale (https://github.com/ubermag/help/issues/132). For tracking multiple skyrmions, there is no easy solution I am afraid.

Is there anything else we can help you with regarding this issue?

zkhodzhaev commented 3 years ago

Thank you, I have other issues. I can open another ticket later.

marijanbeg commented 3 years ago

My apologies, I referred to the wrong issue. This is the right one: https://github.com/ubermag/help/issues/122