Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pre-commits and pytest configuration #66

Merged
merged 13 commits into from
Jun 11, 2024
Merged
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
  •  
  •  
  •  
36 changes: 11 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
default_language_version:
python: python3.8
exclude: 'dev'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-merge-conflict # checks for files that contain merge conflict strings
- id: check-toml # checks toml files for parseable syntax
- id: debug-statements # checks for debugger imports and py37+ `breakpoint()` calls in python source
# - id: trailing-whitespace # needs more checks
# args: [--markdown-linebreak-ext=md]
# exclude: 'micromagneticdata/tests/test_sample/.*'

- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: isort

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
hooks:
- id: nbqa-isort # isort inside Jupyter notebooks

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies: [flake8-rst-docstrings] #, flake8-docstrings]

- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black-jupyter
# Run the linter.
- id: ruff
types_or: [python, pyi, jupyter]
args: [--fix, --exit-non-zero-on-fix]
# Run the formatter.
- id: ruff-format
types_or: [python, pyi, jupyter]

# - repo: https://github.com/codespell-project/codespell
# rev: v2.1.0
Expand Down
292 changes: 152 additions & 140 deletions docs/documentation.ipynb

Large diffs are not rendered by default.

1,693 changes: 255 additions & 1,438 deletions docs/interactive_plotting.ipynb

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions micromagneticdata/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""Analyse micromagnetic data."""

import importlib.metadata

import pytest

from .abstract_drive import AbstractDrive
from .combined_drive import CombinedDrive
from .data import Data
from .drive import Drive
from .mumax3drive import Mumax3Drive
from .oommfdrive import OOMMFDrive
from .abstract_drive import AbstractDrive as AbstractDrive
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
18 changes: 9 additions & 9 deletions micromagneticdata/abstract_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def m0(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> drive.m0
Field(...)

Expand Down Expand Up @@ -137,7 +137,7 @@ def table(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> drive.table # doctest: +SKIP
E...

Expand All @@ -163,7 +163,7 @@ def n(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> drive.n
25

Expand Down Expand Up @@ -192,7 +192,7 @@ def __getitem__(self, item):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> drive[5]
Field(...)

Expand Down Expand Up @@ -228,7 +228,7 @@ def __iter__(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> list(drive)
[...]

Expand Down Expand Up @@ -281,8 +281,8 @@ def __lshift__(self, other):
>>> import micromagneticdata as md
...
>>> 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 = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> drive_1 = md.Drive(name='rectangle', number=1, dirname=dirname)
>>> drive_0 << drive_1
CombinedDrive...

Expand Down Expand Up @@ -334,7 +334,7 @@ def to_xarray(self, *args, **kwargs):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', 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)>...
Expand Down Expand Up @@ -411,7 +411,7 @@ def hv(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> drive.hv(kdims=['x', 'y'])
:DynamicMap...

Expand Down
7 changes: 3 additions & 4 deletions micromagneticdata/combined_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import ubermagutil as uu

import micromagneticdata as md

from .abstract_drive import AbstractDrive


Expand Down Expand Up @@ -41,7 +40,7 @@ class CombinedDrive(md.AbstractDrive):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)

"""

Expand Down Expand Up @@ -91,7 +90,7 @@ def __repr__(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> drive
OOMMFDrive(...)

Expand Down Expand Up @@ -119,7 +118,7 @@ def info(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=6, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=6, dirname=dirname)
>>> drive.info
{...}

Expand Down
16 changes: 8 additions & 8 deletions micromagneticdata/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Data:
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> data = md.Data(name='system_name', dirname=dirname)
>>> data = md.Data(name='rectangle', dirname=dirname)

"""

Expand All @@ -50,7 +50,7 @@ def __init__(self, name, dirname="./"):

if not os.path.exists(self.path):
msg = f"Directory {self.path=} cannot be found."
raise IOError(msg)
raise OSError(msg)

def __repr__(self):
"""Representation string.
Expand All @@ -69,7 +69,7 @@ def __repr__(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> data = md.Data(name='system_name', dirname=dirname)
>>> data = md.Data(name='rectangle', dirname=dirname)
>>> data
Data(...)

Expand Down Expand Up @@ -98,7 +98,7 @@ def info(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> data = md.Data(name='system_name', dirname=dirname)
>>> data = md.Data(name='rectangle', dirname=dirname)
>>> data.info
drive_number...
"""
Expand All @@ -122,7 +122,7 @@ def n(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> data = md.Data(name='system_name', dirname=dirname)
>>> data = md.Data(name='rectangle', dirname=dirname)
>>> data.n
7

Expand Down Expand Up @@ -155,7 +155,7 @@ def __getitem__(self, item):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> data = md.Data(name='system_name', dirname=dirname)
>>> data = md.Data(name='rectangle', dirname=dirname)
>>> data.n
7
>>> data[0] # first (0th) drive
Expand Down Expand Up @@ -191,7 +191,7 @@ def __iter__(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> data = md.Data(name='system_name', dirname=dirname)
>>> data = md.Data(name='rectangle', dirname=dirname)
>>> data.n
7
>>> len(list(data))
Expand Down Expand Up @@ -227,7 +227,7 @@ def selector(self, description="drive", **kwargs):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> data = md.Data(name='system_name', dirname=dirname)
>>> data = md.Data(name='rectangle', dirname=dirname)
>>> data.selector()
BoundedIntText(...)

Expand Down
18 changes: 9 additions & 9 deletions micromagneticdata/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ class Drive(md.AbstractDrive):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Data(name='system_name', dirname=dirname)[0]
>>> drive = md.Data(name='rectangle', dirname=dirname)[0]
>>> drive
OOMMFDrive(...)

2. Getting drive objet directly.

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

Expand All @@ -97,7 +97,7 @@ def __init__(self, name, number, dirname="./", x=None, use_cache=False, **kwargs
self.drive_path = pathlib.Path(f"{dirname}/{name}/drive-{number}")
if not self.drive_path.exists():
msg = f"Directory {self.drive_path!r} does not exist."
raise IOError(msg)
raise OSError(msg)

self.use_cache = use_cache
self.name = name
Expand Down Expand Up @@ -191,7 +191,7 @@ def __getitem__(self, item):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> drive[5]
Field(...)

Expand All @@ -200,7 +200,7 @@ def __getitem__(self, item):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> selection = drive[:8:2]
>>> selection
OOMMFDrive(...)
Expand Down Expand Up @@ -247,7 +247,7 @@ def info(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=6, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=6, dirname=dirname)
>>> drive.info
{...}

Expand All @@ -274,7 +274,7 @@ def calculator_script(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=6, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=6, dirname=dirname)
>>> drive.calculator_script
'# MIF 2...'

Expand Down Expand Up @@ -304,7 +304,7 @@ def ovf2vtk(self, dirname=None):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> drive.ovf2vtk()

"""
Expand Down Expand Up @@ -339,7 +339,7 @@ def slider(self, description="step", **kwargs):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> drive.slider()
IntSlider(...)

Expand Down
9 changes: 4 additions & 5 deletions micromagneticdata/mumax3drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import ubermagutil as uu

import micromagneticdata as md

from .abstract_drive import AbstractDrive


Expand Down Expand Up @@ -55,7 +54,7 @@ class Mumax3Drive(md.Drive):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=1, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=1, dirname=dirname)
>>> drive
Mumax3Drive(...)

Expand All @@ -66,7 +65,7 @@ def __init__(self, name, number, dirname="./", x=None, use_cache=False, **kwargs
f"{dirname}/{name}/drive-{number}/{name}.out"
) # required to initialise self.x in super
if not self._mumax_output_path.exists():
raise IOError(
raise OSError(
f"Output directory {self._mumax_output_path!r} does not exist."
)

Expand Down Expand Up @@ -117,9 +116,9 @@ def __repr__(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=1, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=1, dirname=dirname)
>>> drive
Mumax3Drive(name='system_name', number=1, dirname='...test_sample', x='t')
Mumax3Drive(name='rectangle', number=1, dirname='...test_sample', x='t')

"""
return (
Expand Down
7 changes: 3 additions & 4 deletions micromagneticdata/oommfdrive.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ubermagutil as uu

import micromagneticdata as md

from .abstract_drive import AbstractDrive


Expand Down Expand Up @@ -53,7 +52,7 @@ class OOMMFDrive(md.Drive):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)

"""

Expand Down Expand Up @@ -109,9 +108,9 @@ def __repr__(self):
>>> import micromagneticdata as md
...
>>> dirname = os.path.join(os.path.dirname(__file__), 'tests', 'test_sample')
>>> drive = md.Drive(name='system_name', number=0, dirname=dirname)
>>> drive = md.Drive(name='rectangle', number=0, dirname=dirname)
>>> drive
OOMMFDrive(name='system_name', number=0, dirname='...test_sample', x='t')
OOMMFDrive(name='rectangle', number=0, dirname='...test_sample', x='t')

"""
return (
Expand Down
Loading
Loading