Skip to content

Test dMRI and field map file grouping - #927

Merged
tsalo merged 30 commits into
masterfrom
bids-uris
Aug 6, 2025
Merged

Test dMRI and field map file grouping#927
tsalo merged 30 commits into
masterfrom
bids-uris

Conversation

@tsalo

@tsalo tsalo commented Feb 25, 2025

Copy link
Copy Markdown
Member

Closes none.

Changes proposed in this pull request

  • Write tests to cover field map collection and DWI scan grouping, using mocked up datasets.
  • Modify the utility function group_dwi_scans to accept the BIDSLayout as a parameter instead of relying on the config object. This makes it easier to test. Also the nipreps folks only use the config in workflow functions. They tend to pass fields from it into interfaces and utility functions.

@tsalo tsalo added the testing label Feb 25, 2025
Comment thread qsiprep/tests/test_utils_grouping.py Outdated
Comment thread qsiprep/tests/test_utils_grouping.py Outdated
@tsalo

tsalo commented Aug 5, 2025

Copy link
Copy Markdown
Member Author

I can drop the BIDS-URI tests for now so we at least get these tests in.

Comment thread qsiprep/tests/test_utils_grouping.py
Comment thread qsiprep/utils/grouping.py
Comment on lines -397 to +404
fname: meta.get('PhaseEncodingDirection', 'None')
fname: meta.get('PhaseEncodingDirection', None)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is potentially a meaningful change.

@tsalo
tsalo requested a review from mattcieslak August 5, 2025 18:40
@tsalo
tsalo marked this pull request as ready for review August 5, 2025 18:40
@tsalo tsalo changed the title Test field map collection Test dMRI and field map file grouping Aug 5, 2025
@codecov-commenter

codecov-commenter commented Aug 5, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.12%. Comparing base (317828f) to head (c874de4).
⚠️ Report is 28 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #927      +/-   ##
==========================================
+ Coverage   46.02%   46.12%   +0.10%     
==========================================
  Files          65       65              
  Lines        9764     9764              
  Branches     1074     1074              
==========================================
+ Hits         4494     4504      +10     
+ Misses       5044     5036       -8     
+ Partials      226      224       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

scan_groups, _ = grouping.group_dwi_scans(
layout=layout,
subject_data=subject_data,
using_fsl=True,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattcieslak said to remove using_fsl. It's always True(?), so use that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented in #923.

using_fsl=True,
combine_scans=True,
ignore_fieldmaps=False,
concatenate_distortion_groups=True,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tied to combine_before_denoising. If True, will concatenate across distortion groups before MP-PCA.

This should be respecting MultipartID (concatenate AP run-01 and AP run-02, but not PA) but isn't.

RPE DWI scans are higher priority for distortion correction than EPI fmaps, so it makes sense that we have selected the rpe_series for SDC.

However, the epi field maps that are collected are not correct. The IntendedFor fields I set should only use the AP EPI for the PA DWI. The PA EPI does not have the PA DWI in its IntendedFor.

@tsalo tsalo Aug 6, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to enumerate the possible combinations of metadata fields and what the resulting processing should be. For example, should MultipartID be limited to scans with the same parameters, or can we use it to determine which runs should be concatenated, even across distortion groups?

And if MultipartID should only be applied within distortion groups, then how should users specify which runs should be concatenated?

@tsalo tsalo Aug 6, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #963 and #964.

generate_bids_skeleton(str(bids_dir), dset_yaml)
layout = BIDSLayout(str(bids_dir))
subject_data = {'dwi': layout.get(suffix='dwi', extension='nii.gz', return_type='file')}
scan_groups, _ = grouping.group_dwi_scans(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add a grouping parameter reflecting if DRBUDDI is used. TOPUP allows various different phase encoding directions (e.g., dir-AP, dir-RL, and dir-SI are a valid combination), but DRBUDDI only allows two reverse-PEDs (dir-AP and dir-PA are solid, but don't throw dir-RL into the mix). This needs to be reflected in the groups.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #962.

'fieldmap_info': {
'epi': [
'sub-01_dir-AP_epi.nii.gz',
'sub-01_dir-PA_epi.nii.gz',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #964.

'sub-01_dir-AP_run-1_dwi.nii.gz',
'sub-01_dir-AP_run-2_dwi.nii.gz',
],
'suffix': 'rpe_series',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conclusion: Build dictionary around the selected distortion correction suffix, so there's no need for a second dictionary for the AP scans linking to the PA fmap EPI. HOWEVER, we do need to prioritize supporting B0Field* fields in order to give users control over what is chosen.

ignore_fieldmaps=False,
concatenate_distortion_groups=False,
)
expected = [

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattcieslak: This one is clearly an error. Amelie probably used this option recently, and it worked at the time so this might just be weird.

]
check_expected(scan_groups, expected)

scan_groups, _ = grouping.group_dwi_scans(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably what Amelie had.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weirdly, using_fsl is hardcoded as True in QSIPrep so 🤷

subject_data=subject_data,
using_fsl=True,
combine_scans=True,
ignore_fieldmaps=True,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means ignore distortion correction, not just ignore field maps. Should rename, but logic makes sense.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--ignore fmaps in the CLI apparently ignores all distortion correction, including reverse PED DWI runs. Let's change that!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #965.

@tsalo
tsalo merged commit a826be8 into master Aug 6, 2025
24 checks passed
@tsalo
tsalo deleted the bids-uris branch August 6, 2025 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants