Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
950 changes: 443 additions & 507 deletions docs/documentation.ipynb

Large diffs are not rendered by default.

1,141 changes: 419 additions & 722 deletions docs/interactive_plotting.ipynb

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions micromagneticdata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from .combined_drive import CombinedDrive as CombinedDrive
from .data import Data as Data
from .drive import Drive as Drive
from .mumax3drive import Mumax3Drive as Mumax3Drive
from .oommfdrive import OOMMFDrive as OOMMFDrive

__version__ = importlib.metadata.version(__package__)

Expand Down
67 changes: 22 additions & 45 deletions micromagneticdata/abstract_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ class AbstractDrive(abc.ABC):
def __init__(self, callbacks=None):
self._callbacks = callbacks or []

@abc.abstractmethod
def __repr__(self):
"""Representation string."""
pass # pragma: no cover

@property
def x(self):
"""Independent variable name.
Expand All @@ -57,14 +52,12 @@ def x(self):
--------
1. Getting and setting independent variable name.

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

"""
return self._x
Expand Down Expand Up @@ -96,11 +89,9 @@ def m0(self):
--------
1. Getting initial magnetisation field.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> from micromagneticdata import sample_data
>>> drive = md.Drive(name='rectangle', number=0, dirname=sample_data.dirname)
>>> drive.m0
Field(...)

Expand Down Expand Up @@ -133,11 +124,9 @@ def table(self):
--------
1. Getting table object.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> from micromagneticdata import sample_data
>>> drive = md.Drive(name='rectangle', number=0, dirname=sample_data.dirname)
>>> drive.table # doctest: +SKIP
E...

Expand All @@ -159,11 +148,9 @@ def n(self):
--------
1. Getting the number of steps.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> from micromagneticdata import sample_data
>>> drive = md.Drive(name='rectangle', number=0, dirname=sample_data.dirname)
>>> drive.n
25

Expand All @@ -188,11 +175,9 @@ def __getitem__(self, item):
--------
1. Getting the field of a particular step.

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

Expand Down Expand Up @@ -224,11 +209,9 @@ def __iter__(self):
--------
1. Iterating drive.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> from micromagneticdata import sample_data
>>> drive = md.Drive(name='rectangle', number=0, dirname=sample_data.dirname)
>>> list(drive)
[...]

Expand Down Expand Up @@ -277,12 +260,10 @@ def __lshift__(self, other):
--------
1. Concatenating two drives

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive_0 = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> drive_1 = md.Drive(name='rectangle', number=1, dirname=dirname)
>>> from micromagneticdata import sample_data
>>> drive_0 = md.Drive(name='rectangle', number=0, dirname=sample_data.dirname)
>>> drive_1 = md.Drive(name='rectangle', number=1, dirname=sample_data.dirname)
>>> drive_0 << drive_1
CombinedDrive...

Expand Down Expand Up @@ -330,11 +311,9 @@ def to_xarray(self, *args, **kwargs):
--------
1. Drive to DataArray

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> from micromagneticdata import sample_data
>>> drive = md.Drive(name='rectangle', number=0, dirname=sample_data.dirname)
>>> xr_drive = drive.to_xarray(name='Mag')
>>> xr_drive
<xarray.DataArray 'Mag' (t: 25, x: 20, y: 10, z: 4, vdims: 3)>...
Expand Down Expand Up @@ -407,11 +386,9 @@ def hv(self):

1. Visualising a drive using ``hv``.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> from micromagneticdata import sample_data
>>> drive = md.Drive(name='rectangle', number=0, dirname=sample_data.dirname)
>>> drive.hv(kdims=['x', 'y'])
:DynamicMap...

Expand Down
31 changes: 9 additions & 22 deletions micromagneticdata/combined_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ class CombinedDrive(md.AbstractDrive):

If the passed objects are not of type ``micromagneticdata.Drive``.

Examples
--------
1. Getting drive object.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)

"""

def __init__(self, *drives, **kwargs):
Expand Down Expand Up @@ -86,14 +76,12 @@ def __repr__(self):
--------
1. Representation string.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> drive
OOMMFDrive(...)

>>> from micromagneticdata import sample_data
>>> data = md.Data(name='rectangle', dirname=sample_data.dirname)
>>> combined = data[0] << data[1]
>>> combined
CombinedDrive(...)
"""
drives = ",\n".join(f" {drive!r}" for drive in self.drives)
return f"{self.__class__.__name__}(\n{drives}\n)"
Expand All @@ -114,12 +102,11 @@ def info(self):
--------
1. Getting information about drive.

>>> import os
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='rectangle', number=6, dirname=dirname)
>>> drive.info
>>> from micromagneticdata import sample_data
>>> data = md.Data(name='rectangle', dirname=sample_data.dirname)
>>> combined = data[0] << data[1]
>>> combined.info
{...}

"""
Expand Down
59 changes: 25 additions & 34 deletions micromagneticdata/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,13 @@ class Data:
--------
1. Creating data object using `path`

>>> from pathlib import Path
>>> import micromagneticdata as mdata
>>> path = Path(__file__).parent / 'tests' / 'test_sample' / 'rectangle'
>>> data = mdata.Data(path=path)
>>> from micromagneticdata import sample_data
>>> data = mdata.Data(path=sample_data.dirname / "rectangle")

2. Creating data object using `name` and `dirname`

>>> import os
>>> import micromagneticdata as mdata
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> data = mdata.Data(name='rectangle', dirname=dirname)
>>> data = mdata.Data(name='rectangle', dirname=sample_data.dirname)

"""

Expand Down Expand Up @@ -100,10 +96,9 @@ def __repr__(self):
--------
1. Representation string.

>>> from pathlib import Path
>>> import micromagneticdata as mdata
>>> path = Path(__file__).parent / 'tests' / 'test_sample' / 'rectangle'
>>> data = mdata.Data(path=path)
>>> from micromagneticdata import sample_data
>>> data = mdata.Data(path=sample_data.dirname / "rectangle")
>>> data
Data(path='...rectangle')

Expand All @@ -128,10 +123,9 @@ def info(self):
--------
1. Getting information about data.

>>> from pathlib import Path
>>> import micromagneticdata as mdata
>>> path = Path(__file__).parent / 'tests' / 'test_sample' / 'rectangle'
>>> data = mdata.Data(path=path)
>>> from micromagneticdata import sample_data
>>> data = mdata.Data(path=sample_data.dirname / "rectangle")
>>> data.info
drive_number...
"""
Expand All @@ -143,6 +137,9 @@ def info(self):
drive_info = json.load(f)
drive_info["info.json"] = "available"
records.append(drive_info)
except RuntimeError as e:
print(f"Warning: Missing adapter package: {e}")
records.append({"drive_number": i, "info.json": "missing"})
except FileNotFoundError:
print(f"Warning: Missing info.json for drive-{i}")
records.append({"drive_number": i, "info.json": "missing"})
Expand Down Expand Up @@ -170,12 +167,11 @@ def n(self):
--------
1. Getting the number of drives.

>>> from pathlib import Path
>>> import micromagneticdata as mdata
>>> path = Path(__file__).parent / 'tests' / 'test_sample' / 'rectangle'
>>> data = mdata.Data(path=path)
>>> from micromagneticdata import sample_data
>>> data = mdata.Data(path=sample_data.dirname / "rectangle")
>>> data.n
7
2

"""
return len(list(glob.iglob(os.path.join(self.path, "drive-*"))))
Expand All @@ -202,17 +198,14 @@ def __getitem__(self, item):
--------
1. Getting drive.

>>> from pathlib import Path
>>> import micromagneticdata as mdata
>>> path = Path(__file__).parent / 'tests' / 'test_sample' / 'rectangle'
>>> data = mdata.Data(path=path)
>>> from micromagneticdata import sample_data
>>> data = mdata.Data(path=sample_data.dirname / "rectangle")
>>> data.n
7
>>> data[0] # first (0th) drive
2
>>> data[0] # first drive
OOMMFDrive(...)
>>> data[1] # second (1th) drive
Mumax3Drive(...)
>>> data[-1] # last (6th) drive
>>> data[-1] # last drive
OOMMFDrive(...)

"""
Expand All @@ -238,14 +231,13 @@ def __iter__(self):

1. Iterating data object.

>>> from pathlib import Path
>>> import micromagneticdata as mdata
>>> path = Path(__file__).parent / 'tests' / 'test_sample' / 'rectangle'
>>> data = mdata.Data(path=path)
>>> from micromagneticdata import sample_data
>>> data = mdata.Data(path=sample_data.dirname / "rectangle")
>>> data.n
7
2
>>> len(list(data))
7
2

"""
for i in range(self.n):
Expand Down Expand Up @@ -273,12 +265,11 @@ def selector(self, description="drive", **kwargs):
--------
1. Selection widget.

>>> from pathlib import Path
>>> import micromagneticdata as mdata
>>> path = Path(__file__).parent / 'tests' / 'test_sample' / 'rectangle'
>>> data = mdata.Data(path=path)
>>> from micromagneticdata import sample_data
>>> data = mdata.Data(path=sample_data.dirname / "rectangle")
>>> data.selector()
BoundedIntText(value=0, description='drive', max=6)
BoundedIntText(value=0, description='drive', max=1)

"""
return ipywidgets.BoundedIntText(
Expand Down
Loading
Loading