dclab 0.67.0__cp39-cp39-macosx_11_0_arm64.whl → 0.67.3__cp39-cp39-macosx_11_0_arm64.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.
dclab/_version.py CHANGED
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '0.67.0'
32
- __version_tuple__ = version_tuple = (0, 67, 0)
31
+ __version__ = version = '0.67.3'
32
+ __version_tuple__ = version_tuple = (0, 67, 3)
33
33
 
34
- __commit_id__ = commit_id = 'g52c420117'
34
+ __commit_id__ = commit_id = 'g42c771e2c'
@@ -56,9 +56,9 @@ def verify_dataset(path_in=None):
56
56
  else:
57
57
  # everything is ok
58
58
  exit_status = 0
59
- finally:
60
- # return sys.exit for testing (monkeypatched)
61
- return sys.exit(exit_status)
59
+
60
+ # return sys.exit for testing (monkeypatched)
61
+ return sys.exit(exit_status)
62
62
 
63
63
 
64
64
  def verify_dataset_parser():
@@ -91,11 +91,13 @@ FEATURES_SCALAR = [
91
91
  # Sum of the pressures applied to sample and sheath flow
92
92
  ["pressure", "Pressure [mPa]"],
93
93
  # QPI features computed from holographic data
94
- ["qpi_dm_avg", "Dry mass (average) [pg]"],
95
- ["qpi_dm_sd", "Dry mass (SD) [pg]"],
94
+ ["qpi_dm", "Dry mass [pg]"],
95
+ ["qpi_dm_avg", "DEPRECATED Dry mass (average) [pg]"],
96
+ ["qpi_dm_dns", "Dry mass density [mg/ml]"],
97
+ ["qpi_dm_sd", "DEPRECATED Dry mass (SD) [pg]"],
96
98
  ["qpi_pha_int", "Integrated phase [rad]"],
97
99
  ["qpi_ri_avg", "Refractive index (average)"],
98
- ["qpi_ri_sd", "Refractive index (SD)"],
100
+ ["qpi_ri_sd", "DEPRECATED Refractive index (SD)"],
99
101
  # QPI features from refocused events
100
102
  ["qpi_focus", "Computed focus distance [µm]"],
101
103
  # Size features
Binary file
dclab/downsampling.pyx CHANGED
@@ -176,14 +176,19 @@ def downsample_grid(a, b, samples, remove_invalid=False, ret_idx=False):
176
176
  if not remove_invalid:
177
177
  diff_bad = (samples_int or keep.size) - np.sum(keep)
178
178
  if diff_bad > 0:
179
- # Add a few of the invalid values so that in the end
180
- # we have the desired array size.
181
179
  add_indices_bad = np.where(bad)[0]
182
- np.random.set_state(rs)
183
- add_bad = np.random.choice(add_indices_bad,
184
- size=diff_bad,
185
- replace=False)
186
- keep[add_bad] = True
180
+ if add_indices_bad.size > diff_bad:
181
+ # Add a few of the invalid values so that in the end
182
+ # we have the desired array size.
183
+ np.random.set_state(rs)
184
+ add_bad = np.random.choice(add_indices_bad,
185
+ size=diff_bad,
186
+ replace=False)
187
+ keep[add_bad] = True
188
+ else:
189
+ # We don't have enough bad indices (or just enough),
190
+ # so we add them all.
191
+ keep[add_indices_bad] = True
187
192
 
188
193
  # paulmueller 2024-01-03
189
194
  # if samples_int and not remove_invalid:
dclab/features/bright.py CHANGED
@@ -2,10 +2,19 @@
2
2
  Computation of mean and standard deviation of grayscale values inside the
3
3
  RT-DC event image mask.
4
4
  """
5
+ from __future__ import annotations
6
+
5
7
  import numpy as np
8
+ import numpy.typing as npt
6
9
 
7
10
 
8
- def get_bright(mask, image, ret_data="avg,sd"):
11
+ def get_bright(mask: npt.NDArray[bool] | list[npt.NDArray[bool]],
12
+ image: npt.NDArray | list[npt.NDArray],
13
+ ret_data: str = "avg,sd"
14
+ ) -> (float |
15
+ npt.NDArray |
16
+ tuple[float, float] |
17
+ tuple[npt.NDArray, npt.NDArray]):
9
18
  """Compute avg and/or std of the event brightness
10
19
 
11
20
  The event brightness is defined by the gray-scale values of the
@@ -18,7 +27,7 @@ def get_bright(mask, image, ret_data="avg,sd"):
18
27
  image: ndarray or list of ndarrays of shape (M,N)
19
28
  A 2D array that holds the image in form of grayscale values
20
29
  of an event.
21
- ret_data: str
30
+ ret_data
22
31
  A comma-separated list of metrices to compute
23
32
  - "avg": compute the average
24
33
  - "sd": compute the standard deviation
@@ -2,10 +2,21 @@
2
2
  Computation of mean and standard deviation of grayscale values inside the
3
3
  RT-DC event image mask with background-correction taken into account.
4
4
  """
5
+ from __future__ import annotations
6
+
5
7
  import numpy as np
8
+ import numpy.typing as npt
6
9
 
7
10
 
8
- def get_bright_bc(mask, image, image_bg, bg_off=None, ret_data="avg,sd"):
11
+ def get_bright_bc(mask: npt.NDArray[bool] | list[npt.NDArray[bool]],
12
+ image: npt.NDArray | list[npt.NDArray],
13
+ image_bg: npt.NDArray | list[npt.NDArray],
14
+ bg_off: float | npt.NDArray = None,
15
+ ret_data: str = "avg,sd"
16
+ ) -> (float |
17
+ npt.NDArray |
18
+ tuple[float, float] |
19
+ tuple[npt.NDArray, npt.NDArray]):
9
20
  """Compute avg and/or std of the background-corrected event brightness
10
21
 
11
22
  The background-corrected event brightness is defined by the
@@ -24,7 +35,7 @@ def get_bright_bc(mask, image, image_bg, bg_off=None, ret_data="avg,sd"):
24
35
  bg_off: float or 1D ndarray
25
36
  Additional offset value that is added to `image_bg` before
26
37
  background correction
27
- ret_data: str
38
+ ret_data
28
39
  A comma-separated list of metrices to compute
29
40
  - "avg": compute the average
30
41
  - "sd": compute the standard deviation
@@ -2,10 +2,18 @@
2
2
  Computation of the 10th and 90th percentile of grayscale values inside the
3
3
  RT-DC event image mask with background-correction taken into account.
4
4
  """
5
+ from __future__ import annotations
6
+
5
7
  import numpy as np
8
+ import numpy.typing as npt
6
9
 
7
10
 
8
- def get_bright_perc(mask, image, image_bg, bg_off=None):
11
+ def get_bright_perc(mask: npt.NDArray[bool] | list[npt.NDArray[bool]],
12
+ image: npt.NDArray | list[npt.NDArray],
13
+ image_bg: npt.NDArray | list[npt.NDArray],
14
+ bg_off: float | npt.NDArray = None
15
+ ) -> (tuple[float, float] |
16
+ tuple[npt.NDArray, npt.NDArray]):
9
17
  """Compute 10th and 90th percentile of the bg-corrected event brightness
10
18
 
11
19
  The background-corrected event brightness is defined by the
@@ -29,7 +37,7 @@ def get_bright_perc(mask, image, image_bg, bg_off=None):
29
37
  -------
30
38
  bright_perc_10: float or ndarray of size N
31
39
  10th percentile of brightness
32
- bright_perc_10: float or ndarray of size N
40
+ bright_perc_90: float or ndarray of size N
33
41
  90th percentile of brightness
34
42
  """
35
43
  if isinstance(mask, np.ndarray) and len(mask.shape) == 2:
dclab/features/contour.py CHANGED
@@ -1,8 +1,11 @@
1
1
  """Computation of event contour from event mask"""
2
+ from __future__ import annotations
3
+
2
4
  from collections import deque
3
5
  import numbers
4
6
 
5
7
  import numpy as np
8
+ import numpy.typing as npt
6
9
 
7
10
  # equivalent to
8
11
  # from skimage.measure import find_contours
@@ -14,15 +17,15 @@ class NoValidContourFoundError(BaseException):
14
17
 
15
18
 
16
19
  class LazyContourList(object):
17
- def __init__(self, masks, max_events=1000):
20
+ def __init__(self, masks: npt.ArrayLike, max_events: int = 1000) -> None:
18
21
  """A list-like object that computes contours upon indexing
19
22
 
20
23
  Parameters
21
24
  ----------
22
- masks: array-like
25
+ masks
23
26
  3D array of masks, may be an HDF5 dataset or any other
24
27
  structure that supports indexing
25
- max_events: int
28
+ max_events
26
29
  maximum number of contours to keep in the contour list;
27
30
  set to 0/False/None to cache all contours
28
31
 
@@ -40,7 +43,7 @@ class LazyContourList(object):
40
43
  self.identifier = str(masks[0][:].tobytes())
41
44
  self.shape = len(masks), np.nan, 2
42
45
 
43
- def __getitem__(self, idx):
46
+ def __getitem__(self, idx) -> npt.NDArray:
44
47
  """Compute contour(s) if not already in self.contours"""
45
48
  if not isinstance(idx, numbers.Integral):
46
49
  # slicing!
@@ -74,7 +77,8 @@ class LazyContourList(object):
74
77
  return len(self.masks)
75
78
 
76
79
 
77
- def get_contour(mask):
80
+ def get_contour(mask: npt.NDArray[np.bool | np.int]
81
+ ) -> npt.NDArray | list[npt.NDArray]:
78
82
  """Compute the image contour from a mask
79
83
 
80
84
  The contour is computed in a very inefficient way using scikit-image
@@ -127,7 +131,8 @@ def get_contour(mask):
127
131
  return contours[0]
128
132
 
129
133
 
130
- def get_contour_lazily(mask):
134
+ def get_contour_lazily(mask: npt.NDArray[np.bool | np.int]
135
+ ) -> npt.NDArray | LazyContourList:
131
136
  """Like :func:`get_contour`, but computes contours on demand
132
137
 
133
138
  Parameters
@@ -153,7 +158,7 @@ def get_contour_lazily(mask):
153
158
  return cont
154
159
 
155
160
 
156
- def remove_duplicates(cont):
161
+ def remove_duplicates(cont: npt.NDArray) -> npt.NDArray:
157
162
  """Remove duplicates in a circular contour"""
158
163
  x = np.resize(cont, (len(cont) + 1, 2))
159
164
  selection = np.ones(len(x), dtype=bool)
@@ -7,6 +7,7 @@ from typing import Literal
7
7
  import warnings
8
8
 
9
9
  import numpy as np
10
+ import numpy.typing as npt
10
11
  import scipy.interpolate as spint
11
12
 
12
13
  from ...warn import PipelineWarning
@@ -18,7 +19,6 @@ from .scale_linear import convert # noqa: F401
18
19
  from .scale_linear import scale_emodulus, scale_feature
19
20
  from .viscosity import get_viscosity
20
21
 
21
-
22
22
  #: Set this to True to globally enable spline extrapolation when the
23
23
  #: `area_um`/`deform` data are outside the LUT. This is discouraged and
24
24
  #: a :class:`KnowWhatYouAreDoingWarning` warning will be issued.
@@ -33,8 +33,13 @@ class YoungsModulusLookupTableExceededWarning(PipelineWarning):
33
33
  pass
34
34
 
35
35
 
36
- def extrapolate_emodulus(lut, datax, deform, emod, deform_norm,
37
- deform_thresh=.05, inplace=True):
36
+ def extrapolate_emodulus(lut: npt.NDArray,
37
+ datax: npt.NDArray,
38
+ deform: npt.NDArray,
39
+ emod: npt.NDArray,
40
+ deform_norm: float,
41
+ deform_thresh: float = .05,
42
+ inplace: bool = True) -> npt.NDArray:
38
43
  """Use spline interpolation to fill in nan-values
39
44
 
40
45
  When points (`datax`, `deform`) are outside the convex
@@ -61,16 +66,16 @@ def extrapolate_emodulus(lut, datax, deform, emod, deform_norm,
61
66
  emod: ndarray of size N
62
67
  The emodulus (corresponding to `lut[:, 2]`); If `emod`
63
68
  does not contain nan-values, there is nothing to do here.
64
- deform_norm: float
69
+ deform_norm
65
70
  The normalization value used to normalize `lut[:, 1]` and
66
71
  `deform`.
67
- deform_thresh: float
72
+ deform_thresh
68
73
  Not the entire LUT is used for bivariate spline interpolation.
69
74
  Only the points where `lut[:, 1] > deform_thresh/deform_norm`
70
75
  are used. This is necessary, because for small deformations,
71
76
  the LUT has an extreme slope that kills any meaningful
72
77
  spline interpolation.
73
- inplace: bool
78
+ inplace
74
79
  If True (default), replaces nan values in `emod` in-place.
75
80
  If False, `emod` is not modified.
76
81
  """
@@ -99,50 +104,51 @@ def extrapolate_emodulus(lut, datax, deform, emod, deform_norm,
99
104
  return emod
100
105
 
101
106
 
102
- def get_emodulus(deform: float | np.array,
103
- area_um: float | np.array | None = None,
104
- volume: float | np.array | None = None,
107
+ def get_emodulus(deform: float | npt.NDArray,
108
+ area_um: float | npt.NDArray | None = None,
109
+ volume: float | npt.NDArray | None = None,
105
110
  medium: float | str = "0.49% MC-PBS",
106
111
  channel_width: float = 20.0,
107
112
  flow_rate: float = 0.16,
108
113
  px_um: float = 0.34,
109
- temperature: float | np.ndarray | None = 23.0,
110
- lut_data: str | pathlib.Path | np.ndarray = "LE-2D-FEM-19",
114
+ temperature: float | npt.NDArray | None = 23.0,
115
+ lut_data: (str | pathlib.Path |
116
+ tuple[npt.NDArray, dict]) = "LE-2D-FEM-19",
111
117
  visc_model: Literal['herold-2017',
112
118
  'herold-2017-fallback',
113
119
  'buyukurganci-2022',
114
120
  'kestin-1978',
115
121
  None] = "herold-2017-fallback",
116
122
  extrapolate: bool = INACCURATE_SPLINE_EXTRAPOLATION,
117
- copy: bool = True):
123
+ copy: bool = True) -> npt.NDArray:
118
124
  """Compute apparent Young's modulus using a look-up table
119
125
 
120
126
  Parameters
121
127
  ----------
122
- area_um: float or ndarray
123
- Apparent (2D image) area [µm²] of the event(s)
124
- deform: float or ndarray
128
+ deform
125
129
  Deformation (1-circularity) of the event(s)
126
- volume: float or ndarray
130
+ area_um
131
+ Apparent (2D image) area [µm²] of the event(s)
132
+ volume
127
133
  Apparent volume of the event(s). It is not possible to define
128
134
  `volume` and `area_um` at the same time (makes no sense).
129
135
 
130
136
  .. versionadded:: 0.25.0
131
- medium: str or float
137
+ medium
132
138
  The medium to compute the viscosity for. If a string
133
139
  is given, the viscosity is computed. If a float is given,
134
140
  this value is used as the viscosity in mPa*s (Note that
135
141
  `temperature` and `visc_model` must be set to None in this case).
136
- channel_width: float
142
+ channel_width
137
143
  The channel width [µm]
138
- flow_rate: float
144
+ flow_rate
139
145
  Flow rate [µL/s]
140
- px_um: float
146
+ px_um
141
147
  The detector pixel size [µm] used for pixelation correction.
142
148
  Set to zero to disable.
143
- temperature: float, ndarray, or None
149
+ temperature
144
150
  Temperature [°C] of the event(s)
145
- lut_data: path, str, or tuple of (np.ndarray of shape (N, 3), dict)
151
+ lut_data: str, path, or tuple of (np.ndarray of shape (N, 3), dict)
146
152
  The LUT data to use. If it is a built-in identifier,
147
153
  then the respective LUT will be used. Otherwise, a path to a
148
154
  file on disk or a tuple (LUT array, metadata) is possible.
@@ -150,14 +156,14 @@ def get_emodulus(deform: float | np.array,
150
156
  (e.g. `area_um` and `deform`) are valid interpolation choices.
151
157
 
152
158
  .. versionadded:: 0.25.0
153
- visc_model: str
159
+ visc_model
154
160
  The viscosity model to use,
155
161
  see :func:`dclab.features.emodulus.viscosity.get_viscosity`
156
- extrapolate: bool
162
+ extrapolate
157
163
  Perform extrapolation using :func:`extrapolate_emodulus`. This
158
164
  is discouraged!
159
- copy: bool
160
- Copy input arrays. If set to false, input arrays are
165
+ copy
166
+ Copy input arrays. If set to False, input arrays are
161
167
  overridden.
162
168
 
163
169
  Returns
@@ -326,7 +332,7 @@ def get_emodulus(deform: float | np.array,
326
332
  return emod
327
333
 
328
334
 
329
- def normalize(data, dmax):
335
+ def normalize(data: npt.NDArray, dmax: float) -> npt.NDArray:
330
336
  """Perform normalization in-place for interpolation
331
337
 
332
338
  Note that :func:`scipy.interpolate.griddata` has a `rescale`
@@ -12,6 +12,7 @@ import importlib_resources
12
12
  import warnings
13
13
 
14
14
  import numpy as np
15
+ import numpy.typing as npt
15
16
 
16
17
  from ... import definitions as dfn
17
18
 
@@ -24,7 +25,7 @@ EXTERNAL_LUTS = {}
24
25
 
25
26
 
26
27
  @functools.lru_cache()
27
- def get_internal_lut_names_dict():
28
+ def get_internal_lut_names_dict() -> dict:
28
29
  """Return list of internal lut names"""
29
30
  lutfiles = {}
30
31
  for pp in importlib_resources.files('dclab.features.emodulus').iterdir():
@@ -34,10 +35,10 @@ def get_internal_lut_names_dict():
34
35
  return lutfiles
35
36
 
36
37
 
37
- def get_lut_path(path_or_id):
38
+ def get_lut_path(path_or_id: str | pathlib.Path) -> pathlib.Path:
38
39
  """Find the path to a LUT
39
40
 
40
- path_or_id: str or pathlib.Path
41
+ path_or_id
41
42
  Identifier of a LUT. This can be either an existing path
42
43
  (checked first), or an internal identifier (see
43
44
  :func:`get_internal_lut_names_dict`).
@@ -63,7 +64,8 @@ def get_lut_path(path_or_id):
63
64
  return lut_path
64
65
 
65
66
 
66
- def load_lut(lut_data: str | pathlib.Path | np.ndarray = "LE-2D-FEM-19"):
67
+ def load_lut(lut_data: str | pathlib.Path | tuple[npt.NDArray, dict] =
68
+ "LE-2D-FEM-19") -> tuple[npt.NDArray, dict]:
67
69
  """Load LUT data from disk
68
70
 
69
71
  Parameters
@@ -98,7 +100,7 @@ def load_lut(lut_data: str | pathlib.Path | np.ndarray = "LE-2D-FEM-19"):
98
100
  return lut, meta
99
101
 
100
102
 
101
- def load_mtext(path):
103
+ def load_mtext(path: str | pathlib.Path) -> tuple[npt.NDArray, dict]:
102
104
  """Load column-based data from text files with metadata
103
105
 
104
106
  This file format is used for isoelasticity lines and look-up
@@ -217,7 +219,7 @@ def load_mtext(path):
217
219
  return data, meta
218
220
 
219
221
 
220
- def register_lut(path, identifier=None):
222
+ def register_lut(path: str | pathlib.Path, identifier: str = None) -> None:
221
223
  """Register an external LUT file in dclab
222
224
 
223
225
  This will add it to :const:`EXTERNAL_LUTS`, which is required
@@ -1,9 +1,12 @@
1
1
  """Pixelation correction definitions"""
2
+ from __future__ import annotations
2
3
 
3
4
  import numpy as np
5
+ import numpy.typing as npt
4
6
 
5
7
 
6
- def corr_deform_with_area_um(area_um, px_um=0.34):
8
+ def corr_deform_with_area_um(area_um: float | npt.NDArray,
9
+ px_um: float = 0.34) -> float | npt.NDArray:
7
10
  """Deformation correction for area_um-deform data
8
11
 
9
12
  The contour in RT-DC measurements is computed on a
@@ -14,14 +17,14 @@ def corr_deform_with_area_um(area_um, px_um=0.34):
14
17
 
15
18
  Parameters
16
19
  ----------
17
- area_um: float or ndarray
18
- Apparent (2D image) area in µm² of the event(s)
19
- px_um: float
20
+ area_um
21
+ Area of the event(s) in µm²
22
+ px_um
20
23
  The detector pixel size in µm.
21
24
 
22
25
  Returns
23
26
  -------
24
- deform_delta: float or ndarray
27
+ deform_delta
25
28
  Error of the deformation of the event(s) that must be
26
29
  subtracted from `deform`.
27
30
  deform_corr = deform - deform_delta
@@ -46,7 +49,8 @@ def corr_deform_with_area_um(area_um, px_um=0.34):
46
49
  return delta
47
50
 
48
51
 
49
- def corr_deform_with_volume(volume, px_um=0.34):
52
+ def corr_deform_with_volume(volume: float | npt.NDArray,
53
+ px_um: float = 0.34) -> float | npt.NDArray:
50
54
  """Deformation correction for volume-deform data
51
55
 
52
56
  The contour in RT-DC measurements is computed on a
@@ -57,14 +61,14 @@ def corr_deform_with_volume(volume, px_um=0.34):
57
61
 
58
62
  Parameters
59
63
  ----------
60
- volume: float or ndarray
64
+ volume
61
65
  The "volume" feature (rotation of raw contour) [µm³]
62
- px_um: float
66
+ px_um
63
67
  The detector pixel size in µm.
64
68
 
65
69
  Returns
66
70
  -------
67
- deform_delta: float or ndarray
71
+ deform_delta
68
72
  Error of the deformation of the event(s) that must be
69
73
  subtracted from `deform`.
70
74
  deform_corr = deform - deform_delta
@@ -78,7 +82,13 @@ def corr_deform_with_volume(volume, px_um=0.34):
78
82
  return delta
79
83
 
80
84
 
81
- def get_pixelation_delta_pair(feat1, feat2, data1, data2, px_um=0.34):
85
+ def get_pixelation_delta_pair(
86
+ feat1: str,
87
+ feat2: str,
88
+ data1: float | npt.NDArray,
89
+ data2: float | npt.NDArray,
90
+ px_um: float = 0.34) -> (tuple[float, float] |
91
+ tuple[npt.NDArray, npt.NDArray]):
82
92
  """Convenience function that returns pixelation correction pair"""
83
93
  # determine feature that defines abscissa
84
94
  feat_absc = feat1 if feat1 in ["area_um", "volume"] else feat2
@@ -97,20 +107,28 @@ def get_pixelation_delta_pair(feat1, feat2, data1, data2, px_um=0.34):
97
107
  return delt1, delt2
98
108
 
99
109
 
100
- def get_pixelation_delta(feat_corr, feat_absc, data_absc, px_um=0.34):
110
+ def get_pixelation_delta(feat_corr: str,
111
+ feat_absc: str,
112
+ data_absc: float | npt.NDArray,
113
+ px_um: float = 0.34) -> float | npt.NDArray:
101
114
  """Convenience function for obtaining pixelation correction
102
115
 
103
116
  Parameters
104
117
  ----------
105
- feat_corr: str
118
+ feat_corr
106
119
  Feature for which to compute the pixelation correction
107
120
  (e.g. "deform")
108
- feat_absc: str
121
+ feat_absc
109
122
  Feature with which to compute the correction (e.g. "area_um");
110
- data_absc: ndarray or float
123
+ data_absc
111
124
  Corresponding data for `feat_absc`
112
- px_um: float
125
+ px_um
113
126
  Detector pixel size [µm]
127
+
128
+ Returns
129
+ -------
130
+ For details see :func:`corr_deform_with_area_um` and
131
+ :func:`corr_deform_with_volume`.
114
132
  """
115
133
  if feat_corr == "deform" and feat_absc == "area_um":
116
134
  delt = corr_deform_with_area_um(data_absc, px_um=px_um)