BidsSidecarFile

class BidsSidecarFile(file_path)[source]

A BIDS sidecar file.

Methods

BidsSidecarFile.__init__(file_path)

Constructs a bids sidecar from a file.

BidsSidecarFile.clear_contents()

Set the contents attribute of this object to None.

BidsSidecarFile.get_entity(entity_name)

Return the entity value for the specified entity.

BidsSidecarFile.get_key([entities])

Return a key for this BIDS file given a list of entities.

BidsSidecarFile.is_hed(json_dict)

Return True if the json has HED.

BidsSidecarFile.is_sidecar_for(obj)

Return True if this is a sidecar for obj.

BidsSidecarFile.merge_sidecar_list(sidecar_list)

Merge a list of sidecars into a single sidecar.

BidsSidecarFile.set_contents([content_info, ...])

Set the contents of the sidecar.

Attributes

BidsSidecarFile.contents

Return the current contents of this object.

BidsSidecarFile.__init__(file_path)[source]

Constructs a bids sidecar from a file.

Parameters:

file_path (str) – The real path of the sidecar.

BidsSidecarFile.clear_contents()

Set the contents attribute of this object to None.

BidsSidecarFile.get_entity(entity_name)

Return the entity value for the specified entity.

Parameters:

entity_name (str) – Name of the BIDS entity, for example task, run, or sub.

Returns:

Entity value if any, otherwise None.

Return type:

str or None

BidsSidecarFile.get_key(entities=None)

Return a key for this BIDS file given a list of entities.

Parameters:

entities (tuple) – A tuple of strings representing entities.

Returns:

A key based on this object.

Return type:

str

Notes

If entities is None, then the file path is used as the key.

static BidsSidecarFile.is_hed(json_dict)[source]

Return True if the json has HED.

Parameters:

json_dict (dict) – A dictionary representing a JSON file or merged file.

Returns:

True if the dictionary has HED or HED_assembled as a first or second-level key.

Return type:

bool

BidsSidecarFile.is_sidecar_for(obj)[source]

Return True if this is a sidecar for obj.

Parameters:

obj (BidsFile) – A BidsFile object to check.

Returns:

True if this is a BIDS parent of obj and False otherwise.

Return type:

bool

Notes

  • A sidecar is a sidecar for itself.

static BidsSidecarFile.merge_sidecar_list(sidecar_list, name='merged_sidecar.json')[source]

Merge a list of sidecars into a single sidecar.

Parameters:
  • sidecar_list (list) – A list of Sidecar objects.

  • name (str) – The name of the merged sidecar.

Returns:

A sidecar constructed from the merged list.

Return type:

Sidecar or None

BidsSidecarFile.set_contents(content_info=None, name='unknown', overwrite=False)[source]

Set the contents of the sidecar.

Parameters:
  • content_info (dict, or None) – If None, create a Sidecar from the object’s file-path.

  • name (str) – The name of the sidecar.

  • overwrite (bool) – If True, overwrite contents if already set.

Notes

  • The handling of content_info is as follows:
    • None: This object’s file_path is used.

    • dict: This is interpreted as a JSON dictionary.

BidsSidecarFile.contents

Return the current contents of this object.