Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine Spatially Resolved Magnetization #200

Open
Ponsudana opened this issue Mar 14, 2022 · 2 comments
Open

Determine Spatially Resolved Magnetization #200

Ponsudana opened this issue Mar 14, 2022 · 2 comments

Comments

@Ponsudana
Copy link

Hello Ubermag Team,

How can I determine the spatially resolved magnetization at each cell for the magnetization components at all timesteps?
When I time drive a system for 20 ns and saved the data at a timestep of 5 ps (n=4000), the ODT file containing magnetization values mx, my and mz for all timesteps is obtained.
Now, I wish to determine the spatially resolved magnetization at each cell and save it as an ODT file.
So, I have to read the magnetization from all ODT files (4000 files) and determine the spatially resolved magnetization at each cell.
If region is p1=(-80e-9, -80e-9, 0), p2=(80e-9, 80e-9, 1e-9) and cell is (1e-9, 1e-9, 1e-9), the number of cells are 160 * 160
Now how to write the code to determine spatially resolved magnetization (mxs, mys and mzs) and save it as an ODT file.

Thank you,
Regards,
Ponsudana

@marijanbeg
Copy link
Member

Hi @Ponsudana, thank you for your question. ODT files contain only spatially averaged magnetisation at all time steps. To obtain magnetisation values at all individual time steps, OMF files should be read - micromagneticdata is the package that can be used for that. Unfortunately, it is not documented fully yet, but the basic usage is:

import micromagneticdata as md

data = md.Data(system_name) # system_name is the name you gave to your system
drive = data[N] # N is the drive number in which you used TimeDriver
# Now, the magnetisation field at time_step at point can be accessed as:
drive[time_step](points)

@swapneelap has been working on some very nice functionalities for using xarray - maybe he can provide further information,.

@swapneelap
Copy link
Member

Hello @Ponsudana and @marijanbeg,

With the next ubermag release, it will be possible to obtain an xarray.DataArray from discretisedfield.Field. Taking the same example as above:

import micromagneticdata as md

data = md.Data(system_name)  # system_name is the name you gave to your system
drive = data[N]  # N is the drive number in which you used TimeDriver
# Now, the magnetisation field at time_step at point can be accessed as:
mag_c = drive[time_step].to_xarray().sel(x=<c_x>, y=<c_y>, z=<c_z>, method=nearest)

The values of <c_x>, <c_y>, and <c_z> should be the coordinates (in meter) of the cell. mag_c.values should give an numpy.ndarray containing the magnetization components. One can also extract the magnetization components from cell indices by using to_xarray().isel instead of to_xarray().sel. Taking the example further:

import xarray as xr

collect_xr = []
for step in range(drive.n):
    collect_xr.append(drive[step].to_xarray())

drive_xr = xr.concat(collect_xr, dim='t')  # Collecting all DataArrays in one

mag_c_t = drive_xr.sel(x=<c_x>, y=<c_y>, z=<c_z>, method=nearest)

mag_c_t is an xarray.DataArray which contains the magnetization components of the cell at all the time steps.

We are also working towards adding to_xarray method to micromagneticdata.Drive which will yield the concatenated DataArray directly. This will also be included in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants