API#
- lbm_caiman_python.add_processing_step(ops, step_name, input_files=None, duration_seconds=None, extra=None)[source]#
Append a processing step record to
ops['processing_history'].
- lbm_caiman_python.combine_z_planes(results: dict)[source]#
Combines all z-planes in the results dictionary into a single estimates object.
- Parameters:
- results (dict): Dictionary with estimates for each z-plane.
- Returns:
- estimates.Estimates: Combined estimates for all z-planes.
- lbm_caiman_python.compute_roi_stats(plane_dir) dict[source]#
compute roi quality statistics.
- Parameters:
- plane_dirstr or Path
path to plane output directory.
- Returns:
- dict
dictionary of roi statistics.
- lbm_caiman_python.default_ops() dict[source]#
return default caiman parameters optimized for lbm microscopy data.
- Returns:
- dict
dictionary of parameters for motion correction and cnmf.
- lbm_caiman_python.dff_rolling_percentile(F: ndarray, window_size: int = None, percentile: int = 20, smooth_window: int = None, fs: float = 30.0, tau: float = 1.0) ndarray[source]#
compute dF/F using rolling percentile baseline.
- Parameters:
- Fnp.ndarray
fluorescence traces, shape (n_cells, n_frames).
- window_sizeint, optional
frames for rolling percentile. default: ~10*tau*fs.
- percentileint, default 20
percentile for baseline F0.
- smooth_windowint, optional
smoothing window for dF/F.
- fsfloat, default 30.0
frame rate in Hz.
- taufloat, default 1.0
decay time constant in seconds.
- Returns:
- np.ndarray
dF/F traces, same shape as F.
- lbm_caiman_python.extract_center_square(images, size)[source]#
Extract a square crop from the center of the input images.
- Parameters:
- imagesnumpy.ndarray
Input array. Can be 2D (H x W) or 3D (T x H x W), where: - H is the height of the image(s). - W is the width of the image(s). - T is the number of frames (if 3D).
- sizeint
The size of the square crop. The output will have dimensions (size x size) for 2D inputs or (T x size x size) for 3D inputs.
- Returns:
- numpy.ndarray
A square crop from the center of the input images. The returned array will have dimensions: - (size x size) if the input is 2D. - (T x size x size) if the input is 3D.
- Raises:
- ValueError
If images is not a NumPy array. If images is not 2D or 3D. If the specified size is larger than the height or width of the input images.
Notes
For 2D arrays, the function extracts a square crop directly from the center.
For 3D arrays, the crop is applied uniformly across all frames (T).
If the input dimensions are smaller than the requested size, an error will be raised.
Examples
Extract a center square from a 2D image:
>>> import numpy as np >>> image = np.random.rand(600, 576) >>> cropped = extract_center_square(image, size=200) >>> cropped.shape (200, 200)
Extract a center square from a 3D stack of images:
>>> stack = np.random.rand(100, 600, 576) >>> cropped_stack = extract_center_square(stack, size=200) >>> cropped_stack.shape (100, 200, 200)
- lbm_caiman_python.generate_patch_view(image: Any, pixel_resolution: float, target_patch_size: int = 40, overlap_fraction: float = 0.5)[source]#
Generate a patch visualization for a 2D image with approximately square patches of a specified size in microns. Patches are evenly distributed across the image, using calculated strides and overlaps.
- Parameters:
- imagendarray
A 2D NumPy array representing the input image to be divided into patches.
- pixel_resolutionfloat
The pixel resolution of the image in microns per pixel.
- target_patch_sizefloat, optional
The desired size of the patches in microns. Default is 40 microns.
- overlap_fractionfloat, optional
The fraction of the patch size to use as overlap between patches. Default is 0.5 (50%).
- Returns:
- figmatplotlib.figure.Figure
A matplotlib figure containing the patch visualization.
- axmatplotlib.axes.Axes
A matplotlib axes object showing the patch layout on the image.
Examples
>>> import numpy as np >>> from matplotlib import pyplot as plt >>> data = np.random.random((144, 600)) # Example 2D image >>> pixel_resolution = 0.5 # Microns per pixel >>> fig, ax = generate_patch_view(data, pixel_resolution) >>> plt.show()
- lbm_caiman_python.generate_plane_dirname(plane, nframes=None, frame_start=1, frame_stop=None, suffix=None)[source]#
Generate
zplaneNN[_tpSTART-STOP][_suffix]directory name.
- lbm_caiman_python.get_accepted_cells(plane_dir) tuple[source]#
get indices of accepted and rejected cells.
- Parameters:
- plane_dirstr or Path
path to plane output directory.
- Returns:
- tuple
(accepted_indices, rejected_indices)
- lbm_caiman_python.get_contours(plane_dir, threshold: float = 0.5) list[source]#
get cell contours for visualization.
- Parameters:
- plane_dirstr or Path
path to plane output directory.
- thresholdfloat, default 0.5
threshold for contour extraction (fraction of max).
- Returns:
- list
list of contour coordinates for each cell.
- lbm_caiman_python.get_noise_fft(Y, noise_range=None, noise_method='logmexp', max_num_samples_fft=3072)[source]#
Compute the noise level in the Fourier domain for a given signal.
- Parameters:
- Yndarray
Input data array. The last dimension is treated as time.
- noise_rangelist of float, optional
Frequency range to estimate noise, by default [0.25, 0.5].
- noise_methodstr, optional
Method to compute the mean noise power spectral density (PSD), by default “logmexp”.
- max_num_samples_fftint, optional
Maximum number of samples to use for FFT computation, by default 3072.
- Returns:
- tuple
- snfloat or ndarray
Estimated noise level.
- psdxndarray
Power spectral density of the input data.
- lbm_caiman_python.get_single_patch_coords(dims, stride, overlap, patch_index)[source]#
Get coordinates of a single patch based on stride, overlap parameters of motion-correction.
- Parameters:
- dimstuple
Dimensions of the image as (rows, cols).
- strideint
Number of pixels to include in each patch.
- overlapint
Number of pixels to overlap between patches.
- patch_indextuple
Index of the patch to return.
- lbm_caiman_python.greedyROI(Y, nr=30, gSig=[5, 5], gSiz=[11, 11], nIter=5, kernel=None, nb=1, rolling_sum=False, rolling_length=100, seed_method='auto')[source]#
Greedy initialization of spatial and temporal components using spatial Gaussian filtering
- Parameters:
Y – np.array 3d or 4d array of fluorescence data with time appearing in the last axis.
nr – int number of components to be found
gSig – scalar or list of integers standard deviation of Gaussian kernel along each axis
gSiz – scalar or list of integers size of spatial component
nIter – int number of iterations when refining estimates
kernel – np.ndarray User specified kernel to be used, if present, instead of Gaussian (default None)
nb – int Number of background components
rolling_max – boolean Detect new components based on a rolling sum of pixel activity (default: True)
rolling_length – int Length of rolling window (default: 100)
seed_method – str {‘auto’, ‘manual’, ‘semi’} methods for choosing seed pixels ‘semi’ detects nr components automatically and allows to add more manually if running as notebook ‘semi’ and ‘manual’ require a backend that does not inline figures, e.g. %matplotlib tk
- Returns:
- np.array
2d array of size (# of pixels) x nr with the spatial components. Each column is ordered columnwise (matlab format, order=’F’)
- C: np.array
2d array of size nr X T with the temporal components
- center: np.array
2d array of size nr x 2 [ or 3] with the components centroids
- Return type:
A
- Author:
- Eftychios A. Pnevmatikakis and Andrea Giovannucci based on a matlab implementation by Yuanjun Gao
Simons Foundation, 2015
- lbm_caiman_python.load_ops(ops_input) dict[source]#
load ops from file or return dict as-is.
- Parameters:
- ops_inputstr, Path, dict, or None
path to ops.npy file, dictionary, or None.
- Returns:
- dict
ops dictionary.
- lbm_caiman_python.load_planar_results(plane_dir) dict[source]#
load all results from a plane directory.
- Parameters:
- plane_dirstr or Path
path to plane output directory.
- Returns:
- dict
dictionary containing ops, estimates, F, dff, etc.
- lbm_caiman_python.pipeline(input_data, save_path: str | Path = None, ops: dict = None, planes: list | int = None, roi_mode: int = None, keep_reg: bool = True, keep_raw: bool = False, force_reg: bool = False, force_detect: bool = False, num_timepoints: int = None, frame_indices: list = None, dff_window_size: int = None, dff_percentile: int = 20, dff_smooth_window: int = None, correct_neuropil: bool = True, accept_all_cells: bool = False, save_json: bool = False, reader_kwargs: dict = None, writer_kwargs: dict = None, rastermap_kwargs: dict = None, **kwargs) list[source]#
Auto-detect 3D vs 4D input and dispatch to
run_plane/run_volume.Mirrors
lbm_suite2p_python.pipeline()with CaImAn-specific extras (force_mcorr/force_cnmfaccepted as legacy aliases forforce_reg/force_detect).
- lbm_caiman_python.run_plane(input_data, save_path: str | Path = None, ops: dict = None, keep_reg: bool = True, keep_raw: bool = False, force_reg: bool = False, force_detect: bool = False, frame_indices: list = None, dff_window_size: int = None, dff_percentile: int = 20, dff_smooth_window: int = None, correct_neuropil: bool = True, accept_all_cells: bool = False, save_json: bool = False, rastermap_kwargs: dict = None, plane_name: str = None, reader_kwargs: dict = None, writer_kwargs: dict = None, _volume_plane_idx: int = None, **kwargs) Path[source]#
Process a single imaging plane with CaImAn and emit suite2p-format outputs.
- lbm_caiman_python.run_volume(input_data, save_path: str | Path = None, ops: dict = None, planes: list | int = None, keep_reg: bool = True, keep_raw: bool = False, force_reg: bool = False, force_detect: bool = False, frame_indices: list = None, dff_window_size: int = None, dff_percentile: int = 20, dff_smooth_window: int = None, correct_neuropil: bool = True, accept_all_cells: bool = False, save_json: bool = False, rastermap_kwargs: dict = None, reader_kwargs: dict = None, writer_kwargs: dict = None, **kwargs) list[source]#
Run the pipeline on a volumetric input, one plane at a time.
Each plane gets its own
zplaneNNsubdirectory undersave_path. After all planes complete, volume-level stats and figures are written via the lsp helpers.