bidsschematools.schema¶
Schema loading- and processing-related functions.
Functions
- bidsschematools.schema.dereference(namespace, inplace=True)¶
Replace references in namespace with the contents of the referred object.
- bidsschematools.schema.export_schema(schema)¶
Export the schema to JSON format.
- bidsschematools.schema.filter_schema(schema, **kwargs)¶
Filter the schema based on a set of keyword arguments.
- Parameters:
- Returns:
new_schema – The filtered version of the schema.
- Return type:
Notes
This function calls itself recursively, in order to apply filters at arbitrary depth.
Warning
This function employs a very simple filter. It is very limited.
- bidsschematools.schema.flatten_enums(namespace, inplace=True)¶
Replace enum collections with a single enum, merging enums contents.
The function helps reducing the complexity of the schema by assuming that the values in the conditions (anyOf) are mutually exclusive.
- Parameters:
namespace (dict) – Schema in dictionary form to be flattened.
- Returns:
schema – Schema with flattened enums.
- Return type:
Examples
>>> struct = { ... "anyOf": [ ... {"type": "string", "enum": ["A", "B", "C"]}, ... {"type": "string", "enum": ["D", "E", "F"]}, ... ] ... } >>> flatten_enums(struct) {'type': 'string', 'enum': ['A', 'B', 'C', 'D', 'E', 'F']}
- bidsschematools.schema.load_schema(schema_path=None)¶
Load the schema into a dictionary.
This function allows the schema, like BIDS itself, to be specified in a hierarchy of directories and files. Filenames (minus extensions) and directory names become keys in the associative array (dict) of entries composed from content of files and entire directories.
- Parameters:
schema_path (str, optional) – Directory containing yaml files or yaml file. If
None
, use the default schema packaged withbidsschematools
.- Returns:
Schema in dictionary form.
- Return type:
Notes
This function is cached, so it will only be called once per schema path.
- bidsschematools.schema.validate_schema(schema: Namespace)¶
Validate a schema against the BIDS metaschema.
Exceptions
- exception bidsschematools.schema.BIDSSchemaError¶
Errors indicating invalid values in the schema itself