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.

Initialize an NWBConverter instance by validating the provided source data and dynamically instantiating the data interfaces on the source_data dictionary.

Parameters:
  • source_data (dict[str, dict]) – A dictionary where keys are interface names and values are the corresponding parameters required to initialize each data interface.

  • verbose (bool, optional) – If True, enables verbose mode, by default False. This is propagated to the data interfaces.

display_name: str | None = None#
keywords: tuple[str] = ()#
associated_suffixes: tuple[str] = ()#
info: str | None = None#
data_interface_classes: dict[str, type[BaseDataInterface]] = {}#
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:

DeepDict

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: dict | None = None, conversion_options: dict | None = 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: dict | None = None, conversion_options: dict | None = 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: Annotated[Path, PathType(path_type=file)], nwbfile: NWBFile | None = None, metadata: dict | None = None, overwrite: bool = False, backend: Literal['hdf5', 'zarr'] | None = None, backend_configuration: HDF5BackendConfiguration | ZarrBackendConfiguration | None = None, conversion_options: dict | None = None, append_on_disk_nwbfile: bool = False) 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.

  • append_on_disk_nwbfile (bool, default: False) – Whether to append to an existing NWBFile on disk. If True, the nwbfile parameter must be None. This is useful for appending data to an existing file without overwriting it.

temporally_align_data_interfaces(metadata: dict | None = None, conversion_options: dict | None = None)[source]#

Override this method to implement custom alignment.

static get_default_backend_configuration(nwbfile: NWBFile, backend: Literal['hdf5', 'zarr'] = 'hdf5') 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:

HDF5BackendConfiguration | ZarrBackendConfiguration

class ConverterPipe(data_interfaces: 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.

Initialize an NWBConverter instance by validating the provided source data and dynamically instantiating the data interfaces on the source_data dictionary.

Parameters:
  • source_data (dict[str, dict]) – A dictionary where keys are interface names and values are the corresponding parameters required to initialize each data interface.

  • verbose (bool, optional) – If True, enables verbose mode, by default False. This is propagated to the 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

classmethod validate_source()[source]#

Validate source_data against Converter source_schema.

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