forked from Inria-Empenn/narps_open_pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Inria-Empenn:main' into main
- Loading branch information
Showing
4 changed files
with
132 additions
and
0 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/python | ||
# coding: utf-8 | ||
|
||
""" A mdoule to parse task data from NARPS for the narps_open package """ | ||
|
||
from os.path import join | ||
from json import load | ||
|
||
from narps_open.utils.configuration import Configuration | ||
from narps_open.utils.singleton import SingletonMeta | ||
|
||
class TaskInformation(dict, metaclass=SingletonMeta): | ||
""" This class allows to access information about the task performed in NARPS """ | ||
|
||
task_information_file = join(Configuration()['directories']['dataset'], 'task-MGT_bold.json') | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
# Load information from the task-MGT_bold.json file | ||
with open(self.task_information_file, 'rb') as file: | ||
self.update(load(file)) | ||
|
||
# Compute derived information | ||
self['NumberOfSlices'] = len(self['SliceTiming']) | ||
self['AcquisitionTime'] = self['RepetitionTime'] / self['NumberOfSlices'] | ||
self['TotalReadoutTime'] = self['NumberOfSlices'] * self['EffectiveEchoSpacing'] |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/python | ||
# coding: utf-8 | ||
|
||
""" Tests of the 'narps_open.data.task' module. | ||
Launch this test with PyTest | ||
Usage: | ||
====== | ||
pytest -q test_task.py | ||
pytest -q test_task.py -k <selected_test> | ||
""" | ||
from os.path import join | ||
|
||
from pytest import mark, fixture | ||
|
||
from narps_open.utils.configuration import Configuration | ||
import narps_open.data.task as task | ||
|
||
@fixture(scope='function', autouse=True) | ||
def mock_task_data(mocker): | ||
""" Patch the json.load method to mock task data """ | ||
mocker.patch.object( | ||
task.TaskInformation, 'task_information_file', | ||
join(Configuration()['directories']['test_data'], 'data', 'task', 'task-info.json') | ||
) | ||
|
||
class TestTaskInformation: | ||
""" A class that contains all the unit tests for the TaskInformation class.""" | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_accessing(): | ||
""" Check that task information is reachable """ | ||
|
||
assert task.TaskInformation()['RepetitionTime'] == 1 | ||
assert len(task.TaskInformation()['SliceTiming']) == 6 | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_singleton(): | ||
""" Check that TaskInformation is a singleton. """ | ||
|
||
obj1 = task.TaskInformation() | ||
obj2 = task.TaskInformation() | ||
|
||
assert id(obj1) == id(obj2) | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_derived(): | ||
""" Test the derived values of a TaskInformation object """ | ||
|
||
task_info = task.TaskInformation() | ||
assert task_info['NumberOfSlices'] == 6 | ||
assert task_info['AcquisitionTime'] == 1 / 6 | ||
assert task_info['TotalReadoutTime'] == 12 |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"RepetitionTime": 1, | ||
"EffectiveEchoSpacing": 2, | ||
"SliceTiming": [ | ||
0, | ||
0.4375, | ||
0.875, | ||
0.3125, | ||
0.75, | ||
0.1875 | ||
] | ||
} |