- finalized modal analysis

- Cayley transform for rotated gaussians
- all python objects now picklable
This commit is contained in:
Wim Pomp committed 2026-11-24 11:52:55 +01:00
1 parent 94e4bd3eb6
commit b3c7bf1461
15 files changed
+989 -314

No files matched your search

+4 -3
View File
@@ -14,11 +14,12 @@ os.environ["RUST_BACKTRACE"] = "full"
os.environ["COLORBT_SHOW_HIDDEN"] = "1"
from .smoll_rs import generate_stub
from .smoll_rs import detection, filter, gaussian
from .smoll_rs import detection, filter, gaussian, linalg
sys.modules["smoll.detection"] = detection
sys.modules["smoll.filter"] = filter
sys.modules["smoll.filter"] = gaussian
sys.modules["smoll.gaussian"] = gaussian
sys.modules["smoll.linalg"] = linalg
try:
__version__ = version(Path(__file__).parent.name)
@@ -34,7 +35,7 @@ except Exception: # noqa
__git_commit_hash__ = "unknown"
__all__ = ["detection", "filter", "gaussian"]
__all__ = ["detection", "filter", "gaussian", "linalg"]
def smoll_generate_stub():
+2
View File
@@ -5,12 +5,14 @@ import builtins
from . import detection
from . import filter
from . import gaussian
from . import linalg
__all__ = [
"detection",
"filter",
"gaussian",
"generate_stub",
"linalg",
]
def generate_stub(dest_path: builtins.str) -> None:
+6
View File
@@ -13,6 +13,9 @@ __all__ = [
]
class Detector:
def __new__(cls, variant: builtins.str, *args: typing.Any) -> Detector: ...
def __repr__(self) -> builtins.str: ...
def __getnewargs__(self) -> tuple[builtins.str, typing.Any]: ...
@staticmethod
def abs(threshold: builtins.float) -> Detector: ...
@staticmethod
@@ -20,6 +23,9 @@ class Detector:
def detect(self, array: numpy.typing.ArrayLike) -> numpy.typing.NDArray[numpy.uint64]: ...
class Filter:
def __new__(cls, variant: builtins.str, *args: typing.Any) -> Filter: ...
def __repr__(self) -> builtins.str: ...
def __getnewargs__(self) -> tuple[builtins.str, typing.Any]: ...
@staticmethod
def dog(lower: typing.Sequence[builtins.float], upper: typing.Sequence[builtins.float]) -> Filter: ...
@staticmethod
+107 -34
View File
@@ -7,21 +7,125 @@ import numpy.typing
import typing
__all__ = [
"BackgroundSubtraction",
"ModelAnalysis",
"ModelAnalysisResult",
"gaussian",
"gaussian_pixel_int",
"modal_analysis",
]
class BackgroundSubtraction:
def __new__(cls, t: builtins.str) -> BackgroundSubtraction: ...
def __getnewargs__(self) -> builtins.str: ...
def __repr__(self) -> builtins.str: ...
@staticmethod
def none() -> BackgroundSubtraction: ...
@staticmethod
def constant() -> BackgroundSubtraction: ...
@staticmethod
def tilted() -> BackgroundSubtraction: ...
class ModelAnalysis:
r"""
Applies the algorithm from [Thompson et al. (2002) PNAS, 82:2775].
"""
@property
def sigma(self) -> list[float]: ...
@sigma.setter
def sigma(self, value: numpy.typing.ArrayLike) -> None: ...
@property
def window_shape(self) -> list[int]: ...
@window_shape.setter
def window_shape(self, value: numpy.typing.ArrayLike) -> None: ...
@property
def max_iterations(self) -> builtins.int: ...
@max_iterations.setter
def max_iterations(self, value: builtins.int) -> None: ...
@property
def tolerance(self) -> builtins.float: ...
@tolerance.setter
def tolerance(self, value: builtins.float) -> None: ...
@property
def background_subtraction(self) -> BackgroundSubtraction: ...
@background_subtraction.setter
def background_subtraction(self, value: typing.Any) -> None: ...
@property
def fix_location(self) -> builtins.bool: ...
@fix_location.setter
def fix_location(self, value: builtins.bool) -> None: ...
def __new__(
cls,
sigma: typing.Sequence[builtins.float],
window_shape: typing.Sequence[builtins.int],
max_iterations: builtins.int = 20,
tolerance: builtins.float = 0.01,
background_subtraction: typing.Optional[typing.Any] = None,
fix_location: builtins.bool = False,
) -> ModelAnalysis: ...
def __repr__(self) -> builtins.str: ...
def __getnewargs__(
self,
) -> tuple[
builtins.list[builtins.float],
builtins.list[builtins.int],
builtins.int,
builtins.float,
builtins.str,
builtins.bool,
]: ...
def fit(self, g: numpy.typing.ArrayLike, x: numpy.typing.ArrayLike) -> ModelAnalysisResult: ...
def with_sigma(self, sigma: numpy.typing.ArrayLike) -> ModelAnalysis: ...
def with_window_shape(self, window_shape: numpy.typing.ArrayLike) -> ModelAnalysis: ...
def with_max_iterations(self, max_iterations: builtins.int) -> ModelAnalysis: ...
def with_tolerance(self, tolerance: builtins.float) -> ModelAnalysis: ...
def with_background_subtraction(self, background_subtraction: typing.Any) -> ModelAnalysis: ...
def with_fix_location(self, fix_location: builtins.bool) -> ModelAnalysis: ...
class ModelAnalysisResult:
@property
def iterations(self) -> builtins.int: ...
@property
def integrated_intensity(self) -> builtins.float: ...
@property
def position(self) -> list[float]: ...
@property
def sigma(self) -> list[float]: ...
@property
def background(self) -> list[float]: ...
def __new__(
cls,
iterations: builtins.int,
integrated_intensity: builtins.float,
position: typing.Sequence[builtins.float],
sigma: typing.Sequence[builtins.float],
background: typing.Sequence[builtins.float],
) -> ModelAnalysisResult: ...
def __repr__(self) -> builtins.str: ...
def __getnewargs__(
self,
) -> tuple[
builtins.int,
builtins.float,
builtins.list[builtins.float],
builtins.list[builtins.float],
builtins.list[builtins.float],
]: ...
def gaussian(x: numpy.typing.ArrayLike, p: numpy.typing.ArrayLike) -> numpy.typing.NDArray[numpy.float64]:
r"""
p: I, x0, x1, ... xn-1, s0, s1, ..., sn-1, r0, r1, ..., rm-1, o, o0, o1, ..., on-1
r: upper triangle without diagonal of (I-R)*(I+R)^{-1} (Cayley transform),
for 2D: theta(theta/2)
x: n 1d arrays, defining coordinates in each dimension
p: I, x0, x1, ... xn, s00, s01, ..., s0n, s10, s11, ..., s1n, ..., sn0, sn1, ..., snn, o, o0, o1, ..., on
"""
def gaussian_pixel_int(x: numpy.typing.ArrayLike, p: numpy.typing.ArrayLike) -> numpy.typing.NDArray[numpy.float64]:
r"""
p: I, x0, x1, ... xn, s00, s01, ..., s0n, s10, s11, ..., s1n, ..., sn0, sn1, ..., snn, o, o0, o1, ..., on
p: I, x0, x1, ... xn-1, s0, s1, ..., sn-1, r0, r1, ..., rm-1, o, o0, o1, ..., on-1
r: upper triangle without diagonal of (I-R)*(I+R)^{-1} (Cayley transform),
for 2D: theta(theta/2)
x: n 1d arrays, defining coordinates in each dimension
gaussian, but the signal is integrated over each pixel
Pixels are assumed to be unit hypercubes, i.e. pixel `i` in each dimension
@@ -35,34 +139,3 @@ def gaussian_pixel_int(x: numpy.typing.ArrayLike, p: numpy.typing.ArrayLike) ->
center, 1/2 on its boundary, and 0 elsewhere. Unlike `gaussian`, this works
for rank-deficient covariances.
"""
def modal_analysis(
g: numpy.typing.ArrayLike,
x: typing.Sequence[builtins.float],
s: typing.Sequence[builtins.float],
window_size: typing.Sequence[builtins.int],
n_iter: builtins.int,
tolerance: builtins.float,
background_subtraction: builtins.str,
fix_location: builtins.bool,
) -> builtins.list[builtins.float]:
r"""
Applies the algorithm from [Thompson et al. (2002) PNAS, 82:2775].
Parameters:
- g: an array with the image
- x: approximate coordinates of the spot to localize
- s: sigma
- fix_location: If 1, applied the iterative localization refinement algorithm, starting with the coordinates provided in coo. If 0, only measures the spot intensity at the coordinates provided in coo.
- background_subtraction: 0 -> no background subtraction. 1 -> constant background subtraction. 2 -> tilted plane background subtraction.
- window_size: size of the window (in pixels) around the position in coo, used for the iterative localization and for the background subtraction.
- tolerance: cutoff to determine convergence, i.e. the distance (in pixels) between two iterations
- n_iter: the maximal number of iterations.
Returns
- the intensity value of the spot.
- the coordinates of the spot.
- the backgound offset
- the tilted background
raises MaxIterations if not found after n_iter iterations
"""
+14
View File
@@ -0,0 +1,14 @@
# This file is automatically generated by pyo3_stub_gen
# ruff: noqa: E501, F401, F403, F405
import builtins
import numpy
import numpy.typing
__all__ = [
"rotation_from_skew",
"skew_from_rotation",
]
def rotation_from_skew(a: numpy.typing.ArrayLike) -> numpy.typing.NDArray[numpy.float64]: ...
def skew_from_rotation(r: numpy.typing.ArrayLike) -> builtins.list[builtins.float]: ...