bep032tools.generator package
Subpackages
Submodules
bep032tools.generator.BEP032Generator module
- class bep032tools.generator.BEP032Generator.BEP032Data(sub_id, ses_id=None, modality='ephys', custom_metadata_source=None)
Bases:
object
Representation of a BEP032 Data, as specified by in the [ephys BEP](https://bids.neuroimaging.io/bep032)
The BEP032Data object can track multiple realizations of split, run, task but only a single realization of session and subject, i.e. to represent multiple session folders, multiple BEP032Data objects are required. To include multiple realizations of tasks or runs, call the register_data_sources method for each set of parameters separately.
- Parameters:
sub_id (str) – subject identifier, e.g. ‘0012’ or ‘j.s.smith’
ses-id (str) – session identifier, e.g. ‘20210101’ or ‘007’
tasks (str) – task identifier of data files
runs (str) – run identifier of data files
- property basedir
- generate_all_metadata_files()
- classmethod generate_bids_dataset(csv_file, pathToDir, autoconvert=None)
Create a bids dataset from specifications in a csv file. One row of the csv file corresponds to one BEP032 data file in the output BIDS dataset. The first row has to contain header labels for each row. Valid headers are: Mandatory headers are ‘sub_id’ and ‘ses_id’. Optional headers are ‘run’, ‘task’ and ‘data_source’.
‘data_source’ can be: i) an input file (in any raw data format) that needs to be converted to the BIDS-supported file formats, ii) an input directory where several raw data files are present that need to be combined and converted to a single file in a BIDS-supported format, iii) a file already in a BIDS-supported format that will be copied or linked into the BIDS dataset.
An example csv table could contain:
sub_id | ses_id | data_source | run | task ||---------|————|--------------------|—–|---------| | mouse-A | 2000-01-01 | my_data_file_1.abf | 1 | running | | mouse-A | 2000-01-01 | my_data_file_2.abf | 2 | running | | mouse-B | 2000-01-01 | my_data_folder_2 | | rest |
- Parameters:
csv_file (str) – Csv file that contains sub_id and ses_id and optional columns
pathToDir (str) – Path to directory where the directories will be created.
autoconvert (str) – see organize_data_files
- generate_directory_structure()
Generate the hierarchy of folders that will host the data and metadata files
- Returns:
Path of created data folder
- Return type:
path
- generate_metadata_file_channels(output)
- generate_metadata_file_contacts(output)
- generate_metadata_file_dataset_description(output)
- generate_metadata_file_ephys(output)
- generate_metadata_file_participants(output)
- generate_metadata_file_probes(output)
- generate_metadata_file_scans(output)
- generate_metadata_file_sessions(output)
- generate_metadata_file_tasks(output)
- get_data_folder(mode='absolute')
Generates the path to the folder of the data files
- Parameters:
mode (str) – Returns an absolute or relative path Valid values: ‘absolute’, ‘local’
- Returns:
Path of the data folder
- Return type:
pathlib.Path
- organize_data_files(mode='link', autoconvert=None)
Add all the data files for which info has been gathered in register_data_sources to the BIDS data structure
- Parameters:
mode (str) – Can be either ‘link’, ‘copy’ or ‘move’.
autoconvert (str) – accepted values: ‘nix’, ‘nwb’. Automatically convert to the specified format. Warning: Using this feature can require extensive compute resources. Default: None
- register_data_sources(*sources, task=None, run=None)
Gather all the info about the input data sources (files or directories) that will be yield an output data file in the BIDS data structure.
- Parameters:
*sources (path to recording files or folders to be added as data files.) – If multiple sources are provided they are treated as multiple chunks of the same recording and will be enumerated according to their order.
task (str) – task name used
run (str) – run name used
- validate()
Validate the generated structure using the BEP032 validator
- Parameters:
output_folder (str) – path to the folder to validate
- Returns:
True if validation was successful. False if it failed.
- Return type:
bool
- bep032tools.generator.BEP032Generator.convert_data(source_file_or_folder, output_format)
- bep032tools.generator.BEP032Generator.create_file(source, destination, mode, exist_ok=False)
Create a file at a destination location
- Parameters:
source (str) – Source location of the file.
destination (str) – Destination location of the file.
mode (str) – File creation mode. Valid parameters are ‘copy’, ‘link’ and ‘move’.
exist_ok (bool) – If False, raise an Error if the destination already exist. Default: False
- Raises:
ValueError – In case of invalid creation mode.
- bep032tools.generator.BEP032Generator.extract_structure_from_csv(csv_file)
Load csv file that contains folder structure information and return it as pandas.datafram.
- Parameters:
csv_file (str) – The file to be loaded.
- Returns:
A dataframe containing the essential columns for creating an BEP032 structure
- Return type:
pandas.dataframe
- bep032tools.generator.BEP032Generator.main()
Notes
Usage via command line: BEP032Generator.py [-h] pathToCsv pathToDir
- positional arguments:
pathToCsv Path to your csv file
pathToDir Path to your folder
- optional arguments:
- -h, --help
show this help message and exit