phasorpy 0.5__cp313-cp313-win_arm64.whl → 0.7__cp313-cp313-win_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.
phasorpy/utils.py CHANGED
@@ -1,315 +1,36 @@
1
1
  """Utility functions.
2
2
 
3
3
  The ``phasorpy.utils`` module provides auxiliary and convenience functions
4
- that do not naturally fit into other modules.
4
+ that do not fit naturally into other modules.
5
5
 
6
6
  """
7
7
 
8
8
  from __future__ import annotations
9
9
 
10
10
  __all__ = [
11
- 'anscombe_transformation',
12
- 'anscombe_transformation_inverse',
11
+ 'logger',
13
12
  'number_threads',
14
- 'spectral_vector_denoise',
13
+ 'versions',
15
14
  ]
16
15
 
17
- import math
16
+ import logging
18
17
  import os
19
- from typing import TYPE_CHECKING
20
18
 
21
- if TYPE_CHECKING:
22
- from ._typing import Any, NDArray, ArrayLike, DTypeLike, Literal, Sequence
23
19
 
24
- import numpy
25
-
26
- from ._phasorpy import (
27
- _anscombe,
28
- _anscombe_inverse,
29
- _anscombe_inverse_approx,
30
- _phasor_from_signal_vector,
31
- _signal_denoise_vector,
32
- )
33
- from ._utils import parse_harmonic
34
-
35
-
36
- def spectral_vector_denoise(
37
- signal: ArrayLike,
38
- /,
39
- spectral_vector: ArrayLike | None = None,
40
- *,
41
- axis: int = -1,
42
- harmonic: int | Sequence[int] | Literal['all'] | str | None = None,
43
- sigma: float = 0.05,
44
- vmin: float | None = None,
45
- dtype: DTypeLike | None = None,
46
- num_threads: int | None = None,
47
- ) -> NDArray[Any]:
48
- """Return spectral-vector-denoised signal.
49
-
50
- The spectral vector denoising algorithm is based on a Gaussian weighted
51
- average calculation, with weights obtained in n-dimensional Chebyshev or
52
- Fourier space [4]_.
53
-
54
- Parameters
55
- ----------
56
- signal : array_like
57
- Hyperspectral data to be denoised.
58
- A minimum of three samples are required along `axis`.
59
- The samples must be uniformly spaced.
60
- spectral_vector : array_like, optional
61
- Spectral vector.
62
- For example, phasor coordinates, PCA projected phasor coordinates,
63
- or Chebyshev coefficients.
64
- Must be of same shape as `signal` with `axis` removed and axis
65
- containing spectral space appended.
66
- If None (default), phasor coordinates are calculated at specified
67
- `harmonic`.
68
- axis : int, optional, default: -1
69
- Axis over which `spectral_vector` is computed if not provided.
70
- The default is the last axis (-1).
71
- harmonic : int, sequence of int, or 'all', optional
72
- Harmonics to include in calculating `spectral_vector`.
73
- If `'all'`, include all harmonics for `signal` samples along `axis`.
74
- Else, harmonics must be at least one and no larger than half the
75
- number of `signal` samples along `axis`.
76
- The default is the first harmonic (fundamental frequency).
77
- A minimum of `harmonic * 2 + 1` samples are required along `axis`
78
- to calculate correct phasor coordinates at `harmonic`.
79
- sigma : float, default: 0.05
80
- Width of Gaussian filter in spectral vector space.
81
- Weighted averages are calculated using the spectra of signal items
82
- within an spectral vector Euclidean distance of `3 * sigma` and
83
- intensity above `vmin`.
84
- vmin : float, optional
85
- Signal intensity along `axis` below which not to include in denoising.
86
- dtype : dtype_like, optional
87
- Data type of output arrays. Either float32 or float64.
88
- The default is float64 unless the `signal` is float32.
89
- num_threads : int, optional
90
- Number of OpenMP threads to use for parallelization.
91
- By default, multi-threading is disabled.
92
- If zero, up to half of logical CPUs are used.
93
- OpenMP may not be available on all platforms.
20
+ def logger() -> logging.Logger:
21
+ """Return PhasorPy logger instance.
94
22
 
95
23
  Returns
96
24
  -------
97
- ndarray
98
- Denoised signal of `dtype`.
99
- Spectra with integrated intensity below `vmin` are unchanged.
100
-
101
- References
102
- ----------
103
-
104
- .. [4] Harman RC, Lang RT, Kercher EM, Leven P, and Spring BQ.
105
- `Denoising multiplexed microscopy images in n-dimensional spectral space
106
- <https://doi.org/10.1364/BOE.463979>`_.
107
- *Biomed Opt Express*, 13(8): 4298-4309 (2022)
25
+ logging.Logger
26
+ Logger instance for 'phasorpy' namespace.
108
27
 
109
28
  Examples
110
29
  --------
111
- Denoise a hyperspectral image with a Gaussian filter width of 0.1 in
112
- spectral vector space using first and second harmonic:
113
-
114
- >>> signal = numpy.random.randint(0, 255, (8, 16, 16))
115
- >>> spectral_vector_denoise(signal, axis=0, sigma=0.1, harmonic=[1, 2])
116
- array([[[...]]])
30
+ >>> logger().info('This is a log message')
117
31
 
118
32
  """
119
- num_threads = number_threads(num_threads)
120
-
121
- signal = numpy.asarray(signal)
122
- if axis == -1 or axis == signal.ndim - 1:
123
- axis = -1
124
- else:
125
- signal = numpy.moveaxis(signal, axis, -1)
126
- shape = signal.shape
127
- samples = shape[-1]
128
-
129
- if harmonic is None:
130
- harmonic = 1
131
- harmonic, _ = parse_harmonic(harmonic, samples // 2)
132
- num_harmonics = len(harmonic)
133
-
134
- if vmin is None or vmin < 0.0:
135
- vmin = 0.0
136
-
137
- sincos = numpy.empty((num_harmonics, samples, 2))
138
- for i, h in enumerate(harmonic):
139
- phase = numpy.linspace(
140
- 0,
141
- h * math.pi * 2.0,
142
- samples,
143
- endpoint=False,
144
- dtype=numpy.float64,
145
- )
146
- sincos[i, :, 0] = numpy.cos(phase)
147
- sincos[i, :, 1] = numpy.sin(phase)
148
-
149
- signal = numpy.ascontiguousarray(signal).reshape(-1, samples)
150
- size = signal.shape[0]
151
-
152
- if dtype is None:
153
- if signal.dtype.char == 'f':
154
- dtype = signal.dtype
155
- else:
156
- dtype = numpy.float64
157
- dtype = numpy.dtype(dtype)
158
- if dtype.char not in {'d', 'f'}:
159
- raise ValueError('dtype is not floating point')
160
-
161
- if spectral_vector is None:
162
- spectral_vector = numpy.zeros((size, num_harmonics * 2), dtype=dtype)
163
- _phasor_from_signal_vector(
164
- spectral_vector, signal, sincos, num_threads
165
- )
166
- else:
167
- spectral_vector = numpy.ascontiguousarray(spectral_vector, dtype=dtype)
168
- if spectral_vector.shape[:-1] != shape[:-1]:
169
- raise ValueError('signal and spectral_vector shape mismatch')
170
- spectral_vector = spectral_vector.reshape(
171
- -1, spectral_vector.shape[-1]
172
- )
173
-
174
- if dtype == signal.dtype:
175
- denoised = signal.copy()
176
- else:
177
- denoised = numpy.zeros(signal.shape, dtype=dtype)
178
- denoised[:] = signal
179
- integrated = numpy.zeros(size, dtype=dtype)
180
- _signal_denoise_vector(
181
- denoised, integrated, signal, spectral_vector, sigma, vmin, num_threads
182
- )
183
-
184
- denoised = denoised.reshape(shape)
185
- if axis != -1:
186
- denoised = numpy.moveaxis(denoised, -1, axis)
187
- return denoised
188
-
189
-
190
- def anscombe_transformation(
191
- data: ArrayLike,
192
- /,
193
- **kwargs: Any,
194
- ) -> NDArray[Any]:
195
- r"""Return Anscombe variance-stabilizing transformation.
196
-
197
- The Anscombe transformation normalizes the standard deviation of noisy,
198
- Poisson-distributed data.
199
- It can be used to transform un-normalized phasor coordinates to
200
- approximate standard Gaussian distributions.
201
-
202
- Parameters
203
- ----------
204
- data : array_like
205
- Noisy Poisson-distributed data to be transformed.
206
- **kwargs
207
- Optional `arguments passed to numpy universal functions
208
- <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.
209
-
210
- Returns
211
- -------
212
- ndarray
213
- Anscombe-transformed data with variance of approximately 1.
214
-
215
- Notes
216
- -----
217
- The Anscombe transformation according to [1]_:
218
-
219
- .. math::
220
-
221
- z = 2 \cdot \sqrt{x + 3 / 8}
222
-
223
- References
224
- ----------
225
-
226
- .. [1] Anscombe FJ.
227
- `The transformation of Poisson, binomial and negative-binomial data
228
- <https://doi.org/10.2307/2332343>`_.
229
- *Biometrika*, 35(3-4): 246-254 (1948)
230
-
231
- Examples
232
- --------
233
-
234
- >>> z = anscombe_transformation(numpy.random.poisson(10, 10000))
235
- >>> numpy.allclose(numpy.std(z), 1.0, atol=0.1)
236
- True
237
-
238
- """
239
- return _anscombe(data, **kwargs) # type: ignore[no-any-return]
240
-
241
-
242
- def anscombe_transformation_inverse(
243
- data: ArrayLike,
244
- /,
245
- *,
246
- approx: bool = False,
247
- **kwargs: Any,
248
- ) -> NDArray[Any]:
249
- r"""Return inverse Anscombe transformation.
250
-
251
- Parameters
252
- ----------
253
- data : array_like
254
- Anscombe-transformed data.
255
- approx : bool, default: False
256
- If true, return approximation of exact unbiased inverse.
257
- **kwargs
258
- Optional `arguments passed to numpy universal functions
259
- <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.
260
-
261
- Returns
262
- -------
263
- ndarray
264
- Inverse Anscombe-transformed data.
265
-
266
- Notes
267
- -----
268
- The inverse Anscombe transformation according to [1]_:
269
-
270
- .. math::
271
-
272
- x = (z / 2.0)^2 - 3 / 8
273
-
274
- The approximate inverse Anscombe transformation according to [2]_ and [3]_:
275
-
276
- .. math::
277
-
278
- x = 1/4 \cdot z^2{2}
279
- + 1/4 \cdot \sqrt{3/2} \cdot z^{-1}
280
- - 11/8 \cdot z^{-2}
281
- + 5/8 \cdot \sqrt(3/2) \cdot z^{-3}
282
- - 1/8
283
-
284
- References
285
- ----------
286
-
287
- .. [2] Makitalo M, and Foi A.
288
- `A closed-form approximation of the exact unbiased inverse of the
289
- Anscombe variance-stabilizing transformation
290
- <https://doi.org/10.1109/TIP.2011.2121085>`_.
291
- *IEEE Trans Image Process*, 20(9): 2697-8 (2011).
292
-
293
- .. [3] Makitalo M, and Foi A
294
- `Optimal inversion of the generalized Anscombe transformation for
295
- Poisson-Gaussian noise
296
- <https://doi.org/10.1109/TIP.2012.2202675>`_,
297
- *IEEE Trans Image Process*, 22(1): 91-103 (2013)
298
-
299
- Examples
300
- --------
301
-
302
- >>> x = numpy.random.poisson(10, 100)
303
- >>> x2 = anscombe_transformation_inverse(anscombe_transformation(x))
304
- >>> numpy.allclose(x, x2, atol=1e-3)
305
- True
306
-
307
- """
308
- if approx:
309
- return _anscombe_inverse_approx( # type: ignore[no-any-return]
310
- data, **kwargs
311
- )
312
- return _anscombe_inverse(data, **kwargs) # type: ignore[no-any-return]
33
+ return logging.getLogger('phasorpy')
313
34
 
314
35
 
315
36
  def number_threads(
@@ -342,7 +63,7 @@ def number_threads(
342
63
  >>> number_threads()
343
64
  1
344
65
  >>> number_threads(0) # doctest: +SKIP
345
- 8
66
+ 8 # actual value depends on system
346
67
 
347
68
  """
348
69
  if num_threads is None or num_threads < 0:
@@ -371,3 +92,81 @@ def number_threads(
371
92
  if max_threads is None:
372
93
  return num_threads
373
94
  return min(num_threads, max(max_threads, 1))
95
+
96
+
97
+ def versions(
98
+ *, sep: str = '\n', dash: str = '-', verbose: bool = False
99
+ ) -> str:
100
+ """Return version information for PhasorPy and its dependencies.
101
+
102
+ Parameters
103
+ ----------
104
+ sep : str, optional
105
+ Separator between version items. Defaults to newline.
106
+ dash : str, optional
107
+ Separator between module name and version. Defaults to dash.
108
+ verbose : bool, optional
109
+ Include paths to Python interpreter and modules.
110
+
111
+ Returns
112
+ -------
113
+ str
114
+ Formatted string containing version information.
115
+ Format: ``"<package><dash><version>[<space>(<path>)]<sep>"``
116
+
117
+ Examples
118
+ --------
119
+ >>> print(versions()) # doctest: +SKIP
120
+ Python-3.13.5
121
+ phasorpy-0.6
122
+ numpy-2.3.1
123
+ ...
124
+
125
+ """
126
+ import importlib.metadata
127
+ import os
128
+ import sys
129
+
130
+ if verbose:
131
+ version_strings = [f'Python{dash}{sys.version} ({sys.executable})']
132
+ else:
133
+ version_strings = [f'Python{dash}{sys.version.split()[0]}']
134
+
135
+ for module in (
136
+ 'phasorpy',
137
+ 'numpy',
138
+ 'tifffile',
139
+ 'imagecodecs',
140
+ 'lfdfiles',
141
+ 'sdtfile',
142
+ 'ptufile',
143
+ 'liffile',
144
+ 'matplotlib',
145
+ 'scipy',
146
+ 'skimage',
147
+ 'sklearn',
148
+ 'pandas',
149
+ 'xarray',
150
+ 'click',
151
+ 'pooch',
152
+ ):
153
+ try:
154
+ __import__(module)
155
+ except ModuleNotFoundError:
156
+ version_strings.append(f'{module.lower()}{dash}n/a')
157
+ continue
158
+ lib = sys.modules[module]
159
+ try:
160
+ ver = importlib.metadata.version(module)
161
+ except importlib.metadata.PackageNotFoundError:
162
+ ver = getattr(lib, '__version__', 'unknown')
163
+ ver = f'{module.lower()}{dash}{ver}'
164
+ if verbose:
165
+ try:
166
+ path = getattr(lib, '__file__')
167
+ except NameError:
168
+ pass
169
+ else:
170
+ ver += f' ({os.path.dirname(path)})'
171
+ version_strings.append(ver)
172
+ return sep.join(version_strings)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: phasorpy
3
- Version: 0.5
3
+ Version: 0.7
4
4
  Summary: Analysis of fluorescence lifetime and hyperspectral images using the phasor approach
5
5
  Author: PhasorPy Contributors
6
6
  License-Expression: MIT
@@ -24,7 +24,7 @@ Classifier: Programming Language :: Python :: 3.13
24
24
  Requires-Python: >=3.11
25
25
  Description-Content-Type: text/markdown
26
26
  License-File: LICENSE.txt
27
- Requires-Dist: numpy>=1.25.0
27
+ Requires-Dist: numpy>=1.26.0
28
28
  Requires-Dist: matplotlib>=3.8.0
29
29
  Requires-Dist: scipy>=1.11.0
30
30
  Requires-Dist: click
@@ -66,7 +66,7 @@ PhasorPy is a community-maintained project.
66
66
  in the form of bug reports, bug fixes, feature implementations, documentation,
67
67
  datasets, and enhancement proposals are welcome.
68
68
 
69
- This software project is supported in part by the
69
+ This software project was supported in part by the
70
70
  [Essential Open Source Software for Science (EOSS)](https://chanzuckerberg.com/eoss/)
71
71
  program at
72
72
  [Chan Zuckerberg Initiative](https://chanzuckerberg.com/).
@@ -0,0 +1,35 @@
1
+ phasorpy/__init__.py,sha256=DLmv6dVmHfRp0yUz482irUH9Vs0g77vFkypTDGPUlGs,149
2
+ phasorpy/__main__.py,sha256=0u6C98HYfajV1RoUww8kAc0CxdsON0ijgEyTYExCSLM,149
3
+ phasorpy/_phasorpy.cp313-win_arm64.pyd,sha256=p6B22fTKKoFtjFFWrI2VmeQTQaRf-WJwA9MJ05VE-C8,913920
4
+ phasorpy/_phasorpy.pyx,sha256=I4eMejfkS_7xdGgzIXN--FZAJgns2XcbsqBRInT9XJ0,78536
5
+ phasorpy/_typing.py,sha256=ii-5-8KTs2BZq0Ytu3yJl8ejSQj1V06c1_Jcwa_2Snk,1324
6
+ phasorpy/_utils.py,sha256=8ch3zR0UTKBKEtx-nR4aMMQtrvH5p9_IDN9NeE0pYqo,23082
7
+ phasorpy/cli.py,sha256=WpmVkKbf9gtWmeip8PuewA2wLJZW4qvmCanAZRSdkXY,3692
8
+ phasorpy/cluster.py,sha256=xmV8YPkKsZfhFVFK5RV_mmqDR2klV9ideNBQ86zO028,6141
9
+ phasorpy/color.py,sha256=CGrV0qnZH_Oy2qGrWgkBvq8Bl99BDi9J9oYj-e3tp5I,17659
10
+ phasorpy/component.py,sha256=gpz-vaqnEk2VbVWz0Oq_lk57-6GijRwgA7bjODOlHWM,25338
11
+ phasorpy/conftest.py,sha256=0dCO8UZtEnhZv-JW1_vGvPZOmaihRLOo_Wc857socWI,976
12
+ phasorpy/cursor.py,sha256=NR-Lq57g4v-70zU3rETa03Vg7Jk1y8SLj-UzR__G8yU,15665
13
+ phasorpy/datasets.py,sha256=5cjUcu6jYpJQje1Qyt87p4cnAZtT7qL1vysZjo5zF0k,24972
14
+ phasorpy/experimental.py,sha256=bkQTvxtr3EU8_7f072E0VqeE6FLT9mCV9br_iTFOxZ4,9866
15
+ phasorpy/lifetime.py,sha256=lP9mD9Q6LqkwhLIt-j-2jvTPBAGZM1hLg7Eh5tw11W4,69238
16
+ phasorpy/phasor.py,sha256=HaNbbugZrgGEkyk-EBbwU_V6_v6aOB-ta1FlYpr26Xo,66892
17
+ phasorpy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
+ phasorpy/utils.py,sha256=8EbA7iGzrKREud1dLorphCAMAmXzg3YvPdbCtpKIhLE,4707
19
+ phasorpy/io/__init__.py,sha256=5cARTMKEEQvvtotWJgIAOTvEtylOKn2bZRjgzowUqRc,4920
20
+ phasorpy/io/_flimlabs.py,sha256=gX1jgsrmq18vn7EhqBEqZS9uth5zCazMq4FadU3WylE,11084
21
+ phasorpy/io/_leica.py,sha256=bQw-dLanZukUnaJmOkF9Zib0guRXCMZ9-imaKufAyf8,11037
22
+ phasorpy/io/_ometiff.py,sha256=asWEPQdD7-vacUDC-M2cpPJNVXXfNACoyNKZYrSHTFQ,15840
23
+ phasorpy/io/_other.py,sha256=pa4aJy58SDTMO_TYNL4FZ1bjXBMB21Vp-EtgLlSWBmE,28083
24
+ phasorpy/io/_simfcs.py,sha256=2_e73ge3dsSCuWnlWp-ch2MxgAtCZgyEvK_w9tOp2ks,20177
25
+ phasorpy/plot/__init__.py,sha256=fUMe18wCkopcvWiNXSwd49bqt8EltfsxcnrBpBauK8M,793
26
+ phasorpy/plot/_functions.py,sha256=66V1ozTT9vKR8a3idsmYUdToHr8-e3HHmu9-XTIvs4I,22041
27
+ phasorpy/plot/_lifetime_plots.py,sha256=GV2-OtcEGCzYJFgDQzovKZ_LKUXaHJ2bg7OaRK_6zZ0,19313
28
+ phasorpy/plot/_phasorplot.py,sha256=6N5YmO33BO0RzNw-vebbWora8PX9iSxmC6KTH5YbMmY,53449
29
+ phasorpy/plot/_phasorplot_fret.py,sha256=mS_3ILXsjzS3f-G2XRXgzHGp6aHB-pEg2j_m8JDi73o,19722
30
+ phasorpy-0.7.dist-info/licenses/LICENSE.txt,sha256=KVzeDa0MBRSUYPFFNuo7Atn6v62TiJTgGzHigltEX0o,1104
31
+ phasorpy-0.7.dist-info/METADATA,sha256=IxYy-sGKrlX8ZomLASZpDihh9fT-vIn_4anl_iaf79I,3323
32
+ phasorpy-0.7.dist-info/WHEEL,sha256=QL7uMKXoDJRpSwAf1VOVpjVXYPYll2YWTJ-omqdO8-4,101
33
+ phasorpy-0.7.dist-info/entry_points.txt,sha256=VRhsl3qGiIKwtMraKapmduchTMbdReUi1AoVTe9f3ss,47
34
+ phasorpy-0.7.dist-info/top_level.txt,sha256=4Y0uYzya5R2loleAxZ6s2n53_FysUbgFTfFaU0i9rbo,9
35
+ phasorpy-0.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp313-cp313-win_arm64
5
5