qsiprep.utils.bids module

Utilities to handle BIDS inputs

Fetch some test data

>>> import os
>>> from niworkflows import data
>>> data_root = data.get_bids_examples(variant='BIDS-examples-1-enh-ds054')
>>> os.chdir(data_root)
exception qsiprep.utils.bids.BIDSError(message, bids_root)[source]

Bases: ValueError

exception qsiprep.utils.bids.BIDSWarning[source]

Bases: RuntimeWarning

qsiprep.utils.bids.age_to_months(age: int | float, units: Literal['weeks', 'months', 'years']) int[source]

Convert a given age, in either “weeks”, “months”, or “years”, into months.

>>> age_to_months(1, "years")
12
>>> age_to_months(0.5, "years")
6
>>> age_to_months(2, "weeks")
0
>>> age_to_months(3, "weeks")
1
>>> age_to_months(8, "months")
8

Notes

This function is derived from sources licensed under the Apache-2.0 terms. The original function this work derives from is found at: https://github.com/nipreps/nibabies/blob/7efc8c96d109cb755258209d83b1e164c481cf4e/ nibabies/utils/bids.py#L337

Copyright The NiPreps Developers <nipreps@gmail.com>

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

We support and encourage derived works from this project, please read about our expectations at

qsiprep.utils.bids.cohort_by_months(template, months)[source]

Produce a recommended cohort based on partipants age.

Notes

This function is derived from sources licensed under the Apache-2.0 terms. The original function this work derives from is found at: https://github.com/nipreps/nibabies/blob/7efc8c96d109cb755258209d83b1e164c481cf4e/ nibabies/utils/misc.py#L50

Copyright The NiPreps Developers <nipreps@gmail.com>

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

We support and encourage derived works from this project, please read about our expectations at

qsiprep.utils.bids.collect_data(bids_dir, participant_label, session_id=None, filters=None, bids_validate=True, ignore=None)[source]

Use pybids to retrieve the input data for a given participant.

qsiprep.utils.bids.collect_participants(bids_dir, participant_label=None, strict=False, bids_validate=True)[source]

List the participants under the BIDS root and checks that participants designated with the participant_label argument exist in that folder.

Returns the list of participants to be finally processed.

Requesting all subjects in a BIDS directory root:

>>> collect_participants('ds114')
['01', '02', '03', '04', '05', '06', '07', '08', '09', '10']

Requesting two subjects, given their IDs:

>>> collect_participants('ds114', participant_label=['02', '04'])
['02', '04']

Requesting two subjects, given their IDs (works with ‘sub-’ prefixes):

>>> collect_participants('ds114', participant_label=['sub-02', 'sub-04'])
['02', '04']

Requesting two subjects, but one does not exist:

>>> collect_participants('ds114', participant_label=['02', '14'])
['02']
>>> collect_participants('ds114', participant_label=['02', '14'],
...                      strict=True)  
Traceback (most recent call last):
qsiprep.utils.bids.BIDSError:
...
qsiprep.utils.bids.parse_bids_for_age_months(bids_root: str | Path, subject_id: str, session_id: str | None = None) int | None[source]

Given a BIDS root, query the BIDS metadata files for participant age, and return in chronological months.

The heuristic followed is: 1) Check sub-<subject_id>[/ses-<session_id>]/<sub-<subject_id>[_ses-<session-id>]_scans.tsv 2) Check `sub-<subject_id>/sub-<subject_id>_sessions.tsv 3) Check <root>/participants.tsv

Notes

This function is derived from sources licensed under the Apache-2.0 terms. The original function this work derives from is found at: https://github.com/nipreps/nibabies/blob/7efc8c96d109cb755258209d83b1e164c481cf4e/ nibabies/utils/bids.py#L218

Copyright The NiPreps Developers <nipreps@gmail.com>

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

We support and encourage derived works from this project, please read about our expectations at

qsiprep.utils.bids.scan_groups_to_sidecar(scan_groups)[source]

Create a sidecar that reflects how the preprocessed image was created.

qsiprep.utils.bids.update_metadata_from_nifti_header(metadata, nifti_file)[source]

Update a BIDS metadata dictionary with info from a NIfTI header.

Code borrowed from CuBIDS.

qsiprep.utils.bids.validate_input_dir(exec_env, bids_dir, participant_label)[source]
qsiprep.utils.bids.write_bidsignore(deriv_dir)[source]
qsiprep.utils.bids.write_derivative_description(bids_dir, deriv_dir)[source]