NWB Converter#
Classes:
|
ONICE extension to |
Functions:
To make |
- class onice_conversion.nwbconverter.NWBConverter(*args, **kwargs)#
Bases:
nwb_conversion_tools.nwbconverter.NWBConverter
ONICE extension to
nwb_conversion_tools.NWBConverter
- Parameters
base_dir (
pathlib.Path
) – The base directory of the source data, from which all paths are relative. If not provided at initialization, must be provided when callingrun_conversion()
source_data (dict) – Old style source_data dictionary, kept for compatibility
Methods:
add_container
([container_name, spec])Add a
hail_mary
([base_dir, interface_type])Just try every interface on every file and see what instantiates.
add_interface
([interface_type, device_name, ...])Add a recording interface
add_metadata
(spec)- Parameters
spec (BaseSpec, dict) -- if an object that inherits from
BaseSpec
, then the keys and values of metadata
convert_many
(expt_paths[, out_fns])from_json
(json_path[, hook, base_dir])Reconstitute a parameterized converter from a json file created by
NWBConverter.to_json()
Compile conversion option schemas from each of the data interface classes.
Auto-fill as much of the metadata as possible.
Compile metadata schemas from each of the data interface objects.
Compile input schemas from each of the data interface classes.
run_conversion
([metadata, nwbfile_path, ...])Run the NWB conversion over all the instantiated data interfaces.
to_json
([output_path, mode])Save the converter parameterization from
add_metadata()
andadd_interface()
to a .json file, for use withfrom_json()
to recreate conversion objects :)Attributes:
Return descriptions for the basic file-level metadata container objects,
'NWBFile', 'Subject'
- add_container(container_name: Optional[str] = None, spec: Optional[onice_conversion.spec.base_spec.BaseSpec] = None, **kwargs)#
Add a
- Parameters
container_type (str)
container_name (str)
spec (
BaseSpec
) – Spec object declaring the metadata for the container**kwargs – stored as static metadata and passed to container
Returns:
- property base_nwb_metadata: Dict[str, tuple]#
Return descriptions for the basic file-level metadata container objects,
'NWBFile', 'Subject'
- Returns
dict of tuples of parameter spec for each container type
- hail_mary(base_dir: Optional[pathlib.Path] = None, interface_type: Optional[str] = None)#
Just try every interface on every file and see what instantiates.
- Parameters
base_dir (directory to peruse. if none, then the base_dir provided on init is used.)
interface_type (if provided, only try interfaces of this type)
- Returns
(interface object, path (relative to base_dir), parameter key that was used, and the instantiated object itself)
- Return type
tuple of:
- add_interface(interface_type: Optional[str] = None, device_name: Optional[str] = None, spec: Optional[nwb_conversion_tools.spec.base_spec.BaseSpec] = None, **kwargs)#
Add a recording interface
Specify interface either with an interface type and name, or else give the class itself as
interface_class
. If both are present, use the class.Everything afterwards
- Parameters
interface_type (str) – Type of interface, like ‘recording’ – a name of a package in
interfaces
device_name (str) – Name of specific interface, matching the interfaces
device_name
spec (BaseSpec) – Metadata specifier to parameterize interface object
kwargs – kwargs passed to data interface.
- add_metadata(spec: Union[nwb_conversion_tools.spec.base_spec.BaseSpec, str])#
- Parameters
spec (BaseSpec, dict) – if an object that inherits from
BaseSpec
, then the keys and values of metadata are resolved by the object: ie. the keys are the value ofBaseSpec.specifies
andBaseSpec.parse()
returns a dictionary of keys and values.if dictionary, assumes static metadata (unchanged across multiple sessions/experiments) otherwise, use spec to resolve Either a string representing a “top-level” metadata property, or a tuple of nested metadata properties like (‘NWBFile’, ‘experimenter’)
- property conversion_options_schema#
- classmethod from_json(json_path: Union[str, pathlib.Path, dict], hook: Optional[Callable] = None, base_dir: Optional[Union[str, pathlib.Path]] = None) nwb_conversion_tools.nwbconverter.NWBConverter #
Reconstitute a parameterized converter from a json file created by
NWBConverter.to_json()
- Parameters
json_path (str, pathlib.Path, dict) – Path to the .json file, or else the already-loaded dict
hook (callable) – Optional callable to use with json.load’s
object_hook
base_dir (str, pathlib.Path) – Optional, instantiate the converter with a
base_path
- Return type
Reconstituted Converter!
- get_conversion_options_schema()#
Compile conversion option schemas from each of the data interface classes.
- get_metadata()#
Auto-fill as much of the metadata as possible. Must comply with metadata schema.
- get_metadata_schema()#
Compile metadata schemas from each of the data interface objects.
- get_source_schema()#
Compile input schemas from each of the data interface classes.
- property metadata#
- property metadata_schema#
- run_conversion(metadata: Optional[dict] = None, nwbfile_path: Optional[str] = None, overwrite: Optional[bool] = False, nwbfile: Optional[pynwb.file.NWBFile] = None, conversion_options: Optional[dict] = None, base_dir: Optional[pathlib.Path] = None)#
Run the NWB conversion over all the instantiated data interfaces.
- Parameters
metadata (dict)
nwbfile_path (str, optional) – Location to save the NWBFile, if save_to_file is True. The default is None.
overwrite (bool, optional) – If True, replaces any existing NWBFile at the nwbfile_path location, if save_to_file is True. If False, appends the existing NWBFile at the nwbfile_path location, if save_to_file is True. The default is False.
nwbfile (NWBFile, optional) – A pre-existing NWBFile object to be appended (instead of reading from nwbfile_path).
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 created NWBFile
- Return type
NWBFile
- property source_schema#
- to_json(output_path: Optional[Union[str, pathlib.Path]] = None, mode: str = 'w') dict #
Save the converter parameterization from
add_metadata()
andadd_interface()
to a .json file, for use withfrom_json()
to recreate conversion objects :)- Parameters
output_path (str, pathlib.Path) – Path to write .json file to. if
None
, don’t save, just return dict.mode (str) – Write mode, default: ‘w’
- Return type
dict created and saved
- onice_conversion.nwbconverter._monkeypatch_spikeextractors()#
To make
NWBConverter.hail_mary()
work, we have to override some __del__ methods in spikeextractors that throw errors on incomplete __init__ calls