1. Core#
Functions central to data analysis on datasets collected at the MBO.
- mbo_utilities.read_scan(pathnames, dtype=<class 'numpy.int16'>)[source]#
Reads a ScanImage scan from a given file or set of file paths and returns a ScanMultiROIReordered object with lazy-loaded data.
- Parameters:
- pathnamesstr, Path, or sequence of str/Path
A single path, a wildcard pattern (e.g.
*.tif
), or a list of paths specifying the ScanImage TIFF files to read.- dtypenumpy.dtype, optional
The data type to use when reading the scan data. Default is np.int16.
- Returns:
- ScanMultiROIReordered
A scan object with metadata and lazily loaded data. Raises FileNotFoundError if no files match the specified path(s).
Notes
If the provided path string appears to include escaped characters (for example, unintentional backslashes), a warning message is printed suggesting the use of a raw string (r’…’) or double backslashes.
Examples
>>> import mbo_utilities as mbo >>> import matplotlib.pyplot as plt >>> scan = mbo.read_scan(r"C:\path o\scan\*.tif") >>> plt.imshow(scan[0, 5, 0, 0], cmap='gray') # First frame of z-plane 6
- mbo_utilities.get_metadata(file: PathLike | str, verbose=False)[source]#
Extract metadata from a TIFF file produced by ScanImage or processed via the save_as function.
This function opens the given TIFF file and retrieves critical imaging parameters and acquisition details. It supports both raw ScanImage TIFFs and those modified by downstream processing. If the file contains raw ScanImage metadata, the function extracts key fields such as channel information, number of frames, field-of-view, pixel resolution, and ROI details. When verbose output is enabled, the complete metadata document is returned in addition to the parsed key values.
- Parameters:
- fileos.PathLike or str
The full path to the TIFF file from which metadata is to be extracted.
- verbosebool, optional
If True, returns an extended metadata dictionary that includes all available ScanImage attributes. Default is False.
- Returns:
- dict
A dictionary containing the extracted metadata (e.g., number of planes, frame rate, field-of-view, pixel resolution). When verbose is True, the dictionary also includes a key “all” with the full metadata from the TIFF header.
- Raises:
- ValueError
If no recognizable metadata is found in the TIFF file (e.g., the file is not a valid ScanImage TIFF).
Examples
>>> meta = get_metadata("path/to/rawscan_00001.tif") >>> print(meta["num_frames"]) 5345 >>> meta = get_metadata("path/to/assembled_data.tif") >>> print(meta["shape"]) (14, 5345, 477, 477) >>> meta_verbose = get_metadata("path/to/scanimage_file.tif", verbose=True) >>> print(meta_verbose["all"]) {... Includes all ScanImage FrameData ...}