Imaging#

Base Imaging#

Author: Ben Dichter.

class BaseImagingExtractorInterface(verbose: bool = True, **source_data)[source]#

Bases: BaseExtractorInterface

Parent class for all ImagingExtractorInterfaces.

get_metadata_schema(photon_series_type: Literal['OnePhotonSeries', 'TwoPhotonSeries'] = 'TwoPhotonSeries') dict[source]#

Retrieve JSON schema for metadata.

get_metadata() dict[source]#

Child DataInterface classes should override this to match their metadata.

get_original_timestamps() ndarray[source]#

Retrieve the original unaltered timestamps for the data in this interface.

This function should retrieve the data on-demand by re-initializing the IO.

Returns

timestamps – The timestamps for the data stream.

Return type

numpy.ndarray

get_timestamps() ndarray[source]#

Retrieve the timestamps for the data in this interface.

Returns

timestamps – The timestamps for the data stream.

Return type

numpy.ndarray

set_aligned_timestamps(aligned_timestamps: ndarray)[source]#

Replace all timestamps for this interface with those aligned to the common session start time.

Must be in units seconds relative to the common ‘session_start_time’.

Parameters

aligned_timestamps (numpy.ndarray) – The synchronized timestamps for data in this interface.

Bruker Tiff Imaging#

class BrukerTiffMultiPlaneConverter(folder_path: FolderPathType, plane_separation_type: Literal['disjoint', 'contiguous'] = None, verbose: bool = False)[source]#

Bases: NWBConverter

Initializes the data interfaces for Bruker volumetric imaging data stream. :Parameters: * folder_path (PathType) – The path to the folder that contains the Bruker TIF image files (.ome.tif) and configuration files (.xml, .env).

  • plane_separation_type ({‘contiguous’, ‘disjoint’}) – Defines how to write volumetric imaging data. Use ‘contiguous’ to create the volumetric two photon series, and ‘disjoint’ to create separate imaging plane and two photon series for each plane.

  • verbose (bool, default: True) – Controls verbosity.

classmethod get_source_schema()[source]#

Compile input schemas from each of the data interface classes.

get_conversion_options_schema()[source]#

Compile conversion option schemas from each of the data interface classes.

run_conversion(nwbfile_path: Optional[str] = None, nwbfile: Optional[NWBFile] = None, metadata: Optional[dict] = None, overwrite: bool = False, stub_test: bool = False, stub_frames: int = 100) None[source]#

Run the NWB conversion over all the instantiated data interfaces. :Parameters: * nwbfile_path (FilePathType) – Path for where to write or load (if overwrite=False) the NWBFile.

If specified, the context will always write to this location.

  • nwbfile (NWBFile, optional) – An in-memory NWBFile object to write to the location.

  • metadata (dict, optional) – Metadata dictionary with information used to create the NWBFile when one does not exist or overwrite=True.

  • overwrite (bool, default: False) – Whether to overwrite the NWBFile if one exists at the nwbfile_path. The default is False (append mode).

  • conversion_options (dict, optional) – Similar to source_data, a dictionary containing keywords for each interface for which non-default conversion specification is requested.

class BrukerTiffSinglePlaneConverter(folder_path: FolderPathType, verbose: bool = False)[source]#

Bases: NWBConverter

Initializes the data interfaces for Bruker imaging data stream. :Parameters: * folder_path (PathType) – The path to the folder that contains the Bruker TIF image files (.ome.tif) and configuration files (.xml, .env).

  • verbose (bool, default: True) – Controls verbosity.

classmethod get_source_schema()[source]#

Compile input schemas from each of the data interface classes.

get_conversion_options_schema()[source]#

Compile conversion option schemas from each of the data interface classes.

run_conversion(nwbfile_path: Optional[str] = None, nwbfile: Optional[NWBFile] = None, metadata: Optional[dict] = None, overwrite: bool = False, stub_test: bool = False, stub_frames: int = 100) None[source]#

Run the NWB conversion over all the instantiated data interfaces. :Parameters: * nwbfile_path (FilePathType) – Path for where to write or load (if overwrite=False) the NWBFile.

If specified, the context will always write to this location.

  • nwbfile (NWBFile, optional) – An in-memory NWBFile object to write to the location.

  • metadata (dict, optional) – Metadata dictionary with information used to create the NWBFile when one does not exist or overwrite=True.

  • overwrite (bool, default: False) – Whether to overwrite the NWBFile if one exists at the nwbfile_path. The default is False (append mode).

  • conversion_options (dict, optional) – Similar to source_data, a dictionary containing keywords for each interface for which non-default conversion specification is requested.

HDF5 Imaging#

class Hdf5ImagingInterface(file_path: FilePathType, mov_field: str = 'mov', sampling_frequency: float = None, start_time: float = None, metadata: dict = None, channel_names: Union[list, numpy.ndarray] = None, verbose: bool = True)[source]#

Bases: BaseImagingExtractorInterface

Interface for HDF5 imaging data.

Parameters
  • file_path (FilePathType) – Path to .h5 or .hdf5 file.

  • mov_field (str, default: ‘mov’)

  • sampling_frequency (float, optional)

  • start_time (float, optional)

  • metadata (dict, optional)

  • channel_names (list of str, optional)

  • verbose (bool, default: True)

MicroManager Tiff Imaging#

class MicroManagerTiffImagingInterface(folder_path: FolderPathType, verbose: bool = True)[source]#

Bases: BaseImagingExtractorInterface

Data Interface for MicroManagerTiffImagingExtractor.

Data Interface for MicroManagerTiffImagingExtractor.

Parameters
  • folder_path (FolderPathType) – The folder path that contains the OME-TIF image files (.ome.tif files) and the ‘DisplaySettings’ JSON file.

  • verbose (bool, default: True)

classmethod get_source_schema() dict[source]#

Infer the JSON schema for the source_data from the method signature (annotation typing).

get_metadata() dict[source]#

Child DataInterface classes should override this to match their metadata.

Miniscope Imaging#

class MiniscopeConverter(folder_path: FolderPathType, verbose: bool = True)[source]#

Bases: NWBConverter

Primary conversion class for handling Miniscope data streams.

Initializes the data interfaces for the Miniscope recording and behavioral data stream.

The main Miniscope folder is expected to contain both data streams organized as follows:

C6-J588_Disc5/ (main folder) ├── 15_03_28/ (subfolder corresponding to the recording time) │ ├── Miniscope/ (subfolder containing the microscope video stream) │ │ ├── 0.avi (microscope video) │ │ ├── metaData.json (metadata for the microscope device) │ │ └── timeStamps.csv (timing of this video stream) │ ├── BehavCam_2/ (subfolder containing the behavioral video stream) │ │ ├── 0.avi (bevavioral video) │ │ ├── metaData.json (metadata for the behavioral camera) │ │ └── timeStamps.csv (timing of this video stream) │ └── metaData.json (metadata for the recording, such as the start time) ├── 15_06_28/ │ ├── Miniscope/ │ ├── BehavCam_2/ │ └── metaData.json └── 15_12_28/

Parameters
  • folder_path (FolderPathType) – The path to the main Miniscope folder.

  • verbose (bool, default: True) – Controls verbosity.

classmethod get_source_schema()[source]#

Compile input schemas from each of the data interface classes.

get_conversion_options_schema() dict[source]#

Compile conversion option schemas from each of the data interface classes.

run_conversion(nwbfile_path: Optional[str] = None, nwbfile: Optional[NWBFile] = None, metadata: Optional[dict] = None, overwrite: bool = False, stub_test: bool = False, stub_frames: int = 100) None[source]#

Run the NWB conversion over all the instantiated data interfaces. :Parameters: * nwbfile_path (FilePathType) – Path for where to write or load (if overwrite=False) the NWBFile.

If specified, the context will always write to this location.

  • nwbfile (NWBFile, optional) – An in-memory NWBFile object to write to the location.

  • metadata (dict, optional) – Metadata dictionary with information used to create the NWBFile when one does not exist or overwrite=True.

  • overwrite (bool, default: False) – Whether to overwrite the NWBFile if one exists at the nwbfile_path. The default is False (append mode).

  • conversion_options (dict, optional) – Similar to source_data, a dictionary containing keywords for each interface for which non-default conversion specification is requested.

Sbx Imaging#

class SbxImagingInterface(file_path: FilePathType, sampling_frequency: float = None, verbose: bool = True)[source]#

Bases: BaseImagingExtractorInterface

Data Interface for SbxImagingExtractor.

Parameters
  • file_path (FilePathType) – Path to .sbx file.

  • sampling_frequency (float, optional)

  • verbose (bool, default: True)

get_metadata() dict[source]#

Child DataInterface classes should override this to match their metadata.

ScanImage Imaging#

class ScanImageImagingInterface(file_path: FilePathType, fallback_sampling_frequency: Optional[float] = None, verbose: bool = True)[source]#

Bases: BaseImagingExtractorInterface

Interface for ScanImage TIFF files.

DataInterface for reading Tiff files that are generated by ScanImage. This interface extracts the metadata from the exif of the tiff file.

Parameters
  • file_path (str) – Path to tiff file.

  • fallback_sampling_frequency (float, optional) – The sampling frequency can usually be extracted from the scanimage metadata in exif:ImageDescription:state.acq.frameRate. If not, use this.

classmethod get_source_schema() dict[source]#

Infer the JSON schema for the source_data from the method signature (annotation typing).

get_metadata() dict[source]#

Child DataInterface classes should override this to match their metadata.

Tiff Imaging#

class TiffImagingInterface(file_path: FilePathType, sampling_frequency: float, verbose: bool = True)[source]#

Bases: BaseImagingExtractorInterface

Interface for multi-page TIFF files.

Initialize reading of TIFF file.

Parameters
  • file_path (FilePathType)

  • sampling_frequency (float)

  • verbose (bool, default: True)

classmethod get_source_schema() dict[source]#

Infer the JSON schema for the source_data from the method signature (annotation typing).

Segmentation#

Base Segmentation#

Authors: Heberto Mayorquin, Cody Baker and Ben Dichter.

class BaseSegmentationExtractorInterface(**source_data)[source]#

Bases: BaseExtractorInterface

Parent class for all SegmentationExtractorInterfaces.

get_metadata_schema() dict[source]#

Retrieve JSON schema for metadata.

get_metadata() dict[source]#

Child DataInterface classes should override this to match their metadata.

get_original_timestamps() ndarray[source]#

Retrieve the original unaltered timestamps for the data in this interface.

This function should retrieve the data on-demand by re-initializing the IO.

Returns

timestamps – The timestamps for the data stream.

Return type

numpy.ndarray

get_timestamps() ndarray[source]#

Retrieve the timestamps for the data in this interface.

Returns

timestamps – The timestamps for the data stream.

Return type

numpy.ndarray

set_aligned_timestamps(aligned_timestamps: ndarray)[source]#

Replace all timestamps for this interface with those aligned to the common session start time.

Must be in units seconds relative to the common ‘session_start_time’.

Parameters

aligned_timestamps (numpy.ndarray) – The synchronized timestamps for data in this interface.

add_to_nwbfile(nwbfile: NWBFile, metadata: Optional[dict] = None, stub_test: bool = False, stub_frames: int = 100, include_roi_centroids: bool = True, include_roi_acceptance: bool = True, mask_type: Optional[str] = 'image', plane_segmentation_name: Optional[str] = None, iterator_options: Optional[dict] = None, compression_options: Optional[dict] = None)[source]#
Parameters
  • nwbfile (NWBFile) – The NWBFile to add the plane segmentation to.

  • metadata (dict, optional) – The metadata for the interface

  • stub_test (bool, default: False)

  • stub_frames (int, default: 100)

  • include_roi_centroids (bool, default: True) – Whether to include the ROI centroids on the PlaneSegmentation table. If there are a very large number of ROIs (such as in whole-brain recordings), you may wish to disable this for faster write speeds.

  • include_roi_acceptance (bool, default: True) – Whether to include if the detected ROI was ‘accepted’ or ‘rejected’. If there are a very large number of ROIs (such as in whole-brain recordings), you may wish to ddisable this for faster write speeds.

  • mask_type ({‘image’, ‘pixel’, ‘voxel’}, optional) – There are two types of ROI masks in NWB: ImageMasks and PixelMasks. Image masks have the same shape as the reference images the segmentation was applied to, and weight each pixel

    by its contribution to the ROI (typically boolean, with 0 meaning ‘not in the ROI’).

    Pixel masks are instead indexed by ROI, with the data at each index being the shape of the image by the number

    of pixels in each ROI.

    Voxel masks are instead indexed by ROI, with the data at each index being the shape of the volume by the number

    of voxels in each ROI.

    Specify your choice between these three as mask_type=’image’, ‘pixel’, ‘voxel’, or None. If None, the mask information is not written to the NWB file. Defaults to ‘image’.

  • plane_segmentation_name (str, optional) – The name of the plane segmentation to be added.

  • iterator_options (dict, optional) – The options to use when iterating over the image masks of the segmentation extractor.

  • compression_options (dict, optional) – The options to use when compressing the image masks of the segmentation extractor.

Caiman Segmentation#

class CaimanSegmentationInterface(file_path: FilePathType, verbose: bool = True)[source]#

Bases: BaseSegmentationExtractorInterface

Data interface for CaimanSegmentationExtractor.

Parameters
  • file_path (FilePathType) – Path to .hdf5 file.

  • verbose (bool, default True) – Whether to print progress

Cnmfe Segmentation#

class CnmfeSegmentationInterface(file_path: FilePathType, verbose: bool = True)[source]#

Bases: BaseSegmentationExtractorInterface

Data interface for constrained non-negative matrix factorization (CNMFE) segmentation extractor.

Extract Segmentation#

class ExtractSegmentationInterface(file_path: FilePathType, sampling_frequency: float, output_struct_name: Optional[str] = None, verbose: bool = True)[source]#

Bases: BaseSegmentationExtractorInterface

Data interface for ExtractSegmentationExtractor.

Parameters
  • file_path (FilePathType)

  • sampling_frequency (float)

  • output_struct_name (str, optional)

  • verbose (bool, default : True)

Sima Segmentation#

class SimaSegmentationInterface(file_path: FilePathType, sima_segmentation_label: str = 'auto_ROIs')[source]#

Bases: BaseSegmentationExtractorInterface

Data interface for SimaSegmentationExtractor.

Parameters
  • file_path (FilePathType)

  • sima_segmentation_label (str, default: “auto_ROIs”)

Suite2p Segmentation#

Private utility function to update the metadata with a new plane segmentation name.

class Suite2pSegmentationInterface(folder_path: FolderPathType, channel_name: Optional[str] = None, plane_name: Optional[str] = None, plane_segmentation_name: Optional[str] = None, verbose: bool = True, combined: Optional[bool] = False, plane_no: Optional[int] = None)[source]#

Bases: BaseSegmentationExtractorInterface

Interface for Suite2p segmentation data.

Parameters
  • folder_path (FolderPathType)

  • channel_name (str, optional) – The name of the channel to load, to determine what channels are available use Suite2pSegmentationInterface.get_available_channels(folder_path).

  • plane_name (str, optional) – The name of the plane to load, to determine what planes are available use Suite2pSegmentationInterface.get_available_planes(folder_path).

  • plane_segmentation_name (str, optional) – The name of the plane segmentation to be added.

get_metadata() DeepDict[source]#

Child DataInterface classes should override this to match their metadata.

add_to_nwbfile(nwbfile: NWBFile, metadata: Optional[dict] = None, stub_test: bool = False, stub_frames: int = 100, include_roi_centroids: bool = True, include_roi_acceptance: bool = True, mask_type: Optional[str] = 'image', plane_segmentation_name: Optional[str] = None, iterator_options: Optional[dict] = None, compression_options: Optional[dict] = None)[source]#
Parameters
  • nwbfile (NWBFile) – The NWBFile to add the plane segmentation to.

  • metadata (dict, optional) – The metadata for the interface

  • stub_test (bool, default: False)

  • stub_frames (int, default: 100)

  • include_roi_centroids (bool, default: True) – Whether to include the ROI centroids on the PlaneSegmentation table. If there are a very large number of ROIs (such as in whole-brain recordings), you may wish to disable this for faster write speeds.

  • include_roi_acceptance (bool, default: True) – Whether to include if the detected ROI was ‘accepted’ or ‘rejected’. If there are a very large number of ROIs (such as in whole-brain recordings), you may wish to ddisable this for faster write speeds.

  • mask_type ({‘image’, ‘pixel’, ‘voxel’}, optional) – There are two types of ROI masks in NWB: ImageMasks and PixelMasks. Image masks have the same shape as the reference images the segmentation was applied to, and weight each pixel

    by its contribution to the ROI (typically boolean, with 0 meaning ‘not in the ROI’).

    Pixel masks are instead indexed by ROI, with the data at each index being the shape of the image by the number

    of pixels in each ROI.

    Voxel masks are instead indexed by ROI, with the data at each index being the shape of the volume by the number

    of voxels in each ROI.

    Specify your choice between these three as mask_type=’image’, ‘pixel’, ‘voxel’, or None. If None, the mask information is not written to the NWB file. Defaults to ‘image’.

  • plane_segmentation_name (str, optional) – The name of the plane segmentation to be added.

  • iterator_options (dict, optional) – The options to use when iterating over the image masks of the segmentation extractor.

  • compression_options (dict, optional) – The options to use when compressing the image masks of the segmentation extractor.