datahipy.bids

The datahipy.bids subpackage contains modules that define utility functions to interact with BIDS datasets.

datahipy.bids.const

Define constants used by packages of datahipy.bids.

datahipy.bids.dataset

Utility functions to retrieve BIDS dataset content to be indexed by the Elasticsearch engine of the HIP.

datahipy.bids.dataset.create_bids_layout(bids_dir=None, **kwargs)[source]

Create a pybids representation of a BIDS dataset.

Parameters

bids_dirstr

Path to the BIDS dataset.

kwargsdict

Dictionary of arguments key/value to pass to the pybids BIDSLayout function.

Returns

layoutpybids.BIDSLayout

Pybids representation of the BIDS dataset.

datahipy.bids.dataset.create_empty_bids_dataset(bids_dir=None, dataset_desc=None, project_dir=None)[source]

Create an empty BIDS dataset.

Parameters

bids_dirstr

Path to the BIDS dataset.

dataset_descdict

Dictionary with the content of the dataset_description.json file.

project_dirstr

Path to the project directory in which the BIDS dataset will be nested.

datahipy.bids.dataset.create_initial_bids_changes(bids_dir, content_lines=None)[source]

Create an initial CHANGES file for a BIDS dataset.

Parameters

bids_dirstr

Path to the BIDS dataset.

datahipy.bids.dataset.create_initial_bids_readme(bids_dir, dataset_desc)[source]

Create an initial README file for a BIDS dataset.

Parameters

bids_dirstr

Path to the BIDS dataset.

dataset_descdict

Dictionary with the content of the dataset_description.json file.

datahipy.bids.dataset.create_initial_participants_tsv(bids_dir)[source]

Create an initial participants.tsv file for a BIDS dataset.

Parameters

bids_dirstr

Path to the BIDS dataset.

datahipy.bids.dataset.dataset_clone(input_data, output_file)[source]

Clone a dataset from the public space of the HIP.

Parameters

input_datastr

Path to the input_data JSON file in the following format:

{
    "sourceDatasetPath": "/path/to/public/dataset",
    "targetDatasetPath": "/path/of/dataset/to/be/cloned/in/private/space",
}
output_filestr

Path to the output cloned dataset summary in JSON format to be indexed by the Data Search Engine of the HIP.

datahipy.bids.dataset.dataset_publish(input_data, output_file)[source]

Publish a dataset to the public space of the HIP.

Parameters

input_datastr

Path to the input_data JSON file in the following format:

{
    "sourceDatasetPath": "/path/to/private/or/collab/dataset",
    "targetDatasetPath": "/path/of/dataset/to/be/published/to/public/space",
}
output_filestr

Path to the output published dataset summary in JSON format to be indexed by the Data Search Engine of the HIP.

datahipy.bids.dataset.get_all_datasets_content(input_data=None, output_file=None)[source]

Return a JSON file containing a list of dataset dictionaries as response to HIP request.

Parameters

input_datastr

Path to the HIP json request.

output_filestr

Path to the output JSON file.

datahipy.bids.dataset.get_bids_layout_info(bids_dir)[source]

Return a dictionary with information retrieved via the PyBIDS BIDSLayout object representation of the dataset.

Parameters

bids_dirstr

Path to the BIDS dataset.

Returns

bids_layout_infodict

Dictionary with information retrieved via the PyBIDS BIDSLayout object representation of the dataset.

datahipy.bids.dataset.get_bidsdataset_content(bids_dir=None)[source]

Create a dictionary storing dataset information indexed by the HIP platform.

Parameters

bids_dirstr

Path to the BIDS dataset.

Returns

dataset_descdict

Dictionary storing dataset information indexed by the HIP platform.

datahipy.bids.dataset.get_dataset_size(bids_dir=None)[source]

Return the size of the BIDS dataset in megabytes.

Parameters

bids_dirstr

Path to the BIDS dataset.

Returns

total_size_megabytesstr

Size of the BIDS dataset in megabytes.

datahipy.bids.participant

Utility functions to retrieve participant-level information from a BIDS dataset.

datahipy.bids.participant.get_participants_info(bids_dir)[source]

Update the input dataset_desc dictionary with information from the participants.tsv file.

Parameters

dataset_descdict

Input dictionary with the dataset content to be indexed.

bids_dirstr

Path to the BIDS dataset.

Returns

dataset_descdict

Updated dictionary with the dataset content to be indexed.

datahipy.bids.participant.get_subject_bidsfile_info(bids_dir, **kwargs)[source]

Return a list of dictionaries with BIDS file information for a given subject.

Parameters

bids_dirstr

Path to the BIDS dataset.

kwargsdict

Dictionary of arguments key/value to pass to the pybids BIDSLayout.get() function.

Returns

subject_infolist

List of dictionaries with BIDS file information for a given subject.

datahipy.bids.electrophy

Utility functions to retrieve information about electrophysiology files (EEG/MEG/iEEG) from a BIDS dataset.

datahipy.bids.electrophy.get_channels_info(channels_tsv_file)[source]

Extract the content from a BIDS _channels.tsv file in JSON format.

Parameters

channels_tsv_filestr

Path to the BIDS _channels.tsv file.

Returns

channels_infostr

JSON representation of the content of the BIDS _channels.tsv file.

datahipy.bids.electrophy.get_ieeg_info(layout)[source]

Return iEEG data information to be integrated in the dictionary summarizing a BIDS dataset for indexing.

Parameters

dataset_descdict

Input dictionary with the dataset content to be indexed.

layoutBIDSLayout

BIDSLayout object for the dataset.

Returns

ieeg_infodict

Dictionary storing iEEG data information to be integrated in the dataset content to be indexed.

datahipy.bids.validation

Functions for validating BIDS datasets.

datahipy.bids.validation.add_bidsignore_validation_rule(bids_dir, rule)[source]

Create/update a bidsignore file to ignore specific files by the BIDS Validator.

Parameters

bids_dirstr

Path to the BIDS dataset.

rulestr

Rule to add to the bidsignore file, e.g. “**/_ct.” to ignore all CT files.

datahipy.bids.validation.get_bids_validator_output_info(bids_dir, bids_schema_version=None)[source]

Run the bids-validator on the dataset with the specified schema version and the option to ignore subject consistency.

Parameters

bids_dirstr

Path to the BIDS dataset.

bids_schema_versionstr

BIDS schema version to use for the validation. (e.g. “v1.7.0”)

Returns

bids_validator_output_infodict

Dictionary containing the bids-validator output to be integrated in the dataset content to be indexed.

datahipy.bids.validation.validate_bids_dataset(container_dataset_path, *args)[source]

Validate a BIDS dataset using the BIDS Validator.

Parameters

container_dataset_pathstr

Path to the BIDS dataset

argslist

List of options to pass to the bids-validator. Can be used to ignore warnings (["--ignoreWarnings"]) or nifti headers (["--ignoreNiftiHeaders"]) or to skip checking that any given file for one subject is present for all other subjects (["--ignoreSubjectConsistency"]) or to use a specific BIDS schema (["-s", "v1.6.0"])

Returns

outputdict

Output of the bids-validator as a dictionary.

return_codeint

Return code of the bids-validator.

datahipy.bids.version

Utility functions to retrieve version related information from a BIDS dataset.

datahipy.bids.version.create_bids_changes_tag_entry(tag, changes_list)[source]

Create a release text block entry to be added to the CHANGES file of a BIDS dataset.

Parameters

tagstr

Tag of the dataset.

changes_listlist

List of changes to add to the CHANGES file.

Returns

list

List of lines to be written to the CHANGES file.

datahipy.bids.version.determine_bids_schema_version(dataset_desc)[source]

Determine the BIDS schema version of the BIDS dataset against which it will be validated.

Parameters

dataset_descdict

Content of the dataset_description.json file.

Returns

bids_schema_versionstr

BIDS schema version against which the BIDS dataset will be validated.

datahipy.bids.version.manage_bids_dataset_with_datalad(bids_dir)[source]

Create a Datalad dataset out of an existing BIDS dataset not Datalad-managed yet.

datahipy.bids.version.update_bids_changes(bids_dir, changes_tag_entry)[source]

Append a new release text block to the top to the CHANGES file of a BIDS dataset.

Parameters

bids_dirstr

Path to the BIDS dataset.

tagstr

Tag of the dataset.

changes_tag_entrylist

List of lines to be written to the CHANGES file.

datahipy.bids.bids_manager

Utility functions to modify BIDS datasets created using BIDS_Manager.

datahipy.bids.bids_manager.clean_empty_events_tsv_files(layout)[source]

Remove empty events.tsv files.

Parameters

layoutbids.BIDSLayout

BIDSLayout object representation of the BIDS dataset.

datahipy.bids.bids_manager.correct_bids_ieeg_json_file(bids_ieeg_json)[source]

Correct BIDS iEEG json file.

Parameters

bids_ieeg_jsonstr

Path to the BIDS iEEG json file.

Returns

bids_ieeg_json_contentdict

Corrected content overwritten to the BIDS iEEG json file.

datahipy.bids.bids_manager.correct_bids_ieeg_json_files(layout)[source]

Correct BIDS iEEG json files.

Parameters

layoutbids.BIDSLayout

BIDSLayout object representation of the BIDS dataset.

datahipy.bids.bids_manager.correct_run_index_filename(layout)[source]

Correct run index in BIDS filenames.

Parameters

layoutbids.BIDSLayout

BIDSLayout object representation of the BIDS dataset.

datahipy.bids.bids_manager.ensure_list_fields_in_dataset_description(bids_dir, fields)[source]

Ensure that some fields are list type in dataset_description.json.

Parameters

bids_dirstr

Path to the BIDS dataset.

fieldslist of str

List of fields to ensure are list type.

datahipy.bids.bids_manager.post_import_bids_refinement(bids_dir)[source]

Refine BIDS files after import.

Parameters

bids_dirstr

Path to the BIDS dataset.

datahipy.bids.bids_manager.remove_scans_tsv_files(layout)[source]

Remove scans.tsv files.

Parameters

layoutbids.BIDSLayout

BIDSLayout object representation of the BIDS dataset.