micress-micpy 0.3.1b0__py3-none-any.whl → 0.3.1b2__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
@@ -394,7 +394,7 @@ class Series(np.ndarray):
394
394
  obj.times = [field.time for field in fields]
395
395
  obj.spacings = [field.spacing for field in fields]
396
396
  return obj
397
-
397
+
398
398
  def __array_finalize__(self, obj):
399
399
  if obj is None:
400
400
  return
@@ -403,34 +403,43 @@ class Series(np.ndarray):
403
403
  self.times = getattr(obj, "times", None)
404
404
  self.spacings = getattr(obj, "spacings", None)
405
405
 
406
- def __iter__(self):
406
+ def iter_field(self):
407
+ """Iterate over fields in the series.
408
+
409
+ Yields:
410
+ Field.
411
+ """
407
412
  for item, time, spacing in zip(self, self.times, self.spacings):
408
413
  yield Field(item, time, spacing)
409
414
 
410
- def get(self, index: Union[int, list, slice]) -> Field:
411
- """Get one or more fields from the series.
415
+ def get_field(self, index: int) -> Field:
416
+ """Get a field from the series.
412
417
 
413
418
  Args:
414
- index (Union[int, list, slice]): Index of the field.
419
+ index (int): Index of the field.
415
420
 
416
421
  Returns:
417
422
  Field.
418
423
  """
424
+ return Field(self[index], self.times[index], self.spacings[index])
419
425
 
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")
426
+ def get_series(self, key: Union[int, slice, list]) -> "Series":
427
+ """Get a series of fields.
433
428
 
429
+ Args:
430
+ key (Union[int, slice, list]): Key to list of field IDs, a slice object, or a
431
+ list of field IDs.
432
+
433
+ Returns:
434
+ Series of fields.
435
+ """
436
+ if isinstance(key, int):
437
+ return Series([self.get_field(key)])
438
+ if isinstance(key, slice):
439
+ return Series([self.get_field(i) for i in range(*key.indices(len(self)))])
440
+ if isinstance(key, list):
441
+ return Series([self.get_field(i) for i in key])
442
+ raise TypeError("Invalid argument type")
434
443
 
435
444
  def write(self, filename: str, compressed: bool = True, geometry: bool = True):
436
445
  """Write the series to a binary file.
@@ -445,7 +454,7 @@ class Series(np.ndarray):
445
454
 
446
455
  file_open = gzip.open if compressed else open
447
456
  with file_open(filename, "wb") as file:
448
- for field in self:
457
+ for field in self.iter_field():
449
458
  field.to_file(file, geometry)
450
459
  geometry = False
451
460
 
@@ -588,8 +597,8 @@ class File:
588
597
  """Set the geometry.
589
598
 
590
599
  Args:
591
- shape (Tuple[int, int, int]): Shape of the geometry.
592
- spacing (Tuple[float, float, float]): Spacing of the geometry in μm.
600
+ shape (Tuple[int, int, int]): Shape of the geometry (z, y, x).
601
+ spacing (Tuple[float, float, float]): Spacing of the geometry (dz, dy, dx) in μm.
593
602
  """
594
603
 
595
604
  self.shape = np.array(shape)
@@ -610,8 +619,8 @@ class File:
610
619
 
611
620
  geometry = geo.read(filename, type=geo.Type.BASIC, compressed=compressed)
612
621
 
613
- shape = geometry["shape"]
614
- spacing = geometry["spacing"]
622
+ shape = geometry["shape"][::-1]
623
+ spacing = geometry["spacing"][::-1]
615
624
 
616
625
  self.set_geometry(shape, spacing)
617
626
 
@@ -656,24 +665,34 @@ class File:
656
665
  for position in self.index():
657
666
  yield Field.read(position, shape=self.shape, spacing=self.spacing)
658
667
 
668
+ def read_field(self, field_id: int) -> Field:
669
+ """Read a field from the file.
670
+
671
+ Args:
672
+ field_id (int): Field ID.
673
+
674
+ Returns:
675
+ Field.
676
+ """
677
+ self.index()
678
+
679
+ position = self._index[field_id]
680
+ return Field.read(position, shape=self.shape, spacing=self.spacing)
681
+
659
682
  def read(
660
683
  self, key: Optional[Union[int, slice, list, Callable[[Field], bool]]] = None
661
684
  ) -> Series:
662
- """Read field data from the file.
685
+ """Read a series of fields from the file.
663
686
 
664
687
  Args:
665
- key (Union[int, slice, list, Callable[[Field], bool], optional): Key to
666
- list of field IDs, a slice object, or a condition function.
667
- Defaults to `None`.
688
+ key (Union[int, slice, list, Callable[[Field], bool]]): Key to list of
689
+ field IDs, a slice object, a list of field IDs, or a function that filters
690
+ fields. Defaults to `None`.
668
691
 
669
692
  Returns:
670
- A series of fields.
693
+ Series of fields.
671
694
  """
672
695
 
673
- def read_field(self, field_id: Union[int, slice, list]):
674
- position = self._index[field_id]
675
- return Field.read(position, shape=self.shape, spacing=self.spacing)
676
-
677
696
  def iterable(iterable):
678
697
  if self._verbose:
679
698
  return utils.progress_indicator(
@@ -686,17 +705,16 @@ class File:
686
705
  if key is None:
687
706
  fields = list(field for field in iterable(self.iterate()))
688
707
  elif isinstance(key, int):
689
- fields = [read_field(self, key)]
708
+ fields = [self.read_field(key)]
690
709
  elif isinstance(key, slice):
691
710
  indices = range(*key.indices(len(self._index)))
692
- fields = [read_field(self, i) for i in iterable(indices)]
711
+ fields = [self.read_field(i) for i in iterable(indices)]
693
712
  elif isinstance(key, list):
694
- fields = [read_field(self, i) for i in iterable(key)]
713
+ fields = [self.read_field(i) for i in iterable(key)]
695
714
  elif isinstance(key, Callable):
696
715
  fields = [field for field in iterable(self.iterate()) if key(field)]
697
716
  else:
698
717
  raise TypeError("Invalid argument type")
699
-
700
718
  return Series(fields)
701
719
 
702
720
 
@@ -755,7 +773,7 @@ def plot(
755
773
 
756
774
  if axis not in ["x", "y", "z"]:
757
775
  raise ValueError("Invalid axis")
758
-
776
+
759
777
  if field.ndim != 3:
760
778
  raise ValueError("Invalid field shape")
761
779
 
@@ -768,8 +786,6 @@ def plot(
768
786
  elif axis == "y":
769
787
  x, y = "x", "z"
770
788
  slice_2d = field[:, index, :]
771
- if Field.dimensions(field.shape) == 2:
772
- slice_2d = slice_2d.reshape(slice_2d.shape[1], slice_2d.shape[0])
773
789
  elif axis == "x":
774
790
  x, y = "y", "z"
775
791
  slice_2d = field[:, :, index]
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.1b0"
1
+ __version__ = "0.3.1b2"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: micress-micpy
3
- Version: 0.3.1b0
3
+ Version: 0.3.1b2
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=MbAzv-CXMUXZ8a8gynOQKCQIrOVrhuxL6fSl5wXcH0s,26117
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=mAuhwKKFzwoBU7u49qo92gTigQagh5Nq5rzbLuYGQbI,25
8
+ micress_micpy-0.3.1b2.dist-info/LICENSE,sha256=seHdCiArizUoWZ6bEFg6N3K2ZtfPK35wvOwg0kH-f6o,1488
9
+ micress_micpy-0.3.1b2.dist-info/METADATA,sha256=E4qysyzpM5PH13fhB2MnOQao1XNVOKDp8hCT7fJUah8,1229
10
+ micress_micpy-0.3.1b2.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
11
+ micress_micpy-0.3.1b2.dist-info/top_level.txt,sha256=RiopkpW0AGNYdtOW2eQUWgm3yHGC13q9pWlHb2alhiE,6
12
+ micress_micpy-0.3.1b2.dist-info/RECORD,,
@@ -1,12 +0,0 @@
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,,