NWBConverter#
Contains core class definitions for the NWBConverter and ConverterPipe.
- class NWBConverter(source_data: dict[str, dict], verbose: bool = False)[source]#
Bases:
object
Primary class for all NWB conversion classes.
Validate source_data against source_schema and initialize all data interfaces.
- display_name: Optional[str] = None#
- keywords: tuple[str] = ()#
- associated_suffixes: tuple[str] = ()#
- info: Optional[str] = None#
- data_interface_classes = None#
- classmethod get_source_schema() dict [source]#
Compile input schemas from each of the data interface classes.
- Returns
The compiled source schema from all data interface classes.
- Return type
dict
- classmethod validate_source(source_data: dict[str, dict], verbose: bool = False)[source]#
Validate source_data against Converter source_schema.
- get_metadata_schema() dict [source]#
Compile metadata schemas from each of the data interface objects.
- Returns
The compiled metadata schema from all data interface objects.
- Return type
dict
- get_metadata() DeepDict [source]#
Auto-fill as much of the metadata as possible. Must comply with metadata schema.
- Returns
The metadata dictionary containing auto-filled metadata from all interfaces.
- Return type
- validate_metadata(metadata: dict[str, dict], append_mode: bool = False)[source]#
Validate metadata against Converter metadata_schema.
- get_conversion_options_schema() dict [source]#
Compile conversion option schemas from each of the data interface classes.
- Returns
The compiled conversion options schema from all data interface classes.
- Return type
dict
- validate_conversion_options(conversion_options: dict[str, dict])[source]#
Validate conversion_options against Converter conversion_options_schema.
- create_nwbfile(metadata: Optional[dict] = None, conversion_options: Optional[dict] = None) NWBFile [source]#
Create and return an in-memory pynwb.NWBFile object with the conversion data added to it.
- Parameters
metadata (dict, optional) – Metadata dictionary with information used to create the NWBFile.
conversion_options (dict, optional) – Similar to source_data, a dictionary containing keywords for each interface for which non-default conversion specification is requested.
- Returns
nwbfile – The in-memory object with this interface’s data added to it.
- Return type
pynwb.NWBFile
- add_to_nwbfile(nwbfile: NWBFile, metadata, conversion_options: Optional[dict] = None)[source]#
Add data from the instantiated data interfaces to the given NWBFile.
- Parameters
nwbfile (NWBFile) – The NWB file object to which the data from the data interfaces will be added.
metadata (dict) – The metadata dictionary that contains information used to describe the data.
conversion_options (dict, optional) – A dictionary containing conversion options for each interface, where non-default behavior is requested. Each key corresponds to a data interface name, and the values are dictionaries with options for that interface. By default, None.
- run_conversion(nwbfile_path: Path, nwbfile: Optional[NWBFile] = None, metadata: Optional[dict] = None, overwrite: bool = False, backend: Optional[Literal['hdf5', 'zarr']] = None, backend_configuration: Optional[Union[HDF5BackendConfiguration, ZarrBackendConfiguration]] = None, conversion_options: Optional[dict] = None) None [source]#
Run the NWB conversion over all the instantiated data interfaces.
- Parameters
nwbfile_path (FilePath) – 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).
backend ({“hdf5”, “zarr”}, optional) – The type of backend to use when writing the file. If a backend_configuration is not specified, the default type will be “hdf5”. If a backend_configuration is specified, then the type will be auto-detected.
backend_configuration (HDF5BackendConfiguration or ZarrBackendConfiguration, optional) – The configuration model to use when configuring the datasets for this backend. To customize, call the .get_default_backend_configuration(…) method, modify the returned BackendConfiguration object, and pass that instead. Otherwise, all datasets will use default configuration settings.
conversion_options (dict, optional) – Similar to source_data, a dictionary containing keywords for each interface for which non-default conversion specification is requested.
- temporally_align_data_interfaces(metadata: Optional[dict] = None, conversion_options: Optional[dict] = None)[source]#
Override this method to implement custom alignment.
- static get_default_backend_configuration(nwbfile: NWBFile, backend: Literal['hdf5', 'zarr'] = 'hdf5') Union[HDF5BackendConfiguration, ZarrBackendConfiguration] [source]#
Fill and return a default backend configuration to serve as a starting point for further customization.
- Parameters
nwbfile (pynwb.NWBFile) – The in-memory object with this interface’s data already added to it.
backend (“hdf5” or “zarr”, default: “hdf5”) – The type of backend to use when creating the file.
- Returns
The default configuration for the specified backend type.
- Return type
- class ConverterPipe(data_interfaces: Union[list[neuroconv.basedatainterface.BaseDataInterface], dict[str, neuroconv.basedatainterface.BaseDataInterface]], verbose=False)[source]#
Bases:
NWBConverter
Takes a list or dict of pre-initialized interfaces as arguments to build an NWBConverter class.
Validate source_data against source_schema and initialize all data interfaces.
- classmethod get_source_schema() dict [source]#
Compile input schemas from each of the data interface classes.
- Returns
The compiled source schema from all data interface classes.
- Return type
dict
- get_conversion_options_schema() dict [source]#
Compile conversion option schemas from each of the data interface classes.
- Returns
The compiled conversion options schema containing: - root: True - id: “conversion_options.schema.json” - title: “Conversion options schema” - description: “Schema for the conversion options” - version: “0.1.0” - properties: Dictionary mapping interface names to their unrooted schemas
- Return type
dict