sovabids.rules
#
Module dealing with the rules for bids conversion.
Module Contents#
Functions#
|
|
|
Parse information from a given path, given a set of rules. |
|
Recursively scan the directory for valid files, returning a list with the full-paths to each. |
|
Load rules if given a path, bypass if given a dict. |
|
Apply rules to a single file. |
|
Apply rules to a set of files. |
|
Console script usage for applying rules. |
Attributes#
- sovabids.rules.get_info_from_path(path, rules)[source]#
Parse information from a given path, given a set of rules.
- Parameters:
path (str) – 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) – The path we want to obtain the files from.
rules (str|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|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) – Path to the file.
rules (str|dict) – Path to the rules file or rules dictionary.
bids_path (str) – 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 | list of str) – If str, the path with the files we want to convert to bids. If list of str with the paths of the files we want to convert (ie the output of get_files).
bids_path (str) – The path we want the converted files in.
rules (str|dict) – The path to the rules file, or a dictionary with the rules.
mapping_path (str, 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