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

ENH: Project fsLR mesh onto native sphere to enable single-shot resampling into fsLR #339

Merged
merged 21 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .circleci/ds005_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@ smriprep/sub-01/anat/sub-01_dseg.nii.gz
smriprep/sub-01/anat/sub-01_from-fsnative_to-T1w_mode-image_xfm.txt
smriprep/sub-01/anat/sub-01_from-T1w_to-fsnative_mode-image_xfm.txt
smriprep/sub-01/anat/sub-01_hemi-L_curv.shape.gii
smriprep/sub-01/anat/sub-01_hemi-L_desc-reg_sphere.surf.gii
smriprep/sub-01/anat/sub-01_hemi-L_inflated.surf.gii
smriprep/sub-01/anat/sub-01_hemi-L_midthickness.surf.gii
smriprep/sub-01/anat/sub-01_hemi-L_pial.surf.gii
smriprep/sub-01/anat/sub-01_hemi-L_smoothwm.surf.gii
smriprep/sub-01/anat/sub-01_hemi-L_space-fsLR_desc-reg_sphere.surf.gii
smriprep/sub-01/anat/sub-01_hemi-L_sulc.shape.gii
smriprep/sub-01/anat/sub-01_hemi-L_thickness.shape.gii
smriprep/sub-01/anat/sub-01_hemi-L_white.surf.gii
smriprep/sub-01/anat/sub-01_hemi-R_curv.shape.gii
smriprep/sub-01/anat/sub-01_hemi-R_desc-reg_sphere.surf.gii
smriprep/sub-01/anat/sub-01_hemi-R_inflated.surf.gii
smriprep/sub-01/anat/sub-01_hemi-R_midthickness.surf.gii
smriprep/sub-01/anat/sub-01_hemi-R_pial.surf.gii
smriprep/sub-01/anat/sub-01_hemi-R_smoothwm.surf.gii
smriprep/sub-01/anat/sub-01_hemi-R_space-fsLR_desc-reg_sphere.surf.gii
smriprep/sub-01/anat/sub-01_hemi-R_sulc.shape.gii
smriprep/sub-01/anat/sub-01_hemi-R_thickness.shape.gii
smriprep/sub-01/anat/sub-01_hemi-R_white.surf.gii
smriprep/sub-01/anat/sub-01_label-CSF_probseg.nii.gz
smriprep/sub-01/anat/sub-01_label-GM_probseg.nii.gz
smriprep/sub-01/anat/sub-01_label-WM_probseg.nii.gz
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@

apidoc_module_dir = "../smriprep"
apidoc_output_dir = "api"
apidoc_excluded_paths = ["conftest.py", "*/tests/*", "tests/*", "data/*", "conf/*"]
apidoc_excluded_paths = ["conftest.py", "*/conftest.py", "*/tests/*", "tests/*", "data/*", "conf/*"]
apidoc_separate_modules = True
apidoc_extra_args = ["--module-first", "-d 1", "-T"]

Expand Down
9 changes: 6 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ classifiers =
[options]
python_requires = >=3.8
install_requires =
importlib_resources >= 1.3; python_version < '3.9'
indexed_gzip >= 0.8.8
lockfile
looseversion
Expand Down Expand Up @@ -71,9 +72,11 @@ all =
[options.package_data]
smriprep =
VERSION
data/boilerplate.bib
data/io_spec.json
data/itkIdentityTransform.txt
data/*
data/atlases/*
data/atlases/fs_L/*
data/atlases/fs_R/*
interfaces/tests/data/*

[options.entry_points]
console_scripts =
Expand Down
19 changes: 0 additions & 19 deletions smriprep/conftest.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
import os
from pathlib import Path
from tempfile import TemporaryDirectory
import pytest

os.environ['NO_ET'] = '1'


@pytest.fixture(autouse=True, scope="session")
def default_cwd():
cwd = os.getcwd()
with TemporaryDirectory(prefix="smriprepTest") as tmpdir:
try:
os.chdir(tmpdir)
yield Path(tmpdir)
finally:
os.chdir(cwd)


@pytest.fixture(autouse=True, scope="session")
def populate_default_cwd(default_cwd):
Path.write_bytes(default_cwd / 'lh.white', b'')
25 changes: 25 additions & 0 deletions smriprep/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import atexit
from contextlib import ExitStack
from pathlib import Path

try:
from functools import cache
except ImportError: # PY38
from functools import lru_cache as cache

try: # Prefer backport to leave consistency to dependency spec
from importlib_resources import files, as_file
except ImportError:
from importlib.resources import files, as_file

__all__ = ["load_resource"]

exit_stack = ExitStack()
atexit.register(exit_stack.close)

path = files(__package__)


@cache
def load_resource(fname: str) -> Path:
return exit_stack.enter_context(as_file(path.joinpath(fname)))
77 changes: 77 additions & 0 deletions smriprep/data/atlases/L.atlasroi.32k_fs_LR.shape.gii
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<GIFTI xmlns:xsi="true"
xsi:noNamespaceSchemaLocation="true"
Version="1"
NumberOfDataArrays="1">
<MetaData>
<MD>
<Name><![CDATA[AnatomicalStructurePrimary]]></Name>
<Value><![CDATA[CortexLeft]]></Value>
</MD>
<MD>
<Name><![CDATA[Caret-Version]]></Name>
<Value><![CDATA[5.65]]></Value>
</MD>
<MD>
<Name><![CDATA[Date]]></Name>
<Value><![CDATA[2012-11-13T05:25:24]]></Value>
</MD>
<MD>
<Name><![CDATA[UniqueID]]></Name>
<Value><![CDATA[{1fbd4629-1f40-4e61-a530-3f24c4dd18b4}]]></Value>
</MD>
<MD>
<Name><![CDATA[comment]]></Name>
<Value><![CDATA[Deformed from: CCNMD_MyelinMapping.L.Atlas_Cortex_ROI.164k_fs_LR.func.gii
Deformed with: 164k_fs_LR232k_fs_LR.L.deform_map

Appended File: /media/2TBB/MyelinMapping_Project/CommonFiles/FS_LR/fsaverage.L+R.MedialWall.164k_fs_LR.metric
Deformed from: fsaverage.L.ProbabilisticArchitectonic.164k_fs_L.metric
Deformed with: fsaverage.L.registered-to-fs_LR.164k_fs_LR.deform_map
Appended File: /Users/vanessen/BRAIN_MAP_DATA/PALS_B12_HUMAN/FREESURFER-to-PALS/FREESURFER_AVG-to-PALS/FS_AVERAGE/FS_LR/fsaverage.R.ProbabilisticArchitectonic.164k_fs_LR.metric
Deformed from: fsaverage.R.ProbabilisticArchitectonic.164k_fs_R.metric
Deformed with: fsaverage.R.registered-to-fs_LR.164k_fs_LR.deform_map]]></Value>
</MD>
<MD>
<Name><![CDATA[encoding]]></Name>
<Value><![CDATA[XML_BASE64_GZIP]]></Value>
</MD>
</MetaData>
<LabelTable>
<Label Key="0" Red="1" Green="1" Blue="1" Alpha="0"><![CDATA[???]]></Label>
</LabelTable>
<DataArray Intent="NIFTI_INTENT_NONE"
DataType="NIFTI_TYPE_FLOAT32"
ArrayIndexingOrder="RowMajorOrder"
Dimensionality="1"
Dim0="32492"
Encoding="GZipBase64Binary"
Endian="LittleEndian"
ExternalFileName=""
ExternalFileOffset="0">
<MetaData>
<MD>
<Name><![CDATA[Description]]></Name>
<Value><![CDATA[Multiplied -1.0 by Atlas_Cortex_ROI
Deformed with: 164k_fs_LR232k_fs_LR.L.deform_map]]></Value>
</MD>
<MD>
<Name><![CDATA[Name]]></Name>
<Value><![CDATA[deformed_Atlas_Cortex_ROI]]></Value>
</MD>
<MD>
<Name><![CDATA[UniqueID]]></Name>
<Value><![CDATA[{75dd580c-28b9-4aff-b96a-2b3e5ebf0b26}]]></Value>
</MD>
<MD>
<Name><![CDATA[column-color-mapping]]></Name>
<Value><![CDATA[-1.0 1.0]]></Value>
</MD>
<MD>
<Name><![CDATA[column-threshold]]></Name>
<Value><![CDATA[0.0 0.0]]></Value>
</MD>
</MetaData>
<Data>eJzt3UluwkAQQFHfLFfj6Fllg2KB3UMNfou3SUTXbyywLSQ4jtfPcep4nf/v0+OqurPfSqKf3+jnPXqfq56j6Db76r2n7nuJbnrqPqrvQbvuO83Zu7Wu78zYmr0xc1/WtozXbtmujzP1ZLmHzdDxqWF1S/bZKxoi5u6eeWXe6Myrs+7OuzPn6qy7M76dk3HtTzNWrDu65vvaM9ebtRbQ2+7zNAA8TdXzZsVzfrVrlUrXV1WuCytcx2a/3s7cl/WeJeP9VLamTD0jLTN7qjfM6BidP9JQde6d2btn7py3a9aOOatnrFx/1doz1n1fO/N6s9bKsAa9jZ7/AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4ImO131/j189Z6QP4Emqv/91eA+v3F+1vWJ3teZKvdVaoxsqN2Y/1lnbsnVlPI6ZerK0ZOiIboicHzU7Ym70cQYgztk54P3v759N+IwAAAAAAAAAAAAAAAAAAAAAAAAAoL+K3y939n16lb43r8tvBXX43aPqv+FUuV93/uZqvRHdo627mmd1rmyd2bhiDzv7rjbubvu2Nbrrv87oBgAAetp5H8qYzseu47667anLfjq9jjrso/oeKvdXba/YXa25am90x7et0Q0dGgEAAAAAAAAAAAAAAAAAgK5+AReeB2U=</Data>
</DataArray>
</GIFTI>
77 changes: 77 additions & 0 deletions smriprep/data/atlases/R.atlasroi.32k_fs_LR.shape.gii
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<GIFTI xmlns:xsi="true"
xsi:noNamespaceSchemaLocation="true"
Version="1"
NumberOfDataArrays="1">
<MetaData>
<MD>
<Name><![CDATA[AnatomicalStructurePrimary]]></Name>
<Value><![CDATA[CortexRight]]></Value>
</MD>
<MD>
<Name><![CDATA[Caret-Version]]></Name>
<Value><![CDATA[5.65]]></Value>
</MD>
<MD>
<Name><![CDATA[Date]]></Name>
<Value><![CDATA[2012-11-13T05:40:22]]></Value>
</MD>
<MD>
<Name><![CDATA[UniqueID]]></Name>
<Value><![CDATA[{e3d82af6-38dd-4115-9a0b-ff874545cc6e}]]></Value>
</MD>
<MD>
<Name><![CDATA[comment]]></Name>
<Value><![CDATA[Deformed from: CCNMD_MyelinMapping.R.Atlas_Cortex_ROI.164k_fs_LR.func.gii
Deformed with: 164k_fs_LR232k_fs_LR.R.deform_map

Appended File: /media/2TBB/MyelinMapping_Project/CommonFiles/FS_LR/fsaverage.L+R.MedialWall.164k_fs_LR.metric
Deformed from: fsaverage.L.ProbabilisticArchitectonic.164k_fs_L.metric
Deformed with: fsaverage.L.registered-to-fs_LR.164k_fs_LR.deform_map
Appended File: /Users/vanessen/BRAIN_MAP_DATA/PALS_B12_HUMAN/FREESURFER-to-PALS/FREESURFER_AVG-to-PALS/FS_AVERAGE/FS_LR/fsaverage.R.ProbabilisticArchitectonic.164k_fs_LR.metric
Deformed from: fsaverage.R.ProbabilisticArchitectonic.164k_fs_R.metric
Deformed with: fsaverage.R.registered-to-fs_LR.164k_fs_LR.deform_map]]></Value>
</MD>
<MD>
<Name><![CDATA[encoding]]></Name>
<Value><![CDATA[XML_BASE64_GZIP]]></Value>
</MD>
</MetaData>
<LabelTable>
<Label Key="0" Red="1" Green="1" Blue="1" Alpha="0"><![CDATA[???]]></Label>
</LabelTable>
<DataArray Intent="NIFTI_INTENT_NONE"
DataType="NIFTI_TYPE_FLOAT32"
ArrayIndexingOrder="RowMajorOrder"
Dimensionality="1"
Dim0="32492"
Encoding="GZipBase64Binary"
Endian="LittleEndian"
ExternalFileName=""
ExternalFileOffset="0">
<MetaData>
<MD>
<Name><![CDATA[Description]]></Name>
<Value><![CDATA[Multiplied -1.0 by Atlas_Cortex_ROI
Deformed with: 164k_fs_LR232k_fs_LR.R.deform_map]]></Value>
</MD>
<MD>
<Name><![CDATA[Name]]></Name>
<Value><![CDATA[deformed_Atlas_Cortex_ROI]]></Value>
</MD>
<MD>
<Name><![CDATA[UniqueID]]></Name>
<Value><![CDATA[{ee75ce91-2bc7-4415-8c13-69d60a3f4da4}]]></Value>
</MD>
<MD>
<Name><![CDATA[column-color-mapping]]></Name>
<Value><![CDATA[-1.0 1.0]]></Value>
</MD>
<MD>
<Name><![CDATA[column-threshold]]></Name>
<Value><![CDATA[0.0 0.0]]></Value>
</MD>
</MetaData>
<Data>eJzt3Utu4zAQRVHtLFvz0nsaBHZbH1L1ijqDMwgCsy6VwKIQIN6218/20fb6/L1vr+vqzH47qb6+Cde8er+zrlN1n33t21N128j9VHc9eS/2UK9zv27Ne3uTm7t2JramNyb3pZ4rEs+iaWf+pJ6Ulm8dd/RUN1TO3zt79PyKuUdmjph7dN6VmWdmnZl3ds6RWbNnzFx/1tpX1v209tU1/649cr1RawFrq7hPA8CTdL1f/r7Xd9lDt3PK/85Waf1dzoQdzrHpjcnPBKltic9Sac94ST0pLVc6RrVUN1ydf6WhanbF3BEzj8ztNmvPvDvmzJ4xc/1Za3dYc+R6KevAN1fv/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPBE2+uYytmVrQBddH//6/we3vke1LW9e3d1x2rXuGNrdUfnxuS+1LbkruqG1J6UloSOhIancc0BuNO7+86786u/EQAAAAAAAAAAAAAAAAAAAAAAAAA8T9f/L9f9/+at8llBK3z2UffPcOrc37Vdc3bv3c1XW+9qHtU5s3Vk49/ed1+n9O1pT2zb83tR3QRAf7PvJ3eeQZLXnXFeTFtr1HNG1evPvvbM65zjzrnzOZRrVv3Zrbiv1fa0yn5Weg9cYR/d99C5f5X26pYnNFd3rNha3bBCIwAAAAAAAAAAAAAAAAAAsKp/+88MUQ==</Data>
</DataArray>
</GIFTI>

Large diffs are not rendered by default.

121 changes: 121 additions & 0 deletions smriprep/data/atlases/fs_L/fsaverage.L.sphere.164k_fs_L.surf.gii

Large diffs are not rendered by default.

Large diffs are not rendered by default.

121 changes: 121 additions & 0 deletions smriprep/data/atlases/fs_R/fsaverage.R.sphere.164k_fs_R.surf.gii

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions smriprep/data/io_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"datatype": "anat",
"hemi": ["L", "R"],
"extension": "surf.gii",
"suffix": [ "inflated", "midthickness", "pial", "smoothwm"]
"suffix": [ "inflated", "midthickness", "pial", "white"]
},
"morphometrics": {
"datatype": "anat",
Expand All @@ -89,7 +89,7 @@
"patterns": [
"sub-{subject}[/ses-{session}]/{datatype<anat>|anat}/sub-{subject}[_ses-{session}][_acq-{acquisition}][_ce-{ceagent}][_rec-{reconstruction}][_space-{space}][_desc-{desc}]_{suffix<T1w|T2w|T1rho|T1map|T2map|T2star|FLAIR|FLASH|PDmap|PD|PDT2|dseg|inplaneT[12]|angio>}.{extension<nii|nii.gz|json>|nii.gz}",
"sub-{subject}[/ses-{session}]/{datatype<anat>|anat}/sub-{subject}[_ses-{session}][_acq-{acquisition}][_ce-{ceagent}][_rec-{reconstruction}]_from-{from}_to-{to}_mode-{mode<image|points>|image}_{suffix<xfm>|xfm}.{extension<txt|h5>}",
"sub-{subject}[/ses-{session}]/{datatype<anat>|anat}/sub-{subject}[_ses-{session}][_acq-{acquisition}][_ce-{ceagent}][_rec-{reconstruction}]_hemi-{hemi<L|R>}_{suffix<wm|smoothwm|pial|midthickness|inflated|vinflated|sphere|flat|thickness|sulc|curv>}.{extension<surf.gii|shape.gii>}",
"sub-{subject}[/ses-{session}]/{datatype<anat>|anat}/sub-{subject}[_ses-{session}][_acq-{acquisition}][_ce-{ceagent}][_rec-{reconstruction}]_hemi-{hemi<L|R>}_{suffix<white|smoothwm|pial|midthickness|inflated|vinflated|sphere|flat|thickness|sulc|curv>}.{extension<surf.gii|shape.gii>}",
"sub-{subject}[/ses-{session}]/{datatype<anat>|anat}/sub-{subject}[_ses-{session}][_acq-{acquisition}][_ce-{ceagent}][_rec-{reconstruction}][_space-{space}]_desc-{desc}_{suffix<mask>|mask}.{extension<nii|nii.gz|json>|nii.gz}",
"sub-{subject}[/ses-{session}]/{datatype<anat>|anat}/sub-{subject}[_ses-{session}][_acq-{acquisition}][_ce-{ceagent}][_rec-{reconstruction}][_space-{space}]_label-{label}[_desc-{desc}]_{suffix<probseg>|probseg}.{extension<nii|nii.gz|json>|nii.gz}"
]
Expand Down
4 changes: 2 additions & 2 deletions smriprep/interfaces/cifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def _prepare_cifti(grayordinates: str) -> ty.Tuple[list, dict]:
Examples
--------
>>> surface_labels, metadata = _prepare_cifti('91k')
>>> surface_labels # doctest: +ELLIPSIS
['.../tpl-fsLR_hemi-L_den-32k_desc-nomedialwall_dparc.label.gii', \
>>> surface_labels # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
['.../tpl-fsLR_hemi-L_den-32k_desc-nomedialwall_dparc.label.gii',
'.../tpl-fsLR_hemi-R_den-32k_desc-nomedialwall_dparc.label.gii']
>>> metadata # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
{'Density': '91,282 grayordinates corresponding to all of the grey matter sampled at a \
Expand Down
35 changes: 35 additions & 0 deletions smriprep/interfaces/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pathlib import Path
from shutil import copytree

import pytest

try:
from contextlib import chdir as _chdir
except ImportError: # PY310
import os
from contextlib import contextmanager

@contextmanager # type: ignore
def _chdir(path):
cwd = os.getcwd()
os.chdir(path)
try:
yield
finally:
os.chdir(cwd)


@pytest.fixture(autouse=True)
def _docdir(request, tmp_path):
# Trigger ONLY for the doctests.
doctest_plugin = request.config.pluginmanager.getplugin("doctest")
if isinstance(request.node, doctest_plugin.DoctestItem):
copytree(Path(__file__).parent / "tests" / "data", tmp_path, dirs_exist_ok=True)

# Chdir only for the duration of the test.
with _chdir(tmp_path):
yield

else:
# For normal tests, we have to yield, since this is a yield-fixture.
yield
Loading