-
Notifications
You must be signed in to change notification settings - Fork 52
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
ENH: Support combined surface-volume reference spaces #883
Draft
tsalo
wants to merge
9
commits into
nipreps:master
Choose a base branch
from
tsalo:cifti-combos
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 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1dc7ad0
Draft surface-volume combination parsing.
tsalo 98a753c
Add cifti attribute.
tsalo 76027ab
Update test_spaces.py
tsalo 15569a9
Fix test.
tsalo bb027b0
Merge remote-tracking branch 'upstream/master' into cifti-combos
tsalo f3523eb
Update spaces.py
tsalo 35aa430
Merge remote-tracking branch 'upstream/master' into cifti-combos
tsalo e0f4278
Add cifti argument to get_*.
tsalo b7faf19
Fix test.
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 |
---|---|---|
|
@@ -148,6 +148,8 @@ class Reference: | |
"""The dictionary of specs.""" | ||
standard = attr.ib(default=False, repr=False, type=bool) | ||
"""Whether this space is standard or not.""" | ||
cifti = attr.ib(default=False, repr=False, type=bool) | ||
"""Whether this space is a CIFTI space or not.""" | ||
dim = attr.ib(default=3, repr=False, type=int) | ||
"""Dimensionality of the sampling manifold.""" | ||
|
||
|
@@ -165,12 +167,32 @@ def __attrs_post_init__(self): | |
spec["den"] = FSAVERAGE_DENSITY[space] | ||
object.__setattr__(self, "spec", spec) | ||
|
||
# XXX: This won't cover dhcpAsym, dhcpSym, or onavg | ||
if self.space.startswith("fs"): | ||
object.__setattr__(self, "dim", 2) | ||
|
||
if "volspace" in self.spec: | ||
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. This check would hopefully only be necessary in the short-term, since mixed standard/non-standard CIFTIs should be allowed. |
||
volspace = self.spec["volspace"] | ||
if (self.space in self._standard_spaces) and (volspace not in self._standard_spaces): | ||
raise ValueError( | ||
f"Surface space ({self.space}) is a standard space, " | ||
f"but volume space ({volspace}) is not. " | ||
"Mixing standard and non-standard spaces is not currently allowed." | ||
) | ||
elif (self.space not in self._standard_spaces) and (volspace in self._standard_spaces): | ||
raise ValueError( | ||
f"Surface space ({self.space}) is a non-standard space, " | ||
f"but volume space ({volspace}) is a standard space. " | ||
"Mixing standard and non-standard spaces is not currently allowed." | ||
) | ||
|
||
if self.space in self._standard_spaces: | ||
object.__setattr__(self, "standard", True) | ||
|
||
if "volspace" in self.spec: | ||
object.__setattr__(self, "cifti", True) | ||
|
||
# Check that cohort is handled appropriately | ||
_cohorts = ["%s" % t for t in _tfapi.TF_LAYOUT.get_cohorts(template=self.space)] | ||
if "cohort" in self.spec: | ||
if not _cohorts: | ||
|
@@ -191,6 +213,30 @@ def __attrs_post_init__(self): | |
"Set a valid cohort selector from: %s." % (self.space, _cohorts) | ||
) | ||
|
||
# Check that cohort is handled appropriately for the volume template if necessary | ||
if "volspace" in self.spec: | ||
_cohorts = [ | ||
"%s" % t for t in _tfapi.TF_LAYOUT.get_cohorts(template=self.spec["volspace"]) | ||
] | ||
if "volcohort" in self.spec: | ||
if not _cohorts: | ||
raise ValueError( | ||
'standard space "%s" does not accept a cohort ' | ||
"specification." % self.spec["volspace"] | ||
) | ||
|
||
if str(self.spec["volcohort"]) not in _cohorts: | ||
raise ValueError( | ||
'standard space "%s" does not contain any cohort ' | ||
'named "%s".' % (self.spec["volspace"], self.spec["volcohort"]) | ||
) | ||
elif _cohorts: | ||
_cohorts = ", ".join(['"cohort-%s"' % c for c in _cohorts]) | ||
raise ValueError( | ||
'standard space "%s" is not fully defined.\n' | ||
"Set a valid cohort selector from: %s." % (self.spec["volspace"], _cohorts) | ||
) | ||
|
||
@property | ||
def fullname(self): | ||
""" | ||
|
@@ -205,9 +251,17 @@ def fullname(self): | |
'MNIPediatricAsym:cohort-1' | ||
|
||
""" | ||
if "cohort" not in self.spec: | ||
return self.space | ||
return "%s:cohort-%s" % (self.space, self.spec["cohort"]) | ||
name = self.space | ||
|
||
if "cohort" in self.spec: | ||
name += f":cohort-{self.spec['cohort']}" | ||
|
||
if "volspace" in self.spec: | ||
name += f"::{self.spec['volspace']}" | ||
if "volcohort" in self.spec: | ||
name += f":cohort-{self.spec['volcohort']}" | ||
|
||
return name | ||
|
||
@property | ||
def legacyname(self): | ||
|
@@ -330,13 +384,37 @@ def from_string(cls, value): | |
Reference(space='MNIPediatricAsym', spec={'cohort': '6', 'res': '2'}), | ||
Reference(space='MNIPediatricAsym', spec={'cohort': '6', 'res': 'iso1.6mm'})] | ||
|
||
>>> Reference.from_string( | ||
... "dhcpAsym:cohort-42:den-32k::dhcpVol:cohort-44:res-2" | ||
... ) # doctest: +NORMALIZE_WHITESPACE | ||
[Reference(space='dhcpAsym', spec={'cohort': '42', 'den': '32k', 'volspace': 'dhcpVol', | ||
'volcohort': '44', 'res': '2'})] | ||
|
||
""" | ||
volume_value = None | ||
if "::" in value: | ||
# CIFTI definition with both surface and volume spaces defined | ||
value, volume_value = value.split("::") | ||
# We treat the surface space definition as the "primary" space | ||
_args = value.split(":") | ||
|
||
_args = value.split(":") | ||
spec = defaultdict(list, {}) | ||
for modifier in _args[1:]: | ||
mitems = modifier.split("-", 1) | ||
spec[mitems[0]].append(len(mitems) == 1 or mitems[1]) | ||
|
||
if volume_value: | ||
# Tack on the volume space definition to the surface space definition | ||
volume_args = volume_value.split(":") | ||
# There are two special entities to prevent overloading: volspace and volcohort | ||
spec["volspace"] = [volume_args[0]] | ||
for modifier in volume_args[1:]: | ||
mitems = modifier.split("-", 1) | ||
if mitems[0] == "cohort": | ||
mitems[0] = "volcohort" | ||
spec[mitems[0]].append(len(mitems) == 1 or mitems[1]) | ||
|
||
allspecs = _expand_entities(spec) | ||
|
||
return [cls(_args[0], s) for s in allspecs] | ||
|
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
Oops, something went wrong.
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.
Alternatively, I could use a new
dim
value, like 2.5, instead of adding this attribute.