[ENH]: Optimize HCP datagrabbers tests to improve CI running time. #155
3 changed files with 136 additions and 67 deletions
|
|
@ -35,6 +35,8 @@ Enhancements
|
||||||
- Add :class:`junifer.markers.EdgeCentricFCParcels` and :class:`junifer.markers.EdgeCentricFCSpheres`
|
- Add :class:`junifer.markers.EdgeCentricFCParcels` and :class:`junifer.markers.EdgeCentricFCSpheres`
|
||||||
(:gh:`64` by `Leonard Sasse`_).
|
(:gh:`64` by `Leonard Sasse`_).
|
||||||
|
|
||||||
|
- Change HCP datagrabber tests to decrease CI running time (:gh:`155` by `Fede Raimondo`_).
|
||||||
|
|
||||||
Bugs
|
Bugs
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,11 @@ class HCP1200(PatternDataGrabber):
|
||||||
The list of elements in the dataset.
|
The list of elements in the dataset.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
subjects = [x.name for x in self.datadir.iterdir() if x.is_dir()]
|
subjects = [
|
||||||
|
x.name
|
||||||
|
for x in self.datadir.iterdir()
|
||||||
|
if x.is_dir() and not x.name.startswith(".")
|
||||||
|
]
|
||||||
elems = []
|
elems = []
|
||||||
for subject, task, phase_encoding in product(
|
for subject, task, phase_encoding in product(
|
||||||
subjects, self.tasks, self.phase_encodings
|
subjects, self.tasks, self.phase_encodings
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,31 @@
|
||||||
# Authors: Synchon Mandal <s.mandal@fz-juelich.de>
|
# Authors: Synchon Mandal <s.mandal@fz-juelich.de>
|
||||||
# License: AGPL
|
# License: AGPL
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional, Iterable
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from junifer.datagrabber.hcp import DataladHCP1200
|
from junifer.datagrabber.hcp import DataladHCP1200, HCP1200
|
||||||
from junifer.utils import configure_logging
|
from junifer.utils import configure_logging
|
||||||
|
|
||||||
|
|
||||||
URI = "https://gin.g-node.org/juaml/datalad-example-hcp1200"
|
URI = "https://gin.g-node.org/juaml/datalad-example-hcp1200"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def hcpdg() -> Iterable[DataladHCP1200]:
|
||||||
|
"""Return a HCP1200 datagrabber."""
|
||||||
|
dg = DataladHCP1200()
|
||||||
|
# Set URI to Gin
|
||||||
|
dg.uri = URI
|
||||||
|
# Set correct root directory
|
||||||
|
dg._rootdir = "."
|
||||||
|
with dg:
|
||||||
|
for t_elem in dg.get_elements():
|
||||||
|
dg[t_elem]
|
||||||
|
yield dg
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"tasks, phase_encodings, expected_path_name",
|
"tasks, phase_encodings, expected_path_name",
|
||||||
[
|
[
|
||||||
|
|
@ -38,15 +52,19 @@ URI = "https://gin.g-node.org/juaml/datalad-example-hcp1200"
|
||||||
("MOTOR", "RL", "tfMRI_MOTOR_RL_hp2000_clean.nii.gz"),
|
("MOTOR", "RL", "tfMRI_MOTOR_RL_hp2000_clean.nii.gz"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_dataladhcp1200_datagrabber(
|
def test_hcp1200_datagrabber(
|
||||||
|
hcpdg: DataladHCP1200,
|
||||||
tasks: Optional[str],
|
tasks: Optional[str],
|
||||||
phase_encodings: Optional[str],
|
phase_encodings: Optional[str],
|
||||||
expected_path_name: str,
|
expected_path_name: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test datalad HCP1200 datagrabber.
|
"""Test HCP1200 datagrabber.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
hcpdg : DataladHCP1200
|
||||||
|
The Datalad version of the datagrabber with the first subject
|
||||||
|
already cloned.
|
||||||
tasks : str
|
tasks : str
|
||||||
The parametrized tasks.
|
The parametrized tasks.
|
||||||
phase_encodings : str
|
phase_encodings : str
|
||||||
|
|
@ -56,35 +74,31 @@ def test_dataladhcp1200_datagrabber(
|
||||||
|
|
||||||
"""
|
"""
|
||||||
configure_logging(level="DEBUG")
|
configure_logging(level="DEBUG")
|
||||||
dg = DataladHCP1200(
|
dg = HCP1200(
|
||||||
|
datadir=hcpdg.datadir,
|
||||||
tasks=tasks,
|
tasks=tasks,
|
||||||
phase_encodings=phase_encodings,
|
phase_encodings=phase_encodings,
|
||||||
)
|
)
|
||||||
# Set URI to Gin
|
# Get all elements
|
||||||
dg.uri = URI
|
all_elements = dg.get_elements()
|
||||||
# Set correct root directory
|
# Get test element
|
||||||
dg._rootdir = "."
|
test_element = all_elements[0]
|
||||||
with dg:
|
# Get test element data
|
||||||
# Get all elements
|
out = dg[test_element]
|
||||||
all_elements = dg.get_elements()
|
# Asserts data type
|
||||||
# Get test element
|
assert "BOLD" in out
|
||||||
test_element = all_elements[0]
|
# Assert data file name
|
||||||
# Get test element data
|
assert out["BOLD"]["path"].name == expected_path_name
|
||||||
out = dg[test_element]
|
# Assert data file path exists
|
||||||
# Asserts data type
|
assert out["BOLD"]["path"].exists()
|
||||||
assert "BOLD" in out
|
# Assert data file path is a file
|
||||||
# Assert data file name
|
assert out["BOLD"]["path"].is_file()
|
||||||
assert out["BOLD"]["path"].name == expected_path_name
|
# Assert metadata
|
||||||
# Assert data file path exists
|
assert "meta" in out["BOLD"]
|
||||||
assert out["BOLD"]["path"].exists()
|
meta = out["BOLD"]["meta"]
|
||||||
# Assert data file path is a file
|
assert "element" in meta
|
||||||
assert out["BOLD"]["path"].is_file()
|
assert "subject" in meta["element"]
|
||||||
# Assert metadata
|
assert test_element[0] == meta["element"]["subject"]
|
||||||
assert "meta" in out["BOLD"]
|
|
||||||
meta = out["BOLD"]["meta"]
|
|
||||||
assert "element" in meta
|
|
||||||
assert "subject" in meta["element"]
|
|
||||||
assert test_element[0] == meta["element"]["subject"]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
@ -110,14 +124,18 @@ def test_dataladhcp1200_datagrabber(
|
||||||
("MOTOR", "RL"),
|
("MOTOR", "RL"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_dataladhcp1200_datagrabber_single_access(
|
def test_hcp1200_datagrabber_single_access(
|
||||||
|
hcpdg: DataladHCP1200,
|
||||||
tasks: Optional[str],
|
tasks: Optional[str],
|
||||||
phase_encodings: Optional[str],
|
phase_encodings: Optional[str],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test datalad HCP1200 datagrabber single access.
|
"""Test HCP1200 datagrabber single access.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
hcpdg : DataladHCP1200
|
||||||
|
The Datalad version of the datagrabber with the first subject
|
||||||
|
already cloned.
|
||||||
tasks : str
|
tasks : str
|
||||||
The parametrized tasks.
|
The parametrized tasks.
|
||||||
phase_encodings : str
|
phase_encodings : str
|
||||||
|
|
@ -125,14 +143,11 @@ def test_dataladhcp1200_datagrabber_single_access(
|
||||||
|
|
||||||
"""
|
"""
|
||||||
configure_logging(level="DEBUG")
|
configure_logging(level="DEBUG")
|
||||||
dg = DataladHCP1200(
|
dg = HCP1200(
|
||||||
|
datadir=hcpdg.datadir,
|
||||||
tasks=tasks,
|
tasks=tasks,
|
||||||
phase_encodings=phase_encodings,
|
phase_encodings=phase_encodings,
|
||||||
)
|
)
|
||||||
# Set URI to Gin
|
|
||||||
dg.uri = URI
|
|
||||||
# Set correct root directory
|
|
||||||
dg._rootdir = "."
|
|
||||||
with dg:
|
with dg:
|
||||||
# Get all elements
|
# Get all elements
|
||||||
all_elements = dg.get_elements()
|
all_elements = dg.get_elements()
|
||||||
|
|
@ -149,14 +164,18 @@ def test_dataladhcp1200_datagrabber_single_access(
|
||||||
(["REST1", "REST2"], None),
|
(["REST1", "REST2"], None),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_dataladhcp1200_datagrabber_multi_access(
|
def test_hcp1200_datagrabber_multi_access(
|
||||||
|
hcpdg: DataladHCP1200,
|
||||||
tasks: Optional[str],
|
tasks: Optional[str],
|
||||||
phase_encodings: Optional[str],
|
phase_encodings: Optional[str],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test datalad HCP1200 datagrabber multiple access.
|
"""Test HCP1200 datagrabber multiple access.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
hcpdg : DataladHCP1200
|
||||||
|
The Datalad version of the datagrabber with the first subject
|
||||||
|
already cloned.
|
||||||
tasks : str
|
tasks : str
|
||||||
The parametrized tasks.
|
The parametrized tasks.
|
||||||
phase_encodings : str
|
phase_encodings : str
|
||||||
|
|
@ -164,14 +183,11 @@ def test_dataladhcp1200_datagrabber_multi_access(
|
||||||
|
|
||||||
"""
|
"""
|
||||||
configure_logging(level="DEBUG")
|
configure_logging(level="DEBUG")
|
||||||
dg = DataladHCP1200(
|
dg = HCP1200(
|
||||||
tasks=["REST1", "REST2"],
|
datadir=hcpdg.datadir,
|
||||||
phase_encodings=["LR", "RL"],
|
tasks=tasks,
|
||||||
|
phase_encodings=phase_encodings,
|
||||||
)
|
)
|
||||||
# Set URI to Gin
|
|
||||||
dg.uri = URI
|
|
||||||
# Set correct root directory
|
|
||||||
dg._rootdir = "."
|
|
||||||
with dg:
|
with dg:
|
||||||
# Get all elements
|
# Get all elements
|
||||||
all_elements = dg.get_elements()
|
all_elements = dg.get_elements()
|
||||||
|
|
@ -181,17 +197,23 @@ def test_dataladhcp1200_datagrabber_multi_access(
|
||||||
assert element[2] in ["LR", "RL"]
|
assert element[2] in ["LR", "RL"]
|
||||||
|
|
||||||
|
|
||||||
def test_dataladhcp1200_datagrabber_multi_access_task_simple() -> None:
|
def test_hcp1200_datagrabber_multi_access_task_simple(
|
||||||
"""Test datalad HCP1200 datagrabber simple multiple access for task."""
|
hcpdg: DataladHCP1200,
|
||||||
|
) -> None:
|
||||||
|
"""Test HCP1200 datagrabber simple multiple access for task.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
hcpdg : DataladHCP1200
|
||||||
|
The Datalad version of the datagrabber with the first subject
|
||||||
|
already cloned.
|
||||||
|
"""
|
||||||
configure_logging(level="DEBUG")
|
configure_logging(level="DEBUG")
|
||||||
dg = DataladHCP1200(
|
dg = HCP1200(
|
||||||
|
datadir=hcpdg.datadir,
|
||||||
tasks="REST1",
|
tasks="REST1",
|
||||||
phase_encodings=["LR", "RL"],
|
phase_encodings=["LR", "RL"],
|
||||||
)
|
)
|
||||||
# Set URI to Gin
|
|
||||||
dg.uri = URI
|
|
||||||
# Set correct root directory
|
|
||||||
dg._rootdir = "."
|
|
||||||
with dg:
|
with dg:
|
||||||
# Get all elements
|
# Get all elements
|
||||||
all_elements = dg.get_elements()
|
all_elements = dg.get_elements()
|
||||||
|
|
@ -201,17 +223,23 @@ def test_dataladhcp1200_datagrabber_multi_access_task_simple() -> None:
|
||||||
assert element[2] in ["LR", "RL"]
|
assert element[2] in ["LR", "RL"]
|
||||||
|
|
||||||
|
|
||||||
def test_dataladhcp1200_datagrabber_multi_access_phase_simple() -> None:
|
def test_hcp1200_datagrabber_multi_access_phase_simple(
|
||||||
"""Test datalad HCP1200 datagrabber simple multiple access for phase."""
|
hcpdg: DataladHCP1200,
|
||||||
|
) -> None:
|
||||||
|
"""Test HCP1200 datagrabber simple multiple access for phase.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
hcpdg : DataladHCP1200
|
||||||
|
The Datalad version of the datagrabber with the first subject
|
||||||
|
already cloned.
|
||||||
|
"""
|
||||||
configure_logging(level="DEBUG")
|
configure_logging(level="DEBUG")
|
||||||
dg = DataladHCP1200(
|
dg = HCP1200(
|
||||||
|
datadir=hcpdg.datadir,
|
||||||
tasks=["REST1", "REST2"],
|
tasks=["REST1", "REST2"],
|
||||||
phase_encodings="LR",
|
phase_encodings="LR",
|
||||||
)
|
)
|
||||||
# Set URI to Gin
|
|
||||||
dg.uri = URI
|
|
||||||
# Set correct root directory
|
|
||||||
dg._rootdir = "."
|
|
||||||
with dg:
|
with dg:
|
||||||
# Get all elements
|
# Get all elements
|
||||||
all_elements = dg.get_elements()
|
all_elements = dg.get_elements()
|
||||||
|
|
@ -230,11 +258,11 @@ def test_dataladhcp1200_datagrabber_multi_access_phase_simple() -> None:
|
||||||
(["FOO", "BAR"], "LR"),
|
(["FOO", "BAR"], "LR"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_dataladhcp1200_datagrabber_incorrect_access_task(
|
def test_hcp1200_datagrabber_incorrect_access_task(
|
||||||
tasks: Optional[str],
|
tasks: Optional[str],
|
||||||
phase_encodings: Optional[str],
|
phase_encodings: Optional[str],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test datalad HCP1200 datagrabber incorrect access for task.
|
"""Test HCP1200 datagrabber incorrect access for task.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
|
@ -246,7 +274,8 @@ def test_dataladhcp1200_datagrabber_incorrect_access_task(
|
||||||
"""
|
"""
|
||||||
configure_logging(level="DEBUG")
|
configure_logging(level="DEBUG")
|
||||||
with pytest.raises(ValueError, match="not a valid HCP-YA fMRI task input"):
|
with pytest.raises(ValueError, match="not a valid HCP-YA fMRI task input"):
|
||||||
_ = DataladHCP1200(
|
_ = HCP1200(
|
||||||
|
datadir=".",
|
||||||
tasks=tasks,
|
tasks=tasks,
|
||||||
phase_encodings=phase_encodings,
|
phase_encodings=phase_encodings,
|
||||||
)
|
)
|
||||||
|
|
@ -261,11 +290,11 @@ def test_dataladhcp1200_datagrabber_incorrect_access_task(
|
||||||
(["REST1", "REST2"], "BAR"),
|
(["REST1", "REST2"], "BAR"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_dataladhcp1200_datagrabber_incorrect_access_phase(
|
def test_hcp1200_datagrabber_incorrect_access_phase(
|
||||||
tasks: Optional[str],
|
tasks: Optional[str],
|
||||||
phase_encodings: Optional[str],
|
phase_encodings: Optional[str],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test datalad HCP1200 datagrabber incorrect access for phase.
|
"""Test HCP1200 datagrabber incorrect access for phase.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
|
@ -277,7 +306,41 @@ def test_dataladhcp1200_datagrabber_incorrect_access_phase(
|
||||||
"""
|
"""
|
||||||
configure_logging(level="DEBUG")
|
configure_logging(level="DEBUG")
|
||||||
with pytest.raises(ValueError, match="not a valid HCP-YA phase encoding"):
|
with pytest.raises(ValueError, match="not a valid HCP-YA phase encoding"):
|
||||||
_ = DataladHCP1200(
|
_ = HCP1200(
|
||||||
|
datadir=".",
|
||||||
tasks=tasks,
|
tasks=tasks,
|
||||||
phase_encodings=phase_encodings,
|
phase_encodings=phase_encodings,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_hcp1200_datagrabber_elements(
|
||||||
|
hcpdg: DataladHCP1200,
|
||||||
|
) -> None:
|
||||||
|
"""Test HCP1200 datagrabber elements.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
hcpdg : DataladHCP1200
|
||||||
|
The Datalad version of the datagrabber with the first subject
|
||||||
|
already cloned.
|
||||||
|
"""
|
||||||
|
configure_logging(level="DEBUG")
|
||||||
|
dg = HCP1200(
|
||||||
|
datadir=hcpdg.datadir,
|
||||||
|
tasks="REST1",
|
||||||
|
phase_encodings="LR",
|
||||||
|
)
|
||||||
|
with dg:
|
||||||
|
# Get all elements
|
||||||
|
expected_subjects = [
|
||||||
|
f"sub-{x:02d}" for x in range(1, 10)
|
||||||
|
]
|
||||||
|
found_subjects = []
|
||||||
|
all_elements = dg.get_elements()
|
||||||
|
# Check only specified task and phase encoding are found
|
||||||
|
for element in all_elements:
|
||||||
|
found_subjects.append(element[0])
|
||||||
|
assert element[1] == "REST1"
|
||||||
|
assert element[2] in ["LR", "RL"]
|
||||||
|
|
||||||
|
assert set(found_subjects) == set(expected_subjects)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue