h5rdmtoolbox.layout.core.LayoutSpecification

h5rdmtoolbox.layout.core.LayoutSpecification#

class h5rdmtoolbox.layout.core.LayoutSpecification(func, kwargs, n, rebase=False, description=None, parent=None)[source]#

Specification for a layout

Parameters:
  • func (QueryCallable) – Callable query according to protocol class QueryCallable to be called on the hdf5 file. The first argument of the function will be an opened h5py.File or h5py.Group or h5py.Dataset object.

  • kwargs (Dict) – Keyword arguments passed to the func.

  • n (Union[int, None, Dict]) – Number of matches or condition. Only applicable if query function (func) returns an iterable object. None means that the number can be zero as well, which makes the specification optional. Example: n=1 means that the specification is successful if the query function returns exactly one. If n is a dictionary, the key must be a comparison operator (e.g. ‘$eq’, ‘$gt’, ‘$lt’, ‘$gte’, ‘$lte’), e.g. {‘$eq’: 1} means that the query function must return exactly one result. {‘$gt’: 1} means that the query function must return more than one result.

  • description (Optional[str]) – Optional description explaining the specification

  • parent (Optional[LayoutSpecification]) – Parent specification. If the specification is a conditional one, it has a parent. If this is the case, the function func is called on the parent’s results. If the parent’s specification fails, the specification is not applied. If parent is None, the specification has no parent and is applied to the hdf5 root group.

__init__(func, kwargs, n, rebase=False, description=None, parent=None)[source]#

Methods

__init__(func, kwargs, n[, rebase, ...])

add(func, *[, n, rebase, description])

Add a specification by providing a callable query obj.

add_alternative(func, *, n[, description])

Add an alternative specification by providing a callable query obj.

get_failed()

Return a list of failed specifications

get_summary([exclude_keys])

return a summary as dictionary

get_valid()

Return all successful specifications

is_valid()

Return True if the specification is valid

reset()

Reset the specification and all its children

Attributes

called

Return True if the specification has been called at least once.

failed

Return True if the specification failed

n_calls

Return number of calls

n_fails

Return number of failed calls

n_successes

Return number of successful calls

validation_flag