suite2p.io package

Submodules

suite2p.io.binary module

class suite2p.io.binary.BinaryFile(Ly, Lx, read_filename, write_filename=None)[source]

Bases: object

bin_movie(bin_size, x_range=None, y_range=None, bad_frames=None, reject_threshold=0.5)[source]

Returns binned movie that rejects bad_frames (bool array) and crops to (y_range, x_range).

Parameters
  • bin_size (int) – The size of each bin

  • x_range (int, int) – Crops the data to a minimum and maximum x range.

  • y_range (int, int) – Crops the data to a minimum and maximum y range.

  • bad_frames (int array) – The indices to not include.

  • reject_threshold (float) –

Returns

frames – The frames

Return type

nImg x Ly x Lx

close()[source]

Closes the file.

Return type

None

static convert_numpy_file_to_suite2p_binary(from_filename, to_filename)[source]

Works with npz files, pickled npy files, etc.

Parameters
  • from_filename (str) – The npy file to convert

  • to_filename (str) – The binary file that will be created

Return type

None

property data

Returns all the frames in the file.

Returns

frames – The frame data

Return type

nImg x Ly x Lx

iter_frames(batch_size=1, dtype=<class 'numpy.float32'>)[source]

Iterates through each set of frames, depending on batch_size, yielding both the frame index and frame data.

Parameters
  • batch_size (int) – The number of frames to get at a time

  • dtype (np.dtype) – The nympy data type that the data should return as

Yields
  • indices (array int) – The frame indices.

  • data (batch_size x Ly x Lx) – The frames

ix(indices)[source]

Returns the frames at index values “indices”.

Parameters

indices (int array) – The frame indices to get

Returns

frames – The requested frames

Return type

len(indices) x Ly x Lx

property n_frames

total number of fraames in the read_file.

Return type

int

property nbytes

total number of bytes in the read_file.

property nbytesread

number of bytes per frame (FIXED for given file)

read(batch_size=1, dtype=<class 'numpy.float32'>)[source]

Returns the next frame(s) in the file and its associated indices.

Parameters
  • batch_size (int) – The number of frames to read at once.

  • frames (batch_size x Ly x Lx) – The frame data

Return type

Optional[Tuple[ndarray, ndarray]]

sampled_mean()[source]

Returns the sampled mean.

Return type

float

property shape

The dimensions of the data in the file

Return type

Tuple[int, int, int]

Returns

  • n_frames (int) – The number of frames

  • Ly (int) – The height of each frame

  • Lx (int) – The width of each frame

property size

Returns the total number of pixels

Returns

size

Return type

int

write(data)[source]

Writes frame(s) to the file.

Parameters

data (2D or 3D array) – The frame(s) to write. Should be the same width and height as the other frames in the file.

Return type

None

suite2p.io.binary.binned_mean(mov, bin_size)[source]

Returns an array with the mean of each time bin (of size ‘bin_size’).

Return type

ndarray

suite2p.io.binary.from_slice(s)[source]

Creates an np.arange() array from a Python slice object. Helps provide numpy-like slicing interfaces.

Return type

Optional[ndarray]

suite2p.io.binary.temporary_pointer(file)[source]

context manager that resets file pointer location to its original place upon exit.

suite2p.io.h5 module

suite2p.io.h5.h5py_to_binary(ops)[source]

finds h5 files and writes them to binaries

Parameters

ops (dictionary) – ‘nplanes’, ‘h5_path’, ‘h5_key’, ‘save_path’, ‘save_folder’, ‘fast_disk’, ‘nchannels’, ‘keep_movie_raw’, ‘look_one_level_down’

Returns

ops – ‘Ly’, ‘Lx’, ops[‘reg_file’] or ops[‘raw_file’] is created binary

Return type

dictionary of first plane

suite2p.io.nwb module

suite2p.io.nwb.read_nwb(fpath)[source]
suite2p.io.nwb.save_nwb(save_folder)[source]

convert folder with plane folders to NWB format

suite2p.io.save module

suite2p.io.save.combined(save_folder, save=True)[source]

Combines all the folders in save_folder into a single result file.

can turn off saving (for gui loading)

Multi-plane recordings are arranged to best tile a square. Multi-roi recordings are arranged by their dx,dy physical localization. Multi-plane / multi-roi recordings are tiled after using dx,dy.

suite2p.io.save.compute_dydx(ops1)[source]

suite2p.io.sbx module

suite2p.io.sbx.sbx_to_binary(ops, ndeadcols=- 1, ndeadrows=0)[source]

finds scanbox files and writes them to binaries

Parameters

ops (dictionary) – ‘nplanes’, ‘data_path’, ‘save_path’, ‘save_folder’, ‘fast_disk’, ‘nchannels’, ‘keep_movie_raw’, ‘look_one_level_down’

Returns

ops – ‘Ly’, ‘Lx’, ops[‘reg_file’] or ops[‘raw_file’] is created binary

Return type

dictionary of first plane

suite2p.io.server module

suite2p.io.server.send_jobs(save_folder, host=None, username=None, password=None, server_root=None, n_cores=4)[source]

send each plane to compute on server separately

add your own host, username, password and path on server for where to save the data

suite2p.io.server.ssh_connect(host, username, password)[source]

from paramiko example

suite2p.io.server.unix_path(path)[source]

suite2p.io.tiff module

suite2p.io.tiff.generate_tiff_filename(functional_chan, align_by_chan, save_path, k, ichan)[source]

Calculates a suite2p tiff filename from different parameters.

Parameters
  • functional_chan (int) – The channel number with functional information

  • align_by_chan (int) – Which channel to use for alignment

  • save_path (str) – The directory to save to

  • k (int) – The file number

  • wchan (int) – The channel number.

Returns

filename

Return type

str

suite2p.io.tiff.mesoscan_to_binary(ops)[source]

finds mesoscope tiff files and writes them to binaries

Parameters

ops (dictionary) – ‘nplanes’, ‘data_path’, ‘save_path’, ‘save_folder’, ‘fast_disk’, ‘nchannels’, ‘keep_movie_raw’, ‘look_one_level_down’, ‘lines’, ‘dx’, ‘dy’

Returns

ops – ops[‘reg_file’] or ops[‘raw_file’] is created binary assigns keys ‘Ly’, ‘Lx’, ‘tiffreader’, ‘first_tiffs’, ‘frames_per_folder’, ‘nframes’, ‘meanImg’, ‘meanImg_chan2’

Return type

dictionary of first plane

suite2p.io.tiff.ome_to_binary(ops)[source]

converts ome.tiff to *.bin file for non-interleaved red channel recordings assumes SINGLE-PAGE tiffs where first channel has string ‘Ch1’ and also SINGLE FOLDER

Parameters

ops (dictionary) – keys nplanes, nchannels, data_path, look_one_level_down, reg_file

Returns

ops – creates binaries ops[‘reg_file’] assigns keys: tiffreader, first_tiffs, frames_per_folder, nframes, meanImg, meanImg_chan2

Return type

dictionary of first plane

suite2p.io.tiff.open_tiff(file, sktiff)[source]

Returns image and its length from tiff file with either ScanImageTiffReader or tifffile, based on ‘sktiff’

Return type

Tuple[Union[TiffFile, ScanImageTiffReader], int]

suite2p.io.tiff.save_tiff(mov, fname)[source]

Save image stack array to tiff file.

Parameters
  • mov (nImg x Ly x Lx) – The frames to save

  • fname (str) – The tiff filename to save to

Return type

None

suite2p.io.tiff.tiff_to_binary(ops)[source]

finds tiff files and writes them to binaries

Parameters

ops (dictionary) – ‘nplanes’, ‘data_path’, ‘save_path’, ‘save_folder’, ‘fast_disk’, ‘nchannels’, ‘keep_movie_raw’, ‘look_one_level_down’

Returns

ops – ops[‘reg_file’] or ops[‘raw_file’] is created binary assigns keys ‘Ly’, ‘Lx’, ‘tiffreader’, ‘first_tiffs’, ‘frames_per_folder’, ‘nframes’, ‘meanImg’, ‘meanImg_chan2’

Return type

dictionary of first plane

suite2p.io.tiff.use_sktiff_reader(tiff_filename, batch_size=None)[source]

Returns False if ScanImageTiffReader works on the tiff file, else True (in which case use tifffile).

Return type

bool

suite2p.io.utils module

suite2p.io.utils.find_files_open_binaries(ops1, ish5=False)[source]

finds tiffs or h5 files and opens binaries for writing

Parameters

ops1 (list of dictionaries) – ‘keep_movie_raw’, ‘data_path’, ‘look_one_level_down’, ‘reg_file’…

Returns

ops1 – adds fields ‘filelist’, ‘first_tiffs’, opens binaries

Return type

list of dictionaries

suite2p.io.utils.get_h5_list(ops)[source]

make list of h5 files to process if ops[‘look_one_level_down’], then all h5’s in all folders + one level down

suite2p.io.utils.get_sbx_list(ops)[source]

make list of scanbox files to process if ops[‘subfolders’], then all tiffs ops[‘data_path’][0] / ops[‘subfolders’] / *.sbx if ops[‘look_one_level_down’], then all tiffs in all folders + one level down TODO: Implement “tiff_list” functionality

suite2p.io.utils.get_tif_list(ops)[source]

make list of tiffs to process if ops[‘subfolders’], then all tiffs ops[‘data_path’][0] / ops[‘subfolders’] / *.tif if ops[‘look_one_level_down’], then all tiffs in all folders + one level down if ops[‘tiff_list’], then ops[‘data_path’][0] / ops[‘tiff_list’] ONLY

suite2p.io.utils.init_ops(ops)[source]

initializes ops files for each plane in recording

Parameters

ops (dictionary) – ‘nplanes’, ‘save_path’, ‘save_folder’, ‘fast_disk’, ‘nchannels’, ‘keep_movie_raw’ + (if mesoscope) ‘dy’, ‘dx’, ‘lines’

Returns

ops1 – adds fields ‘save_path0’, ‘reg_file’ (depending on ops: ‘raw_file’, ‘reg_file_chan2’, ‘raw_file_chan2’)

Return type

list of dictionaries

suite2p.io.utils.list_files(froot, look_one_level_down, exts)[source]

get list of files with exts in folder froot + one level down maybe

suite2p.io.utils.list_h5(ops)[source]
suite2p.io.utils.search_for_ext(rootdir, extension='tif', look_one_level_down=False)[source]

Module contents