io#

Data Loading/Writing functions for mesoscope data

Functions to load and save ScanImage data

labtools.mesoscope.io.bigtiff_nframes(path: Union[pathlib.Path, ScanImageTiffReader.ScanImageTiffReader]) β†’ int[source]#

Check the number of frames in a bigtiff

labtools.mesoscope.io.iter_bigtiff(path: Optional[pathlib.Path] = None, batch_size: int = 1, reader: Optional[ScanImageTiffReader.ScanImageTiffReader] = None, start_frame: int = 0, end_frame: Optional[int] = None)[source]#

Iterate through frames in a BigTiff file

Examples

for frame in iter_bigtiff(path):

# do something with the frame

Parameters
  • path (pathlib.Path) – Path to input tiff

  • batch_size (int) – Number of images to yield at once

  • reader (ScanImageTiffReader) – Optional - an already-opened TiffReader. Either path or reader needs to be passed

labtools.mesoscope.io.bigtiff_to_video(path: pathlib.Path, output: Optional[pathlib.Path] = None, ops: Optional[pathlib.Path] = None, start_frame: int = 0, end_frame: Optional[int] = None, source_fps: int = 30, output_fps: int = 30, codec: str = 'libx264', pix_fmt: str = 'yuv420p', input_kwargs: Optional[dict] = None, output_kwargs: Optional[dict] = None, verbosity: int = 1, brightness: float = 1, dfof_kwargs: Optional[dict] = None) β†’ pathlib.Path[source]#

Convert a bigtiff to a video file using scikit-image.

Parameters
  • path (Path) – Input bigtiff path

  • output (Path) – Optional, output video path. If None, then just replace extension with .mp4

  • ops (Path) – Ops file. if None, try to get <path>_ops.json

  • start_frame (int) – Frame of input to start on

  • end_frame (int) – Frame of input to end output video

  • source_fps (int) – fps of source video

  • output_fps (int) – fps to convert output video to

  • codec (str) – video codec!

  • pix_fmt (str) – pixel format (default yuv420p)

  • input_kwargs – Passed to skvideo.io.FFMpegWriter

  • output_kwargs – Passed to skvideo.io.FFMpegWriter

  • brightness (float) – adjust brightness (linearly, by multiplication lmao)

  • dfof_kwargs (dict) – if not None, a dictionary passed to dfof()

Returns

Path of encoded video

References

https://github.com/MouseLand/suite2p/blob/main/suite2p/io/tiff.py

labtools.mesoscope.io.gamma_correct(frame: numpy.ndarray, gamma: float = 1)[source]#

8-bit gamma

labtools.mesoscope.io.minmax(frame, max_=255)[source]#
labtools.mesoscope.io.iterative_median(reader: ScanImageTiffReader.ScanImageTiffReader, batch_size: int = 10) β†’ numpy.ndarray[source]#

Find the median of a big huge video by taking the med

labtools.mesoscope.io.dfof(input: ScanImageTiffReader.ScanImageTiffReader, method: Literal['median', 'mean'] = 'median', iterative=False, **kwargs) β†’ numpy.ndarray[source]#

Calculate the median of each frame of a video

labtools.mesoscope.io.restack_bigtiff(frame: numpy.ndarray, ops: dict) β†’ numpy.ndarray[source]#

bigtiffs are usually just huge vertical strips.

Use the ops file to unstack them into normal frames.

Note

This is just an approximation for the sake of making a video, don’t use this for analysis!

References

https://github.com/MouseLand/suite2p/blob/main/suite2p/io/tiff.py