micress-micpy 0.2.15b0__py3-none-any.whl → 0.2.17b0__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
@@ -1,4 +1,4 @@
1
- """This module provides methods to read and write binary files."""
1
+ """The `micpy.bin` module provides methods to read and write binary files."""
2
2
 
3
3
  from dataclasses import dataclass
4
4
  from typing import Callable, IO, List, Tuple, Generator
@@ -420,26 +420,27 @@ class Field(np.ndarray):
420
420
  vmin: float = None,
421
421
  vmax: float = None,
422
422
  cmap: str = "micpy",
423
- ):
423
+ ) -> Tuple["matplotlib.Figure", "matplotlib.Axes"]:
424
424
  """Plot a slice of the field.
425
425
 
426
426
  Args:
427
- plane (str, optional): Plane of the slice. Defaults to "xz".
428
- slice_id (int, optional): Slice ID. Defaults to 0.
429
- title (str, optional): Title of the plot. Defaults to None.
430
- xlabel (str, optional): Label of the x-axis. Defaults to None (auto).
431
- ylabel (str, optional): Label of the y-axis. Defaults to None (auto).
432
- figsize (Tuple[float, float], optional): Figure size. Defaults to None (auto).
433
- dpi (int, optional): Figure DPI. Defaults to None (auto).
434
- aspect (str, optional): Aspect ratio. Defaults to "equal".
435
- ax (Axes, optional): Axes to plot on. Defaults to None.
436
- cax (Axes, optional): Axes to plot color bar on. Defaults to None.
437
- vmin (float, optional): Minimum value of the color bar. Defaults to None.
438
- vmax (float, optional): Maximum value of the color bar. Defaults to None.
439
- cmap (str, optional): Color map. Defaults to "micpy".
427
+ plane (str, optional): Plane of the slice. Defaults to `xz`.
428
+ slice_id (int, optional): Slice ID. Defaults to `0`.
429
+ title (str, optional): Title of the plot. Defaults to `None`.
430
+ xlabel (str, optional): Label of the x-axis. Defaults to `None` (auto).
431
+ ylabel (str, optional): Label of the y-axis. Defaults to `None` (auto).
432
+ figsize (Tuple[float, float], optional): Figure size. Defaults to `None`
433
+ (auto).
434
+ dpi (int, optional): Figure DPI. Defaults to `None` (auto).
435
+ aspect (str, optional): Aspect ratio. Defaults to `equal`.
436
+ ax (Axes, optional): Axes to plot on. Defaults to `None`.
437
+ cax (Axes, optional): Axes to plot color bar on. Defaults to `None`.
438
+ vmin (float, optional): Minimum value of the color bar. Defaults to `None`.
439
+ vmax (float, optional): Maximum value of the color bar. Defaults to `None`.
440
+ cmap (str, optional): Color map. Defaults to `micpy`.
440
441
 
441
442
  Returns:
442
- Tuple[Figure, Axes]: Figure and axes of the plot.
443
+ Figure and axes of the plot.
443
444
  """
444
445
  if matplotlib is None:
445
446
  raise ImportError("matplotlib is not installed")
@@ -517,20 +518,21 @@ class FieldList(List[Field]):
517
518
  figsize: Tuple[float, float] = None,
518
519
  dpi: int = None,
519
520
  **kwargs,
520
- ):
521
+ ) -> Tuple["matplotlib.Figure", "matplotlib.Axes"]:
521
522
  """Plot the fields in a grid.
522
523
 
523
524
  Args:
524
- cols (int, optional): Number of columns. Defaults to None (auto).
525
- normalize (bool, optional): Normalize the color bar. Defaults to False.
526
- sharex (bool, optional): Share x-axis. Defaults to False.
527
- sharey (bool, optional): Share y-axis. Defaults to False.
528
- figsize (Tuple[float, float], optional): Figure size. Defaults to None (auto).
529
- dpi (int, optional): Figure DPI. Defaults to None (auto).
530
- **kwargs: Keyword arguments passed to Field.plot().
525
+ cols (int, optional): Number of columns. Defaults to `None` (auto).
526
+ normalize (bool, optional): Normalize the color bar. Defaults to `False`.
527
+ sharex (bool, optional): Share x-axis. Defaults to `False`.
528
+ sharey (bool, optional): Share y-axis. Defaults to `False`.
529
+ figsize (Tuple[float, float], optional): Figure size. Defaults to `None`
530
+ (auto).
531
+ dpi (int, optional): Figure DPI. Defaults to `None` (auto).
532
+ **kwargs: Keyword arguments passed to `Field.plot()`.
531
533
 
532
534
  Returns:
533
- Tuple[Figure, Axes]: Figure and axes of the plot.
535
+ Figure and axes of the plot.
534
536
  """
535
537
  if matplotlib is None:
536
538
  raise ImportError("matplotlib is not installed")
@@ -583,11 +585,12 @@ class File:
583
585
 
584
586
  Args:
585
587
  filename (str): File name.
586
- chunk_size (int, optional): Chunk size in bytes. Defaults to 8388608 (8 MiB).
587
- verbose (bool, optional): Verbose output. Defaults to True.
588
+ chunk_size (int, optional): Chunk size in bytes. Defaults to `8388608`
589
+ (8 MiB).
590
+ verbose (bool, optional): Verbose output. Defaults to `True`.
588
591
 
589
592
  Raises:
590
- FileNotFoundError: If file is not found.
593
+ `FileNotFoundError`: If file is not found.
591
594
  """
592
595
  if not os.path.isfile(filename):
593
596
  raise FileNotFoundError(f"File not found: {filename}")
@@ -697,7 +700,7 @@ class File:
697
700
  """Get the times of the fields in the file.
698
701
 
699
702
  Returns:
700
- List[float]: List of times.
703
+ List of times.
701
704
  """
702
705
  return [position.time for position in self.index()]
703
706
 
@@ -706,7 +709,7 @@ class File:
706
709
 
707
710
  Args:
708
711
  shape (Tuple[int, int, int]): Shape of the geometry.
709
- spacing (Tuple[float, float, float]): Spacing of the geometry.
712
+ spacing (Tuple[float, float, float]): Spacing of the geometry in μm³.
710
713
  """
711
714
 
712
715
  self.shape = np.array(shape)
@@ -721,24 +724,28 @@ class File:
721
724
 
722
725
  Args:
723
726
  filename (str): Filename of a geometry file.
724
- type (Type, optional): Data type to be read. Defaults to Type.EXTENDED.
725
- compressed (bool, optional): True if file is compressed, False otherwise.
726
- Defaults to True.
727
+ type (Type, optional): Data type to be read. Defaults to `Type.EXTENDED`.
728
+ compressed (bool, optional): `True` if file is compressed, `False`
729
+ otherwise. Defaults to True.
727
730
  """
728
731
  geo_dict = geo.read(filename, type=type, compressed=compressed)
729
- self.set_geo(geo_dict["shape"], geo_dict["spacing"])
732
+
733
+ shape = geo_dict["shape"]
734
+ spacing = utils.convert_si(geo_dict["spacing"], "cm", "μm")
735
+
736
+ self.set_geo(shape, spacing)
730
737
 
731
738
  def find_geo(self, type: geo.Type = geo.Type.EXTENDED, compressed: bool = None):
732
739
  """Find geometry file and read it.
733
740
 
734
741
  Args:
735
- type (Type, optional): Data type to be read. Defaults to Type.EXTENDED.
742
+ type (Type, optional): Data type to be read. Defaults to `Type.EXTENDED`.
736
743
  compressed (bool, optional): True if file is compressed, False otherwise.
737
- Defaults to None (auto).
744
+ Defaults to `None` (auto).
738
745
 
739
746
  Raises:
740
- GeometryFileNotFoundError: If no geometry file is found.
741
- MultipleGeometryFilesError: If multiple geometry files are found.
747
+ `GeometryFileNotFoundError`: If no geometry file is found.
748
+ `MultipleGeometryFilesError`: If multiple geometry files are found.
742
749
  """
743
750
  filename = geo.find(self._filename)
744
751
 
@@ -764,25 +771,25 @@ class File:
764
771
  self._info(f"Grid Shape (Cell Count): {tuple(cells)}")
765
772
  self._info(f"Grid Spacing (Cell Size): {tuple(spacing)}μm³")
766
773
 
767
- def iterate(self):
774
+ def iterate(self) -> Generator[Field, None, None]:
768
775
  """Iterate over fields in the file.
769
776
 
770
777
  Returns:
771
- Field: Field data.
778
+ Field data.
772
779
  """
773
780
  for position in self.index():
774
781
  yield Field.read(position, shape=self.shape, spacing=self.spacing)
775
782
 
776
- def read(self, key: int or slice or list or Callable[[Field], bool] = None):
783
+ def read(self, key: int or slice or list or Callable[[Field], bool] = None) -> FieldList:
777
784
  """Read a field from the file.
778
785
 
779
786
  Args:
780
787
  key (int or list or slice or Callable[[Field], bool], optional): Field ID,
781
788
  list of field IDs, a slice object, or a condition function.
782
- Defaults to None.
789
+ Defaults to `None`.
783
790
 
784
791
  Returns:
785
- FieldList: List of fields.
792
+ List of fields.
786
793
  """
787
794
 
788
795
  def read_field(self, field_id: int or slice or list):
micpy/geo.py CHANGED
@@ -1,4 +1,4 @@
1
- """This module provides methods to read and write geometry files."""
1
+ """The `micpy.geo` modules provides methods to read and write geometry files."""
2
2
 
3
3
  import enum
4
4
  import gzip
@@ -31,11 +31,11 @@ BASIC_MODEL = [
31
31
 
32
32
  EXTENSION_MODEL = [
33
33
  ("extension_header", np.int32),
34
- ("version", np.string_, 10),
35
- ("compile_date", np.string_, 10),
36
- ("run_date", np.string_, 10),
37
- ("platform", np.string_, 10),
38
- ("precision", np.string_, 10),
34
+ ("version", np.bytes_, 10),
35
+ ("compile_date", np.bytes_, 10),
36
+ ("run_date", np.bytes_, 10),
37
+ ("platform", np.bytes_, 10),
38
+ ("precision", np.bytes_, 10),
39
39
  ("extension_footer", np.int32),
40
40
  ]
41
41
 
@@ -59,7 +59,7 @@ class MultipleGeometryFilesError(GeometryFileError):
59
59
  """Raised when multiple potential geometry files are found."""
60
60
 
61
61
 
62
- def find(filename: str) -> str:
62
+ def find(filename: str) -> Path:
63
63
  """Find the geometry file for a given binary file.
64
64
 
65
65
  This method assumes that (a) both files share a common basename and (b) the
@@ -69,7 +69,7 @@ def find(filename: str) -> str:
69
69
  filename (str): Filename of a binary file.
70
70
 
71
71
  Returns:
72
- Path: Path to the geometry file.
72
+ Path to the geometry file.
73
73
  """
74
74
  basename = _get_basename(Path(filename))
75
75
  matches = list(basename.parent.glob(f"{basename.name}[._]geoF*"))
@@ -91,10 +91,10 @@ def read(filename: str, type: Type = Type.EXTENDED, compressed: bool = True) ->
91
91
  filename (str): Filename of a geometry file.
92
92
  type (Type, optional): Data type to be read.
93
93
  compressed (bool, optional): True if file is compressed, False otherwise.
94
- Defaults to True.
94
+ Defaults to `True`.
95
95
 
96
96
  Returns:
97
- dict: Dictionary representation of the geometry file.
97
+ Dictionary representation of the geometry file.
98
98
  """
99
99
  array_data = read_ndarray(filename, type, compressed)
100
100
  return _ndarray_to_dict(array_data)
@@ -107,12 +107,12 @@ def read_ndarray(
107
107
 
108
108
  Args:
109
109
  filename (str): Filename of a geometry file.
110
- type (Type, optional): Data type to be read. Defaults to Type.EXTENDED.
111
- compressed (bool, optional): True if file is compressed, False otherwise.
112
- Defaults to True.
110
+ type (Type, optional): Data type to be read. Defaults to `Type.EXTENDED`.
111
+ compressed (bool, optional): `True` if file is compressed, `False` otherwise.
112
+ Defaults to `True`.
113
113
 
114
114
  Returns:
115
- ndarray: NumPy array representation of the geometry file.
115
+ NumPy array representation of the geometry file.
116
116
  """
117
117
  opener = gzip.open if compressed else open
118
118
  with opener(filename, "rb") as f:
@@ -130,9 +130,9 @@ def write(
130
130
  Args:
131
131
  filename (str): Filename of a geometry file.
132
132
  data (dict): Dictionary representation of a geometry file.
133
- type (Type, optional): Data type to be written. Defaults to Type.EXTENDED.
134
- compressed (bool, optional): True if file should be compressed, False otherwise.
135
- Defaults to True.
133
+ type (Type, optional): Data type to be written. Defaults to `Type.EXTENDED`.
134
+ compressed (bool, optional): `True` if file should be compressed, `False`
135
+ otherwise. Defaults to `True`.
136
136
  """
137
137
  array_data = _dict_to_ndarray(data, type)
138
138
  write_ndarray(filename, array_data, compressed)
@@ -144,8 +144,8 @@ def write_ndarray(filename: str, data: ndarray, compressed: bool = True):
144
144
  Args:
145
145
  filename (str): Filename of a geometry file.
146
146
  data (ndarray): NumPy array representation of a geometry file.
147
- compressed (bool, optional): True if file should be compressed, False otherwise.
148
- Defaults to True.
147
+ compressed (bool, optional): `True` if file should be compressed, `False`
148
+ otherwise. Defaults to `True`.
149
149
  """
150
150
  if not _validate_data_type(data):
151
151
  raise ValueError("Invalid data type")
@@ -180,7 +180,7 @@ def get_basic(
180
180
  def _get_basename(path: Path) -> Path:
181
181
  """Extract the basename from a binary filename.
182
182
 
183
- A specific check for the '.mcr' extension is added due to historical naming
183
+ A specific check for the `.mcr` extension is added due to historical naming
184
184
  conventions related to the association of binary files and their geometry files.
185
185
  """
186
186
  if not path.name:
micpy/matplotlib.py CHANGED
@@ -13,24 +13,23 @@ except ImportError:
13
13
 
14
14
  def _register_colormaps():
15
15
  colors = [
16
- "#1102d8",
17
- "#3007ba",
18
- "#500b9d",
19
- "#6f0e81",
20
- "#8d1364",
21
- "#ac1748",
22
- "#cb1b2b",
23
- "#ea1e0f",
24
- "#f83605",
25
- "#fa600f",
26
- "#fb8817",
27
- "#fdb120",
28
- "#ffda29",
29
- "#ffed4d",
30
- "#fff380",
31
- "#fffbb4",
16
+ "#1102d8", # 17, 2, 216
17
+ "#3007ba", # 48, 7, 186
18
+ "#500b9d", # 80, 11, 157
19
+ "#6f0e81", # 111, 14, 129
20
+ "#8d1364", # 141, 19, 100
21
+ "#ac1748", # 172, 23, 72
22
+ "#cb1b2b", # 203, 27, 43
23
+ "#ea1e0f", # 234, 30, 15
24
+ "#f83605", # 248, 54, 5
25
+ "#fa600f", # 250, 96, 15
26
+ "#fb8817", # 251, 136, 23
27
+ "#fdb120", # 253, 177, 32
28
+ "#ffda29", # 255, 218, 41
29
+ "#ffed4d", # 255, 237, 77
30
+ "#fff380", # 255, 243, 128
31
+ "#fffbb4", # 255, 251, 180
32
32
  ]
33
-
34
33
  version = LooseVersion(matplotlib.__version__) >= LooseVersion("3.7")
35
34
 
36
35
  create = matplotlib.colors.LinearSegmentedColormap.from_list
micpy/tab.py CHANGED
@@ -1,4 +1,4 @@
1
- """This module provides methods to read and parse tabular files."""
1
+ """The `micpy.tab` module provides methods to read and parse tabular files."""
2
2
 
3
3
  import io
4
4
  import re
@@ -20,15 +20,15 @@ def parse(
20
20
 
21
21
  Args:
22
22
  string (str): The content of a tabular file as a string.
23
- parse_header (bool, optional): Whether to parse the header. Defaults to True.
23
+ parse_header (bool, optional): Whether to parse the header. Defaults to `True`.
24
24
  ignore_invalid_header (bool, optional): Whether to ignore invalid headers.
25
- Defaults to True.
25
+ Defaults to `True`.
26
26
 
27
27
  Raises:
28
- FormatError: If the number of columns in the header does not match the body.
28
+ `FormatError`: If the number of columns in the header does not match the body.
29
29
 
30
30
  Returns:
31
- DataFrame: The content of the file as a pandas DataFrame.
31
+ The content of the file as a pandas DataFrame.
32
32
  """
33
33
  lines = string.splitlines()
34
34
  return _parse_lines(lines, parse_header, ignore_invalid_header)
@@ -41,15 +41,15 @@ def read(
41
41
 
42
42
  Args:
43
43
  filename (str): Path to the file.
44
- parse_header (bool, optional): Whether to parse the header. Defaults to True.
44
+ parse_header (bool, optional): Whether to parse the header. Defaults to `True`.
45
45
  ignore_invalid_header (bool, optional): Whether to ignore invalid headers.
46
- Defaults to True.
46
+ Defaults to `True`.
47
47
 
48
48
  Raises:
49
- FormatError: If the number of columns in the header does not match the body.
49
+ `FormatError`: If the number of columns in the header does not match the body.
50
50
 
51
51
  Returns:
52
- DataFrame: The content of the file as a pandas DataFrame.
52
+ The content of the file as a pandas DataFrame.
53
53
  """
54
54
  with open(filename, mode="r", encoding="utf8") as file:
55
55
  lines = file.readlines()
micpy/utils.py CHANGED
@@ -4,6 +4,17 @@ import sys
4
4
  import time
5
5
 
6
6
 
7
+ def convert_si(value, unit_in, unit_out):
8
+ """Convert value from one SI unit to another SI unit."""
9
+ SI = {"μm": 0.000001, "mm": 0.001, "cm": 0.01, "m": 1.0}
10
+
11
+ if isinstance(value, (float, int)):
12
+ return value * SI[unit_in] / SI[unit_out]
13
+ elif isinstance(value, (tuple, list)):
14
+ return [v * SI[unit_in] / SI[unit_out] for v in value]
15
+ raise ValueError("Unsupported value type.")
16
+
17
+
7
18
  def progress_indicator(iterable, description="Progress", unit="Iteration", start=1):
8
19
  """Progress indicator for iterable."""
9
20
 
micpy/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.2.15b0"
1
+ __version__ = "0.2.17b0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: micress-micpy
3
- Version: 0.2.15b0
3
+ Version: 0.2.17b0
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=GzY0Gva3wp0n6vcKqv9yR3zzcg6ib1GtFzCKv8yXsR0,26777
3
+ micpy/geo.py,sha256=pwMDSwG8i9XqmX2DWrSWuvtpni_Z7VLO586LNgEuORk,7366
4
+ micpy/matplotlib.py,sha256=SLfk7H1v5L7H_L-a_FqobS0nKY3eSbFRF01h433SpVQ,2090
5
+ micpy/tab.py,sha256=QCnfggxRWkKgS9-zGj8kyCjhfUw7QeTgGZWedHh4MTw,3548
6
+ micpy/utils.py,sha256=-JS5SRqH4QMD6_pXBKPVw5zPNTbaqkcOUu9ej5Gi0QU,1282
7
+ micpy/version.py,sha256=JOpzAb63fvBI_jPvlsPW3cGBI7CByIaM5IXZyr6SXOU,26
8
+ micress_micpy-0.2.17b0.dist-info/LICENSE,sha256=seHdCiArizUoWZ6bEFg6N3K2ZtfPK35wvOwg0kH-f6o,1488
9
+ micress_micpy-0.2.17b0.dist-info/METADATA,sha256=z2YjOYSHKOAtMtFk1NXS1bHkV31fKPHJcJZllNB1ZjQ,3824
10
+ micress_micpy-0.2.17b0.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
11
+ micress_micpy-0.2.17b0.dist-info/top_level.txt,sha256=RiopkpW0AGNYdtOW2eQUWgm3yHGC13q9pWlHb2alhiE,6
12
+ micress_micpy-0.2.17b0.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- micpy/__init__.py,sha256=7wQUaseppjQYZW1iAVNm2WSDjvBLlqtY8tiHsfDaW5Q,148
2
- micpy/bin.py,sha256=0RB4FTad00sriZvQdHuTvkzT9D4_pLS_eFwpYS7EOhA,26492
3
- micpy/geo.py,sha256=dcXcxvAxPpe4Rrs1ImYs8H67c2228brabdefJMoLn0g,7354
4
- micpy/matplotlib.py,sha256=toxFTtTaA-usuWUltMp0XufQee4-n68XH7SN2In2NZY,1845
5
- micpy/tab.py,sha256=ZXhL6bg17W3jqFFX28htCOAV9W_W3op_-GD7iU5a_wY,3547
6
- micpy/utils.py,sha256=Kt1AvhMvWer9uftbb88X7N27aXtQdJl26grHmmm2vOQ,859
7
- micpy/version.py,sha256=tyiEmp3lrfZHINaXvAGtz6wbg_fRgizg1D1jsMt3PXo,26
8
- micress_micpy-0.2.15b0.dist-info/LICENSE,sha256=seHdCiArizUoWZ6bEFg6N3K2ZtfPK35wvOwg0kH-f6o,1488
9
- micress_micpy-0.2.15b0.dist-info/METADATA,sha256=Po-1cfNOIsV2m9wU_oj8kKzf2LllWQf-50PQD5O_g3c,3824
10
- micress_micpy-0.2.15b0.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
11
- micress_micpy-0.2.15b0.dist-info/top_level.txt,sha256=RiopkpW0AGNYdtOW2eQUWgm3yHGC13q9pWlHb2alhiE,6
12
- micress_micpy-0.2.15b0.dist-info/RECORD,,