sl-shared-assets 1.0.0rc20__py3-none-any.whl → 1.0.0rc21__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sl-shared-assets might be problematic. Click here for more details.
- sl_shared_assets/__init__.py +27 -27
- sl_shared_assets/__init__.pyi +24 -22
- sl_shared_assets/cli.py +266 -40
- sl_shared_assets/cli.pyi +73 -14
- sl_shared_assets/data_classes/__init__.py +23 -20
- sl_shared_assets/data_classes/__init__.pyi +18 -18
- sl_shared_assets/data_classes/configuration_data.py +407 -26
- sl_shared_assets/data_classes/configuration_data.pyi +172 -15
- sl_shared_assets/data_classes/runtime_data.py +49 -43
- sl_shared_assets/data_classes/runtime_data.pyi +37 -40
- sl_shared_assets/data_classes/session_data.py +168 -914
- sl_shared_assets/data_classes/session_data.pyi +55 -350
- sl_shared_assets/data_classes/surgery_data.py +3 -3
- sl_shared_assets/data_classes/surgery_data.pyi +2 -2
- sl_shared_assets/tools/__init__.py +8 -1
- sl_shared_assets/tools/__init__.pyi +11 -1
- sl_shared_assets/tools/ascension_tools.py +27 -26
- sl_shared_assets/tools/ascension_tools.pyi +5 -5
- sl_shared_assets/tools/packaging_tools.py +14 -1
- sl_shared_assets/tools/packaging_tools.pyi +4 -0
- sl_shared_assets/tools/project_management_tools.py +164 -0
- sl_shared_assets/tools/project_management_tools.pyi +48 -0
- {sl_shared_assets-1.0.0rc20.dist-info → sl_shared_assets-1.0.0rc21.dist-info}/METADATA +21 -4
- sl_shared_assets-1.0.0rc21.dist-info/RECORD +36 -0
- sl_shared_assets-1.0.0rc21.dist-info/entry_points.txt +8 -0
- sl_shared_assets/suite2p/__init__.py +0 -8
- sl_shared_assets/suite2p/__init__.pyi +0 -4
- sl_shared_assets/suite2p/multi_day.py +0 -224
- sl_shared_assets/suite2p/multi_day.pyi +0 -104
- sl_shared_assets/suite2p/single_day.py +0 -564
- sl_shared_assets/suite2p/single_day.pyi +0 -220
- sl_shared_assets-1.0.0rc20.dist-info/RECORD +0 -40
- sl_shared_assets-1.0.0rc20.dist-info/entry_points.txt +0 -4
- {sl_shared_assets-1.0.0rc20.dist-info → sl_shared_assets-1.0.0rc21.dist-info}/WHEEL +0 -0
- {sl_shared_assets-1.0.0rc20.dist-info → sl_shared_assets-1.0.0rc21.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,564 +0,0 @@
|
|
|
1
|
-
"""This module stores the classes used to configure the single-day (within-session) sl-suite2p pipeline. This is the
|
|
2
|
-
'original' suite2p pipeline used to process brain activity data collected as part of a single continuous recording. It
|
|
3
|
-
is used as the first step of the multi-day brain activity processing pipeline used in the lab. Both single-day
|
|
4
|
-
(original) and multi-day (extended) pipelines are available as part of the Sun lab maintained sl-suite2p package."""
|
|
5
|
-
|
|
6
|
-
from typing import Any
|
|
7
|
-
from pathlib import Path
|
|
8
|
-
from dataclasses import field, asdict, dataclass
|
|
9
|
-
|
|
10
|
-
import numpy as np
|
|
11
|
-
from ataraxis_base_utilities import ensure_directory_exists
|
|
12
|
-
from ataraxis_data_structures import YamlConfig
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@dataclass
|
|
16
|
-
class Main:
|
|
17
|
-
"""Stores global parameters that broadly define the suite2p single-day processing configuration."""
|
|
18
|
-
|
|
19
|
-
nplanes: int = 1
|
|
20
|
-
"""The number of imaging planes, stored as a sequence inside each input TIFF file."""
|
|
21
|
-
|
|
22
|
-
nchannels: int = 1
|
|
23
|
-
"""The number of imaging channels per imaging plane. Typically, this is either 1 or 2. The algorithm expects images
|
|
24
|
-
from different channels of the same plane to be saved sequentially (e.g.: plane 1 ch1, plane 1 ch2, plane 2 ch1,
|
|
25
|
-
etc.)."""
|
|
26
|
-
|
|
27
|
-
functional_chan: int = 1
|
|
28
|
-
"""The channel used for extracting functional ROIs (cells). Note, this parameter uses 1-based indexing, where '1'
|
|
29
|
-
means the first channel and '2' means the second channel."""
|
|
30
|
-
|
|
31
|
-
tau: float = 0.4
|
|
32
|
-
"""The timescale of the sensor, in seconds, used for computing the deconvolution kernel. The kernel is fixed to
|
|
33
|
-
have this decay and is not fit to the data. Note, the default value is optimized for GCaMP6f animals recorded with
|
|
34
|
-
the Mesoscope and likely needs to be increased for most other use cases."""
|
|
35
|
-
|
|
36
|
-
force_sktiff: bool = True
|
|
37
|
-
"""Determines whether to force the use of scikit-image (tifffile) for reading TIFF files. Generally, it is
|
|
38
|
-
recommended to have this enabled as it forces suite2p to use the tifffile library, which is compatible with more
|
|
39
|
-
formats than ScanImage tiff reader. In the future, this option may be deprecated in favor of tifffile altogether."""
|
|
40
|
-
|
|
41
|
-
fs: float = 10.0014
|
|
42
|
-
"""The sampling rate per plane in Hertz. For instance, if you have a 10-plane recording acquired at 30Hz, then the
|
|
43
|
-
sampling rate per plane is 3Hz, so set this to 3."""
|
|
44
|
-
|
|
45
|
-
do_bidiphase: bool = False
|
|
46
|
-
"""Determines whether to perform the computation of bidirectional phase offset for misaligned line scanning
|
|
47
|
-
experiments (applies to two-photon recordings only)."""
|
|
48
|
-
|
|
49
|
-
bidiphase: int = 0
|
|
50
|
-
"""The user-specified bidirectional phase offset for line scanning experiments. If set to any value besides 0, then
|
|
51
|
-
this offset is used and applied to all frames in the recording when 'do_bidiphase' is True. If set to 0, then the
|
|
52
|
-
suite2p will estimate the bidirectional phase offset automatically from ‘nimg_init’ frames. The computed or
|
|
53
|
-
user-defined offset is applied to all frames before the main processing pipeline."""
|
|
54
|
-
|
|
55
|
-
bidi_corrected: bool = False
|
|
56
|
-
"""Tracks whether bidirectional phase correction has been applied to the registered dataset. This argument is
|
|
57
|
-
generally not meant to be set by the user and is instead written automatically when the algorithm performs
|
|
58
|
-
the bidirectional phase offset correction."""
|
|
59
|
-
|
|
60
|
-
frames_include: int = -1
|
|
61
|
-
"""Determines the number of frames of the session's movie to process for each plane. If set to 0, the suite2p will
|
|
62
|
-
not do any processing. If negative (-1), the suite2p will process all available frames."""
|
|
63
|
-
|
|
64
|
-
multiplane_parallel: bool = False
|
|
65
|
-
"""Determines whether to parallelize plane processing for multi-plane data. Note, plane processing contains some
|
|
66
|
-
steps that are automatically parallelized to use all available cores and other that are sequential. Due to this
|
|
67
|
-
mixture of steps, processing planes in parallel results in noticeably higher processing speeds, but also increases
|
|
68
|
-
the memory (RAM) overhead and average CPU core utilization. Generally, it is recommended to enable this option on
|
|
69
|
-
machines with sufficient RAM capacity and CPU core pool size."""
|
|
70
|
-
|
|
71
|
-
parallel_planes: int = 3
|
|
72
|
-
"""Determines the maximum number of planes to process in parallel when 'multiplane_parallel' is True. Note, due to
|
|
73
|
-
some processing steps being automatically parallelized, this parameter mostly controls the overall core utilization
|
|
74
|
-
and RAM overhead. Each parallel plane task will at times try to use all available cores. There are diminishing
|
|
75
|
-
returns when setting it to very high values. Most machines should have this set to a value between 3 and 9."""
|
|
76
|
-
|
|
77
|
-
ignore_flyback: list[int] = field(default_factory=list)
|
|
78
|
-
"""The list of 'flyback' plane indices to ignore when processing the data. Flyback planes typically contain no valid
|
|
79
|
-
imaging data, so it is common to exclude them from processing."""
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
@dataclass
|
|
83
|
-
class FileIO:
|
|
84
|
-
"""Stores general I/O parameters that specify input data location, format, and working and output directories."""
|
|
85
|
-
|
|
86
|
-
fast_disk: str = ""
|
|
87
|
-
"""The path to the root 'working' directory where to store the temporary binary files created during processing.
|
|
88
|
-
This field allows optimizing processing on machines with slow storage drives and fast NVME 'work' drives by caching
|
|
89
|
-
all data on the fast drive during runtime. Do not modify this field unless your use case specifically benefits
|
|
90
|
-
from caching the data on a different drive than the one that stores the raw data. If this field is not modified,
|
|
91
|
-
'save_path0' is used to store the temporary files."""
|
|
92
|
-
|
|
93
|
-
delete_bin: bool = False
|
|
94
|
-
"""Determines whether to delete the binary file(s) created during the frame registration stage (registered .bin
|
|
95
|
-
file). Note, if the data produced by the 'single-day' pipeline is intended to be later processed as part of the
|
|
96
|
-
'multi-day' pipeline, this has to be False. The multi-day pipeline reuses the registered binary files to extract
|
|
97
|
-
the fluorescence of cells tracked across days."""
|
|
98
|
-
|
|
99
|
-
mesoscan: bool = True
|
|
100
|
-
"""Indicates whether the data submitted to the pipeline are ScanImage Mesoscope multi-page TIFFs."""
|
|
101
|
-
|
|
102
|
-
bruker: bool = False
|
|
103
|
-
"""Indicates whether the data submitted to the pipeline are single-page BRUKER TIFFs."""
|
|
104
|
-
|
|
105
|
-
bruker_bidirectional: bool = False
|
|
106
|
-
"""Indicates whether BRUKER files contain bidirectional multiplane recordings."""
|
|
107
|
-
|
|
108
|
-
h5py: list[str] = field(default_factory=list)
|
|
109
|
-
"""The list of paths to h5py (.hdf / .h5) files to use as pipeline inputs, if the input data uses .h5 format. If
|
|
110
|
-
provided, these paths overwrite the 'data_path' field."""
|
|
111
|
-
|
|
112
|
-
h5py_key: str = "data"
|
|
113
|
-
"""The key used to access the frame data array inside each input file specified by 'h5py' field paths. This should
|
|
114
|
-
only be provided if 'h5py' is not set to an empty list."""
|
|
115
|
-
|
|
116
|
-
nwb_file: str = ""
|
|
117
|
-
"""The path to the NWB file to use as pipeline input."""
|
|
118
|
-
|
|
119
|
-
nwb_driver: str = ""
|
|
120
|
-
"""The location or name of the driver to use for reading the NWB file."""
|
|
121
|
-
|
|
122
|
-
nwb_series: str = ""
|
|
123
|
-
"""The name of the TwoPhotonSeries in the NWB file from which to retrieve the data."""
|
|
124
|
-
|
|
125
|
-
save_path0: str = ""
|
|
126
|
-
"""The path to the root output directory where the pipeline results should be saved. Note, the pipeline generates
|
|
127
|
-
the 'save_folder' under the root directory specified by this argument and output all data to the generated save
|
|
128
|
-
folder."""
|
|
129
|
-
|
|
130
|
-
save_folder: str = "suite2p"
|
|
131
|
-
"""The name of the folder under which the pipeline results should be stored. If this is not provided, the pipeline
|
|
132
|
-
defaults to using 'suite2p' as the save directory, created under the root directory specified by 'save_path0'. Note,
|
|
133
|
-
if the data produced by the 'single-day' pipeline is intended to be later processed as part of the 'multi-day'
|
|
134
|
-
pipeline, do NOT modify this field. The multi-day pipeline expects the save_folder to be 'suite2p' (default)."""
|
|
135
|
-
|
|
136
|
-
data_path: list[str] = field(default_factory=list)
|
|
137
|
-
"""The list of paths to the directories where to search for the input TIFF files. This is used during the initial
|
|
138
|
-
conversion of the raw data (expected to be .tiff / .tif) to the binary file format used by the suite2p pipeline."""
|
|
139
|
-
|
|
140
|
-
look_one_level_down: bool = False
|
|
141
|
-
"""Determines whether to search for TIFF files in the subfolders of the directories provided as 'data_path' field.
|
|
142
|
-
If True, the 'subfolders' field has to be set to a valid list of subfolder names to search."""
|
|
143
|
-
|
|
144
|
-
subfolders: list[str] = field(default_factory=list)
|
|
145
|
-
"""Stores specific subfolder names to search through for TIFF files. All subfolders must be stored under the
|
|
146
|
-
one or more directories specified by 'data_path'."""
|
|
147
|
-
|
|
148
|
-
move_bin: bool = False
|
|
149
|
-
"""Determines whether to move the binary file(s) to the save directory after processing, if 'fast_disk' differs
|
|
150
|
-
from the 'save_path0'. Note, if using non-default 'save_folder' name, enabling this option will move the binary
|
|
151
|
-
files from the temporary 'suite2p' folder to the 'save_folder'. Otherwise, if the save folder and the temporary
|
|
152
|
-
folder are both 'suite2p', the binaries are automatically created and stored inside the 'save_folder'."""
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
@dataclass
|
|
156
|
-
class Output:
|
|
157
|
-
"""Stores parameters for aggregating and saving the processing results of each plane as a unified directory or
|
|
158
|
-
file."""
|
|
159
|
-
|
|
160
|
-
save_nwb: bool = False
|
|
161
|
-
"""Determines whether to save the single-session pipeline output as an NWB file."""
|
|
162
|
-
|
|
163
|
-
save_mat: bool = False
|
|
164
|
-
"""Determines whether to save the single-session pipeline output as a MATLAB file (e.g., Fall.mat)."""
|
|
165
|
-
|
|
166
|
-
combined: bool = True
|
|
167
|
-
"""Determines whether to combine results across planes into a 'combined' folder at the end of processing. If the
|
|
168
|
-
results of the single-day pipeline are intended to be later processed as part of the multi-day pipeline, this has
|
|
169
|
-
to be True. This option is safe to use even with single-plane data."""
|
|
170
|
-
|
|
171
|
-
aspect: float = 0.666666666
|
|
172
|
-
"""The pixel-to-micron ratio (X:Y) used in the GUI to ensure all images are displayed correctly. This field is not
|
|
173
|
-
used during headless processing."""
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
@dataclass
|
|
177
|
-
class Registration:
|
|
178
|
-
"""Stores parameters for rigid registration, which is used to correct motion artifacts between frames by
|
|
179
|
-
counter-shifting the entire frame."""
|
|
180
|
-
|
|
181
|
-
do_registration: bool = True
|
|
182
|
-
"""Determines whether to run the non-rigid motion registration."""
|
|
183
|
-
|
|
184
|
-
align_by_chan: int = 1
|
|
185
|
-
"""The channel to use for frame alignment (registration). This field uses 1-based indexing, so 1 means 1st channel
|
|
186
|
-
and 2 means 2nd channel. If the recording features both a functional and non-functional channels, it is recommended
|
|
187
|
-
to use the non-functional channel for this purpose."""
|
|
188
|
-
|
|
189
|
-
nimg_init: int = 500
|
|
190
|
-
"""The number of frames to use to compute the reference image. During registration, each frame is registered to the
|
|
191
|
-
reference image to remove motion artifacts."""
|
|
192
|
-
|
|
193
|
-
batch_size: int = 100
|
|
194
|
-
"""The number of frames to register simultaneously in each batch. When processing data on fast (NVME) drives,
|
|
195
|
-
increasing this parameter has minimal benefits and results in undue RAM use overhead. Therefore, on fast drives,
|
|
196
|
-
keep this number low. On slow drives, increasing this number may result in faster runtime, at the expense of
|
|
197
|
-
increased RAM use."""
|
|
198
|
-
|
|
199
|
-
maxregshift: float = 0.1
|
|
200
|
-
"""The maximum allowed shift during registration, given as a fraction of the frame size, in pixels
|
|
201
|
-
(e.g., 0.1 indicates 10%). This determines how much the algorithm is allowed to shift the entire frame to align it
|
|
202
|
-
to the reference image."""
|
|
203
|
-
|
|
204
|
-
smooth_sigma: float = 1.15
|
|
205
|
-
"""The standard deviation (in pixels) of the Gaussian filter used to smooth the phase correlation between the
|
|
206
|
-
reference image and the current frame."""
|
|
207
|
-
|
|
208
|
-
smooth_sigma_time: float = 0.0
|
|
209
|
-
"""The standard deviation (in frames) of the Gaussian used to temporally smooth the data before computing
|
|
210
|
-
phase correlation."""
|
|
211
|
-
|
|
212
|
-
keep_movie_raw: bool = False
|
|
213
|
-
"""Determines whether to keep the binary file of the raw (non-registered) frames. This is desirable when initially
|
|
214
|
-
configuring the suite2p parameters, as it allows visually comparing registered frames to non-registered frames in
|
|
215
|
-
the GUI. For well-calibrated runtimes, it is advised to have this set to False."""
|
|
216
|
-
|
|
217
|
-
two_step_registration: bool = False
|
|
218
|
-
"""Determines whether to perform a two-step registration. This process consists of the initial registration
|
|
219
|
-
(first step) followed by refinement (second step) registration. This procedure is helpful when working with low
|
|
220
|
-
signal-to-noise data and requires 'keep_movie_raw' to be set to True."""
|
|
221
|
-
|
|
222
|
-
reg_tif: bool = False
|
|
223
|
-
"""Determines whether to write the registered binary data to TIFF files, in addition to keeping it as the .bin
|
|
224
|
-
(binary) suite2p files."""
|
|
225
|
-
|
|
226
|
-
reg_tif_chan2: bool = False
|
|
227
|
-
"""Determines whether to generate TIFF files for the registered channel 2 data, if processed data contains two
|
|
228
|
-
channels."""
|
|
229
|
-
|
|
230
|
-
th_badframes: float = 1.0
|
|
231
|
-
"""The threshold for excluding poor-quality frames when performing cropping. Primarily, this is used during two-step
|
|
232
|
-
registration to exclude frames with excessive motion from the refinement registration step. Setting this to a
|
|
233
|
-
smaller value excludes more frames."""
|
|
234
|
-
|
|
235
|
-
norm_frames: bool = True
|
|
236
|
-
"""Determines whether to normalize frames during shift detection to improve registration accuracy."""
|
|
237
|
-
|
|
238
|
-
force_refImg: bool = False
|
|
239
|
-
"""Determines whether to force the use of a pre-stored reference image for registration, instead of recomputing the
|
|
240
|
-
image during runtime."""
|
|
241
|
-
|
|
242
|
-
pad_fft: bool = False
|
|
243
|
-
"""Determines whether to pad the image during the FFT portion of the registration to reduce edge effects."""
|
|
244
|
-
|
|
245
|
-
do_regmetrics: bool = True
|
|
246
|
-
"""Determines whether to compute the registration quality metrics. This step is optional, registration metrics are
|
|
247
|
-
NOT used by the suite2p processing pipeline. However, these metrics are important for assessing the registration
|
|
248
|
-
quality via the GUI. Note, computing the registration metrics is a fairly expensive operation, sometimes taking as
|
|
249
|
-
much time as computing the registration offsets."""
|
|
250
|
-
|
|
251
|
-
reg_metric_n_pc: int = 10
|
|
252
|
-
"""The number of Principle Components (PCs) used to compute the registration metrics. Note, the time to compute
|
|
253
|
-
the registration metrics scales with the number of computed PCs, so it is recommended to keep the number as low
|
|
254
|
-
as feasible for each use case."""
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
@dataclass
|
|
258
|
-
class OnePRegistration:
|
|
259
|
-
"""Stores parameters for additional pre-registration processing used to improve the registration of 1-photon
|
|
260
|
-
datasets."""
|
|
261
|
-
|
|
262
|
-
one_p_reg: bool = False
|
|
263
|
-
"""Determines whether to perform high-pass spatial filtering and tapering to improve one-photon image
|
|
264
|
-
registration. For two-photon datasets, this should be set to False."""
|
|
265
|
-
|
|
266
|
-
spatial_hp_reg: int = 42
|
|
267
|
-
"""The spatial high-pass filter window size, in pixels."""
|
|
268
|
-
|
|
269
|
-
pre_smooth: float = 0.0
|
|
270
|
-
"""The standard deviation for Gaussian smoothing applied before spatial high-pass filtering. The smoothing will
|
|
271
|
-
only be applied if this field is greater than 0.0."""
|
|
272
|
-
|
|
273
|
-
spatial_taper: float = 40.0
|
|
274
|
-
"""The number of pixels to ignore at the image edges to reduce edge artifacts during registration."""
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
@dataclass
|
|
278
|
-
class NonRigid:
|
|
279
|
-
"""Stores parameters for non-rigid registration, which is used to improve motion registration in complex
|
|
280
|
-
datasets by dividing frames into subregions and shifting each subregion independently of other subregions."""
|
|
281
|
-
|
|
282
|
-
nonrigid: bool = True
|
|
283
|
-
"""Determines whether to perform non-rigid registration to correct for local motion and deformation. This is
|
|
284
|
-
primarily used for correcting non-uniform motion."""
|
|
285
|
-
|
|
286
|
-
block_size: list[int] = field(default_factory=lambda: [128, 128])
|
|
287
|
-
"""The block size, in pixels, for non-rigid registration, defining the dimensions of subregions used in
|
|
288
|
-
the correction. It is recommended to keep this size a power of 2 and / or 3 for more efficient FFT computation.
|
|
289
|
-
During processing, each frame will be split into sub-regions with these dimensions and the registration will then be
|
|
290
|
-
applied to each region."""
|
|
291
|
-
|
|
292
|
-
snr_thresh: float = 1.2
|
|
293
|
-
"""The signal-to-noise ratio threshold. The phase correlation peak must be this many times higher than the
|
|
294
|
-
noise level for the algorithm to accept the block shift and apply it to the output dataset."""
|
|
295
|
-
|
|
296
|
-
maxregshiftNR: float = 5.0
|
|
297
|
-
"""The maximum allowed shift, in pixels, for each block relative to the rigid registration shift."""
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
@dataclass
|
|
301
|
-
class ROIDetection:
|
|
302
|
-
"""Stores parameters for cell ROI detection."""
|
|
303
|
-
|
|
304
|
-
preclassify: float = 0.5
|
|
305
|
-
"""The classifier probability threshold used to pre-filter the cells before signal extraction. This is the minimum
|
|
306
|
-
classifier confidence value (that the classified ROI is a cell) for the ROI to be processed further. If this is set
|
|
307
|
-
to 0.0, then all detected ROIs (cells) are kept."""
|
|
308
|
-
|
|
309
|
-
roidetect: bool = True
|
|
310
|
-
"""Determines whether to perform ROI detection and classification."""
|
|
311
|
-
|
|
312
|
-
sparse_mode: bool = True
|
|
313
|
-
"""Determines whether to use the sparse mode for cell detection, which is well-suited for data with sparse
|
|
314
|
-
signals."""
|
|
315
|
-
|
|
316
|
-
spatial_scale: int = 0
|
|
317
|
-
"""The optimal spatial scale, in pixels, for the processed data. This is used to adjust detection sensitivity. A
|
|
318
|
-
value of 0 means automatic detection based on the data's spatial scale. Values above 0 are applied in increments of
|
|
319
|
-
6 pixels (1 -> 6 pixels, 2-> 12 pixels, etc.)."""
|
|
320
|
-
|
|
321
|
-
connected: bool = True
|
|
322
|
-
"""Determines whether to require the detected ROIs to be fully connected regions."""
|
|
323
|
-
|
|
324
|
-
threshold_scaling: float = 2.0
|
|
325
|
-
"""The scaling factor for the detection threshold. This determines how distinctly ROIs have to stand out from
|
|
326
|
-
background noise to be considered valid."""
|
|
327
|
-
|
|
328
|
-
spatial_hp_detect: int = 25
|
|
329
|
-
"""The window size, in pixels, for spatial high-pass filtering applied before neuropil subtraction during
|
|
330
|
-
ROI detection."""
|
|
331
|
-
|
|
332
|
-
max_overlap: float = 0.75
|
|
333
|
-
"""The maximum allowed fraction of overlapping pixels between ROIs. ROIs that overlap above this threshold are be
|
|
334
|
-
discarded."""
|
|
335
|
-
|
|
336
|
-
high_pass: int = 100
|
|
337
|
-
"""The window size, in frames, for running mean subtraction over time to remove low-frequency ROI drift."""
|
|
338
|
-
|
|
339
|
-
smooth_masks: bool = True
|
|
340
|
-
"""Determines whether to smooth the ROI masks in the final pass of cell detection."""
|
|
341
|
-
|
|
342
|
-
max_iterations: int = 50
|
|
343
|
-
"""The maximum number of iterations allowed for cell extraction. Generally, more iterations lead to more accurate
|
|
344
|
-
cell detection, but having the value too high may be detrimental."""
|
|
345
|
-
|
|
346
|
-
nbinned: int = 5000
|
|
347
|
-
"""The maximum number of binned frames to use for ROI detection. Settings this value to a higher number leads to
|
|
348
|
-
more ROIs being detected, but reduces processing speed and increases RAM overhead."""
|
|
349
|
-
|
|
350
|
-
denoise: bool = False
|
|
351
|
-
"""Determines whether to denoise the binned movie before cell detection in sparse mode to enhance performance.
|
|
352
|
-
If enabled, 'sparse_mode' has to be True."""
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
@dataclass
|
|
356
|
-
class CellposeDetection:
|
|
357
|
-
"""Stores parameters for the Cellpose algorithm, which can optionally be used to improve cell ROI extraction."""
|
|
358
|
-
|
|
359
|
-
anatomical_only: int = 0
|
|
360
|
-
"""Specifies the Cellpose mode for cell detection:
|
|
361
|
-
0: Do not use Cellpose. This automatically disables all other fields in this section.
|
|
362
|
-
1: Detect masks on the max projection divided by the mean image.
|
|
363
|
-
2: Detect masks on the mean image.
|
|
364
|
-
3: Detect masks on the enhanced mean image.
|
|
365
|
-
4: Detect masks on the max projection image.
|
|
366
|
-
"""
|
|
367
|
-
|
|
368
|
-
diameter: int = 0
|
|
369
|
-
"""Specifies the diameter, in pixels, to look for when finding cell ROIs. If set to 0, Cellpose estimates the
|
|
370
|
-
diameter automatically.."""
|
|
371
|
-
|
|
372
|
-
cellprob_threshold: float = 0.0
|
|
373
|
-
"""The threshold for cell detection, used to filter out low-confidence ROIs."""
|
|
374
|
-
|
|
375
|
-
flow_threshold: float = 1.5
|
|
376
|
-
"""The flow threshold, used to control the algorithm's sensitivity to cell boundaries."""
|
|
377
|
-
|
|
378
|
-
spatial_hp_cp: int = 0
|
|
379
|
-
"""The window size, in pixels, for spatial high-pass filtering applied to the image before Cellpose processing."""
|
|
380
|
-
|
|
381
|
-
pretrained_model: str = "cyto"
|
|
382
|
-
"""Specifies the pretrained model to use for cell detection. Can be a built-in model name (e.g., 'cyto') or a
|
|
383
|
-
path to a custom model."""
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
@dataclass
|
|
387
|
-
class SignalExtraction:
|
|
388
|
-
"""Stores parameters for extracting fluorescence signals from ROIs and surrounding neuropil regions."""
|
|
389
|
-
|
|
390
|
-
neuropil_extract: bool = True
|
|
391
|
-
"""Determines whether to extract neuropil signals. Typically, this is set to True to support later
|
|
392
|
-
delta-fluorescence-over-fluorescence (dff) analysis."""
|
|
393
|
-
|
|
394
|
-
allow_overlap: bool = False
|
|
395
|
-
"""Determines whether to allow overlap pixels (pixels shared by multiple ROIs) to be used in the signal extraction.
|
|
396
|
-
Typically this is set to False to avoid contamination."""
|
|
397
|
-
|
|
398
|
-
min_neuropil_pixels: int = 350
|
|
399
|
-
"""The minimum number of pixels required to compute the neuropil signal for each cell."""
|
|
400
|
-
|
|
401
|
-
inner_neuropil_radius: int = 2
|
|
402
|
-
"""The number of pixels to keep between the ROI and the surrounding neuropil region to avoid signal bleed-over."""
|
|
403
|
-
|
|
404
|
-
lam_percentile: int = 50
|
|
405
|
-
"""The percentile of Lambda within area to ignore when excluding the brightest pixels during neuropil extraction.
|
|
406
|
-
Specifically, pixels with relative brightness above this threshold are excluded from neuropil signal to filter
|
|
407
|
-
out bright speckle outliers.
|
|
408
|
-
"""
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
@dataclass
|
|
412
|
-
class SpikeDeconvolution:
|
|
413
|
-
"""Stores parameters for deconvolve fluorescence signals to infer spike trains."""
|
|
414
|
-
|
|
415
|
-
spikedetect: bool = True
|
|
416
|
-
"""Determines whether to perform fluorescence spike deconvolution."""
|
|
417
|
-
|
|
418
|
-
neucoeff: float = 0.7
|
|
419
|
-
"""The neuropil coefficient applied for signal correction before deconvolution. Specifically, the neuropil signal
|
|
420
|
-
is scaled by this coefficient before it is subtracted from the ROI signal when computing df/f values."""
|
|
421
|
-
|
|
422
|
-
baseline: str = "maximin"
|
|
423
|
-
"""Specifies the method to compute the baseline of each trace. This baseline is then subtracted from each cell's
|
|
424
|
-
fluorescence. ‘maximin’ computes a moving baseline by filtering the data with a Gaussian of width
|
|
425
|
-
'sig_baseline' * 'fs', and then minimum filtering with a window of 'win_baseline' * 'fs', and then maximum
|
|
426
|
-
filtering with the same window. ‘constant’ computes a constant baseline by filtering with a Gaussian of width
|
|
427
|
-
'sig_baseline' * 'fs' and then taking the minimum value of this filtered trace. ‘constant_percentile’ computes a
|
|
428
|
-
constant baseline by taking the 'prctile_baseline' percentile of the trace."""
|
|
429
|
-
|
|
430
|
-
win_baseline: float = 60.0
|
|
431
|
-
"""The time window, in seconds, over which to compute the baseline filter."""
|
|
432
|
-
|
|
433
|
-
sig_baseline: float = 10.0
|
|
434
|
-
"""The standard deviation, in seconds, of the Gaussian filter applied to smooth the baseline signal."""
|
|
435
|
-
|
|
436
|
-
prctile_baseline: float = 8.0
|
|
437
|
-
"""The percentile used to determine the baseline level of each trace (typically a low percentile reflecting
|
|
438
|
-
minimal activity)."""
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
@dataclass
|
|
442
|
-
class Classification:
|
|
443
|
-
"""Stores parameters for classifying detected ROIs as real cells or artifacts."""
|
|
444
|
-
|
|
445
|
-
soma_crop: bool = True
|
|
446
|
-
"""Determines whether to crop dendritic regions from detected ROIs to focus on the cell body for classification
|
|
447
|
-
purposes."""
|
|
448
|
-
|
|
449
|
-
use_builtin_classifier: bool = False
|
|
450
|
-
"""Determines whether to use the built-in classifier for cell detection."""
|
|
451
|
-
|
|
452
|
-
classifier_path: str = ""
|
|
453
|
-
"""The path to a custom classifier file, if not using the built-in classifier."""
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
@dataclass
|
|
457
|
-
class Channel2:
|
|
458
|
-
"""Stores parameters for processing the second channel in multichannel datasets."""
|
|
459
|
-
|
|
460
|
-
chan2_thres: float = 0.65
|
|
461
|
-
"""The threshold for considering an ROI detected in one channel as detected (present) in the second channel.
|
|
462
|
-
This threshold specifies the ratio of channel 1 pixels to channel 2 pixels for the ROI to be considered present in
|
|
463
|
-
both channels."""
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
@dataclass
|
|
467
|
-
class SingleDayS2PConfiguration(YamlConfig):
|
|
468
|
-
"""Aggregates all user-addressable parameters of the single-day suite2p pipeline used to discover cell ROIs and
|
|
469
|
-
extract their fluorescence data.
|
|
470
|
-
|
|
471
|
-
This class is used during single-day processing to instruct suite2p on how to process the data. This class is based
|
|
472
|
-
on the 'default_ops' from the original suite2p package. As part of the suite2p refactoring performed in sl-suite2p
|
|
473
|
-
package, the 'default_ops' has been replaced with this class instance. Compared to the 'original' ops, it allows
|
|
474
|
-
saving configuration parameters as a .YAML file, which offers a better way of viewing and editing the parameters and
|
|
475
|
-
running suite2p pipeline on remote compute servers.
|
|
476
|
-
"""
|
|
477
|
-
|
|
478
|
-
# Define the instances of each nested settings class as fields
|
|
479
|
-
main: Main = field(default_factory=Main)
|
|
480
|
-
"""Stores global parameters that broadly define the suite2p single-day processing configuration."""
|
|
481
|
-
file_io: FileIO = field(default_factory=FileIO)
|
|
482
|
-
"""Stores general I/O parameters that specify input data location, format, and working and output directories."""
|
|
483
|
-
output: Output = field(default_factory=Output)
|
|
484
|
-
"""Stores parameters for aggregating and saving the processing results of each plane as a unified directory or
|
|
485
|
-
file."""
|
|
486
|
-
registration: Registration = field(default_factory=Registration)
|
|
487
|
-
"""Stores parameters for rigid registration, which is used to correct motion artifacts between frames by
|
|
488
|
-
counter-shifting the entire frame."""
|
|
489
|
-
one_p_registration: OnePRegistration = field(default_factory=OnePRegistration)
|
|
490
|
-
"""Stores parameters for additional pre-registration processing used to improve the registration of 1-photon
|
|
491
|
-
datasets."""
|
|
492
|
-
non_rigid: NonRigid = field(default_factory=NonRigid)
|
|
493
|
-
"""Stores parameters for non-rigid registration, which is used to improve motion registration in complex
|
|
494
|
-
datasets."""
|
|
495
|
-
roi_detection: ROIDetection = field(default_factory=ROIDetection)
|
|
496
|
-
"""Stores parameters for cell ROI detection and extraction."""
|
|
497
|
-
cellpose_detection: CellposeDetection = field(default_factory=CellposeDetection)
|
|
498
|
-
"""Stores parameters for the Cellpose algorithm, which can optionally be used to improve cell ROI extraction."""
|
|
499
|
-
signal_extraction: SignalExtraction = field(default_factory=SignalExtraction)
|
|
500
|
-
"""Stores parameters for extracting fluorescence signals from ROIs and surrounding neuropil regions."""
|
|
501
|
-
spike_deconvolution: SpikeDeconvolution = field(default_factory=SpikeDeconvolution)
|
|
502
|
-
"""Stores parameters for deconvolve fluorescence signals to infer spike trains."""
|
|
503
|
-
classification: Classification = field(default_factory=Classification)
|
|
504
|
-
"""Stores parameters for classifying detected ROIs as real cells or artifacts."""
|
|
505
|
-
channel2: Channel2 = field(default_factory=Channel2)
|
|
506
|
-
"""Stores parameters for processing the second channel in multichannel datasets."""
|
|
507
|
-
|
|
508
|
-
def to_npy(self, output_directory: Path) -> None:
|
|
509
|
-
"""Saves the managed configuration data as an 'ops.npy' file under the target directory.
|
|
510
|
-
|
|
511
|
-
This method is mostly called by internal sl-suite2p functions to translate the user-specified configuration
|
|
512
|
-
file into the format used by suite2p pipelines.
|
|
513
|
-
|
|
514
|
-
Notes:
|
|
515
|
-
If the target output directory does not exist when this method is called, it will be created.
|
|
516
|
-
|
|
517
|
-
Args:
|
|
518
|
-
output_directory: The path to the directory where the 'ops.npy' file should be saved.
|
|
519
|
-
"""
|
|
520
|
-
ensure_directory_exists(output_directory) # Creates the directory, if necessary
|
|
521
|
-
file_path = output_directory.joinpath("ops.npy") # Computes the output path
|
|
522
|
-
# Dumps the configuration data to 'ops.npy' file.
|
|
523
|
-
np.save(file_path, self.to_ops(), allow_pickle=True) # type: ignore
|
|
524
|
-
|
|
525
|
-
def to_config(self, output_directory: Path) -> None:
|
|
526
|
-
"""Saves the managed configuration data as a 'single_day_s2p_configuration.yaml' file under the target
|
|
527
|
-
directory.
|
|
528
|
-
|
|
529
|
-
This method is typically used to dump the 'default' configuration parameters to disk as a user-editable
|
|
530
|
-
.yaml file. The user is then expected to modify these parameters as needed, before the class data is loaded and
|
|
531
|
-
used by the suite2p pipeline.
|
|
532
|
-
|
|
533
|
-
Notes:
|
|
534
|
-
If the target output directory does not exist when this method is called, it will be created.
|
|
535
|
-
|
|
536
|
-
Args:
|
|
537
|
-
output_directory: The path to the directory where the 'single_day_s2p_configuration.yaml' file should be
|
|
538
|
-
saved.
|
|
539
|
-
"""
|
|
540
|
-
ensure_directory_exists(output_directory) # Creates the directory, if necessary
|
|
541
|
-
file_path = output_directory.joinpath("single_day_s2p_configuration.yaml") # Computes the output path
|
|
542
|
-
|
|
543
|
-
# Note, this uses the same configuration name as the SessionData class, making it automatically compatible with
|
|
544
|
-
# Sun lab data structure.
|
|
545
|
-
self.to_yaml(file_path=file_path) # Dumps the data to a 'yaml' file.
|
|
546
|
-
|
|
547
|
-
def to_ops(self) -> dict[str, Any]:
|
|
548
|
-
"""Converts the class instance to a dictionary and returns it to caller.
|
|
549
|
-
|
|
550
|
-
This method is mostly called by internal sl-suite2p functions to translate the default configuration parameters
|
|
551
|
-
to the dictionary format used by suite2p pipelines.
|
|
552
|
-
"""
|
|
553
|
-
|
|
554
|
-
# Creates an empty dictionary to store all keys and values
|
|
555
|
-
combined_ops = {}
|
|
556
|
-
|
|
557
|
-
# Iterates through all dataclass fields
|
|
558
|
-
# noinspection PyTypeChecker
|
|
559
|
-
for section_name, section in asdict(self).items():
|
|
560
|
-
# Adds all keys and values from each section to the combined dictionary
|
|
561
|
-
if isinstance(section, dict):
|
|
562
|
-
combined_ops.update(section)
|
|
563
|
-
|
|
564
|
-
return combined_ops
|