sl-shared-assets 1.0.0rc15__py3-none-any.whl → 1.0.0rc17__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.

@@ -5,6 +5,9 @@ is used as the first step of the multi-day brain activity processing pipeline us
5
5
 
6
6
  from typing import Any
7
7
  from dataclasses import field, asdict, dataclass
8
+ from pathlib import Path
9
+ import numpy as np
10
+ from ataraxis_base_utilities import ensure_directory_exists
8
11
 
9
12
  from ataraxis_data_structures import YamlConfig
10
13
 
@@ -13,158 +16,179 @@ from ataraxis_data_structures import YamlConfig
13
16
  class Main:
14
17
  """Stores global parameters that broadly define the suite2p single-day processing configuration."""
15
18
 
16
- nplanes: int = 3
17
- """The number of imaging planes in each TIFF file sequence. For Mesoscope frames, this is the number of individual
18
- ROI boxes drawn over the cranial window."""
19
+ nplanes: int = 1
20
+ """The number of imaging planes, stored as a sequence inside each input TIFF file."""
19
21
 
20
22
  nchannels: int = 1
21
- """The number of channels per imaging plane. Typically this is either 1 or 2."""
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.)."""
22
26
 
23
27
  functional_chan: int = 1
24
- """The channel used for extracting functional ROIs (uses 1-based indexing, e.g., 1 means the first channel)."""
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."""
25
30
 
26
31
  tau: float = 0.4
27
32
  """The timescale of the sensor, in seconds, used for computing the deconvolution kernel. The kernel is fixed to
28
- have this decay and is not fit to the data. Note, the default value is optimized for GCamp6f animals recorded with
29
- the Mesoscope."""
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."""
30
35
 
31
36
  force_sktiff: bool = True
32
- """Determines whether to force the use of scikit-image for reading TIFF files. Generally, it is recommended to have
33
- this enabled as it forces suite2p to use tifffile library, which has better safety and compatibility than
34
- ScanImage tiff reader for certain types of tiff files."""
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."""
35
40
 
36
41
  fs: float = 10.0014
37
- """The sampling rate per plane in Hertz. For instance, if you have a 10 plane recording acquired at 30Hz, then the
42
+ """The sampling rate per plane in Hertz. For instance, if you have a 10-plane recording acquired at 30Hz, then the
38
43
  sampling rate per plane is 3Hz, so set this to 3."""
39
44
 
40
45
  do_bidiphase: bool = False
41
- """Determines whether to perform computation of bidirectional phase offset for misaligned line scanning
42
- (applies to two-photon recordings only). The suite2p estimates the bidirectional phase offset from
43
- ‘nimg_init’ frames if this is set to 1 (and ‘bidiphase’ to 0), and then applies this computed offset to all
44
- frames."""
46
+ """Determines whether to perform the computation of bidirectional phase offset for misaligned line scanning
47
+ experiments (applies to two-photon recordings only)."""
45
48
 
46
49
  bidiphase: int = 0
47
50
  """The user-specified bidirectional phase offset for line scanning experiments. If set to any value besides 0, then
48
- this offset is used and applied to all frames in the recording."""
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."""
49
54
 
50
55
  bidi_corrected: bool = False
51
- """Indicates whether bidirectional phase correction has been applied tot he registered dataset."""
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."""
52
59
 
53
60
  frames_include: int = -1
54
- """Determines the number of frames to process, if greater than zero. If negative (-1), the suite2p is configured
55
- to process all available frames."""
56
-
57
- multiplane_parallel: bool = True
58
- """Determines whether to parallelize plane processing for multiplane data. Note, while enabling this option improves
59
- processing speeds, it also increases the memory (RAM) overhead resulting from processing all planes in-parallel.
60
- """
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."""
61
76
 
62
77
  ignore_flyback: list[int] = field(default_factory=list)
63
- """The list of plane indices to ignore as flyback planes that typically contain no valid imaging data."""
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."""
64
80
 
65
81
 
66
82
  @dataclass
67
83
  class FileIO:
68
84
  """Stores general I/O parameters that specify input data location, format, and working and output directories."""
69
85
 
70
- fast_disk: list[str] = field(default_factory=list)
71
- """Specifies the locations where to store the temporary binary files created during processing. If no directories
72
- are provided here, 'save_path0' is used to store the temporary files."""
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."""
73
92
 
74
93
  delete_bin: bool = False
75
- """Determines whether to delete the binary file created during the cell registration stage (registered cells .bin
76
- file). Since registered cell binaries are used by multi-day registration extension, this need to be False for all
77
- lab recordings."""
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."""
78
98
 
79
99
  mesoscan: bool = True
80
- """Indicates whether the input file is a ScanImage Mesoscope recording. For our data, this is always True and all
81
- other formats are False."""
100
+ """Indicates whether the data submitted to the pipeline are ScanImage Mesoscope multi-page TIFFs."""
82
101
 
83
102
  bruker: bool = False
84
- """Indicates whether the provided TIFF files are single-page BRUKER TIFFs."""
103
+ """Indicates whether the data submitted to the pipeline are single-page BRUKER TIFFs."""
85
104
 
86
105
  bruker_bidirectional: bool = False
87
- """Specifies whether BRUKER files are bidirectional multiplane recordings."""
106
+ """Indicates whether BRUKER files contain bidirectional multiplane recordings."""
88
107
 
89
108
  h5py: list[str] = field(default_factory=list)
90
- """The list of paths to h5py files that will be used as inputs. If provided, these paths overwrite the 'data_path'
91
- field."""
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."""
92
111
 
93
112
  h5py_key: str = "data"
94
- """The key used to access the data array in an h5py file. This should only be provided if 'h5py' is not set to
95
- an empty list."""
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."""
96
115
 
97
116
  nwb_file: str = ""
98
- """Specifies the path to the NWB file to use as an input."""
117
+ """The path to the NWB file to use as pipeline input."""
99
118
 
100
119
  nwb_driver: str = ""
101
- """The location or name of the driver for reading the NWB file."""
120
+ """The location or name of the driver to use for reading the NWB file."""
102
121
 
103
122
  nwb_series: str = ""
104
- """The name of the TwoPhotonSeries in the NWB file to retrieve data from."""
123
+ """The name of the TwoPhotonSeries in the NWB file from which to retrieve the data."""
105
124
 
106
- save_path0: list[str] = field(default_factory=list)
107
- """Lists directory paths where the pipeline results should be saved. Typically, this is defined as a single-item
108
- list that stores the path to the output folder used by the processed session's data."""
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."""
109
129
 
110
- save_folder: list[str] = field(default_factory=list)
111
- """Lists folder names under which the results should be stored. If this is not provided, the pipeline defaults to
112
- using 'suite2p' as the root folder, created under the path specified by save_path0. Note, if the data produced by
113
- the 'single-day' pipeline is also processed using sl-suite2p 'multi-day' pipeline, do not modify this field. The
114
- multi-day pipeline expects the save_folder to be 'suite2p' (default)."""
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."""
115
139
 
116
140
  look_one_level_down: bool = False
117
- """Determines whether to search for TIFF files in the subfolders when searching for Tiff files. If this is True,
118
- the list of evaluated subfolders have to be defined via the 'subfolders' field."""
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."""
119
143
 
120
144
  subfolders: list[str] = field(default_factory=list)
121
- """The list of specific subfolder names to search through for TIFF files."""
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'."""
122
147
 
123
148
  move_bin: bool = False
124
- """Determines whether to move the binary file to the save directory after processing, if 'fast_disk' differs from
125
- the 'save_path0'."""
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'."""
126
153
 
127
154
 
128
155
  @dataclass
129
156
  class Output:
130
- """Stores I/O settings that specify the output format and organization of the data processing results."""
131
-
132
- preclassify: float = 0.5
133
- """The probability threshold for pre-classification of cells to use before signal extraction. If this is set to
134
- 0.0, then all detected ROIs are kept and signals are computed."""
157
+ """Stores parameters for aggregating and saving the processing results of each plane as a unified directory or
158
+ file."""
135
159
 
136
160
  save_nwb: bool = False
137
- """Determines whether to save the output as an NWB file."""
161
+ """Determines whether to save the single-session pipeline output as an NWB file."""
138
162
 
139
163
  save_mat: bool = False
140
- """Determines whether to save the results in MATLAB format (e.g., Fall.mat)."""
164
+ """Determines whether to save the single-session pipeline output as a MATLAB file (e.g., Fall.mat)."""
141
165
 
142
166
  combined: bool = True
143
- """Determines whether to combine results across planes into a separate 'combined' folder at the end of
144
- processing."""
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."""
145
170
 
146
171
  aspect: float = 0.666666666
147
- """The pixel-to-micron ratio (X:Y) for correctly displaying the image aspect ratio in the GUI (not used in headless
148
- processing)."""
149
-
150
- report_time: bool = False
151
- """Determines whether to return a dictionary reporting the processing time for each plane."""
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."""
152
174
 
153
175
 
154
176
  @dataclass
155
177
  class Registration:
156
- """Stores parameters for rigid registration, which is used to correct motion artifacts between frames."""
178
+ """Stores parameters for rigid registration, which is used to correct motion artifacts between frames by
179
+ counter-shifting the entire frame."""
157
180
 
158
181
  do_registration: bool = True
159
- """Determines whether to run the motion registration."""
182
+ """Determines whether to run the non-rigid motion registration."""
160
183
 
161
184
  align_by_chan: int = 1
162
- """The channel to use for alignment (uses 1-based indexing, so 1 means 1st channel and 2 means 2nd channel). If the
163
- recording features both a functional and non-functional channels, it may be better to use the non-functional
164
- channel for this purpose."""
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."""
165
188
 
166
189
  nimg_init: int = 500
167
- """The number of frames to use to compute the reference image for registration."""
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."""
168
192
 
169
193
  batch_size: int = 100
170
194
  """The number of frames to register simultaneously in each batch. When processing data on fast (NVME) drives,
@@ -174,11 +198,12 @@ class Registration:
174
198
 
175
199
  maxregshift: float = 0.1
176
200
  """The maximum allowed shift during registration, given as a fraction of the frame size, in pixels
177
- (e.g., 0.1 indicates 10%)."""
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."""
178
203
 
179
204
  smooth_sigma: float = 1.15
180
- """The standard deviation (in pixels) of the Gaussian used to smooth the phase correlation between the reference
181
- image and the current frame."""
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."""
182
207
 
183
208
  smooth_sigma_time: float = 0.0
184
209
  """The standard deviation (in frames) of the Gaussian used to temporally smooth the data before computing
@@ -187,34 +212,47 @@ class Registration:
187
212
  keep_movie_raw: bool = False
188
213
  """Determines whether to keep the binary file of the raw (non-registered) frames. This is desirable when initially
189
214
  configuring the suite2p parameters, as it allows visually comparing registered frames to non-registered frames in
190
- the GUI. For well-calibrated runtime, it is advised to have this set to False."""
215
+ the GUI. For well-calibrated runtimes, it is advised to have this set to False."""
191
216
 
192
217
  two_step_registration: bool = False
193
- """Determines whether to perform a two-step registration (initial registration followed by refinement registration).
194
- This may be necessary for low signal-to-noise data. This requires 'keep_movie_raw' to be set to True."""
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."""
195
221
 
196
222
  reg_tif: bool = False
197
- """Determines whether to write the registered binary data to TIFF files."""
223
+ """Determines whether to write the registered binary data to TIFF files, in addition to keeping it as the .bin
224
+ (binary) suite2p files."""
198
225
 
199
226
  reg_tif_chan2: bool = False
200
- """Determines whether to generate TIFF files for the registered non-functional (channel 2) data."""
201
-
202
- subpixel: int = 10
203
- """The precision for the subpixel registration (1/subpixel steps)."""
227
+ """Determines whether to generate TIFF files for the registered channel 2 data, if processed data contains two
228
+ channels."""
204
229
 
205
230
  th_badframes: float = 1.0
206
- """The threshold for excluding poor-quality frames when performing cropping. Setting this to a smaller value
207
- excludes more frames."""
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."""
208
234
 
209
235
  norm_frames: bool = True
210
236
  """Determines whether to normalize frames during shift detection to improve registration accuracy."""
211
237
 
212
238
  force_refImg: bool = False
213
- """Determines whether to force the use of a pre-stored reference image for registration."""
239
+ """Determines whether to force the use of a pre-stored reference image for registration, instead of recomputing the
240
+ image during runtime."""
214
241
 
215
242
  pad_fft: bool = False
216
243
  """Determines whether to pad the image during the FFT portion of the registration to reduce edge effects."""
217
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
+
218
256
 
219
257
  @dataclass
220
258
  class OnePRegistration:
@@ -223,14 +261,14 @@ class OnePRegistration:
223
261
 
224
262
  one_p_reg: bool = False
225
263
  """Determines whether to perform high-pass spatial filtering and tapering to improve one-photon image
226
- registration. For 2-photon datasets, this should be set to False."""
264
+ registration. For two-photon datasets, this should be set to False."""
227
265
 
228
266
  spatial_hp_reg: int = 42
229
- """The window size, in pixels, for spatial high-pass filtering performed before registration."""
267
+ """The spatial high-pass filter window size, in pixels."""
230
268
 
231
269
  pre_smooth: float = 0.0
232
- """The standard deviation for Gaussian smoothing applied before spatial high-pass filtering
233
- (applied only if > 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."""
234
272
 
235
273
  spatial_taper: float = 40.0
236
274
  """The number of pixels to ignore at the image edges to reduce edge artifacts during registration."""
@@ -239,15 +277,17 @@ class OnePRegistration:
239
277
  @dataclass
240
278
  class NonRigid:
241
279
  """Stores parameters for non-rigid registration, which is used to improve motion registration in complex
242
- datasets."""
280
+ datasets by dividing frames into subregions and shifting each subregion independently of other subregions."""
243
281
 
244
282
  nonrigid: bool = True
245
- """Determines whether to perform non-rigid registration to correct for local motion and deformation. This is used
246
- for correcting non-uniform motion."""
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."""
247
285
 
248
286
  block_size: list[int] = field(default_factory=lambda: [128, 128])
249
287
  """The block size, in pixels, for non-rigid registration, defining the dimensions of subregions used in
250
- the correction. It is recommended to keep this size a power of 2 and / or 3 for more efficient FFT computation."""
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."""
251
291
 
252
292
  snr_thresh: float = 1.2
253
293
  """The signal-to-noise ratio threshold. The phase correlation peak must be this many times higher than the
@@ -259,19 +299,24 @@ class NonRigid:
259
299
 
260
300
  @dataclass
261
301
  class ROIDetection:
262
- """Stores parameters for cell ROI detection and extraction."""
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."""
263
308
 
264
309
  roidetect: bool = True
265
- """Determines whether to perform ROI detection and subsequent signal extraction."""
310
+ """Determines whether to perform ROI detection and classification."""
266
311
 
267
312
  sparse_mode: bool = True
268
313
  """Determines whether to use the sparse mode for cell detection, which is well-suited for data with sparse
269
314
  signals."""
270
315
 
271
316
  spatial_scale: int = 0
272
- """The optimal spatial scale, in pixels, of the recording. This is used to adjust detection sensitivity. A value of
273
- 0 means automatic detection based on the recording's spatial scale. Values above 0 are applied in increments of 6
274
- pixels (1 -> 6 pixels, 2-> 12 pixels, etc.)."""
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.)."""
275
320
 
276
321
  connected: bool = True
277
322
  """Determines whether to require the detected ROIs to be fully connected regions."""
@@ -289,13 +334,14 @@ class ROIDetection:
289
334
  discarded."""
290
335
 
291
336
  high_pass: int = 100
292
- """The window size, in frames, for running mean subtraction over time to remove low-frequency drift."""
337
+ """The window size, in frames, for running mean subtraction over time to remove low-frequency ROI drift."""
293
338
 
294
339
  smooth_masks: bool = True
295
340
  """Determines whether to smooth the ROI masks in the final pass of cell detection."""
296
341
 
297
342
  max_iterations: int = 50
298
- """The maximum number of iterations allowed for cell extraction."""
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."""
299
345
 
300
346
  nbinned: int = 5000
301
347
  """The maximum number of binned frames to use for ROI detection. Settings this value to a higher number leads to
@@ -320,14 +366,14 @@ class CellposeDetection:
320
366
  """
321
367
 
322
368
  diameter: int = 0
323
- """Specifies the diameter, in pixels, of cells to look for. If set to 0, Cellpose estimates the diameter
324
- automatically.."""
369
+ """Specifies the diameter, in pixels, to look for when finding cell ROIs. If set to 0, Cellpose estimates the
370
+ diameter automatically.."""
325
371
 
326
372
  cellprob_threshold: float = 0.0
327
- """The threshold for cell detection, used to filter out low-confidence detections."""
373
+ """The threshold for cell detection, used to filter out low-confidence ROIs."""
328
374
 
329
375
  flow_threshold: float = 1.5
330
- """The flow threshold, used to control the sensitivity to cell boundaries."""
376
+ """The flow threshold, used to control the algorithm's sensitivity to cell boundaries."""
331
377
 
332
378
  spatial_hp_cp: int = 0
333
379
  """The window size, in pixels, for spatial high-pass filtering applied to the image before Cellpose processing."""
@@ -342,7 +388,8 @@ class SignalExtraction:
342
388
  """Stores parameters for extracting fluorescence signals from ROIs and surrounding neuropil regions."""
343
389
 
344
390
  neuropil_extract: bool = True
345
- """Determines whether to extract neuropil signals."""
391
+ """Determines whether to extract neuropil signals. Typically, this is set to True to support later
392
+ delta-fluorescence-over-fluorescence (dff) analysis."""
346
393
 
347
394
  allow_overlap: bool = False
348
395
  """Determines whether to allow overlap pixels (pixels shared by multiple ROIs) to be used in the signal extraction.
@@ -355,7 +402,10 @@ class SignalExtraction:
355
402
  """The number of pixels to keep between the ROI and the surrounding neuropil region to avoid signal bleed-over."""
356
403
 
357
404
  lam_percentile: int = 50
358
- """The percentile of Lambda within area to ignore when excluding the brightest pixels during neuropil extraction."""
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
+ """
359
409
 
360
410
 
361
411
  @dataclass
@@ -363,18 +413,19 @@ class SpikeDeconvolution:
363
413
  """Stores parameters for deconvolve fluorescence signals to infer spike trains."""
364
414
 
365
415
  spikedetect: bool = True
366
- """Determines whether to perform spike deconvolution."""
416
+ """Determines whether to perform fluorescence spike deconvolution."""
367
417
 
368
418
  neucoeff: float = 0.7
369
- """The neuropil coefficient applied for signal correction before deconvolution."""
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."""
370
421
 
371
422
  baseline: str = "maximin"
372
- """Specifies the method to compute the baseline of each trace. This baseline is then subtracted from each cell.
373
- ‘maximin’ computes a moving baseline by filtering the data with a Gaussian of width 'sig_baseline' * 'fs', and then
374
- minimum filtering with a window of 'win_baseline' * 'fs', and then maximum filtering with the same window.
375
- ‘constant’ computes a constant baseline by filtering with a Gaussian of width 'sig_baseline' * 'fs' and then taking
376
- the minimum value of this filtered trace. ‘constant_percentile’ computes a constant baseline by taking the
377
- 'prctile_baseline' percentile of the trace."""
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."""
378
429
 
379
430
  win_baseline: float = 60.0
380
431
  """The time window, in seconds, over which to compute the baseline filter."""
@@ -407,23 +458,21 @@ class Channel2:
407
458
  """Stores parameters for processing the second channel in multichannel datasets."""
408
459
 
409
460
  chan2_thres: float = 0.65
410
- """The threshold for considering an ROI registered in one channel as detected in the second channel."""
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."""
411
464
 
412
465
 
413
466
  @dataclass
414
467
  class SingleDayS2PConfiguration(YamlConfig):
415
- """Stores the user-addressable suite2p configuration parameters for the single-day (original) pipeline, organized
416
- into subsections.
468
+ """Aggregates all user-addressable parameters of the single-day suite2p pipeline used to discover cell ROIs and
469
+ extract their fluorescence data.
417
470
 
418
471
  This class is used during single-day processing to instruct suite2p on how to process the data. This class is based
419
472
  on the 'default_ops' from the original suite2p package. As part of the suite2p refactoring performed in sl-suite2p
420
- package, the 'default_ops' has been replaced with this class instance. Compared to 'original' ops, it allows saving
421
- configuration parameters as a .YAML file, which offers a better way of viewing and editing the parameters and
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
422
475
  running suite2p pipeline on remote compute servers.
423
-
424
- Notes:
425
- The .YAML file uses section names that match the suite2p documentation sections. This way, users can always
426
- consult the suite2p documentation for information on the purpose of each field inside every subsection.
427
476
  """
428
477
 
429
478
  # Define the instances of each nested settings class as fields
@@ -432,9 +481,11 @@ class SingleDayS2PConfiguration(YamlConfig):
432
481
  file_io: FileIO = field(default_factory=FileIO)
433
482
  """Stores general I/O parameters that specify input data location, format, and working and output directories."""
434
483
  output: Output = field(default_factory=Output)
435
- """Stores I/O settings that specify the output format and organization of the data processing results."""
484
+ """Stores parameters for aggregating and saving the processing results of each plane as a unified directory or
485
+ file."""
436
486
  registration: Registration = field(default_factory=Registration)
437
- """Stores parameters for rigid registration, which is used to correct motion artifacts between frames."""
487
+ """Stores parameters for rigid registration, which is used to correct motion artifacts between frames by
488
+ counter-shifting the entire frame."""
438
489
  one_p_registration: OnePRegistration = field(default_factory=OnePRegistration)
439
490
  """Stores parameters for additional pre-registration processing used to improve the registration of 1-photon
440
491
  datasets."""
@@ -454,11 +505,49 @@ class SingleDayS2PConfiguration(YamlConfig):
454
505
  channel2: Channel2 = field(default_factory=Channel2)
455
506
  """Stores parameters for processing the second channel in multichannel datasets."""
456
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
+ np.save(file_path, self.to_ops(), allow_pickle=True) # Dumps the configuration data to 'ops.npy' file.
523
+
524
+ def to_config(self, output_directory: Path) -> None:
525
+ """Saves the managed configuration data as a 'single_day_s2p_configuration.yaml' file under the target
526
+ directory.
527
+
528
+ This method is typically used to dump the 'default' configuration parameters to disk as a user-editable
529
+ .yaml file. The user is then expected to modify these parameters as needed, before the class data is loaded and
530
+ used by the suite2p pipeline.
531
+
532
+ Notes:
533
+ If the target output directory does not exist when this method is called, it will be created.
534
+
535
+ Args:
536
+ output_directory: The path to the directory where the 'single_day_s2p_configuration.yaml' file should be
537
+ saved.
538
+ """
539
+ ensure_directory_exists(output_directory) # Creates the directory, if necessary
540
+ file_path = output_directory.joinpath("single_day_s2p_configuration.yaml") # Computes the output path
541
+
542
+ # Note, this uses the same configuration name as the SessionData class, making it automatically compatible with
543
+ # Sun lab data structure.
544
+ self.to_yaml(file_path=file_path) # Dumps the data to a 'yaml' file.
545
+
457
546
  def to_ops(self) -> dict[str, Any]:
458
547
  """Converts the class instance to a dictionary and returns it to caller.
459
548
 
460
- This dictionary can be passed to suite2p functions either as an 'ops' or 'db' argument to control the
461
- processing runtime.
549
+ This method is mostly called by internal sl-suite2p functions to translate the default configuration parameters
550
+ to the dictionary format used by suite2p pipelines.
462
551
  """
463
552
 
464
553
  # Creates an empty dictionary to store all keys and values
@@ -469,11 +558,6 @@ class SingleDayS2PConfiguration(YamlConfig):
469
558
  for section_name, section in asdict(self).items():
470
559
  # Adds all keys and values from each section to the combined dictionary
471
560
  if isinstance(section, dict):
472
- # Since some keys in the original suite2p configuration file use 'unconventional' names, we opted to use
473
- # conventional names in our configuration file. To make the 'ops' version of this file fully compatible
474
- # with suite2p, we need to translate all such modified keys back to values expected by suite2p.
475
- if "one_p_reg" in section.keys():
476
- section["1Preg"] = section.pop("one_p_reg")
477
561
  combined_ops.update(section)
478
562
 
479
563
  return combined_ops
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sl-shared-assets
3
- Version: 1.0.0rc15
3
+ Version: 1.0.0rc17
4
4
  Summary: Stores assets shared between multiple Sun (NeuroAI) lab data pipelines.
5
5
  Project-URL: Homepage, https://github.com/Sun-Lab-NBB/sl-shared-assets
6
6
  Project-URL: Documentation, https://sl-shared-assets-api-docs.netlify.app/