-
Notifications
You must be signed in to change notification settings - Fork 59
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
Test field map collection #927
Draft
tsalo
wants to merge
15
commits into
master
Choose a base branch
from
bids-uris
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c8cbac2
Test field map collection.
tsalo d538f36
Update test_utils_grouping.py
tsalo 706e7f1
Update test_utils_grouping.py
tsalo 1c91eab
Update test_utils_grouping.py
tsalo fd5b49a
Update test_utils_grouping.py
tsalo e8bcc12
Update test_utils_grouping.py
tsalo d390544
Update test_utils_grouping.py
tsalo e8ac23c
Work on complex grouping tests.
tsalo fec9ef0
Update test_utils_grouping.py
tsalo 30437f6
Update test_utils_grouping.py
tsalo 292fba1
Update test_utils_grouping.py
tsalo 7d95696
Update grouping.py
tsalo 0a21d7e
Merge branch 'master' into bids-uris
tsalo 81edc29
Update grouping.py
tsalo 957f478
Update.
tsalo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,74 @@ | |
], | ||
} | ||
|
||
dset_fmap_intendedfor_relpath = { | ||
'01': [ | ||
{ | ||
'fmap': [ | ||
{ | ||
'dir': 'PA', | ||
'suffix': 'epi', | ||
'metadata': { | ||
'IntendedFor': ['dwi/sub-01_dir-AP_dwi.nii.gz'], | ||
}, | ||
}, | ||
], | ||
'dwi': [ | ||
{ | ||
'dir': 'AP', | ||
'suffix': 'dwi', | ||
}, | ||
], | ||
}, | ||
], | ||
} | ||
dset_fmap_intendedfor_bidsuri = { | ||
'01': [ | ||
{ | ||
'fmap': [ | ||
{ | ||
'dir': 'PA', | ||
'suffix': 'epi', | ||
'metadata': { | ||
'IntendedFor': ['bids::sub-01/dwi/sub-01_dir-AP_dwi.nii.gz'], | ||
}, | ||
}, | ||
], | ||
'dwi': [ | ||
{ | ||
'dir': 'AP', | ||
'suffix': 'dwi', | ||
}, | ||
], | ||
}, | ||
], | ||
} | ||
dset_fmap_b0fields = { | ||
'01': [ | ||
{ | ||
'fmap': [ | ||
{ | ||
'dir': 'PA', | ||
'suffix': 'epi', | ||
'metadata': { | ||
'B0FieldIdentifier': 'pepolar', | ||
}, | ||
}, | ||
], | ||
'dwi': [ | ||
{ | ||
'dir': 'AP', | ||
'suffix': 'dwi', | ||
'metadata': { | ||
'B0FieldIdentifier': 'pepolar', | ||
'B0FieldSource': 'pepolar', | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
} | ||
|
||
|
||
def test_get_entity_groups_with_multipartid(tmpdir): | ||
"""Test the get_entity_groups function.""" | ||
|
@@ -117,6 +185,44 @@ def test_get_entity_groups_without_multipartid(tmpdir): | |
check_expected(entity_groups, expected) | ||
|
||
|
||
def test_get_fieldmaps(tmp_path_factory): | ||
"""Test the get_fieldmaps function.""" | ||
base_dir = tmp_path_factory.mktemp('test_get_fieldmaps') | ||
|
||
# Check that relative paths are correctly handled | ||
bids_dir = base_dir / 'dset_fmap_intendedfor_relpath' | ||
generate_bids_skeleton(str(bids_dir), dset_fmap_intendedfor_relpath) | ||
layout = BIDSLayout(str(bids_dir)) | ||
dwi_file = layout.get(suffix='dwi', extension='nii.gz', return_type='filename')[0] | ||
fieldmaps = layout.get_fieldmap(dwi_file, return_list=True) | ||
assert len(fieldmaps) == 1 | ||
assert fieldmaps[0]['suffix'] == 'epi' | ||
assert layout.get_file(fieldmaps[0]['epi']).get_metadata()['IntendedFor'] == [ | ||
'dwi/sub-01_dir-AP_dwi.nii.gz' | ||
] | ||
|
||
# Check that BIDS URI paths are correctly handled | ||
bids_dir = base_dir / 'dset_fmap_intendedfor_bidsuri' | ||
generate_bids_skeleton(str(bids_dir), dset_fmap_intendedfor_bidsuri) | ||
layout = BIDSLayout(str(bids_dir)) | ||
dwi_file = layout.get(suffix='dwi', extension='nii.gz', return_type='filename')[0] | ||
fieldmaps = layout.get_fieldmap(dwi_file, return_list=True) | ||
assert len(fieldmaps) == 1 | ||
assert fieldmaps[0]['suffix'] == 'epi' | ||
assert layout.get_file(fieldmaps[0]['epi']).get_metadata()['IntendedFor'] == [ | ||
'bids::sub-01/dwi/sub-01_dir-AP_dwi.nii.gz' | ||
] | ||
|
||
# Check that B0FieldIdentifier and B0FieldSource are correctly handled | ||
bids_dir = base_dir / 'dset_fmap_b0fields' | ||
generate_bids_skeleton(str(bids_dir), dset_fmap_b0fields) | ||
layout = BIDSLayout(str(bids_dir)) | ||
dwi_file = layout.get(suffix='dwi', extension='nii.gz', return_type='filename')[0] | ||
fieldmaps = layout.get_fieldmap(dwi_file, return_list=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't expect this to work. We probably need custom code like SDCFlows uses. |
||
assert len(fieldmaps) == 1 | ||
assert fieldmaps[0]['suffix'] == 'epi' | ||
|
||
|
||
def check_expected(subject_data, expected): | ||
"""Check expected values.""" | ||
if isinstance(expected, str): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BIDSLayout.get_fieldmap
doesn't work on BIDS URIs, so we need to either work around it like SDCFlows does or contribute to PyBIDS to make it work.