suite2p.io package#
Copyright © 2023 Howard Hughes Medical Institute, Authored by Carsen Stringer and Marius Pachitariu.
BinaryFile #
Source code in suite2p/io/binary.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
data
property
#
data
Return all frames in the file.
Returns:
| Name | Type | Description |
|---|---|---|
frames |
ndarray
|
All frame data as an array of shape (n_frames, Ly, Lx). |
shape
property
#
shape
Return the dimensions of the data in the file.
Returns:
| Name | Type | Description |
|---|---|---|
n_frames |
int
|
Number of frames. |
Ly |
int
|
Height of each frame in pixels. |
Lx |
int
|
Width of each frame in pixels. |
size
property
#
size
Return the total number of pixels across all frames.
Returns:
| Name | Type | Description |
|---|---|---|
size |
int
|
Product of n_frames * Ly * Lx. |
__init__ #
__init__(Ly, Lx, filename, n_frames=None, dtype='int16', write=False)
Open or create a Suite2p binary file backed by a memory-mapped numpy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Ly
|
int
|
Height of each frame in pixels. |
required |
Lx
|
int
|
Width of each frame in pixels. |
required |
filename
|
str
|
Path to the binary file to read from or write to. |
required |
n_frames
|
int
|
Number of frames. Required when creating a new file for writing. Inferred from file size when reading. |
None
|
dtype
|
str, optional (default "int16")
|
Data type of each pixel value. |
'int16'
|
write
|
bool, optional (default False)
|
If True, open the file for reading and writing. If False, open read-only. |
False
|
Source code in suite2p/io/binary.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
close #
close()
Closes the file.
Source code in suite2p/io/binary.py
114 115 116 117 118 | |
convert_numpy_file_to_suite2p_binary
staticmethod
#
convert_numpy_file_to_suite2p_binary(from_filename, to_filename)
Convert a numpy file (.npy, .npz) to a Suite2p binary file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_filename
|
str
|
Path to the source numpy file to convert. |
required |
to_filename
|
str
|
Path to the binary file that will be created. |
required |
Source code in suite2p/io/binary.py
57 58 59 60 61 62 63 64 65 66 67 68 69 | |
sampled_mean #
sampled_mean()
Compute the mean image from up to 1000 evenly spaced frames.
Returns:
| Name | Type | Description |
|---|---|---|
mean_img |
ndarray
|
Mean image of shape (Ly, Lx), averaged over the sampled frames. |
Source code in suite2p/io/binary.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
write_tiff #
write_tiff(fname, range_dict={})
Write binary file contents to a TIFF file, optionally cropped by frame/y/x ranges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Output TIFF file path. |
required |
range_dict
|
dict
|
Dictionary with optional keys "frame_range", "y_range", "x_range", each a tuple of (start, stop) indices. Defaults to the full extent of each dimension. |
{}
|
Source code in suite2p/io/binary.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
BinaryFileCombined #
Source code in suite2p/io/binary.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
__init__ #
__init__(LY, LX, Ly, Lx, dy, dx, read_filenames)
Open multiple Suite2p binary files for combined reading across ROIs/planes.
Stitches multiple binary files into a single full-frame view by placing each ROI at its (dy, dx) offset within a canvas of size (LY, LX).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
LY
|
int
|
Height of the full combined frame in pixels. |
required |
LX
|
int
|
Width of the full combined frame in pixels. |
required |
Ly
|
ndarray
|
Array of per-ROI frame heights. |
required |
Lx
|
ndarray
|
Array of per-ROI frame widths. |
required |
dy
|
ndarray
|
Array of y-offsets for placing each ROI in the full frame. |
required |
dx
|
ndarray
|
Array of x-offsets for placing each ROI in the full frame. |
required |
read_filenames
|
list of str
|
Paths to the binary files to read, one per ROI. |
required |
Source code in suite2p/io/binary.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
close #
close()
Close all underlying binary files.
Source code in suite2p/io/binary.py
261 262 263 264 | |
temporary_pointer #
temporary_pointer(file)
Context manager that saves and restores a file's pointer position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
file object
|
An open file with tell() and seek() methods. |
required |
Source code in suite2p/io/binary.py
195 196 197 198 199 200 201 202 203 204 205 206 207 | |
Copyright © 2023 Howard Hughes Medical Institute, Authored by Carsen Stringer and Marius Pachitariu.
dcimg_to_binary #
dcimg_to_binary(dbs, settings, reg_file, reg_file_chan2)
finds dcimg files and writes them to binaries
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
"nplanes", "data_path", "save_path", "save_folder", "fast_disk", "nchannels", "keep_movie_raw", "look_one_level_down" |
required |
Returns:
| Type | Description |
|---|---|
settings : dictionary of first plane
|
settings["reg_file"] or settings["raw_file"] is created binary assigns keys "Ly", "Lx", "tiffreader", "first_tiffs", "nframes", "meanImg", "meanImg_chan2" |
Source code in suite2p/io/dcam.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
Copyright © 2023 Howard Hughes Medical Institute, Authored by Carsen Stringer and Marius Pachitariu.
h5py_to_binary #
h5py_to_binary(dbs, settings, reg_file, reg_file_chan2)
Read HDF5 files and write interleaved plane/channel data to binary files.
Iterates over all HDF5 files listed in dbs[0]["file_list"], de-interleaves
planes and channels, and writes each plane's frames to the corresponding binary
file. Supports 3D, 4D, and 5D HDF5 datasets (higher-dimensional data is
flattened to frames x Ly x Lx before de-interleaving).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dbs
|
list of dict
|
Database dictionaries for each plane. Must contain keys "file_list", "nplanes", "nchannels", "batch_size", "h5py_key", and "functional_chan". Updated in-place with "Ly", "Lx", "nframes", "nframes_per_folder", "meanImg", and "meanImg_chan2". |
required |
settings
|
dict
|
Suite2p settings dictionary, saved alongside each plane's database. |
required |
reg_file
|
list of file objects
|
Opened binary files for writing each plane's functional channel data. |
required |
reg_file_chan2
|
list of file objects
|
Opened binary files for writing each plane's second channel data (used only when nchannels > 1). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dbs |
list of dict
|
Updated database dictionaries with image dimensions, frame counts, and mean images populated. |
Source code in suite2p/io/h5.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
VideoReader #
Uses cv2 to read video files
Source code in suite2p/io/movie.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
shape
property
#
shape
The dimensions of the data in the file
Returns:
| Name | Type | Description |
|---|---|---|
n_frames |
int
|
The number of frames |
Ly |
int
|
The height of each frame |
Lx |
int
|
The width of each frame |
__init__ #
__init__(filenames)
Uses cv2 to open video files and obtain their details for reading
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filenames
|
int
|
list of video files |
required |
Source code in suite2p/io/movie.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
close #
close()
Closes the video files
Source code in suite2p/io/movie.py
51 52 53 54 55 56 57 | |
get_frames #
get_frames(cframes)
read frames "cframes" from videos
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cframes
|
array
|
start and stop of frames to read, or consecutive list of frames to read |
required |
Source code in suite2p/io/movie.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
movie_to_binary #
movie_to_binary(dbs, settings, reg_file, reg_file_chan2)
finds movie files and writes them to binaries
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dbs
|
list of dict
|
Database dictionaries for each plane. Must contain keys "file_list", "nplanes", "nchannels", "batch_size", "h5py_key", and "functional_chan". Updated in-place with "Ly", "Lx", "nframes", "nframes_per_folder", "meanImg", and "meanImg_chan2". |
required |
settings
|
dict
|
Suite2p settings dictionary, saved alongside each plane's database. |
required |
reg_file
|
list of file objects
|
Opened binary files for writing each plane's functional channel data. |
required |
reg_file_chan2
|
list of file objects
|
Opened binary files for writing each plane's second channel data (used only when nchannels > 1). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dbs |
list of dict
|
Updated database dictionaries with image dimensions, frame counts, and mean images populated. |
Source code in suite2p/io/movie.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
Copyright © 2023 Howard Hughes Medical Institute, Authored by Carsen Stringer and Marius Pachitariu.
nd2_to_binary #
nd2_to_binary(settings)
finds nd2 files and writes them to binaries
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
"nplanes", "data_path", "save_path", "save_folder", "fast_disk", "nchannels", "keep_movie_raw", "look_one_level_down" |
required |
Returns:
| Type | Description |
|---|---|
settings : dictionary of first plane
|
settings["reg_file"] or settings["raw_file"] is created binary assigns keys "Ly", "Lx", "tiffreader", "first_tiffs", "nframes", "meanImg", "meanImg_chan2" |
Source code in suite2p/io/nd2.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
Copyright © 2023 Howard Hughes Medical Institute, Authored by Carsen Stringer and Marius Pachitariu.
nwb_to_binary #
nwb_to_binary(settings)
convert nwb file to binary (experimental)
converts single plane single channel nwb file to binary for suite2p processing
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
requires "nwb_file" key optional keys "nwb_driver", "nwb_series" uses "nplanes", "save_path", "save_folder", "fast_disk", "nchannels", "keep_movie_raw", "look_one_level_down" |
required |
Returns:
| Type | Description |
|---|---|
settings : dictionary of first plane
|
settings["reg_file"] or settings["raw_file"] is created binary assigns keys "Ly", "Lx", "tiffreader", "first_tiffs", "frames_per_folder", "nframes", "meanImg", "meanImg_chan2" |
Source code in suite2p/io/nwb.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
read_nwb #
read_nwb(fpath)
read NWB file for use in the GUI
Source code in suite2p/io/nwb.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
save_nwb #
save_nwb(save_folder)
convert folder with plane folders to NWB format
Source code in suite2p/io/nwb.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
Copyright © 2023 Yoav Livneh Lab, Authored by Yael Prilutski.
raw_to_binary #
raw_to_binary(ops, use_recorded_defaults=True)
Finds RAW files and writes them to binaries
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ops
|
dictionary
|
"data_path" |
required |
use_recorded_defaults
|
bool
|
Recorded session parameters are used when 'True', otherwise |ops| is expected to contain the following (additional) keys: "nplanes", "nchannels", "fs" |
True
|
Returns:
| Type | Description |
|---|---|
ops : dictionary of first plane
|
|
Source code in suite2p/io/raw.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
Copyright © 2023 Howard Hughes Medical Institute, Authored by Carsen Stringer and Marius Pachitariu.
combined #
combined(save_folder, save=True)
Combine all plane folders in save_folder into a single result file.
Loads per-plane results (stat, F, Fneu, spks, iscell, redcell), shifts ROI coordinates by the tiled offsets, and concatenates them into combined arrays. Multi-plane recordings are arranged to best tile a square. Multi-ROI recordings are arranged by their dx, dy physical localization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_folder
|
str
|
Path to the suite2p output folder containing plane subdirectories (e.g. "plane0", "plane1", ...). |
required |
save
|
bool, optional (default True)
|
If True, save combined results (F.npy, Fneu.npy, spks.npy, stat.npy, db.npy, settings.npy, and optionally Fall.mat) to a "combined" subfolder. If False, only iscell.npy (and redcell.npy) are saved. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
stat |
ndarray
|
Concatenated ROI statistics across all planes. |
db |
dict
|
Combined database dictionary with merged mean images and full-frame dimensions. |
settings |
dict
|
Suite2p settings dictionary. |
F |
ndarray
|
Combined fluorescence traces of shape (n_cells_total, n_frames). |
Fneu |
ndarray
|
Combined neuropil traces of shape (n_cells_total, n_frames). |
spks |
ndarray
|
Combined deconvolved spike traces of shape (n_cells_total, n_frames). |
iscell0 |
ndarray
|
Binary cell classification labels for each ROI. |
iscell1 |
ndarray
|
Cell classification probabilities for each ROI. |
redcell0 |
ndarray
|
Binary red-cell labels for each ROI. |
redcell1 |
ndarray
|
Red-cell probabilities for each ROI. |
hasred |
bool
|
Whether red-cell classification data was found. |
Source code in suite2p/io/save.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
compute_dydx #
compute_dydx(db1)
Compute pixel offsets (dy, dx) for tiling multiple planes/ROIs into a combined view.
If the databases do not contain "dx" and "dy" fields, arranges planes in a grid that best tiles a square. If offsets are present (e.g. mesoscope ROIs), uses the physical offsets and further tiles across planes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db1
|
list of dict
|
List of per-plane database dictionaries. Each must contain "Ly" and "Lx". May contain "dx" and "dy" for physical ROI offsets. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dy |
ndarray
|
Y-offsets (in pixels) for each plane, shape (len(db1),). |
dx |
ndarray
|
X-offsets (in pixels) for each plane, shape (len(db1),). |
Source code in suite2p/io/save.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
save_mat #
save_mat(ops, stat, F, Fneu, spks, iscell, redcell, F_chan2=None, Fneu_chan2=None)
Save Suite2p results to a MATLAB .mat file.
Converts pathlib paths to strings, replaces None values with empty arrays,
and writes all results to "Fall.mat" in the save path specified in ops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ops
|
dict
|
Suite2p options dictionary. Must contain "save_path". The "date_proc" field is converted to a string if present. |
required |
stat
|
ndarray
|
Array of ROI statistics dictionaries (one per detected cell). |
required |
F
|
ndarray
|
Fluorescence traces of shape (n_cells, n_frames). |
required |
Fneu
|
ndarray
|
Neuropil fluorescence traces of shape (n_cells, n_frames). |
required |
spks
|
ndarray
|
Deconvolved spike traces of shape (n_cells, n_frames). |
required |
iscell
|
ndarray
|
Cell classification array of shape (n_cells, 2), with columns for binary label and probability. |
required |
redcell
|
ndarray
|
Red channel cell classification array, or None. |
required |
F_chan2
|
ndarray
|
Second channel fluorescence traces of shape (n_cells, n_frames). |
None
|
Fneu_chan2
|
ndarray
|
Second channel neuropil fluorescence traces of shape (n_cells, n_frames). |
None
|
Source code in suite2p/io/save.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
Copyright © 2023 Howard Hughes Medical Institute, Authored by Carsen Stringer and Marius Pachitariu.
sbx_to_binary #
sbx_to_binary(settings, ndeadcols=-1, ndeadrows=0)
finds scanbox files and writes them to binaries
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
dictionary
|
"nplanes", "data_path", "save_path", "save_folder", "fast_disk", "nchannels", "keep_movie_raw", "look_one_level_down" |
required |
Returns:
| Type | Description |
|---|---|
settings : dictionary of first plane
|
"Ly", "Lx", settings["reg_file"] or settings["raw_file"] is created binary |
Source code in suite2p/io/sbx.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
Copyright © 2023 Howard Hughes Medical Institute, Authored by Carsen Stringer and Marius Pachitariu.
send_jobs #
send_jobs(save_folder, host=None, username=None, password=None, server_root=None, local_root=None, n_cores=8)
send each plane to compute on server separately
add your own host, username, password and path on server for where to save the data
Source code in suite2p/io/server.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
ssh_connect #
ssh_connect(host, username, password, verbose=True)
from paramiko example
Source code in suite2p/io/server.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
Copyright © 2023 Howard Hughes Medical Institute, Authored by Carsen Stringer and Marius Pachitariu.
ome_to_binary #
ome_to_binary(dbs, settings, reg_file, reg_file_chan2)
Convert non-interleaved OME-TIFF files to binary, splitting channels by filename.
Designed for recordings where channels are stored in separate TIFF files (distinguished by "Ch1"/"Ch2" in the filename) rather than interleaved pages. Supports both single-page and multi-page TIFFs, and handles bidirectional Bruker plane ordering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dbs
|
list of dict
|
Database dictionaries for each plane. Must contain keys "file_list", "first_files", "batch_size", "nplanes", "nchannels", "functional_chan", and optionally "bruker_bidirectional". Updated in-place with "Ly", "Lx", "nframes", "frames_per_file", "frames_per_folder", "meanImg", and "meanImg_chan2". |
required |
settings
|
dict
|
Suite2p settings dictionary, saved alongside each plane's database. |
required |
reg_file
|
list of file objects
|
Opened binary files for writing each plane's functional channel data. |
required |
reg_file_chan2
|
list of file objects
|
Opened binary files for writing each plane's second channel data (used only when nchannels > 1). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dbs |
list of dict
|
Updated database dictionaries with image dimensions, frame counts, and mean images populated. |
Source code in suite2p/io/tiff.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | |
open_tiff #
open_tiff(file, sktiff)
Open a TIFF file and return the reader object and the number of pages.
Uses either tifffile or ScanImageTiffReader depending on sktiff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
Path to the TIFF file. |
required |
sktiff
|
bool
|
If True, use tifffile (TiffFile). If False, use ScanImageTiffReader. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tif |
TiffFile or ScanImageTiffReader
|
Opened TIFF reader object. |
Ltif |
int
|
Number of pages (frames) in the TIFF file. |
Source code in suite2p/io/tiff.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
read_tiff #
read_tiff(file, tif, Ltif, ix, batch_size, use_sktiff)
Read a batch of frames from an open TIFF file starting at index ix.
Reads up to batch_size frames and converts the data to int16. Returns None
if ix is past the end of the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
Path to the TIFF file (used by tifffile's |
required |
tif
|
TiffFile or ScanImageTiffReader
|
Already-opened TIFF reader object. |
required |
Ltif
|
int
|
Total number of pages (frames) in the TIFF file. |
required |
ix
|
int
|
Starting frame index to read from. |
required |
batch_size
|
int
|
Maximum number of frames to read in this batch. |
required |
use_sktiff
|
bool
|
If True, read with tifffile ( |
required |
Returns:
| Name | Type | Description |
|---|---|---|
im |
ndarray or None
|
Frames as an int16 array of shape (nfr, Ly, Lx), or None if |
Source code in suite2p/io/tiff.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
tiff_to_binary #
tiff_to_binary(dbs, settings, reg_file, reg_file_chan2)
Read TIFF files and write interleaved plane/channel data to binary files.
Iterates over all TIFF files listed in dbs[0]["file_list"], de-interleaves
planes and channels, and writes each plane's frames to the corresponding binary
file. Also computes per-plane mean images and frame counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dbs
|
list of dict
|
Database dictionaries for each plane/ROI. Must contain keys "file_list", "first_files", "batch_size", "force_sktiff", "nplanes", "nchannels", and optionally "nrois", "swap_order", "lines". Updated in-place with "Ly", "Lx", "nframes", "frames_per_file", "frames_per_folder", "meanImg", and "meanImg_chan2". |
required |
settings
|
dict
|
Suite2p settings dictionary, saved alongside each plane's database. |
required |
reg_file
|
list of file objects
|
Opened binary files for writing each plane's functional channel data. |
required |
reg_file_chan2
|
list of file objects
|
Opened binary files for writing each plane's second channel data (used only when nchannels > 1). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dbs |
list of dict
|
Updated database dictionaries with image dimensions, frame counts, and mean images populated. |
Source code in suite2p/io/tiff.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
use_sktiff_reader #
use_sktiff_reader(tiff_filename, batch_size)
Test whether ScanImageTiffReader can read a TIFF file.
Attempts to read a small batch from the file using ScanImageTiffReader. If it succeeds, returns False (use ScanImageTiffReader). If it fails or the package is not installed, returns True (fall back to tifffile).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tiff_filename
|
str
|
Path to the TIFF file to test. |
required |
batch_size
|
int
|
Number of frames to attempt reading as a test. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
use_sktiff |
bool
|
True if tifffile should be used, False if ScanImageTiffReader works. |
Source code in suite2p/io/tiff.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
Copyright © 2023 Howard Hughes Medical Institute, Authored by Carsen Stringer and Marius Pachitariu.
find_files_open_binaries #
find_files_open_binaries(settings)
Find input files and open binary files for writing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
dict
|
Suite2p settings dictionary. |
required |
Returns:
| Type | Description |
|---|---|
None
|
No longer used!! |
Source code in suite2p/io/utils.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
get_file_list #
get_file_list(db)
Build the list of input files to process from the database configuration.
Supports three modes: an explicit file list (db["file_list"]), subfolder-based discovery (db["subfolders"]), or recursive search with optional one-level-down lookup (db["look_one_level_down"]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
dict
|
Database dictionary. Must contain "data_path" (list of str). Optionally contains "file_list" (list of str), "subfolders" (list of str), "look_one_level_down" (bool), and "input_format" (str, default "tif"). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
fsall |
list of str
|
List of all file paths to process. |
first_files |
ndarray
|
Boolean array of length len(fsall), where True marks the first file from each folder. |
Source code in suite2p/io/utils.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
get_suite2p_path #
get_suite2p_path(path)
Find the root suite2p folder within a given path.
Walks the path components backwards to locate the last occurrence of a folder named "suite2p" and returns the path up to and including that folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
File or directory path that should contain a "suite2p" folder component. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
new_path |
Path
|
Path truncated at the "suite2p" folder. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If "suite2p" is not found in any component of |
Source code in suite2p/io/utils.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
init_dbs #
init_dbs(db0)
Initialize per-plane database dictionaries and create output directories.
Creates a deep copy of db0 for each plane (and each ROI for mesoscope recordings),
setting up save paths, binary file paths, and fast-disk directories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db0
|
dict
|
Base database dictionary. Must contain "nplanes", "nchannels", "keep_movie_raw", "save_path0", and "save_folder". Optionally contains "fast_disk", "iplane", "lines", "dy", and "dx" (for mesoscope recordings with multiple ROIs). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dbs |
list of dict
|
List of per-plane database dictionaries, each with added keys "save_path", "fast_disk", "settings_path", "db_path", "reg_file", and optionally "raw_file", "reg_file_chan2", "raw_file_chan2", "lines", "dy", "dx", "iroi", "iplane". |
Source code in suite2p/io/utils.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
list_files #
list_files(froot, look_one_level_down, exts)
Collect files matching the given extensions from a folder, optionally including subfolders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
froot
|
str
|
Root directory to search for files. |
required |
look_one_level_down
|
bool
|
If True, also search immediate subdirectories of |
required |
exts
|
list of str
|
Glob patterns to match (e.g. [".tif", ".tiff"]). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
fs |
list of str
|
Naturally sorted list of matching file paths. |
first_files |
ndarray
|
Boolean array of length len(fs), where True marks the first file from each folder (used to track folder boundaries). |
Source code in suite2p/io/utils.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |