#!/usr/bin/env python # coding: utf-8 # # 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) # 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]: get_ipython().system('ls example-macrospin/') # ## 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() # ### 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 # 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]: get_ipython().run_line_magic('matplotlib', 'inline') import matplotlib.pyplot as plt fig, axes = plt.subplots() axes.plot(t_array, mx_array) # To see which data columns are available in the table, we can use: # In[13]: system.dt.columns # or # In[14]: list(system.dt.columns)