smlmlp.locs_individual_gaussfit module
- smlmlp.locs_individual_gaussfit(crops, X0, Y0, /, ch=None, *, optimizer='lm', estimator='mle', distribution='poisson', channels_pixels_nm=1.0, channels_gains=1.0, channels_QE=1.0, cuda=False, parallel=False, channels_psf_xsigmas_nm=93.8, channels_psf_ysigmas_nm=93.8, channels_psf_thetas_deg=0.0, channels_fit_thetas=False)[source]
Fit each crop independently with an anisotropic 2D Gaussian model.
The function loops through channels, initializes a
funclp.Gaussian2Dmodel per event, runs the selected optimizer/estimator combination, and returns localized coordinates with fitted parameters.- Parameters:
crops (sequence of array-like) – Sequence of crop stacks, one per channel, shaped
(N, Y, X).X0 (array-like) – Detection-aligned 1D vector of x-origin pixel indices.
Y0 (array-like) – Detection-aligned 1D vector of y-origin pixel indices.
ch (array-like or None, optional) – One-based channel index for each detection. Required when
cropshas several channels.optimizer (str, optional) – Optimizer key.
estimator (str, optional) – Estimator key.
distribution (str, optional) – Distribution key used by the estimator.
channels_pixels_nm (float or sequence, optional) – Pixel size specification per channel.
channels_gains (float or sequence, optional) – Gain value(s) used to convert fitted amplitudes.
channels_QE (float or sequence, optional) – Quantum efficiency value(s) used to convert fitted amplitudes.
cuda (bool, optional) – Whether to run the fit on GPU.
parallel (bool, optional) – Whether to enable CPU parallelization.
channels_psf_xsigmas_nm (float or sequence, optional) – Initial/fixed PSF sigma along x for each channel.
channels_psf_ysigmas_nm (float or sequence, optional) – Initial/fixed PSF sigma along y for each channel.
channels_psf_thetas_deg (float or sequence, optional) – Initial/fixed PSF angle in degrees for each channel.
channels_fit_thetas (bool, optional) – Whether to fit the PSF rotation angle.
- Returns:
A tuple
(mux, muy, info)where:muxis the detection-aligned x localization array in nanometers,muyis the detection-aligned y localization array in nanometers,infois a dictionary with fitted parameter arrays.
infocontains:'amp'Detection-aligned converted amplitudes.
'offset'Detection-aligned converted offsets.
'sigmax'Detection-aligned fitted x sigmas.
'sigmay'Detection-aligned fitted y sigmas.
- Return type:
tuple
Notes
X0andY0are split bychso each origin vector follows the crop order inside its channel stack.A local coordinate grid is built from the channel pixel size, and each anisotropic Gaussian is initialized at the crop center.
The optimizer updates local Gaussian parameters, local coordinates are shifted by crop origins, and all outputs are remapped to detection order.
Examples
>>> import numpy as np >>> crops = [np.random.rand(2, 7, 7).astype(np.float32)] >>> x0 = np.array([10, 20], dtype=np.float32) >>> y0 = np.array([30, 40], dtype=np.float32) >>> mux, muy, info = locs_individual_gaussfit( ... crops, ... x0, ... y0, ... channels_pixels_nm=[(100.0, 100.0)], ... channels_psf_xsigmas_nm=[90.0], ... channels_psf_ysigmas_nm=[90.0], ... ) >>> mux.shape == muy.shape True >>> sorted(info) ['amp', 'offset', 'sigmax', 'sigmay']
>>> mux, muy, info = locs_individual_gaussfit( ... crops, ... x0, ... y0, ... channels_pixels_nm=[(100.0, 120.0)], ... channels_psf_xsigmas_nm=[80.0], ... channels_psf_ysigmas_nm=[95.0], ... channels_psf_thetas_deg=[5.0], ... channels_fit_thetas=True, ... ) >>> info['sigmax'].ndim 1