Drive#

class micromagneticdata.Drive(name, number, dirname='.', x=None, use_cache=False, **kwargs)#

Drive class.

This class provides utility for the analysis of individual drives.

Parameters:
  • name (str) – System’s name.

  • number (int) – Drive number.

  • dirname (str, optional) – Directory in which system’s data is saved. Defults to './'.

  • x (str, optional) – Independent variable column name. Defaults to None and depending on the driver used, one is found automatically.

  • use_cache (bool, optional) – If True the Drive object will read tabular data and the names and number of magnetisation files only once. Note: this prevents Drive to detect new data when looking at the output of a running simulation. If set to False the data is read every time the user accesses it. Defaults to False.

Raises:

IOError – If the drive directory cannot be found.

Examples

  1. Getting drive object from data object.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = dirname=os.path.join(os.path.dirname(__file__),
...                                'tests', 'test_sample')
>>> drive = md.Data(name='system_name', dirname=dirname)[0]
>>> drive
OOMMFDrive(...)
  1. Getting drive objet directly.

>>> drive = md.Drive(name='system_name', number=1, dirname=dirname)
>>> drive
Mumax3Drive(...)

Methods

__dir__

Default dir() implementation.

__eq__

Return self==value.

__getitem__

Magnetisation field of an individual step or subpart of the drive.

__iter__

Iterator.

__lshift__

Concatenate multiple drives of the same type.

__repr__

Representation string.

ovf2vtk

OVF to VTK conversion.

register_callback

Register a callback to which a field is passed before being returned.

slider

Widget for selecting individual steps.

to_xarray

Export micromagneticdata.Drive as xarray.DataArray

Properties

calculator_script

MIF file.

callbacks

Return all registered callbacks.

dirname

Descriptor allowing setting attributes only with values of a certain type.

hv

Plot interface, Holoviews/hvplot based.

info

Drive information.

m0

Inital magnetisation.

n

Number of steps.

name

Descriptor allowing setting attributes only with values of a certain type.

number

Descriptor allowing setting attributes only with scalars (numbers.Real).

table

Table object.

use_cache

Use caching for scalar data and the list of magnetisation files.

x

Independent variable name.


__getitem__(item)#

Magnetisation field of an individual step or subpart of the drive.

If an int is passed a single magnetisation field (discretisedfield.Field object) is returned. Additional callbacks (if registered) are applied to this field before it is returned.

If a slice is passed a new drive object with the magnetisation steps defined via the slice is returned. Additional callbacks (if registered) are passed to the new drive object.

Returns:

  • discretisedfield.Field – Magnetisation field if an int is passed.

  • micromagneticdata.Drive – Drive with selected data if a slice is passed.

Examples

  1. Getting the field of a particular step.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = dirname=os.path.join(os.path.dirname(__file__),
...                                'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive[5]
Field(...)

2. Selecting a part of the drive. >>> import os >>> import micromagneticdata as md … >>> dirname = dirname=os.path.join(os.path.dirname(__file__), … ‘tests’, ‘test_sample’) >>> drive = md.Drive(name=’system_name’, number=0, dirname=dirname) >>> selection = drive[:8:2] >>> selection OOMMFDrive(…) >>> selection.n 4

__lshift__(other)#

Concatenate multiple drives of the same type.

Multiple drives with the same independent variable (typically drives of the same type, e.g. TimeDriver) can be concatenated into one combined drive. The resulting object has one large table with scalar values and allows iterating over all magnetisation files of the individual drives.

Parameters:

other (micromagneticdata.Drive, micromagneticdata.CombinedDrive) – The drive to append to the current object.

Returns:

The concatenated drives.

Return type:

micromagneticdata.CombinedDrive

Examples

  1. Concatenating two drives

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = dirname=os.path.join(os.path.dirname(__file__),
...                                'tests', 'test_sample')
>>> drive_0 = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive_1 = md.Drive(name='system_name', number=1, dirname=dirname)
>>> drive_0 << drive_1
CombinedDrive...
static __new__(cls, name, number, dirname='.', x=None, use_cache=False, **kwargs)#

Create a new OOMMFDrive or Mumax3Drive depending on the directory structure.

If a subdirectory <name>.out exists a Mumax3Drive is created else an OOMMFDrive.

ovf2vtk(dirname=None)#

OVF to VTK conversion.

This method iterates through all magnetisation fields in the drive and generates a VTK file for each of them.

Parameters:

dirname (pathlib.Path) – Directory in which files are saved.

Examples

  1. Iterating drive.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = dirname=os.path.join(os.path.dirname(__file__),
...                                'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive.ovf2vtk()
register_callback(callback)#

Register a callback to which a field is passed before being returned.

slider(description='step', **kwargs)#

Widget for selecting individual steps.

This method is based on ipywidgets.IntSlider, so any keyword argument accepted by it can be passed.

Parameters:

description (str, optional) – Widget description. Defaults to 'step'.

Returns:

Slider widget.

Return type:

ipywidgets.IntSlider

Examples

  1. Slider widget.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = dirname=os.path.join(os.path.dirname(__file__),
...                                'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive.slider()
IntSlider(...)
abstract property calculator_script#

MIF file. This property returns a string with the content of MIF file.

Returns:

MIF file content.

Return type:

str

Examples

  1. Getting MIF file.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = dirname=os.path.join(os.path.dirname(__file__),
...                                'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=6, dirname=dirname)
>>> drive.calculator_script
'# MIF 2...'
  1. Getting mx3 file

TODO add mumax3 output to the pre-computed data

property info#

Drive information.

This property returns a dictionary with information about the drive.

Returns:

Drive information.

Return type:

dict

Examples

  1. Getting information about drive.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = dirname=os.path.join(os.path.dirname(__file__),
...                                'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=6, dirname=dirname)
>>> drive.info
{...}
property table#

Table object.

This property returns an ubermagtable.Table object. As an independent variable x, the column chosen via x property is selected.

Returns:

Table object.

Return type:

ubermagtable.Table

Examples

  1. Getting table object.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = dirname=os.path.join(os.path.dirname(__file__),
...                                'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive.table  
E...
property use_cache#

Use caching for scalar data and the list of magnetisation files.

The existing cache is cleared when set to False.

Parameters:

use_cache (bool) – If True the Drive object will read tabular data and the names and number of magnetisation files only once. Note: this prevents Drive to detect new data when looking at the output of a running simulation. If set to False the data is read every time the user accesses it. Defaults to False.