io#

I/O functions for the SD card

class miniscope_io.io.SDCard(drive: str | Path, layout: SDLayout)#

I/O for data on an SDCard

an instance of sdcard.SDLayout (typically in formats ) configures how the data is laid out on the SD card. This class makes the i/o operations abstract over multiple layouts

Parameters:
check_valid() bool#

Checks that the header sector has the appropriate write keys in it

Returns:

bool - True if valid, False if not

property config: SDConfig#
property frame: int | None#

When reading, the number of the frame that would be read if we were to call read()

property frame_count: int#

Total number of frames in recording.

Inferred from n_buffers_recorded and reading a single frame to get the number of buffers per frame.

property position: int | None#

When entered as context manager, the current position of the internal file descriptor

positions#

)

As we read, we store the locations of each frame before reading it. Later, we can assign to frame to seek back to those positions. Assigning to frame works without caching position, but has to manually iterate through each frame.

Type:

A mapping between frame number and byte position in the video that makes for faster seeking

read(return_header: Literal[True] = True) Frame#
read(return_header: Literal[False] = False) ndarray

Read a single frame

Parameters:

return_header (bool) – If True, return headers from individual buffers (default False)

Returns:

numpy.ndarray , or a tuple(ndarray, List[DataHeader]) if return_header is True

skip()#

Skip a frame

Read the buffer headers to determine buffer sizes and just seek ahead

to_video(path: Path | str, fourcc: Literal['GREY', 'mp4v', 'XVID'] = 'GREY', isColor: bool = False, force: bool = False, progress: bool = True)#

Save contents of SD card to video with opencv

Parameters:
  • path (pathlib.Path) – Output video path, with video extension .avi or .mp4

  • fourcc (str) – FourCC code used with opencv. Other codecs may be available depending on your opencv installation, but by default opencv supports one of: * GREY (default) * mp4v * XVID

  • isColor (bool) – Indicates whether output video is in color (default: False)

  • force (bool) – If True, overwrite output video if one already exists (default: False)

  • progress (bool) – If True (default) show progress bar.