Metadata Processing Reference#
Complete reference for all metadata handling in LBM-Suite2p-Python.
Table of Contents#
1. Core Metadata Sources & Extraction#
Function |
File:Line |
Input |
Output Fields |
Notes |
|---|---|---|---|---|
|
mbo_utilities |
ScanImage metadata dict |
Single value (fs, nframes, etc.) |
primary metadata accessor from mbo_utilities |
|
mbo_utilities |
Metadata dict or ops |
VoxelSize object with |
returns microns/pixel; defaults to 1.0 if unavailable |
|
mbo_utilities |
ScanImage metadata |
|
determines acquisition mode from SI metadata |
|
default_ops.py:170-222 |
Optional metadata dict |
ops dict with |
merges defaults with extracted metadata |
|
default_ops.py:6-167 |
None |
Complete Suite2p default parameters |
80+ fields for registration, detection, extraction |
2. Suite2p ops Dictionary Fields#
2.1 Spatial/Dimensional Metadata#
Field |
Type |
Source |
Purpose |
|---|---|---|---|
|
int |
Binary write |
image height in pixels |
|
int |
Binary write |
image width in pixels |
|
int |
Binary size / metadata |
total frame count |
|
int |
Suite2p |
frames in functional channel |
|
int |
default_ops |
number of z-planes |
|
int |
default_ops |
channels per acquisition |
|
[int, int] |
Registration |
valid Y crop region after registration |
|
[int, int] |
Registration |
valid X crop region after registration |
|
float |
get_voxel_size |
X pixel size in microns |
|
float |
get_voxel_size |
Y pixel size in microns |
|
float |
get_voxel_size |
Z-plane spacing in microns |
|
[dx, dy, dz] |
grid_search |
combined voxel dimensions |
|
float |
default_ops |
aspect ratio (um/px X / um/px Y) |
2.2 Temporal Metadata#
Field |
Type |
Source |
Purpose |
|---|---|---|---|
|
float |
get_param(metadata, “fs”) |
frame rate in Hz (per plane) |
|
float |
default_ops (1.0) |
calcium indicator decay constant (seconds) |
|
int |
pipeline |
actual volume timepoints (frames/planes) |
|
int |
default_ops (-1) |
number of frames to process (-1=all) |
2.3 Image Metadata (Processing Results)#
Field |
Shape |
Notes |
|---|---|---|
|
(Ly, Lx) |
full-size mean projection |
|
(Ly, Lx) |
full-size enhanced mean (neuropil) |
|
(Ly, Lx) |
full-size registration reference |
|
(yrange, xrange) |
cropped max projection |
|
(yrange, xrange) |
cropped correlation map |
|
(Ly, Lx) |
standard deviation of movie |
2.4 Registration Metadata#
Field |
Type |
Purpose |
|---|---|---|
|
bool/int |
whether registration was performed |
|
bool |
compute bidirectional phase offset |
|
float |
phase offset value in pixels |
|
bool |
whether bidirectional correction applied |
|
bool |
use piecewise-rigid registration |
|
[int, int] |
patch size for nonrigid registration |
|
float |
max allowed shift as fraction of frame |
|
float |
gaussian smoothing before registration |
|
float |
temporal smoothing for reference |
|
int |
enable two-step registration (coarse then fine) |
2.5 Detection/Classification Metadata#
Field |
Type |
Purpose |
|---|---|---|
|
bool |
whether to run ROI detection |
|
int |
0=functional; 1/2/4 enable cellpose and select |
|
int/list |
expected cell diameter in pixels |
|
int/list |
original user-specified diameter (preserved) |
|
int |
ROI scale: 0=multi, 1=6px, 2=12px, 3=24px, 4=48px |
|
float |
detection threshold multiplier |
|
float |
cellpose probability threshold |
|
float |
cellpose flow error threshold |
|
bool |
use sparse detection algorithm |
|
bool |
keep ROIs fully connected |
2.6 Path Metadata#
Field |
Purpose |
|---|---|
|
plane output directory |
|
parent results directory |
|
results folder name |
|
input data path |
|
path to ops.npy |
|
path to data_raw.bin |
|
path to data.bin |
|
path to structural channel binary |
3. stat.npy Array Fields (Per-ROI Metadata)#
Field |
Type |
Purpose |
|---|---|---|
|
np.int32[] |
Y pixel coordinates of ROI |
|
np.int32[] |
X pixel coordinates of ROI |
|
np.int32[] |
Z pixel coordinates (if 3D) |
|
int |
number of pixels in ROI |
|
np.float32[] |
intensity weights (sum=1) |
|
bool[] |
mask of overlapping pixels |
|
[y, x] |
centroid position |
|
float |
median Z position (if 3D) |
|
float |
fitted radius in pixels |
|
float |
elongation metric (height/width) |
|
float |
compactness (npix / πr²) |
|
float |
mean pixel value in ROI |
|
float |
max pixel value in ROI |
|
int |
source algorithm (0=suite2p, 1=cellpose) |
|
float |
mean registration shift |
|
float |
mean rigid shift |
|
float |
mean nonrigid shift |
4. Processing History Metadata#
Function |
File:Line |
Purpose |
|---|---|---|
|
run_lsp.py:82-130 |
appends step to |
Each history entry contains:
Field |
Type |
Content |
|---|---|---|
|
str |
step name (binary_write, registration, detection, etc.) |
|
str |
ISO format datetime |
|
str |
package version |
|
str |
suite2p version |
|
list[str] |
source file paths |
|
float |
processing time |
|
dict |
step-specific metadata |
5. Format Conversion Metadata#
5.1 Suite2p to Cellpose#
Function |
File:Line |
Input |
Output |
|---|---|---|---|
|
conversion.py:269-349 |
ops.npy, stat.npy |
masks.npy, cellpose_seg.npy |
|
conversion.py:552-642 |
Suite2p dir |
{name}.tif + {name}_seg.npy |
|
conversion.py:221-246 |
stat array, shape |
label mask (0=bg, N=ROI_ID) |
cellpose_seg.npy structure:
{
"img": projection_image, # summary image
"masks": label_mask, # uint16 label image
"outlines": outline_mask, # binary outlines
"chan_choose": [0, 0], # channel selection
"ismanual": bool_array, # manual edit flags
"filename": projection_path, # source image path
"flows": flow_fields, # optical flow (or None)
"est_diam": diameter, # estimated diameter
"cellprob_threshold": float, # detection threshold
"flow_threshold": float, # flow error threshold
}
5.2 Cellpose to Suite2p#
Function |
File:Line |
Input |
Output |
|---|---|---|---|
|
conversion.py:352-465 |
masks.npy, cellpose_seg.npy |
ops.npy, stat.npy, iscell.npy |
|
conversion.py:645-728 |
edited _seg.npy |
updated stat.npy, iscell.npy |
|
conversion.py:249-266 |
label mask, image |
stat array |
conversion_meta.npy structure:
{
"source_format": "suite2p" | "cellpose",
"source_path": str,
"converted_at": ISO_timestamp,
"n_rois": int,
"shape": [Ly, Lx],
"img_key": str, # for suite2p to cellpose
"traces_extracted": bool, # for cellpose to suite2p
}
6. Validation & Comparison Metadata#
Function |
File:Line |
Returns |
|---|---|---|
|
conversion.py:31-119 |
|
|
conversion.py:731-811 |
|
7. Cell Filtering Metadata#
Function |
File:Line |
Metadata Used |
Notes |
|---|---|---|---|
|
postprocessing.py:179-314 |
|
converts µm to px via voxel size |
|
postprocessing.py:317-412 |
|
pixel count per ROI |
|
postprocessing.py:415-494 |
|
aspect ratio from bounding box |
|
postprocessing.py:497-600 |
filter config list |
returns iscell_filtered, removed_mask, filter_results |
Filter result metadata:
{
"filter_name": str,
"n_removed": int,
"n_remaining": int,
"threshold": value,
"removed_indices": array,
}
8. Multi-ROI Merging Metadata#
Function |
File:Line |
Purpose |
|---|---|---|
|
merging.py:11-44 |
groups directories by plane from pattern |
|
merging.py:105-232 |
merges ROI directories into single plane |
Coordinate transformations during merge:
stat["xpix"] += x_offset(horizontal concatenation)stat["med"][1] += x_offset(centroid update)traces concatenated along ROI axis
9. Normcorre Registration Metadata#
Function |
File:Line |
Parameters |
|---|---|---|
|
normcorre.py:35-76 |
default registration parameters |
normcorre_ops fields:
Field |
Default |
Purpose |
|---|---|---|
|
(10, 10) |
max (y, x) shift in pixels |
|
(48, 48) |
patch size for piecewise-rigid |
|
(24, 24) |
patch overlap |
|
10 |
subpixel precision |
|
3 |
threshold for rigid vs. piecewise |
|
“copy” |
how to handle borders |
|
“median” |
template computation method |
|
500 |
max frames for template |
10. dF/F Computation Metadata#
Function |
File:Line |
Metadata Parameters |
|---|---|---|
|
postprocessing.py:794-900+ |
|
Auto-calculation from metadata:
window_size = ~10 × tau × fs(baseline window)smooth_window = ~0.5 × tau × fs(temporal smoothing)
11. Cellpose Training Metadata#
Function |
File:Line |
Purpose |
|---|---|---|
|
cellpose.py |
train custom model from pretrained cpsam |
|
cellpose.py |
export images + masks for training |
|
cellpose.py |
launch GUI for manual annotation |
Training requires paired files:
{name}.tif- image file{name}_seg.npy- matching segmentation (naming convention critical)
12. File Format Metadata Storage#
Format |
Metadata Location |
Access Method |
|---|---|---|
|
Separate |
dimensions from |
|
Embedded (allow_pickle=True) |
|
|
TIFF tags + ScanImage metadata |
mbo_utilities extraction |
|
|
|
|
HDF5 attributes |
|
|
ops.json export |
|
13. Lazy Array Metadata Access#
Array Type |
Metadata Attribute |
Source |
|---|---|---|
|
|
ScanImage TIFF headers |
|
|
ScanImage JSON embedded |
|
|
inherited from base |
|
|
inherited from base |
|
|
loaded from ops.npy |
|
|
|
|
|
HDF5 attributes |
|
|
associated ops.npy |
Additional MboRawArray properties:
.fix_phase- phase correction enabled.use_fft- FFT subpixel correction.roi- current ROI mode.num_rois- total ROI count
14. Volume Statistics Metadata#
Function |
File:Line |
Collected Data |
|---|---|---|
|
volume.py:276+ |
per-plane ops aggregation |
Volume metadata structure:
{
"planes": [plane_indices],
"n_rois_per_plane": [counts],
"total_rois": int,
"voxel_size": (dx, dy, dz),
"volume_shape": (nz, ny, nx),
"processing_times": {plane: seconds},
}
15. Image Cropping/Expansion Logic#
Function |
File:Line |
Purpose |
|---|---|---|
|
conversion.py:130-206 |
handles full vs. cropped images |
Size handling:
Full-size images (
meanImg,meanImgE,refImg): Shape = (Ly, Lx)Cropped images (
max_proj,Vcorr): Shape = (yrange[1]-yrange[0], xrange[1]-xrange[0])Expansion: cropped images padded with zeros to (Ly, Lx) using
yrange,xrange
16. Metadata Normalization Functions#
Function |
File:Line |
Purpose |
|---|---|---|
|
postprocessing.py:13-17 |
converts (n, 2) to (n,) boolean |
|
postprocessing.py:1223-1249 |
loads ops from path, dir, or returns dict |
|
postprocessing.py:695-747 |
serializes numpy types for JSON export |
JSON serialization handles:
np.ndarray→listnp.integer→intnp.floating→floatnp.bool_→boolPath→str
17. Metadata Flow Diagram#
Input Files (TIFF/Zarr/HDF5)
│
▼
┌─────────────────────┐
│ mbo_utilities │
│ - get_param() │
│ - get_voxel_size() │
│ - detect_stack_type│
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ default_ops() │
│ Merge: defaults + │
│ metadata + user │
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ pipeline() │──────┐
│ - plane_ops copy │ │
│ - processing_history │
└─────────┬───────────┘ │
│ │
▼ ▼
┌─────────────────┐ ┌──────────────┐
│ Binary Write │ │ run_plane_bin│
│ Updates: Ly,Lx │ │ Suite2p core │
│ nframes, shape │ └──────┬───────┘
└─────────────────┘ │
▼
┌────────────────┐
│ Registration │
│ Updates: yrange│
│ xrange, refImg │
└────────┬───────┘
│
▼
┌────────────────┐
│ Detection │
│ Creates: stat │
│ iscell, F, Fneu│
└────────┬───────┘
│
▼
┌────────────────┐
│ Postprocessing │
│ - Cell filters │
│ - dF/F compute │
│ - Plot generate│
└────────┬───────┘
│
▼
┌────────────────┐
│ Output Files │
│ ops.npy, stat │
│ F, Fneu, spks │
│ iscell, norm │
└────────────────┘
Summary#
The ops dictionary serves as the central metadata hub in Suite2p, with additional structured data in:
stat.npy- per-ROI spatial and intensity metadataiscell.npy- classification results (n_rois, 2)F.npy,Fneu.npy,spks.npy,norm_traces.npy- trace data (n_rois, nframes)processing_history- append-only log within ops
All metadata flows through the pipeline with consistent access patterns via mbo_utilities for input extraction and numpy serialization for output storage.