micress-micpy 0.3.0b0__py3-none-any.whl → 0.3.1b1__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,48 @@ 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]
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
396
397
 
397
- def __array__(self):
398
- return self.stack
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)
423
-
424
- def __dir__(self) -> List[str]:
425
- return list(set(dir(type(self)) + dir(self.stack)))
413
+ Args:
414
+ index (Union[int, list, slice]): Index of the field.
426
415
 
427
- def __repr__(self):
428
- return repr(self.stack)
416
+ Returns:
417
+ Field.
418
+ """
429
419
 
430
- def __str__(self):
431
- return str(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")
432
433
 
433
434
  def write(self, filename: str, compressed: bool = True, geometry: bool = True):
434
435
  """Write the series to a binary file.
@@ -586,8 +587,8 @@ class File:
586
587
  """Set the geometry.
587
588
 
588
589
  Args:
589
- shape (Tuple[int, int, int]): Shape of the geometry.
590
- spacing (Tuple[float, float, float]): Spacing of the geometry in μm³.
590
+ shape (Tuple[int, int, int]): Shape of the geometry (z, y, x).
591
+ spacing (Tuple[float, float, float]): Spacing of the geometry (dz, dy, dx) in μm.
591
592
  """
592
593
 
593
594
  self.shape = np.array(shape)
@@ -608,8 +609,8 @@ class File:
608
609
 
609
610
  geometry = geo.read(filename, type=geo.Type.BASIC, compressed=compressed)
610
611
 
611
- shape = geometry["shape"]
612
- spacing = geometry["spacing"]
612
+ shape = geometry["shape"][::-1]
613
+ spacing = geometry["spacing"][::-1]
613
614
 
614
615
  self.set_geometry(shape, spacing)
615
616
 
@@ -641,9 +642,9 @@ class File:
641
642
  size = cells * spacing
642
643
 
643
644
  self._info(f"Geometry: {dimensions}-Dimensional Grid")
644
- self._info(f"Grid Size: {tuple(size)}μm³")
645
+ self._info(f"Grid Size [μm]: {tuple(size)}")
645
646
  self._info(f"Grid Shape (Cell Count): {tuple(cells)}")
646
- self._info(f"Grid Spacing (Cell Size): {tuple(spacing)}μm³")
647
+ self._info(f"Grid Spacing (Cell Size) [μm]: {tuple(spacing)}")
647
648
 
648
649
  def iterate(self) -> Generator[Field, None, None]:
649
650
  """Iterate over fields in the file.
@@ -713,7 +714,7 @@ class PlotArgs:
713
714
  cax (matplotlib.Axes, optional): Axes of the color bar. Defaults to `None`.
714
715
  vmin (float, optional): Minimum value of the color bar. Defaults to `None`.
715
716
  vmax (float, optional): Maximum value of the color bar. Defaults to `None`.
716
- cmap (str, optional): Colormap. Defaults to `
717
+ cmap (str, optional): Colormap. Defaults to `micpy`.
717
718
  """
718
719
 
719
720
  title: Optional[str] = None
@@ -754,6 +755,9 @@ def plot(
754
755
  if axis not in ["x", "y", "z"]:
755
756
  raise ValueError("Invalid axis")
756
757
 
758
+ if field.ndim != 3:
759
+ raise ValueError("Invalid field shape")
760
+
757
761
  if args is None:
758
762
  args = PlotArgs()
759
763
 
@@ -763,8 +767,6 @@ def plot(
763
767
  elif axis == "y":
764
768
  x, y = "x", "z"
765
769
  slice_2d = field[:, index, :]
766
- if Field.dimensions(field.shape) == 2:
767
- slice_2d = slice_2d.reshape(slice_2d.shape[1], slice_2d.shape[0])
768
770
  elif axis == "x":
769
771
  x, y = "y", "z"
770
772
  slice_2d = field[:, :, index]
@@ -778,7 +780,8 @@ def plot(
778
780
  if args.title is not None:
779
781
  ax.set_title(args.title)
780
782
  else:
781
- ax.set_title(f"t={np.round(field.time, 7)}s")
783
+ if isinstance(field, Field):
784
+ ax.set_title(f"t={np.round(field.time, 7)}s")
782
785
  if args.xlabel is not None:
783
786
  ax.set_xlabel(args.xlabel)
784
787
  else:
micpy/geo.py CHANGED
@@ -165,8 +165,8 @@ def build(
165
165
 
166
166
  Args:
167
167
  filename (str): Filename of a binary file.
168
- shape (tuple): Shape of the geometry.
169
- spacing (tuple): Spacing of the geometry.
168
+ shape (tuple): Shape of the geometry (z, y, x).
169
+ spacing (tuple): Spacing of the geometry (dz, dy, dx) in μm.
170
170
  """
171
171
  geo_filename = _get_basename(Path(filename)).with_suffix(".geoF")
172
172
  geo_data = {
micpy/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.3.0b0"
1
+ __version__ = "0.3.1b1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: micress-micpy
3
- Version: 0.3.0b0
3
+ Version: 0.3.1b1
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=LQiaAxLCyBw_7kfimFbZtqqMoP3iAYFVKDc4Ohvyxm8,25729
3
+ micpy/geo.py,sha256=z7dP3hC2Fhed4N5eRrlWlC4jtIXiYPIx2BYNhn10dfw,7447
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=zKEPT4cdwsCB_uCEMo5TXBcz3hseWXYp71mYqedQBds,25
8
+ micress_micpy-0.3.1b1.dist-info/LICENSE,sha256=seHdCiArizUoWZ6bEFg6N3K2ZtfPK35wvOwg0kH-f6o,1488
9
+ micress_micpy-0.3.1b1.dist-info/METADATA,sha256=5oK-n39nupCZmnR1PNSesTpWkYhTFREiJFGAuY_mZ7g,1229
10
+ micress_micpy-0.3.1b1.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
11
+ micress_micpy-0.3.1b1.dist-info/top_level.txt,sha256=RiopkpW0AGNYdtOW2eQUWgm3yHGC13q9pWlHb2alhiE,6
12
+ micress_micpy-0.3.1b1.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,,