Skip to content

Commit d0a454d

Browse files
Merge pull request #869 from MouseLand/refactor
Update documentation to reflect default parameters
2 parents 8d2c099 + 636629f commit d0a454d

File tree

6 files changed

+184
-72
lines changed

6 files changed

+184
-72
lines changed

docs/inputs.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ this array into a numpy array called ``bad_frames.npy``:
5959
Put this file into the first folder in your ops['data_path'] (the first
6060
folder you choose in the GUI).
6161

62+
.. _inputs-diff-file-types:
63+
6264
Different file types
6365
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6466

@@ -173,7 +175,7 @@ Elements of these ``BinaryRWFile`` instances can be accessed similar to how one
173175
f_input.shape # returns shape of your input (num_frames, Ly, Lx)
174176
f_input[0] # returns the first frame with shape (Ly, Lx)
175177

176-
Also, ``BinaryRWFile`` instances can be directly passed to the several wrapper functions ``suite2p`` offers (e.g., ``suite2p.detection_wrapper``, ``suite2p.extraction_wrapper``, etc.). If you'd like to run only specific modules, you will have to use the ``BinaryRWFile`` class. For example, this is how you can run the detection module on an input file that has already been registered.
178+
Also, ``BinaryRWFile`` instances can be directly passed to the several wrapper functions ``suite2p`` offers (e.g., ``suite2p.detection_wrapper``, ``suite2p.extraction_wrapper``, etc.). These wrapper functions can also directly work with Numpy arrays so feel free to pass them as inputs. If you'd like to run only specific modules, you will have to use the ``BinaryRWFile`` class. For example, this is how you can run the detection module on an input file that has already been registered.
177179

178180
::
179181

docs/settings.rst

Lines changed: 133 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
Settings (ops.npy)
22
------------------
33

4-
Here is a summary of all the parameters that the pipeline takes, and its
5-
default value.
4+
Suite2p can be run with different configurations using the ``ops`` dictionary. The ``ops`` dictionary will describe the settings used for a particular run of the pipeline. Here is a summary of all the parameters that the pipeline takes and their default values.
65

76
Main settings
87
~~~~~~~~~~~~~
@@ -27,6 +26,8 @@ These are the essential settings that are dataset-specific.
2726
- 1.0 for GCaMP6m
2827
- 1.25-1.5 for GCaMP6s
2928

29+
- **force_sktiff**: (*boolean, default: False*) specifies whether or not to use scikit-image for reading in tiffs
30+
3031
- **fs**: (*float, default: 10.0*) Sampling rate (per plane). For
3132
instance, if you have a 10 plane recording acquired at 30Hz, then the
3233
sampling rate per plane is 3Hz, so set ops['fs'] = 3.
@@ -42,16 +43,60 @@ These are the essential settings that are dataset-specific.
4243
line scanning (set by user). If set to any value besides 0, then this
4344
offset is used and applied to all frames in the recording.
4445

46+
- **bidi_corrected**: (*bool, default: False*) Specifies whether to do bidi correction.
47+
4548
- **frames_include**: (*int, default: -1*) if greater than zero, only *frames_include* frames are processed. useful for testing parameters on a subset of data.
4649

50+
- **multiplane_parallel**: (*boolean, default: False*) specifies whether or not to run pipeline on server
51+
52+
- **ignore_flyback**: (*list[ints], default: empty list*) specifies which planes will be ignored as flyback planes by the pipeline.
53+
54+
File input/output settings
55+
~~~~~~~~~~~~~~~~~~~~~~~~~~
56+
57+
Suite2p can accomodate many different file formats. Refer to this
58+
:ref:`page <inputs-diff-file-types>` for a detailed list of formats suite2p can work with.
59+
60+
- **fast_disk**: (*list[str], default: empty list*) specifies location where temporary binary file will be stored. Defaults to ``save_path0`` if no directory is provided by user.
61+
62+
- **delete_bin** (*bool, default:False*) specifies whether to delete binary file created during registration stage.
63+
64+
- **mesoscan** (*bool, default: False*) specifies whether file being read in is a scanimage mesoscope recording
65+
66+
- **bruker** (*bool, default: False*) specifies whether provided tif files are single page BRUKER tiffs
67+
68+
- **bruker_bidirectional** (*bool, default: False*) specifies whether BRUKER files are bidirectional multiplane recordings. The ``True`` setting corresponds to the following plane order (first plane is indexed as zero): [0,1,2,2,1,0]. ``False`` corresponds to [0,1,2,0,1,2].
69+
70+
- **h5py** (*list[str], default: empty list*) specifies path to h5py file that will be used as inputs. Keep in mind the pathname provided here overwrites the pathname specified in ``ops[data_path]``.
71+
72+
- **h5py_key** (*str, default: 'data'*) key used to access data array in h5py file. Only use this when the ``h5py`` setting is set to ``True``.
73+
74+
- **nwb_file** (*str, default: ''*) specifies path to NWB file you use to use as input
75+
76+
- **nwb_driver** (*str, default: ''*) location of driver for NWB file. Leave this empty if the pathname refers to a local file.
77+
78+
- **nwb_series** (*str, default: ''*) Name of TwoPhotonSeries values you wish to retrieve from your NWB file.
79+
80+
- **save_path0** (*list[str], default: empty list*) List containing pathname of where you'd like to save your pipeline results. If list is empty, the first element of ``ops['data_path']`` is used.
81+
82+
- **save_folder** (*list[str], default: empty list*) List containing directory name you'd like results to be saved under. Defaults to ``"suite2p"``.
83+
84+
- **look_one_level_down**: (*bool, default: False*) specifies whether to look in all subfolders when searching for tiffs. Make sure to specify subfolders in the ``subfolders`` parameter below.
85+
86+
- **subfolders** (*list[str], default: empty list*) Specifies subfolders you'd like to look through. Make sure to have the above parameter ``ops[look_one_level_down] = True`` when using this parameter.
87+
88+
- **move_bin** (*bool, default: False*) If True and ``ops['fast_disk']`` is different from ``ops[save_disk]``, the created binary file is moved to ``ops['save_disk']``.
89+
4790
Output settings
4891
~~~~~~~~~~~~~~~
4992

50-
- **preclassify**: (*float, default: 0.3*) (**new**) apply classifier
93+
- **preclassify**: (*float, default: 0.0*) (**new**) apply classifier
5194
before signal extraction with probability threshold of "preclassify".
5295
If this is set to 0.0, then all detected ROIs are kept and signals
5396
are computed.
5497

98+
- **save_nwb**: (*bool, default: False*) whether to save output as NWB file
99+
55100
- **save_mat**: (*bool, default: False*) whether to save the results in
56101
matlab format in file "Fall.mat". NOTE the cells you click in the GUI
57102
will NOT change "Fall.mat". But there is a **new** button in the GUI
@@ -69,8 +114,11 @@ Output settings
69114
a timing dictionary for each plane. Timing dictionary will contain keys
70115
corresponding to stages and values corresponding to the duration of that stage.
71116

72-
Registration
73-
~~~~~~~~~~~~
117+
118+
Registration settings
119+
~~~~~~~~~~~~~~~~~~~~~
120+
121+
These settings are specific to the registration module of suite2p.
74122

75123
- **do_registration**: (*bool, default: True*) whether or not to run
76124
registration
@@ -81,7 +129,7 @@ Registration
81129
expression, you may want to use this channel for alignment rather
82130
than the functional channel.
83131

84-
- **nimg_init**: (*int, default: 200*) how many frames to use to
132+
- **nimg_init**: (*int, default: 300*) how many frames to use to
85133
compute reference image for registration
86134

87135
- **batch_size**: (*int, default: 500*) how many frames to register
@@ -119,13 +167,24 @@ Registration
119167
- **reg_tif_chan2**: (*bool, default: False*) whether or not to write
120168
the registered binary of the non-functional channel to tiff files
121169

122-
**1P registration settings**
170+
- **subpixel**: (*int, default:10*) Precision of Subpixel Registration (1/subpixel steps)
171+
172+
- **th_badframes**: (*float, default: 1.0*) Involved with setting threshold for excluding frames for cropping. Set this smaller to exclude more frames.
173+
174+
- **norm_frames**: (*bool, default: True*) Normalize frames when detecting shifts
175+
176+
- **force_refImg**: (*bool, default: False*) Specifies whether to use refImg stored in ``ops``. Make sure that ``ops['refImg']`` has a valid file pathname.
177+
178+
- **pad_fft**: (*bool, default: False*) Specifies whether to pad image or not during FFT portion of registration.
179+
180+
1P registration
181+
^^^^^^^^^^^^^^^
123182

124183
- **1Preg**: (*bool, default: False*) whether to perform high-pass
125184
spatial filtering and tapering (parameters set below), which help
126185
with 1P registration
127186

128-
- **spatial_hp**: (*int, default: 42*) window in pixels for spatial
187+
- **spatial_hp_reg**: (*int, default: 42*) window in pixels for spatial
129188
high-pass filtering before registration
130189

131190
- **pre_smooth**: (*float, default: 0*) if > 0, defines stddev of
@@ -136,7 +195,8 @@ Registration
136195
on edges - they are set to zero (important for vignetted windows, for
137196
FFT padding do not set BELOW 3*ops['smooth_sigma'])
138197

139-
**Non-rigid registration**
198+
Non-rigid registration
199+
^^^^^^^^^^^^^^^^^^^^^^
140200

141201
- **nonrigid**: (*bool, default: True*) whether or not to perform
142202
non-rigid registration, which splits the field of view into blocks
@@ -156,13 +216,13 @@ Registration
156216
- **maxregshiftNR**: (*float, default: 5.0*) maximum shift in pixels of
157217
a block relative to the rigid shift
158218

159-
ROI detection
160-
~~~~~~~~~~~~~
219+
ROI detection settings
220+
~~~~~~~~~~~~~~~~~~~~~~
161221

162222
- **roidetect**: (*bool, default: True*) whether or not to run ROI
163223
detect and extraction
164224

165-
- **sparse_mode**: (*bool, default: False*) whether or not to use sparse_mode cell detection
225+
- **sparse_mode**: (*bool, default: True*) whether or not to use sparse_mode cell detection
166226

167227
- **spatial_scale**: (*int, default: 0*), what the optimal scale of the
168228
recording is in pixels. if set to 0, then the algorithm determines it
@@ -172,12 +232,14 @@ ROI detection
172232
- **connected**: (*bool, default: True*) whether or not to require ROIs
173233
to be fully connected (set to *0* for dendrites/boutons)
174234

175-
- **threshold_scaling**: (*float, default: 5.0*) this controls the
235+
- **threshold_scaling**: (*float, default: 1.0*) this controls the
176236
threshold at which to detect ROIs (how much the ROIs have to stand
177237
out from the noise to be detected). if you set this higher, then
178238
fewer ROIs will be detected, and if you set it lower, more ROIs will
179239
be detected.
180240

241+
- **spatial_hp_detect**: (*int, default: 25*) window for spatial high-pass filtering for neuropil subtracation before ROI detection takes place.
242+
181243
- **max_overlap**: (*float, default: 0.75*) we allow overlapping ROIs
182244
during cell detection. After detection, ROIs with more than
183245
ops['max_overlap'] fraction of their pixels overlapping with other
@@ -200,8 +262,33 @@ ROI detection
200262
- **nbinned**: (*int, default: 5000*) maximum number of binned frames
201263
to use for ROI detection.
202264

203-
Signal extraction
204-
~~~~~~~~~~~~~~~~~
265+
- **denoise**: (*bool, default: False*) Whether or not binned movie should be denoised before cell detection in sparse_mode. If True, make sure to set ``ops['sparse_mode']`` is also set to True.
266+
267+
Cellpose Detection
268+
^^^^^^^^^^^^^^^^^^
269+
These settings are only used if ``ops['anatomical_only']`` is set to an integer greater than 0.
270+
271+
- **anatomical_only**: (*int, default: 0*) If greater than 0, specifies what to use `Cellpose <https://cellpose.readthedocs.io/>`_ on.
272+
273+
- 1: Will find masks on max projection image divided by mean image.
274+
- 2: Will find masks on mean image
275+
- 3: Will find masks on enhanced mean image
276+
- 4: Will find masks on maximum projection image
277+
278+
- **diameter**: (*int, default: 0*) Diameter that will be used for cellpose. If set to zero, diameter is estimated.
279+
280+
- **cellprob_threshold**: (*float, default: 0.0*) specifies threshold for cell detection that will be used by cellpose.
281+
282+
- **flow_threshold**: (*float, default: 1.5*) specifies flow threshold that will be used for cellpose.
283+
284+
- **spatial_hp_cp**: (*int, default: 0*) Window for spatial high-pass filtering of image to be used for cellpose.
285+
286+
- **pretrained_model**: (*str, default: 'cyto'*) Path to pretrained model or string for model type (can be user's model ).
287+
288+
Signal extraction settings
289+
~~~~~~~~~~~~~~~~~~~~~~~~~~
290+
291+
- **neuropil_extract**: (*bool, default: True*) Whether or not to extract signal from neuropil. If False, Fneu is set to zero.
205292

206293
- **allow_overlap**: (*bool, default: False*) whether or not to extract
207294
signals from pixels which belong to two ROIs. By default, any pixels
@@ -214,39 +301,58 @@ Signal extraction
214301
- **inner_neuropil_radius**: (*int, default: 2*) number of pixels to
215302
keep between ROI and neuropil donut
216303

217-
Spike deconvolution
218-
~~~~~~~~~~~~~~~~~~~
304+
- **lam_percentile**: (*int, default: 50*)Percentile of Lambda within area to ignore when excluding cell pixels for neuropil extraction
219305

220-
We neuropil-correct the trace Fout = F - ops['neucoeff'] \* Fneu, and
221-
then baseline-correct these traces with an ops['baseline'] filter, and
306+
Spike deconvolution settings
307+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
308+
309+
We neuropil-correct the trace ``Fout = F - ops['neucoeff'] * Fneu``, and
310+
then baseline-correct these traces with an ``ops['baseline']`` filter, and
222311
then detect spikes.
223312

313+
- **spikedetect**: (*bool, default: True*) Whether or not to run spike_deconvolution
314+
224315
- **neucoeff**: (*float, default: 0.7*) neuropil coefficient for all ROIs.
225316

226317
- **baseline**: (*string, default 'maximin'*) how to compute the
227318
baseline of each trace. This baseline is then subtracted from each
228319
cell. *'maximin'* computes a moving baseline by filtering the data
229-
with a Gaussian of width ops['sig_baseline'] \* ops['fs'], and then
230-
minimum filtering with a window of ops['win_baseline'] \* ops['fs'],
320+
with a Gaussian of width ``ops['sig_baseline'] * ops['fs']``, and then
321+
minimum filtering with a window of ``ops['win_baseline'] * ops['fs']``,
231322
and then maximum filtering with the same window. *'constant'*
232323
computes a constant baseline by filtering with a Gaussian of width
233-
ops['sig_baseline'] \* ops['fs'] and then taking the minimum value of
324+
``ops['sig_baseline'] * ops['fs']`` and then taking the minimum value of
234325
this filtered trace. *'constant_percentile'* computes a constant
235-
baseline by taking the ops['prctile_baseline'] percentile of the
326+
baseline by taking the ``ops['prctile_baseline']`` percentile of the
236327
trace.
237328

238329
- **win_baseline**: (*float, default: 60.0*) window for maximin filter
239330
in seconds
240331

241332
- **sig_baseline**: (*float, default: 10.0*) Gaussian filter width in
242333
seconds, used before maximin filtering or taking the minimum value of
243-
the trace, ops['baseline'] = 'maximin' or 'constant'.
334+
the trace, ``ops['baseline'] = 'maximin'`` or ``'constant'``.
244335

245336
- **prctile_baseline**: (*float, optional, default: 8*) percentile of
246-
trace to use as baseline if ops['baseline'] = 'constant_percentile'.
337+
trace to use as baseline if ``ops['baseline'] = 'constant_percentile'``.
338+
339+
Classification settings
340+
~~~~~~~~~~~~~~~~~~~~~~~
247341

248-
Channel 2 settings
249-
~~~~~~~~~~~~~~~~~~
342+
- **soma_crop**: (*bool, default: True*) Specifies whether to crop dendrites for cell classification stats (e.g., compactness)
343+
344+
- **use_builtin_classifier**: (*bool, default: False*) Specifies whether or not to use built-in classifier for cell detection. This will override classifier specified in ``ops['classifier_path']`` if set to True.
345+
346+
- **classifier_path**: (*str, default: ''*) Path to classifier file you want to use for cell classification
347+
348+
Channel 2 specific settings
349+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
250350

251351
- **chan2_thres**: threshold for calling an ROI "detected" on a second
252352
channel
353+
354+
355+
Miscellaneous settings
356+
~~~~~~~~~~~~~~~~~~~~~~
357+
358+
- **suite2p_version**: specifies version of suite2p pipeline that was run with these settings. Changing this parameter will NOT change the version of suite2p used.

scripts/generate_test_data.py

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ def generate_1p1c1500_expected_data(ops):
3232
suite2p.run_s2p(ops=test_ops)
3333
rename_output_dir('1plane1chan1500')
3434

35-
# def generate_1p2c_expected_data(ops):
36-
# """
37-
# Generates expected output for test_1plane_2chan_sourcery of test_full_pipeline.py.
38-
# """
39-
# test_ops = FullPipelineTestUtils.initialize_ops_test_1plane_2chan_sourcery(ops.copy())
40-
# suite2p.run_s2p(ops=test_ops)
41-
# rename_output_dir('1plane2chan')
42-
4335
def generate_2p2c1500_expected_data(ops):
4436
"""
4537
Generates expected output for test_2plane_2chan_with_batches of test_full_pipeline.py.
@@ -78,17 +70,18 @@ def generate_detection_1plane1chan_test_data(ops):
7870
[[Path(ops['data_path'][0]).joinpath('detection/pre_registered.npy')]],
7971
(404, 360)
8072
)
81-
ops, stat = suite2p.detection.detect(ops[0])
82-
ops['neuropil_extract'] = True
83-
cell_masks, neuropil_masks = masks.create_masks(stat, ops['Ly'], ops['Lx'], ops=ops)
84-
output_dict = {
85-
'stat': stat,
86-
'cell_masks': cell_masks,
87-
'neuropil_masks': neuropil_masks
88-
}
89-
np.save('expected_detect_output_1p1c0.npy', output_dict)
90-
# Remove suite2p directory generated by prepare function
91-
shutil.rmtree(os.path.join(test_data_dir_path, 'suite2p'))
73+
with suite2p.io.BinaryRWFile(Ly = ops[0]['Ly'], Lx = ops[0]['Lx'], filename=ops[0]['reg_file']) as f_reg:
74+
ops, stat = suite2p.detection.detection_wrapper(f_reg, ops=ops[0])
75+
ops['neuropil_extract'] = True
76+
cell_masks, neuropil_masks = masks.create_masks(stat, ops['Ly'], ops['Lx'], ops=ops)
77+
output_dict = {
78+
'stat': stat,
79+
'cell_masks': cell_masks,
80+
'neuropil_masks': neuropil_masks
81+
}
82+
np.save('expected_detect_output_1p1c0.npy', output_dict)
83+
# Remove suite2p directory generated by prepare function
84+
shutil.rmtree(os.path.join(test_data_dir_path, 'suite2p'))
9285

9386
def generate_detection_2plane2chan_test_data(ops):
9487
"""
@@ -114,16 +107,17 @@ def generate_detection_2plane2chan_test_data(ops):
114107
two_plane_ops[1]['meanImg_chan2'] = np.load(detection_dir.joinpath('meanImg_chan2p1.npy'))
115108
for i in range(len(two_plane_ops)):
116109
op = two_plane_ops[i]
117-
# Neuropil_masks are later needed for extraction test data step
118-
op['neuropil_extract'] = True
119-
op, stat = suite2p.detection.detect(ops=op)
120-
cell_masks, neuropil_masks = masks.create_masks(stat, op['Ly'], op['Lx'], ops=op)
121-
output_dict = {
122-
'stat': stat,
123-
'cell_masks': cell_masks,
124-
'neuropil_masks': neuropil_masks
125-
}
126-
np.save('expected_detect_output_%ip%ic%i.npy' % (ops['nchannels'], ops['nplanes'], i), output_dict)
110+
with suite2p.io.BinaryRWFile(Ly = op['Ly'], Lx = op['Lx'], filename=op['reg_file']) as f_reg:
111+
# Neuropil_masks are later needed for extraction test data step
112+
op['neuropil_extract'] = True
113+
op, stat = suite2p.detection.detection_wrapper(f_reg, ops=op)
114+
cell_masks, neuropil_masks = masks.create_masks(stat, op['Ly'], op['Lx'], ops=op)
115+
output_dict = {
116+
'stat': stat,
117+
'cell_masks': cell_masks,
118+
'neuropil_masks': neuropil_masks
119+
}
120+
np.save('expected_detect_output_%ip%ic%i.npy' % (ops['nchannels'], ops['nplanes'], i), output_dict)
127121
# Get rid of registered binary files that were created for detection module in
128122
# DetectionTestUtils.prepare
129123
remove_binary_file(test_data_dir_path, 0, '')

0 commit comments

Comments
 (0)