micress-micpy 0.3.0b0__py3-none-any.whl → 0.3.1b0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
micpy/bin.py CHANGED
@@ -388,47 +388,49 @@ class Field(np.ndarray):
388
388
  self.to_file(file, geometry)
389
389
 
390
390
 
391
- class Series:
392
- def __init__(self, fields: List[Field]):
393
- self.stack = np.stack(fields)
394
- self.times = [field.time for field in fields]
395
- self.spacings = [field.spacing for field in fields]
396
-
397
- def __array__(self):
398
- return self.stack
391
+ class Series(np.ndarray):
392
+ def __new__(cls, fields: List[Field]):
393
+ obj = np.asarray(fields).view(cls)
394
+ obj.times = [field.time for field in fields]
395
+ obj.spacings = [field.spacing for field in fields]
396
+ return obj
397
+
398
+ def __array_finalize__(self, obj):
399
+ if obj is None:
400
+ return
399
401
 
400
- def __len__(self):
401
- return len(self.stack)
402
+ # pylint: disable=attribute-defined-outside-init
403
+ self.times = getattr(obj, "times", None)
404
+ self.spacings = getattr(obj, "spacings", None)
402
405
 
403
406
  def __iter__(self):
404
- for item, time, spacing in zip(self.stack, self.times, self.spacings):
407
+ for item, time, spacing in zip(self, self.times, self.spacings):
405
408
  yield Field(item, time, spacing)
406
409
 
407
- def __getitem__(self, index):
408
- if isinstance(index, int):
409
- return Field(self.stack[index], self.times[index], self.spacings[index])
410
- elif isinstance(index, slice):
411
- return Series(
412
- [
413
- Field(item, time, spacing)
414
- for item, time, spacing in zip(
415
- self.stack[index], self.times[index], self.spacings[index]
416
- )
417
- ]
418
- )
419
- raise TypeError("Invalid argument type")
410
+ def get(self, index: Union[int, list, slice]) -> Field:
411
+ """Get one or more fields from the series.
420
412
 
421
- def __getattr__(self, name):
422
- return getattr(self.stack, name)
413
+ Args:
414
+ index (Union[int, list, slice]): Index of the field.
423
415
 
424
- def __dir__(self) -> List[str]:
425
- return list(set(dir(type(self)) + dir(self.stack)))
416
+ Returns:
417
+ Field.
418
+ """
426
419
 
427
- def __repr__(self):
428
- return repr(self.stack)
420
+ if isinstance(index, int):
421
+ return Field(self[index], self.times[index], self.spacings[index])
422
+ elif isinstance(index, slice):
423
+ series = self[index]
424
+ series.times = self.times[index]
425
+ series.spacings = self.spacings[index]
426
+ return series
427
+ elif isinstance(index, list):
428
+ series = self[index]
429
+ series.times = [self.times[i] for i in index]
430
+ series.spacings = [self.spacings[i] for i in index]
431
+ return series
432
+ raise TypeError("Invalid argument type")
429
433
 
430
- def __str__(self):
431
- return str(self.stack)
432
434
 
433
435
  def write(self, filename: str, compressed: bool = True, geometry: bool = True):
434
436
  """Write the series to a binary file.
@@ -587,7 +589,7 @@ class File:
587
589
 
588
590
  Args:
589
591
  shape (Tuple[int, int, int]): Shape of the geometry.
590
- spacing (Tuple[float, float, float]): Spacing of the geometry in μm³.
592
+ spacing (Tuple[float, float, float]): Spacing of the geometry in μm.
591
593
  """
592
594
 
593
595
  self.shape = np.array(shape)
@@ -641,9 +643,9 @@ class File:
641
643
  size = cells * spacing
642
644
 
643
645
  self._info(f"Geometry: {dimensions}-Dimensional Grid")
644
- self._info(f"Grid Size: {tuple(size)}μm³")
646
+ self._info(f"Grid Size [μm]: {tuple(size)}")
645
647
  self._info(f"Grid Shape (Cell Count): {tuple(cells)}")
646
- self._info(f"Grid Spacing (Cell Size): {tuple(spacing)}μm³")
648
+ self._info(f"Grid Spacing (Cell Size) [μm]: {tuple(spacing)}")
647
649
 
648
650
  def iterate(self) -> Generator[Field, None, None]:
649
651
  """Iterate over fields in the file.
@@ -713,7 +715,7 @@ class PlotArgs:
713
715
  cax (matplotlib.Axes, optional): Axes of the color bar. Defaults to `None`.
714
716
  vmin (float, optional): Minimum value of the color bar. Defaults to `None`.
715
717
  vmax (float, optional): Maximum value of the color bar. Defaults to `None`.
716
- cmap (str, optional): Colormap. Defaults to `
718
+ cmap (str, optional): Colormap. Defaults to `micpy`.
717
719
  """
718
720
 
719
721
  title: Optional[str] = None
@@ -753,6 +755,9 @@ def plot(
753
755
 
754
756
  if axis not in ["x", "y", "z"]:
755
757
  raise ValueError("Invalid axis")
758
+
759
+ if field.ndim != 3:
760
+ raise ValueError("Invalid field shape")
756
761
 
757
762
  if args is None:
758
763
  args = PlotArgs()
@@ -778,7 +783,8 @@ def plot(
778
783
  if args.title is not None:
779
784
  ax.set_title(args.title)
780
785
  else:
781
- ax.set_title(f"t={np.round(field.time, 7)}s")
786
+ if isinstance(field, Field):
787
+ ax.set_title(f"t={np.round(field.time, 7)}s")
782
788
  if args.xlabel is not None:
783
789
  ax.set_xlabel(args.xlabel)
784
790
  else:
micpy/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.3.0b0"
1
+ __version__ = "0.3.1b0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: micress-micpy
3
- Version: 0.3.0b0
3
+ Version: 0.3.1b0
4
4
  Summary: MicPy is a Python package to facilitate MICRESS workflows.
5
5
  Author: Lukas Koschmieder
6
6
  Author-email: l.koschmieder@access-technology.de
@@ -0,0 +1,12 @@
1
+ micpy/__init__.py,sha256=7wQUaseppjQYZW1iAVNm2WSDjvBLlqtY8tiHsfDaW5Q,148
2
+ micpy/bin.py,sha256=3xclBJLbbBW9N8w9izFEgFh3S2yKgYzrdQKjJsXftSU,25831
3
+ micpy/geo.py,sha256=lVRTtPnTEykkSXNyLm3wnxXOwz72PFu0Spv8ZGHyUHo,7417
4
+ micpy/matplotlib.py,sha256=GF2ghyBORC5RRjW00DdsHu5aSkpMFdI9wqg6d_psPsI,1198
5
+ micpy/tab.py,sha256=QCnfggxRWkKgS9-zGj8kyCjhfUw7QeTgGZWedHh4MTw,3548
6
+ micpy/utils.py,sha256=Kt1AvhMvWer9uftbb88X7N27aXtQdJl26grHmmm2vOQ,859
7
+ micpy/version.py,sha256=o80l_DIF5j_g0KFIiC8SP5DtyipTIK4_NRfkjHjz1Mk,25
8
+ micress_micpy-0.3.1b0.dist-info/LICENSE,sha256=seHdCiArizUoWZ6bEFg6N3K2ZtfPK35wvOwg0kH-f6o,1488
9
+ micress_micpy-0.3.1b0.dist-info/METADATA,sha256=UFUfB1rNxBQxj1OlMO9Qo3YX92weqibYc59tujF8lBo,1229
10
+ micress_micpy-0.3.1b0.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
11
+ micress_micpy-0.3.1b0.dist-info/top_level.txt,sha256=RiopkpW0AGNYdtOW2eQUWgm3yHGC13q9pWlHb2alhiE,6
12
+ micress_micpy-0.3.1b0.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- micpy/__init__.py,sha256=7wQUaseppjQYZW1iAVNm2WSDjvBLlqtY8tiHsfDaW5Q,148
2
- micpy/bin.py,sha256=6CiN1KUrIVDn5pXtf05n-A7D7yOFAUXAbfBUeXpgcGs,25521
3
- micpy/geo.py,sha256=lVRTtPnTEykkSXNyLm3wnxXOwz72PFu0Spv8ZGHyUHo,7417
4
- micpy/matplotlib.py,sha256=GF2ghyBORC5RRjW00DdsHu5aSkpMFdI9wqg6d_psPsI,1198
5
- micpy/tab.py,sha256=QCnfggxRWkKgS9-zGj8kyCjhfUw7QeTgGZWedHh4MTw,3548
6
- micpy/utils.py,sha256=Kt1AvhMvWer9uftbb88X7N27aXtQdJl26grHmmm2vOQ,859
7
- micpy/version.py,sha256=v6LLclreYkCiqxCP6QRdhtVAzCVndQ77c0lTMqPZjXk,25
8
- micress_micpy-0.3.0b0.dist-info/LICENSE,sha256=seHdCiArizUoWZ6bEFg6N3K2ZtfPK35wvOwg0kH-f6o,1488
9
- micress_micpy-0.3.0b0.dist-info/METADATA,sha256=RbN1IrUFx14nsUJB2fIeLxrxFD49sF1sujNg1vBmlpA,1229
10
- micress_micpy-0.3.0b0.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
11
- micress_micpy-0.3.0b0.dist-info/top_level.txt,sha256=RiopkpW0AGNYdtOW2eQUWgm3yHGC13q9pWlHb2alhiE,6
12
- micress_micpy-0.3.0b0.dist-info/RECORD,,