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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions micromagneticdata/abstract_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def n(self):
def _step_files(self):
"""List of filenames of individual snapshots."""

@abc.abstractmethod
def __getitem__(self, item):
"""Magnetisation field of an individual step.

Expand All @@ -200,10 +201,6 @@ def __getitem__(self, item):
Field(...)

"""
field = df.Field.fromfile(filename=self._step_files[item])
with contextlib.suppress(FileNotFoundError):
field.mesh.load_subregions(self._m0_path)
return self._apply_callbacks(field)

def __iter__(self):
"""Iterator.
Expand Down
11 changes: 11 additions & 0 deletions micromagneticdata/combined_drive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import functools
import numbers
import operator

import ubermagutil as uu
Expand Down Expand Up @@ -140,6 +141,16 @@ def table(self):
def _step_files(self):
return sum((drive._step_files for drive in self.drives), start=[])

def __getitem__(self, item):
if not isinstance(item, numbers.Integral):
raise TypeError(f"{type(item)=} is not supported")
if item >= self.n or item < -self.n:
raise IndexError("List index out of range.")
for drive in self.drives:
if item < drive.n:
return self._apply_callbacks(drive[item])
item -= drive.n

def __lshift__(self, other):
if isinstance(other, md.Drive):
return self.__class__(*self.drives, other)
Expand Down
6 changes: 5 additions & 1 deletion micromagneticdata/drive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import abc
import contextlib
import copy
import json
import numbers
Expand Down Expand Up @@ -212,7 +213,10 @@ def __getitem__(self, item):

"""
if isinstance(item, numbers.Integral):
return super().__getitem__(item)
field = df.Field.fromfile(filename=self._step_files[item])
with contextlib.suppress(FileNotFoundError):
field.mesh.load_subregions(self._m0_path)
return self._apply_callbacks(field)
elif isinstance(item, slice):
step_files = self._step_files[item]
table = copy.copy(self.table)
Expand Down