AbstractDrive#

class micromagneticdata.AbstractDrive(callbacks=None)#

Drive class.

This class provides utility for the analysis of individual drives.

Parameters:

callbacks (list of callables, optional) – List of callback functions that are applied to individual fields of the drive when accessing them.


Methods

__dir__

Default dir() implementation.

__eq__

Return self==value.

__getitem__

Magnetisation field of an individual step.

__iter__

Iterator.

__lshift__

Concatenate multiple drives of the same type.

__repr__

Representation string.

register_callback

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

to_xarray

Export micromagneticdata.Drive as xarray.DataArray

Properties

callbacks

Return all registered callbacks.

hv

Plot interface, Holoviews/hvplot based.

info

Drive information.

m0

Inital magnetisation.

n

Number of steps.

table

Table object.

x

Independent variable name.


__getitem__(item)#

Magnetisation field of an individual step.

Returns:

Magnetisation field.

Return type:

discretisedfield.Field

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(...)
__iter__()#

Iterator.

This iterator iterates through all magnetisation field in drive and yields discretisedfield.Field objects.

Returns:

Magnetisation field.

Return type:

discretisedfield.Field

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)
>>> list(drive)
[...]
abstract __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...
abstract __repr__()#

Representation string.

abstract register_callback(callback)#

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

to_xarray(*args, **kwargs)#

Export micromagneticdata.Drive as xarray.DataArray

The method depends on discretisedfield.Field.to_xarray and derives the last four dimensions x, y, z, and comp in the output xarray.DataArray from it. The arguments and named arguments to this method are passed on to discretisedfield.Field.to_xarray.

Depending on type of driver, the dimensions and coordinates of the output may change. If the number of stored steps in the micromagneticdata.Drive are more than one, the output contains an extra dimension named after micromagneticdata.Drive.table.x with proper coordinate values. For the case of HysteresisDriver, the new dimension has four coordinates, namely B_hysteresis, Bx_hysteresis, By_hysteresis, and Bz_hysteresis. The first represents the norm of the hysteresis field, while the rest three represents the components along the respective axes. For a micromagneticdata.Drive with a single discretisedfield.Field, the value of the single discretisedfield.Field.to_xarray is returned.

micromagneticdata.Drive.info is returned as the output xarray.DataArray attributes, besides the ones derived from discretisedfield.Field.to_xarray.

Parameters:
  • args (any) – Arguments to discretisedfield.Field.to_xarray

  • kwargs (any) – Named arguments to discretisedfield.Field.to_xarray

Returns:

micromagneticdata.Drive as xarray.DataArray

Return type:

xarray.DataArray

Examples

  1. Drive to DataArray

>>> 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)
>>> xr_drive = drive.to_xarray(name='Mag')
>>> xr_drive
<xarray.DataArray 'Mag' (t: 25, x: 20, y: 10, z: 4, vdims: 3)>
...
  1. Magnetization in a cell over time for TimeDriver

>>> xr_drive.isel(x=2, y=2, z=2)
<xarray.DataArray 'Mag' (t: 25, vdims: 3)>
...
property callbacks#

Return all registered callbacks.

property hv#

Plot interface, Holoviews/hvplot based.

This property provides access to the different plotting methods. It is also callable to quickly generate plots. It is based on discretisedfield.plotting.Hv. For more details and the available methods refer to the documentation linked below.

Examples

  1. Visualising a drive using hv.

>>> 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.hv(kdims=['x', 'y'])
:DynamicMap...
abstract property info#

Drive information.

property m0#

Inital magnetisation.

This property returns a discretisedfield.Field object for the initial magnetisation field.

Returns:

Initial magnetisation field.

Return type:

discretisedfield.Field

Examples

  1. Getting initial magnetisation field.

>>> 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.m0
Field(...)
property n#

Number of steps.

This property returns the number of rows in the drive table.

Returns:

Number of steps.

Return type:

int

Examples

  1. Getting the number of steps.

>>> 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.n
25
abstract 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...
abstract property x#

Independent variable name.

Parameters:

value (str) – Independent variable name.

Returns:

Representation string.

Return type:

str

Raises:

ValueError – If the column name does not exist in table.

Examples

  1. Getting and setting independent variable name.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = dirname=os.path.join(os.path.dirname(__file__),
...                                'tests', 'test_sample')
>>> drive = md.Data(name='hysteresis', dirname=dirname)[0]
>>> drive.x
'B_hysteresis'
>>> drive.x = 'Bx_hysteresis'