Sidecar

class Sidecar(files, name=None)[source]

Contents of a JSON file or JSON files.

Methods

Sidecar.__init__(files[, name])

Construct a Sidecar object representing a JSON file.

Sidecar.extract_definitions(hed_schema[, ...])

Gather and validate definitions in metadata.

Sidecar.get_as_json_string()

Return this sidecar's column metadata as a string.

Sidecar.get_column_refs()

Returns a list of column refs found in this sidecar.

Sidecar.get_def_dict(hed_schema[, ...])

Return the definition dict for this sidecar.

Sidecar.load_sidecar_file(file)

Load column metadata from a given json file.

Sidecar.load_sidecar_files(files)

Load json from a given file or list.

Sidecar.save_as_json(save_filename)

Save column metadata to a JSON file.

Sidecar.validate(hed_schema[, ...])

Create a SidecarValidator and validate this sidecar with the schema.

Attributes

Sidecar.all_hed_columns

Return all columns that are HED compatible.

Sidecar.column_data

Generate the ColumnMetadata for this sidecar.

Sidecar.def_dict

Definitions from this sidecar.

Sidecar.__init__(files, name=None)[source]

Construct a Sidecar object representing a JSON file.

Parameters:
  • files (str or FileLike or list) – A string or file-like object representing a JSON file, or a list of such.

  • name (str or None) – Optional name identifying this sidecar, generally a filename.

Sidecar.extract_definitions(hed_schema, error_handler=None)[source]

Gather and validate definitions in metadata.

Parameters:
  • hed_schema (HedSchema) – The schema to used to identify tags.

  • error_handler (ErrorHandler or None) – The error handler to use for context, uses a default one if None.

Returns:

Contains all the definitions located in the sidecar.

Return type:

DefinitionDict

Sidecar.get_as_json_string()[source]

Return this sidecar’s column metadata as a string.

Returns:

The json string representing this sidecar.

Return type:

str

Sidecar.get_column_refs()[source]

Returns a list of column refs found in this sidecar.

This does not validate

Returns:

A list of unique column refs found.

Return type:

column_refs(list)

Sidecar.get_def_dict(hed_schema, extra_def_dicts=None)[source]

Return the definition dict for this sidecar.

Parameters:
  • hed_schema (HedSchema) – Identifies tags to find definitions.

  • extra_def_dicts (list, DefinitionDict, or None) – Extra dicts to add to the list.

Returns:

A single definition dict representing all the data(and extra def dicts).

Return type:

DefinitionDict

Sidecar.load_sidecar_file(file)[source]

Load column metadata from a given json file.

Parameters:

file (str or FileLike) – If a string, this is a filename. Otherwise, it will be parsed as a file-like.

Raises:

HedFileError

  • If the file was not found or could not be parsed into JSON.

Sidecar.load_sidecar_files(files)[source]

Load json from a given file or list.

Parameters:

files (str or FileLike or list) – A string or file-like object representing a JSON file, or a list of such.

Raises:

HedFileError

  • If the file was not found or could not be parsed into JSON.

Sidecar.save_as_json(save_filename)[source]

Save column metadata to a JSON file.

Parameters:

save_filename (str) – Path to save file.

Sidecar.validate(hed_schema, extra_def_dicts=None, name=None, error_handler=None)[source]

Create a SidecarValidator and validate this sidecar with the schema.

Parameters:
  • hed_schema (HedSchema) – Input data to be validated.

  • extra_def_dicts (list or DefinitionDict) – Extra def dicts in addition to sidecar.

  • name (str) – The name to report this sidecar as.

  • error_handler (ErrorHandler) – Error context to use. Creates a new one if None.

Returns:

A list of issues associated with each level in the HED string.

Return type:

issues (list of dict)

Sidecar.all_hed_columns

Return all columns that are HED compatible.

Returns:

A list of all valid HED columns by name.

Return type:

column_refs(list)

Sidecar.column_data

Generate the ColumnMetadata for this sidecar.

Returns:

ColumnMetadata}): The column metadata defined by this sidecar.

Return type:

dict({str

Sidecar.def_dict

Definitions from this sidecar.

Generally you should instead call get_def_dict to get the relevant definitions.

Returns:

The definitions for this sidecar.

Return type:

DefinitionDict