API#

lbm_suite2p_python.get_common_path(ops_files: list | tuple)[source]#

Find the common path of all files in ops_files. If there is a single file or no common path, return the first non-empty path.

lbm_suite2p_python.load_ops(ops_input: str | Path | list[str | Path])[source]#

Simple utility load a suite2p npy file

lbm_suite2p_python.load_results_dict(ops_filepath, apply_zscore=True, z_plane=None) dict[source]#

Load stat, iscell, spks files and return as a dict

Parameters:
ops_filepathstr or Path

path to the ops.npy file.

apply_zscorebool, optional

whether to apply zscore to traces (default is False).

z_planeint or None, optional

the z-plane index for this file. If provided, it is stored in the output.

Returns:
dict
dictionary with keys:
  • ‘output_ops’: dict loaded from ops file,

  • ‘spks’: spks (2d array: neurons x time),

  • ‘stats’: stats loaded from stat.npy,

  • ‘iscell’: boolean array from iscell.npy,

  • ‘xy’: x-y positions from stats,

  • ‘z_plane’: an array (of shape [n_neurons,]) with the provided z_plane index.

lbm_suite2p_python.plot_projection(ops, savepath=None, fig_label=None, vmin=None, vmax=None, add_scalebar=False, proj='meanImg', display_masks=False, accepted_only=False)[source]#
lbm_suite2p_python.plot_rastermap(spks, model, neuron_bin_size=None, fps=17, vmin=0, vmax=0.8, xmin=0, xmax=None, save_path=None, title=None, title_kwargs={}, fig_text=None)[source]#
lbm_suite2p_python.plot_traces(f, save_path='', fps=17.0, start_neurons=20, window=120, title='', offset=None, lw=0.5, cmap='tab10', signal_units='dff')[source]#

Plot stacked fluorescence traces with automatic offset and scale bars.

Parameters:
fndarray

2d array of fluorescence traces (n_neurons x n_timepoints).

save_pathstr, optional

Path to save the output plot (default is “./stacked_traces.png”).

fpsfloat, optional

Sampling rate in frames per second (default is 17.0).

start_neuronsint, optional

Number of neurons to display (default is 20).

windowfloat, optional

Time window (in seconds) to display (default is 120).

offsetfloat or None, optional

Vertical offset between traces; if None, computed automatically.

lwfloat, optional

Line width for data points.

signal_unitsstr, optional

Units of fluorescence signal. Options: “DF/F0 %”, “DF/F0”, “raw signal” (default: “DF/F0 %”).

lbm_suite2p_python.plot_volume_signal(filepath, savepath)[source]#

Plots the mean fluorescence signal per z-plane with standard deviation error bars.

This function loads signal statistics from a .npy file and visualizes the mean fluorescence signal per z-plane, with error bars representing the standard deviation.

Parameters:
filepathstr or Path

Path to the .npy file containing the volume stats. The output of get_volume_stats().

savepathstr or Path

Path to save the generated figure.

Notes

  • The .npy file should contain structured data with plane, mean_trace, and std_trace fields.

  • Error bars represent the standard deviation of the fluorescence signal.

lbm_suite2p_python.run_plane(ops, input_file_path, save_path, save_folder=None, replot=False, dryrun=False)[source]#

Processes a single imaging plane using suite2p, handling registration, segmentation, and plotting of results.

Parameters:
opsdict

Dictionary containing suite2p parameters.

input_file_pathstr or Path

Path to the input TIFF file.

save_pathstr or Path

Directory to save the results.

save_folderstr, optional

Subdirectory for saving results (default: filename of input file).

replotbool, optional

If True, regenerates plots even if they exist (default: False).

dryrunbool, optional

If True, print input files that will be processed and filepaths that will be created.

Returns:
dict

Processed ops dictionary containing results.

Raises:
FileNotFoundError

If input_file_path does not exist.

TypeError

If save_folder is not a string.

Exception

If plotting functions fail.

lbm_suite2p_python.save_images_to_movie(image_input, savepath, duration=None, format='.mp4')[source]#

Convert a sequence of saved images into a movie.

Parameters:
image_inputstr, Path, or list

Directory containing saved segmentation images or a list of image file paths.

savepathstr or Path

Path to save the video file.

durationint, optional

Desired total video duration in seconds. If None, defaults to 1 FPS (1 image per second).

formatstr, optional

Video format: “.mp4” (PowerPoint-compatible), “.avi” (lossless), “.mov” (ProRes). Default is “.mp4”.

Examples

>>> import mbo_utilities as mbo
>>> import lbm_suite2p_python as lsp

Get all png files autosaved during LBM-Suite2p-Python run_volume() >>> segmentation_pngs = mbo.get_files(“path/suite3d/results/”, “segmentation.png”, max_depth=3) >>> lsp.save_images_to_movie(segmentation_pngs, “path/to/save/segmentation.png”, format=”.mp4”)