Path Spec#

Classes:

Path(format, *args, **kwargs)

Specify a metadata variable embedded in a path using parse

Paths(format, *args, **kwargs)

Like spec.Path but allows multiple values for a single key

Glob(key, format[, only_dirs])

Sort of the opposite of Path -- specify some path given some metadata values

class onice_conversion.spec.path.Path(format: str, *args, **kwargs)#

Bases: onice_conversion.spec.base_spec.BaseSpec

Specify a metadata variable embedded in a path using parse

See the parse documentation for more details, but briefly, to specify the metadata variables subject_id == 'jonny' and session_id = '001' in a file path data/recordings/jonny_spikes_001.spikes, one would use a format == 'data/recordings/{subject_id}_spikes_{session_id}.spikes. Additional options like specifying a format for the values, etc. can be found in the parse documentation.

Raises an exception if multiple matching values are found in Path._parse() , this is the singular version, and if there are multiple matches that means it’s mis-specified To allow multiple matches, try Paths

Parameters

retype (Callable (optional))

Methods:

_parse_dir(base_path)

First part of Path._parse() , given a base directory and parser, return a list of dicts of matching keys found.

_parse(base_path[, metadata])

Parse metadata stored in some path name relative to

_expand_named_fields(named_fields)

Convert nested key specs like key[key2] into nested dicts

_full_name()

Returns the full module and class name of an object, eg.

_get_init_args()

introspect object and get all arguments passed on __init__

children()

Generator for iterating over children (added)

parse(base_path[, metadata])

Parse all parameters from self and child _parse() methods, combining into single dictionary

to_dict()

Get a dictionary description of this spec object, of the form.

Attributes:

parent

specifies

Which metadata variables are specified by this Spec object and its children

_parse_dir(base_path: Union[str, pathlib.Path]) list#

First part of Path._parse() , given a base directory and parser, return a list of dicts of matching keys found.

_parse(base_path: Union[str, pathlib.Path], metadata: Optional[dict] = None) dict#
Parse metadata stored in some path name relative to

using the parser created by format.

If the input path is not absolute, it is made absolute relative to base_path so that it matches format

Raises a AmbiguityError if multiple matches for a single key are found, and a ValueError if zero matches are found.

Parameters

base_path (pathlib.Path) – Path to _parse!!!

Return type

dict of metadata params

_expand_named_fields(named_fields)#

Convert nested key specs like key[key2] into nested dicts

borroed from: https://github.com/r1chardj0n3s/parse/blob/0477aa58673cd957c19d377e029347ce72c08b1b/parse.py#L944

_full_name()#

Returns the full module and class name of an object, eg. nwb_conversion_tools.spec.external_file.JSON

Return type

str

_get_init_args()#

introspect object and get all arguments passed on __init__

depends on introspecting up frames so should only be called during the top-level __init__ of the base class :)

Return type

dict of argument names and params

children() Iterable[onice_conversion.spec.base_spec.BaseSpec]#

Generator for iterating over children (added)

property parent: onice_conversion.spec.base_spec.BaseSpec#
parse(base_path: pathlib.Path, metadata: Optional[dict] = None) dict#

Parse all parameters from self and child _parse() methods, combining into single dictionary

Parameters
  • base_path (Path) – The base path we compute the spec’d value from!

  • metadata (dict) – other metadata used by the parsing function, usually passed in NWBConverter.run_conversion()

property specifies: Tuple[str, ...]#

Which metadata variables are specified by this Spec object and its children

Return type

tuple of strings

to_dict() dict#

Get a dictionary description of this spec object, of the form:

{
    'module': self.__module__,
    'class': type(self).__name__,
    'kwargs': self._init_args,
    'children': [ ... same structure as top-level without children list ...]
}

That allows a spec to be reconstituted with from_dict()

Return type

dict of initialization parameters, as described above

class onice_conversion.spec.path.Paths(format: str, *args, **kwargs)#

Bases: onice_conversion.spec.path.Path

Like spec.Path but allows multiple values for a single key

Parameters

retype (Callable (optional))

Methods:

_expand_named_fields(named_fields)

Convert nested key specs like key[key2] into nested dicts

_full_name()

Returns the full module and class name of an object, eg.

_get_init_args()

introspect object and get all arguments passed on __init__

_parse_dir(base_path)

First part of Path._parse() , given a base directory and parser, return a list of dicts of matching keys found.

children()

Generator for iterating over children (added)

parse(base_path[, metadata])

Parse all parameters from self and child _parse() methods, combining into single dictionary

to_dict()

Get a dictionary description of this spec object, of the form.

Attributes:

parent

specifies

Which metadata variables are specified by this Spec object and its children

_expand_named_fields(named_fields)#

Convert nested key specs like key[key2] into nested dicts

borroed from: https://github.com/r1chardj0n3s/parse/blob/0477aa58673cd957c19d377e029347ce72c08b1b/parse.py#L944

_full_name()#

Returns the full module and class name of an object, eg. nwb_conversion_tools.spec.external_file.JSON

Return type

str

_get_init_args()#

introspect object and get all arguments passed on __init__

depends on introspecting up frames so should only be called during the top-level __init__ of the base class :)

Return type

dict of argument names and params

_parse_dir(base_path: Union[str, pathlib.Path]) list#

First part of Path._parse() , given a base directory and parser, return a list of dicts of matching keys found.

children() Iterable[onice_conversion.spec.base_spec.BaseSpec]#

Generator for iterating over children (added)

property parent: onice_conversion.spec.base_spec.BaseSpec#
parse(base_path: pathlib.Path, metadata: Optional[dict] = None) dict#

Parse all parameters from self and child _parse() methods, combining into single dictionary

Parameters
  • base_path (Path) – The base path we compute the spec’d value from!

  • metadata (dict) – other metadata used by the parsing function, usually passed in NWBConverter.run_conversion()

property specifies: Tuple[str, ...]#

Which metadata variables are specified by this Spec object and its children

Return type

tuple of strings

to_dict() dict#

Get a dictionary description of this spec object, of the form:

{
    'module': self.__module__,
    'class': type(self).__name__,
    'kwargs': self._init_args,
    'children': [ ... same structure as top-level without children list ...]
}

That allows a spec to be reconstituted with from_dict()

Return type

dict of initialization parameters, as described above

class onice_conversion.spec.path.Glob(key: str, format: str, only_dirs: bool = False, *args, **kwargs)#

Bases: onice_conversion.spec.base_spec.BaseSpec

Sort of the opposite of Path – specify some path given some metadata values

Replaces any named format variables in {brackets}, and then globs any `’*’`s

Parameters
  • key (str) – The key that will define what’s returned from Parse

  • format (str) – A globlike format string to match files within the base directory, eg to match parentdir_335092/some_file_250269287.bin we might use "parentdir_*/some_file_*.bin"

    Can also use previously defined metadata, eg to replace some part of the file with subject_id, use "parentdir_{subject_id}/" etc.

  • only_dirs (bool) – Only match directories, not files (default: False)

  • *args ()

  • **kwargs ()

Methods:

__init__(key, format[, only_dirs])

Parameters
  • key (str) -- The key that will define what's returned from Parse

_parse(base_path[, metadata])

Find a path by first replacing {format_strings} with variables from the passed metadata dict and then globbing over any '*'

_expand_named_fields(named_fields)

Convert nested key specs like key[key2] into nested dicts

_full_name()

Returns the full module and class name of an object, eg.

_get_init_args()

introspect object and get all arguments passed on __init__

children()

Generator for iterating over children (added)

parse(base_path[, metadata])

Parse all parameters from self and child _parse() methods, combining into single dictionary

to_dict()

Get a dictionary description of this spec object, of the form.

Attributes:

parent

specifies

Which metadata variables are specified by this Spec object and its children

__init__(key: str, format: str, only_dirs: bool = False, *args, **kwargs)#
Parameters
  • key (str) – The key that will define what’s returned from Parse

  • format (str) – A globlike format string to match files within the base directory, eg to match parentdir_335092/some_file_250269287.bin we might use "parentdir_*/some_file_*.bin"

    Can also use previously defined metadata, eg to replace some part of the file with subject_id, use "parentdir_{subject_id}/" etc.

  • only_dirs (bool) – Only match directories, not files (default: False)

  • *args ()

  • **kwargs ()

_parse(base_path: Union[str, pathlib.Path], metadata: Optional[dict] = None) dict#

Find a path by first replacing {format_strings} with variables from the passed metadata dict and then globbing over any ‘*’

This class ensures a single path is returned, and raises an AmbiguityError otherwise. To return multiple paths, use Globs

Parameters
  • base_path

  • metadata

_expand_named_fields(named_fields)#

Convert nested key specs like key[key2] into nested dicts

borroed from: https://github.com/r1chardj0n3s/parse/blob/0477aa58673cd957c19d377e029347ce72c08b1b/parse.py#L944

_full_name()#

Returns the full module and class name of an object, eg. nwb_conversion_tools.spec.external_file.JSON

Return type

str

_get_init_args()#

introspect object and get all arguments passed on __init__

depends on introspecting up frames so should only be called during the top-level __init__ of the base class :)

Return type

dict of argument names and params

children() Iterable[onice_conversion.spec.base_spec.BaseSpec]#

Generator for iterating over children (added)

property parent: onice_conversion.spec.base_spec.BaseSpec#
parse(base_path: pathlib.Path, metadata: Optional[dict] = None) dict#

Parse all parameters from self and child _parse() methods, combining into single dictionary

Parameters
  • base_path (Path) – The base path we compute the spec’d value from!

  • metadata (dict) – other metadata used by the parsing function, usually passed in NWBConverter.run_conversion()

property specifies: Tuple[str, ...]#

Which metadata variables are specified by this Spec object and its children

Return type

tuple of strings

to_dict() dict#

Get a dictionary description of this spec object, of the form:

{
    'module': self.__module__,
    'class': type(self).__name__,
    'kwargs': self._init_args,
    'children': [ ... same structure as top-level without children list ...]
}

That allows a spec to be reconstituted with from_dict()

Return type

dict of initialization parameters, as described above