Analysis (pylorenzmie.analysis)#
Mask#
- class pylorenzmie.analysis.Mask.Mask(shape=None, fraction=0.1, exclude=None)[source]#
Bases:
LMObjectPixel selection mask for subsampling a hologram during fitting.
Randomly selects a fraction of pixels for analysis, with optional exclusion of saturated, NaN, or infinite pixels. Regenerates automatically whenever
shape,fraction, orexcludeis changed.Inherits from
pylorenzmie.lib.LMObject.- Parameters:
shape (tuple[int, int], optional) –
(height, width)of the image. Default:None.fraction (float, optional) – Fraction of pixels to include. Default: 0.1.
exclude (numpy.ndarray of bool, optional) – Boolean array of pixels to force-exclude. Default:
None.
Notes
Call
update()to resample the mask without changing any parameter. Subclasses may override_select()to implement non-uniform sampling strategies.References
T. G. Dimiduk, R. W. Perry, J. Fung and V. N. Manoharan, “Random-subset fitting of digital holograms for fast three-dimensional particle tracking,” Applied Optics 53, G177–G183 (2014).
RadialMask#
- class pylorenzmie.analysis.RadialMask.RadialMask(shape=None, fraction=0.1, exclude=None)[source]#
Bases:
MaskPixel selection mask with radially-weighted sampling probability.
Overrides
Mask._select()to sample pixels with a probability that varies with radial distance from the image center.When
fraction < 0.5the image center has probability zero of being selected; probability increases toward the edges, emphasizing the outer ring fringes of a holographic pattern. Whenfraction >= 0.5all pixels have a nonzero selection probability; the distribution becomes more uniform asfraction→ 1.Inherits all parameters from
Mask.
Localizer#
- class pylorenzmie.analysis.Localizer.Localizer(diameter=31, nfringes=20)[source]#
Bases:
LMObjectDetect and localize holographic features in a normalized image.
Uses
CircleTransformto enhance ring-like patterns, then callstrackpy.locate()to find feature centers. Bounding boxes are sized to enclose a specified number of fringes.Inherits from
pylorenzmie.lib.LMObject.- Parameters:
diameter (int, optional) – Nominal feature diameter passed to
trackpy.locate[pixels]. Default: 31.nfringes (int, optional) – Number of interference fringes to enclose in each bounding box. Default: 20.
- property properties: dict[str, bool | int | float | str]#
nfringes and diameter.
- Type:
Localization parameters
- localize(image, diameter=None, nfringes=None, **kwargs)[source]#
Localize features in a normalized holographic microscopy image.
- Parameters:
image (numpy.ndarray or list of numpy.ndarray) – Normalized hologram intensity.
diameter (int, optional) – Override
diameterfor this call.nfringes (int, optional) – Override
nfringesfor this call.**kwargs – Additional keyword arguments passed to
trackpy.locate.
- Return type:
- Returns:
predictions (pandas.DataFrame) – Columns:
x_p,y_p,bbox.bboxis((x0, y0), width, height).
- detect(image, diameter=None, nfringes=None, **kwargs)#
Localize features in a normalized holographic microscopy image.
- Parameters:
image (numpy.ndarray or list of numpy.ndarray) – Normalized hologram intensity.
diameter (int, optional) – Override
diameterfor this call.nfringes (int, optional) – Override
nfringesfor this call.**kwargs – Additional keyword arguments passed to
trackpy.locate.
- Return type:
- Returns:
predictions (pandas.DataFrame) – Columns:
x_p,y_p,bbox.bboxis((x0, y0), width, height).
Estimator#
- class pylorenzmie.analysis.Estimator.Estimator(instrument, n_p=1.5, k_p=0.0)[source]#
Bases:
LMObjectEstimate initial parameters of a holographic feature.
Uses the azimuthal average of a cropped hologram to estimate the axial position and radius of the scattering particle, providing initial values for
Optimizer.Inherits from
pylorenzmie.lib.LMObject.- Parameters:
instrument (Instrument) – Optical parameters of the microscope.
n_p (float, optional) – Particle refractive index. Default: 1.5. Cannot be estimated from the azimuthal profile; serves as an initial value for the optimizer.
k_p (float, optional) – Imaginary part of the refractive index. Default: 0.
Notes
Call
estimate()to populate all particle parameters. Results are available viapropertiesafterwards.predict()is a backward-compatibility alias forestimate().This class provides a lightweight conventional-algorithm baseline. For higher-quality initial estimates — including
n_p— use the CATCH deep neural network model [1] [2].References
- instrument: Instrument#
Optimizer#
- class pylorenzmie.analysis.Optimizer.Optimizer(model=None, data=None, robust=False, fixed=None, settings=None, **kwargs)[source]#
Bases:
LMObjectFit a generative light-scattering model to holographic data.
Wraps
scipy.optimize.least_squares(). Themethodclass attribute must appear as a substring of the model’smethodstring for the pairing to be valid (e.g.'numpy'matches both'numpy'and'cupy numpy').- Parameters:
model (LorenzMie, optional) – Generative scattering model. Default:
LorenzMie().data (numpy.ndarray, optional) – Target intensities for optimization.
robust (bool, optional) – Use robust Cauchy loss instead of standard least squares. Default:
False.fixed (list[str], optional) – Names of model properties held constant during fitting. Default:
['noise', 'numerical_aperture'].settings (dict, optional) – Keyword arguments forwarded to
scipy.optimize.least_squares. Defaults to sensible values for holographic particle fitting.**kwargs – Forwarded to
LorenzMie()whenmodelis not supplied.
- result#
Fitted values and uncertainties after
optimize()has run;Nonebefore the first call.- Type:
pandas.Series or None
- metadata#
Fixed model properties and optimizer settings.
- Type:
- property properties: dict[str, bool | int | float | str]#
Optimizer settings merged with model properties.
- property settings: dict[str, bool | int | float | str]#
Settings forwarded to
scipy.optimize.least_squares.Notes
method:'lm'(Levenberg-Marquardt, default),'trf', or'dogbox'. Only'lm'supportsloss='linear'.loss:'linear'(standard LS),'cauchy','huber','soft_l1', or'arctan'.x_scale:'jac'for dynamic rescaling, or an explicit array of scales matched to the free parameters.
- property result: Series | None#
Fitted values, uncertainties, and statistics.
Returns
Nonebeforeoptimize()has been called. Each fitted parameterpappears alongsided``+``p(its uncertainty). Also includessuccess,npix, andredchi.
- optimize()[source]#
Fit model to data.
- Return type:
- Returns:
result (pandas.Series) – Fitted values, uncertainties, and goodness-of-fit statistics.
cupyOptimizer#
- class pylorenzmie.analysis.cupyOptimizer.cupyOptimizer(*args, double_precision=True, **kwargs)[source]#
Bases:
OptimizerGPU-accelerated optimizer using CuPy.
Subclass of
Optimizerthat keeps hologram computation and residual evaluation on the GPU. Only the final residual vector is transferred to the CPU for scipy’s Levenberg-Marquardt solver.Inherits from
Optimizer.- Parameters:
double_precision (bool, optional) – If True (default), use double-precision arithmetic on the GPU.
*args, **kwargs – Passed to
Optimizer.
Notes
The
methodattribute is'cupy', which is a substring ofcupyLorenzMie.method = 'cupy numpy', satisfying the optimizer compatibility check.- property data#
Feature#
- class pylorenzmie.analysis.Feature.Feature(data=None, coordinates=None, mask=None, model=None, fixed=None)[source]#
Bases:
LMObjectA holographic feature associated with a single particle.
Bundles image data, pixel coordinates, a pixel mask, a generative scattering model, an initial-parameter estimator, and an optimizer for a single particle crop.
- Parameters:
data (numpy.ndarray, optional) – Normalized hologram crop.
coordinates (numpy.ndarray, optional) – Pixel coordinates of shape
(2, npts).mask (Mask, optional) – Pixel selection mask. Default:
Mask().model (LorenzMie, optional) – Generative scattering model. Default:
LorenzMie().fixed (list[str], optional) – Model properties held constant during fitting. Default: the Optimizer default (
['noise', 'numerical_aperture']).
- property data: ndarray[tuple[Any, ...], dtype[float]] | ndarray[tuple[Any, ...], dtype[int]]#
Normalized hologram crop.
- estimate()[source]#
Estimate initial particle parameters from the hologram crop.
Sets z_p, a_p, n_p on the particle from the azimuthal profile. Sets x_p, y_p to the center of the feature in the coordinate system of
coordinates(local or frame).- Return type:
- Returns:
properties (pandas.Series) – Estimated particle properties.
- optimize()[source]#
Optimize particle parameters to fit the hologram crop.
- Return type:
- Returns:
result (pandas.Series) – Fitted values, uncertainties, and goodness-of-fit statistics.
Frame#
- class pylorenzmie.analysis.Frame.Frame(instrument=None, localizer=None, data=None)[source]#
Bases:
LMObjectFull-frame holographic microscopy analysis pipeline.
Manages detection, estimation, and optimization of all particle features in a single normalized hologram. Instrument settings are shared across all features detected in the frame.
Inherits from
pylorenzmie.lib.LMObject.- Parameters:
instrument (Instrument, optional) – Microscope parameters shared by all features. Default:
Instrument().localizer (Localizer, optional) – Feature detection backend. Default:
Localizer().data (numpy.ndarray, optional) – Normalized hologram. Setting data clears any previous detection results.
- coordinates#
Pixel coordinate grid of shape
(2, height, width).- Type:
- results#
Tracking and characterization results from the most recent
optimize()oranalyze()call.- Type:
- property properties: dict[str, bool | int | float | str]#
Adjustable parameters of this object.
Returns a flat
dictmapping parameter names to their current values. Only parameters included here are visible to the serialization methods and toOptimizerduring fitting.Subclasses must override the getter using:
@ParentClass.properties.getter def properties(self) -> Properties: props = super().properties props.update(...) return props
The base-class getter returns an empty dict; the base-class setter iterates over the supplied dict and calls
setattrfor every key that already exists as an attribute. Unknown keys are silently ignored and logged at DEBUG level.
- property data: ndarray[tuple[Any, ...], dtype[float]] | ndarray[tuple[Any, ...], dtype[int]] | None#
Normalized hologram intensity.
- property results: Series | DataFrame | list[Series | DataFrame]#
Tracking and characterization results from the most recent fit.
- detect()[source]#
Detect and localize features in
data.- Return type:
- Returns:
nfeatures (int) – Number of features found.
Trajectory#
- class pylorenzmie.analysis.Trajectory.Trajectory[source]#
Bases:
LMObjectAccumulate per-frame characterization results over time.
Each call to
append()stores one frame’s worth ofFrameoutput.datareturns the combined time series as a singlepandas.DataFrame.Inherits from
pylorenzmie.lib.LMObject.- property properties: dict[str, bool | int | float | str]#
Adjustable parameters of this object.
Returns a flat
dictmapping parameter names to their current values. Only parameters included here are visible to the serialization methods and toOptimizerduring fitting.Subclasses must override the getter using:
@ParentClass.properties.getter def properties(self) -> Properties: props = super().properties props.update(...) return props
The base-class getter returns an empty dict; the base-class setter iterates over the supplied dict and calls
setattrfor every key that already exists as an attribute. Unknown keys are silently ignored and logged at DEBUG level.
- append(results)[source]#
Append one frame of results.
- Parameters:
results (pandas.DataFrame or pandas.Series) – Output from
Frame.optimize()orFrame.analyze().- Return type: