Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on compressed+uncompressed images in collect_data #627

Open
effigies opened this issue Apr 12, 2021 · 0 comments
Open

Error on compressed+uncompressed images in collect_data #627

effigies opened this issue Apr 12, 2021 · 0 comments
Labels
effort:low Estimated low effort task impact:low Estimated low impact task

Comments

@effigies
Copy link
Member

effigies commented Apr 12, 2021

If a dataset contains a compressed and uncompressed version of a file that will be operated on, the behavior or downstream tools may change. sMRIPrep will align and average a compressed and uncompressed T1w image, wasting time and possibly producing slightly confusing reports. In fMRIPrep, each BOLD series will get a workflow, and Nipype will crash due to duplication, as extension does not enter into the node name.

The best place to resolve this is in collect_data:

def collect_data(
bids_dir,
participant_label,
task=None,
echo=None,
bids_validate=True,
bids_filters=None,
):
"""
Uses pybids to retrieve the input data for a given participant
Examples
--------
>>> bids_root, _ = collect_data(str(datadir / 'ds054'), '100185',
... bids_validate=False)
>>> bids_root['fmap'] # doctest: +ELLIPSIS
['.../ds054/sub-100185/fmap/sub-100185_magnitude1.nii.gz', \
'.../ds054/sub-100185/fmap/sub-100185_magnitude2.nii.gz', \
'.../ds054/sub-100185/fmap/sub-100185_phasediff.nii.gz']
>>> bids_root['bold'] # doctest: +ELLIPSIS
['.../ds054/sub-100185/func/sub-100185_task-machinegame_run-01_bold.nii.gz', \
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-02_bold.nii.gz', \
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-03_bold.nii.gz', \
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-04_bold.nii.gz', \
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-05_bold.nii.gz', \
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-06_bold.nii.gz']
>>> bids_root['sbref'] # doctest: +ELLIPSIS
['.../ds054/sub-100185/func/sub-100185_task-machinegame_run-01_sbref.nii.gz', \
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-02_sbref.nii.gz', \
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-03_sbref.nii.gz', \
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-04_sbref.nii.gz', \
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-05_sbref.nii.gz', \
'.../ds054/sub-100185/func/sub-100185_task-machinegame_run-06_sbref.nii.gz']
>>> bids_root['t1w'] # doctest: +ELLIPSIS
['.../ds054/sub-100185/anat/sub-100185_T1w.nii.gz']
>>> bids_root['t2w'] # doctest: +ELLIPSIS
[]
>>> bids_root, _ = collect_data(str(datadir / 'ds051'), '01',
... bids_validate=False, bids_filters={'t1w':{'run': 1}})
>>> bids_root['t1w'] # doctest: +ELLIPSIS
['.../ds051/sub-01/anat/sub-01_run-01_T1w.nii.gz']
"""
if isinstance(bids_dir, BIDSLayout):
layout = bids_dir
else:
layout = BIDSLayout(str(bids_dir), validate=bids_validate)
queries = {
"fmap": {"datatype": "fmap"},
"bold": {"datatype": "func", "suffix": "bold"},
"sbref": {"datatype": "func", "suffix": "sbref"},
"flair": {"datatype": "anat", "suffix": "FLAIR"},
"t2w": {"datatype": "anat", "suffix": "T2w"},
"t1w": {"datatype": "anat", "suffix": "T1w"},
"roi": {"datatype": "anat", "suffix": "roi"},
}
bids_filters = bids_filters or {}
for acq, entities in bids_filters.items():
queries[acq].update(entities)
if task:
queries["bold"]["task"] = task
if echo:
queries["bold"]["echo"] = echo
subj_data = {
dtype: sorted(
layout.get(
return_type="file",
subject=participant_label,
extension=["nii", "nii.gz"],
**query,
)
)
for dtype, query in queries.items()
}
# Special case: multi-echo BOLD, grouping echos
if any(["_echo-" in bold for bold in subj_data["bold"]]):
subj_data["bold"] = group_multiecho(subj_data["bold"])
return subj_data, layout

When the same file is present in compressed and uncompressed form, we should raise an error rather than return both, so that each downstream tool does not have to decide how best to deal with these.

Issue discovered in nipreps/fmriprep#2396.

@effigies effigies added effort:low Estimated low effort task impact:low Estimated low impact task labels Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort:low Estimated low effort task impact:low Estimated low impact task
Projects
None yet
Development

No branches or pull requests

1 participant