Exporting data

There are fundamentally two different data types:

  • spatially averaged data (as in the odt [OOMMF Data Table] file)
  • spatially resolved data (as in the omf, omv files)

Access the raw OOMMF output files

When Jupyter OOMMF needs a micromagnetic calculation to be carried out, it is writing a mif file, and then asks OOMMF to execute that miffile, and export data to the file system.

It it thus possible to read the output files from the disk as one would normally with OOMMF. This allows re-use of all existing tools to analyse OOMMF data (including muview, ovf2vtk, …)

Example

In [1]:
import oommfc as oc
system = oc.examples.macrospin()
td = oc.TimeDriver()
td.drive(system, t=0.1e-9, n=5)
2018/6/26 12:2: Calling OOMMF (example-macrospin/example-macrospin.mif) ... [0.7s]

From the last output line, we can see that the OOMMF data is stored in the directory example-macrospin. We can display the content:

In [2]:
!ls example-macrospin/
example-macrospin.mif
example-macrospin.odt
example-macrospin-Oxs_TimeDriver-Magnetization-00-0000036.omf
example-macrospin-Oxs_TimeDriver-Magnetization-01-0000066.omf
example-macrospin-Oxs_TimeDriver-Magnetization-02-0000092.omf
example-macrospin-Oxs_TimeDriver-Magnetization-03-0000113.omf
example-macrospin-Oxs_TimeDriver-Magnetization-04-0000130.omf
m0.omf

Exporting the OOMMF Data Table

The file example-macrospin.odt is automatically read and available as a pandas data table in the system.dt object. We can thus use all the export functionality that pandas supports. For example

In [3]:
# display beginning of data table in notebook
system.dt.head()
Out[3]:
E Ecount max_dm/dt dE/dt deltaE E_Zeeman iteration stage_iteration stage mx my mz last_time_step t
0 -5.033171e-18 217.0 37867.797392 -1.241326e-07 -4.522273e-20 -5.033171e-18 36.0 36.0 0.0 -0.597360 -0.038383 0.801054 3.586075e-13 2.000000e-11
1 -6.131373e-18 392.0 13822.238704 -1.653875e-08 -6.256125e-21 -6.131373e-18 66.0 29.0 1.0 0.216713 0.027838 0.975838 3.708125e-13 4.000000e-11
2 -6.266081e-18 543.0 4664.609034 -1.883547e-09 -1.210170e-21 -6.266081e-18 92.0 25.0 2.0 -0.072403 -0.013953 0.997278 6.216520e-13 6.000000e-11
3 -6.281233e-18 664.0 1577.051840 -2.152969e-10 -2.059347e-22 -6.281233e-18 113.0 20.0 3.0 0.024163 0.006131 0.999689 9.181643e-13 8.000000e-11
4 -6.282947e-18 761.0 550.439309 -2.622797e-11 -3.440007e-23 -6.282947e-18 130.0 16.0 4.0 -0.008347 -0.002458 0.999962 1.290222e-12 1.000000e-10

MS Excel, html, latex, json

In [4]:
system.dt.to_excel("data-odt.xlsx")
In [5]:
system.dt.to_html("data-odt.html")
In [6]:
system.dt.to_latex("data-odt.tex")
In [7]:
system.dt.to_json("data-odt.json")

Numpy arrays

Given a pandas table, we can extract each column as a (Pandas) Series:

In [10]:
t_series = system.dt['t']
t_series
Out[10]:
0    2.000000e-11
1    4.000000e-11
2    6.000000e-11
3    8.000000e-11
4    1.000000e-10
Name: t, dtype: float64

Or convert this into a numpy array:

In [11]:
import numpy as np
t_array = np.array(system.dt['t'])
mx_array = np.array(system.dt['mx'])

for example to plot the data in some custom way:

In [12]:
%matplotlib inline
import matplotlib.pyplot as plt
fig, axes = plt.subplots()
axes.plot(t_array, mx_array)
Out[12]:
[<matplotlib.lines.Line2D at 0x7f84587defd0>]
../_images/ipynb_exporting-data_18_1.png

To see which data columns are available in the table, we can use:

In [13]:
system.dt.columns
Out[13]:
Index(['E', 'Ecount', 'max_dm/dt', 'dE/dt', 'deltaE', 'E_Zeeman', 'iteration',
       'stage_iteration', 'stage', 'mx', 'my', 'mz', 'last_time_step', 't'],
      dtype='object')

or

In [14]:
list(system.dt.columns)
Out[14]:
['E',
 'Ecount',
 'max_dm/dt',
 'dE/dt',
 'deltaE',
 'E_Zeeman',
 'iteration',
 'stage_iteration',
 'stage',
 'mx',
 'my',
 'mz',
 'last_time_step',
 't']