locan.analysis.drift.Drift#
- class locan.analysis.drift.Drift(meta=None, chunks=None, chunk_size=None, n_chunks=None, target='first', method='icp', kwargs_chunk=None, kwargs_register=None)[source]#
Bases:
_Analysis
Estimate drift from localization coordinates by registering points in successive time-chunks of localization data using an iterative closest point algorithm (icp) or image cross-correlation algorithm (cc).
- Parameters:
locdata (LocData) – Localization data representing the source on which to perform the manipulation.
chunks (Sequence[tuple[int, ...]] | None) – Localization chunks as defined by a list of index-tuples. One of chunks, chunk_size or n_chunks must be different from None.
chunk_size (int | None) – Number of consecutive localizations to form a single chunk of data. One of chunks, chunk_size or n_chunks must be different from None.
n_chunks (int | None) – Number of chunks. One of chunks, chunk_size or n_chunks must be different from None.
target (Literal["first", "previous"]) – The chunk on which all other chunks are aligned. One of ‘first’, ‘previous’.
meta (locan.analysis.metadata_analysis_pb2.AMetadata) – Metadata about the current analysis routine.
method (Literal["cc", "icp"]) – The method used for computation. One of iterative closest point algorithm ‘icp’ or image cross-correlation algorithm ‘cc’.
bin_size (tuple) – Only for method=’cc’: Size per image pixel
kwargs_chunk (dict[str, Any] | None) – Other parameter passed to
LocData.from_chunks()
.kwargs_icp (dict[str, Any] | None) – Other parameter passed to
_register_icp_open3d()
.kwargs_cc (dict[str, Any] | None) – Other parameter passed to
register_cc()
.
- Variables:
count (int) – A counter for counting instantiations.
parameter (dict) – A dictionary with all settings for the current computation.
meta (locan.analysis.metadata_analysis_pb2.AMetadata) – Metadata about the current analysis routine.
locdata (LocData | None) – Localization data representing the source on which to perform the manipulation.
collection (LocData | None) – Collection of locdata chunks
transformations (list[Transformation] | None) – Transformations for locdata chunks
transformation_models (dict[str, list[DriftModel | DriftComponent] | None]) – The fitted model objects.
locdata_corrected (LocData | None) – Localization data with drift-corrected coordinates.
Methods
__init__
([meta, chunks, chunk_size, ...])apply_correction
([locdata, from_model])Correct drift by applying the estimated transformations to locdata.
compute
(locdata)Run the computation.
fit_transformation
([slice_data, ...])Fit drift model to selected component of the estimated transformations.
fit_transformations
([slice_data, ...])Fit model parameter to all estimated transformation components.
plot
([ax, transformation_component, ...])Plot the transformation components as function of average frame for each locdata chunk.
report
(*args, **kwargs)Show a report about analysis results.
Attributes
A counter for counting Analysis class instantiations (class attribute).
- apply_correction(locdata=None, from_model=True)[source]#
Correct drift by applying the estimated transformations to locdata.
- Parameters:
locdata (
Optional
[LocData
]) – Localization data to apply correction on. If None correction is applied to self.locdata.from_model (
bool
) – If True compute transformation matrix from fitted transformation models and apply interpolated transformations. If False use the estimated transformation matrix for each data chunk.
- Return type:
Self
- compute(locdata)[source]#
Run the computation.
- Parameters:
locdata (LocData) – Localization data representing the source on which to perform the manipulation.
- Return type:
Self
-
count:
int
= 0# A counter for counting Analysis class instantiations (class attribute).
- fit_transformation(slice_data=None, transformation_component='matrix', element=0, drift_model='linear', verbose=False)[source]#
Fit drift model to selected component of the estimated transformations.
- Parameters:
slice_data (
Optional
[slice
]) – Reduce data to a selection on the localization chunks.transformation_component (
Literal
['matrix'
,'offset'
]) – One of ‘matrix’ or ‘offset’element (
int
) – The element of flattened transformation matrix or offsetdrift_model (
UnionType
[DriftComponent
,str
,None
]) – A drift model as defined by aDriftComponent
instance or the parameter type as defined inDriftComponent
. For None no change will occur. To reset transformation_models set the transformation_component to None: e.g. self.transformation_components = None or self.transformation_components[‘matrix’] = None.verbose (
bool
) – Print the fitted model curves using lmfit.
- Return type:
Self
- fit_transformations(slice_data=None, matrix_models=None, offset_models=None, verbose=False)[source]#
Fit model parameter to all estimated transformation components.
- Parameters:
slice_data (
Optional
[slice
]) – Reduce data to a selection on the localization chunks.matrix_models (
Optional
[list
[DriftComponent
]]) – Models to use for fitting each matrix component. Length of list must be equal to the square of the transformations dimension (4 or 9). If None, no matrix transformation will be carried out when callingapply_correction()
.offset_models (
Optional
[list
[DriftComponent
]]) – Models to use for fitting each offset component. Length of list must be equal to the transformations dimension (2 or 3). If None, no offset transformation will be carried out when callingapply_correction()
.verbose (
bool
) – Print the fitted model curves.
- Return type:
Self
- plot(ax=None, transformation_component='matrix', element=None, window=1, **kwargs)[source]#
Plot the transformation components as function of average frame for each locdata chunk.
- Parameters:
ax (
Optional
[Axes
]) – The axes on which to show the imagetransformation_component (
Literal
['matrix'
,'offset'
]) – One of ‘matrix’ or ‘offset’element (
Optional
[int
]) – The element of flattened transformation matrix or offset to be plotted; if None all plots are shown.window (
int
) – Window for running average that is applied before plotting. Not implemented yet.kwargs (
Any
) – Other parameters passed tomatplotlib.pyplot.plot()
.
- Returns:
Axes object with the plot.
- Return type:
matplotlib.axes.Axes