API reference
- class napari_correct_drift.ArrayAxesStandardizer(out_order, in_order)
- This class standardizes the axes of numpy arrays by rearranging
the axes order.
Axes orders are given by strings, e. g. ‘tzcyx’
- out_order
A string representing the desired output order of the array axes.
- Type
str
- in_order
A string representing the current order of the array axes.
- Type
str
- __call__(data)
Standardizes given data array
Takes an input numpy array and standardizes the axes according to the output order. It returns the standardized array.
- Parameters
data (np.array) – A numpy array that needs to be standardized.
- Returns
A standardized numpy array.
- Return type
np.array
- Raises
AssertionError – If the shape of the input array does not match the input order.
- __init__(out_order, in_order)
Initializes the class and checks for any invalid inputs.
- Parameters
out_order (str) – A string representing the desired output order of the array axes.
in_order (str) – A string representing the current order of the array axes.
- Raises
AssertionError – If in_order contains any elements not in out_order or if out_order or in_order contains duplicates.
- inv(data)
Inverse standardization
Applies the inverse transform to the input data. The input data is expected to be a numpy array with the shape specified by the ‘out_order’ argument passed to the constructor. The output is a numpy array with the shape specified by the ‘in_order’ argument passed to the constructor.
- Parameters
data (np.array) – The input data to be transformed.
- Returns
The transformed data.
- Return type
np.array
- Raises
AssertionError – If the input data does not have the same shape
as specified by the 'out_order' argument. –
- class napari_correct_drift.CorrectDrift(data, dims)
Main drift correction class
- is_multi_channel
True if the data has multiple channels.
- Type
bool
- is_3d
True if the data has a z dimension.
- Type
bool
- dims
The dimension order of the input data.
- Type
str
- data_arranger
An ArrayAxesStandardizer instance used to rearrange the input data.
- data
The rearranged input data.
- Type
np.array
- T, C, Z, Y, X
The number of time points, channels, z-slices, rows, and columns in the input data.
- Type
int
- __init__(data, dims)
Init of main drift correction class
- Parameters
data (np.array) – image data
dims (str) – corresponding axes
- apply_drifts(offsets, extend_output=False, order=1, mode='constant')
Apply drifts to effectively create the corrected output image
- Parameters
offsets (np.array) – the drift table
extend_output (bool, optional) – if True, the output array is extended to always contain the original frame. Defaults to False.
order (int, optional) – order of interpolation (1=linear). Defaults to 1.
mode (str, optional) – border treatment. Defaults to “constant”.
- Returns
the corrected output image
- Return type
np.array
- estimate_drift(t0=0, channel=0, increment=1, upsample_factor=1, roi=None, normalization='phase', mode='relative', max_shifts=None, use_window=True)
Estimate drift entry point.
Calls _estimate_drift_relative or _estimate_drift_absolute depending on given mode
- Parameters
t0 (int, optional) – key frame. Defaults to 0.
channel (int, optional) – key channel. Defaults to 0.
increment (int, optional) – frame increment. Defaults to 1.
upsample_factor (int, optional) – upsample factor. Defaults to 1.
roi (ROIRect, optional) – ROI. Defaults to None.
normalization (str, optional) – normalization. Defaults to “phase”.
mode (str, optional) – mode of drift correction. Defaults to “relative”.
max_shifts (Tuple[int, int, int], optional) – maximum allowed shifts. Defaults to None.
use_winsow (bool) – use Hann window to prevent spectral leakage. Defautls to True.
- Raises
AttributeError – if mode is not supported
- interpolate_drift(offsets)
Linear interpolation of missing values given as np.nan values
- Parameters
offsets (np.array) – The drift table containing missing values (np.nan)
- Raises
RuntimeError – When too few values for interpolation
- Returns
offsets with linearly interpolated values
- Return type
offsets (np.array)
- class napari_correct_drift.CorrectDriftDock(napari_viewer)
Main user interface for Napari-Correct-Drift.
The main widget is structured in several groups:
Input Axes: Select napari layer to process
Correct Drift: Estimate, load or correct drift
Key Frames: Set the key frames and mode for correction
Parameters: Set Parameters of the drift correction
Outliers: Handle outlier drifts
- __init__(napari_viewer)
- class napari_correct_drift.ROIRect(x_min, x_max, y_min, y_max, z_min, z_max, t0, c0)
Helper classes for 3D bounding-box, localized in channels and time
- x_min, x_max, y_min, y_max, z_min, z_max
special boundaries of the ROI rectangle.
- Type
int
- t0
frame index
- Type
int
- c0
channel index
- Type
int
- __init__(x_min, x_max, y_min, y_max, z_min, z_max, t0, c0)
- classmethod from_bbox(bbox, t0, c0)
Creates ROIRect from from bounding box list:
[z_min, z_max, y_min, y_max, x_min, x_max,]
- Parameters
bbox (np.array) – bounding box
t0 (int) – key frame
c0 (int) – key channel
- classmethod from_shape_poly(shape_poly, dims, z_min, z_max)
Creates ROIRect from napari shape polygon
- Parameters
shape_poly (np.array) – napari polygon shape
dims (str) – dimensions string
z_min (int) – z min
z_max (int) – z max
- class napari_correct_drift.TableWidget(ist=None, viewer=None)
A editable table widget containing the estimated drifts.
The underlying table data can be saved or copied to clipboard.
- __init__(ist=None, viewer=None)
- napari_correct_drift.sample_2d()
Creates 2D + time example data
- napari_correct_drift.sample_3d()
Creates 3D + time example data
- napari_correct_drift.sample_3d_ch()
Creates 2D + channel + time example data
- napari_correct_drift.window_nd(shape, win_func=<function hann>)
N-dimensional windowing using 1d win_func. Default Hann window.
Note 1: shape should be at least 2d
Note 2: this function is cached.
- Parameters
shape (Tuple[int, ...]) – Desired output shape
win_func (Callable, optional) – 1d Window function as in scipy.signal.windows. Defaults to windows.hann.
- Returns
Array with applied window function.
- Return type
np.array
- Return type
array