sovabids.rules

Module dealing with the rules for bids conversion.

Attributes

Functions

_regex_match(pattern, string)

get_info_from_path(path, rules)

Parse information from a given path, given a set of rules.

get_files(source_path, rules)

Recursively scan the directory for valid files, returning a list with the full-paths to each.

load_rules(rules)

Load rules if given a path, bypass if given a dict.

apply_rules_to_single_file(file, rules, bids_path[, ...])

Apply rules to a single file.

apply_rules(source_path, bids_path, rules[, mapping_path])

Apply rules to a set of files.

sovapply()

Console script usage for applying rules.

Module Contents

sovabids.rules.LOGGER
sovabids.rules._regex_match(pattern, string)[source]
sovabids.rules.get_info_from_path(path, rules)[source]

Parse information from a given path, given a set of rules.

Parameters:
  • path (str | pathlib.Path) – The path from where we want to extract information.

  • rules (dict) – A dictionary following the “Rules File Schema”.

Notes

See the Rules File Schema documentation for the expected schema of the dictionary.

sovabids.rules.get_files(source_path, rules)[source]

Recursively scan the directory for valid files, returning a list with the full-paths to each.

The valid files are given by the ‘non-bids.eeg_extension’ rule. See the “Rules File Schema”.

Parameters:
  • source_path (str | pathlib.Path) – The path we want to obtain the files from.

  • rules (str | pathlib.Path | dict) – The path to the rules file, or the rules dictionary.

Returns:

filepaths – A list containing the path to each valid file in the source_path.

Return type:

list of str

sovabids.rules.load_rules(rules)[source]

Load rules if given a path, bypass if given a dict.

Parameters:

rules (str | pathlib.Path | dict) – The path to the rules file, or the rules dictionary.

Returns:

The rules dictionary.

Return type:

dict

sovabids.rules.apply_rules_to_single_file(file, rules, bids_path, write=False, preview=False)[source]

Apply rules to a single file.

Parameters:
  • file (str | pathlib.Path) – Path to the file.

  • rules (str | pathlib.Path | dict) – Path to the rules file or rules dictionary.

  • bids_path (str | pathlib.Path) – Path to the bids directory

  • write (bool, optional) – Whether to write the converted files to disk or not.

  • preview (bool, optional) – Whether to return a dictionary with a “preview” of the conversion. This dict will have the same schema as the “Mapping File Schema” but may have flat versions of its fields. UNDER CONSTRUCTION

Returns:

  • mapping (dict) – The mapping obtained from applying the rules to the given file

  • preview (bool|dict) – If preview = False, then False. If True, then the preview dictionary.

sovabids.rules.apply_rules(source_path, bids_path, rules, mapping_path='')[source]

Apply rules to a set of files.

Parameters:
  • source_path (str | pathlib.Path | list of str | list of pathlib.Path) – If str or Path, the path with the files we want to convert to bids. If list with the paths of the files we want to convert (ie the output of get_files).

  • bids_path (str | pathlib.Path) – The path we want the converted files in.

  • rules (str | pathlib.Path | dict) – The path to the rules file, or a dictionary with the rules.

  • mapping_path (str | pathlib.Path, optional) – The fullpath where we want to write the mappings file. If ‘’, then bids_path/code/sovabids/mappings.yml will be used.

Returns:

A dictionary following: {

‘General’: rules given, ‘Individual’:list of mapping dictionaries for each file

}

Return type:

dict

sovabids.rules.sovapply()[source]

Console script usage for applying rules.