-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,429 additions
and
3 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,106 @@ | ||
#!/usr/bin/python | ||
# coding: utf-8 | ||
|
||
""" Tests of the 'narps_open.pipelines.team_4SZ2' module. | ||
Launch this test with PyTest | ||
Usage: | ||
====== | ||
pytest -q test_team_4SZ2.py | ||
pytest -q test_team_4SZ2.py -k <selected_test> | ||
""" | ||
from os.path import join, exists, abspath | ||
from filecmp import cmp | ||
|
||
from pytest import helpers, mark | ||
from nipype import Workflow, Node, Function | ||
from nipype.interfaces.base import Bunch | ||
|
||
from narps_open.utils.configuration import Configuration | ||
from narps_open.pipelines.team_4SZ2 import PipelineTeam4SZ2 | ||
|
||
class TestPipelinesTeam4SZ2: | ||
""" A class that contains all the unit tests for the PipelineTeam4SZ2 class.""" | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_create(): | ||
""" Test the creation of a PipelineTeam4SZ2 object """ | ||
|
||
pipeline = PipelineTeam4SZ2() | ||
|
||
# 1 - check the parameters | ||
assert pipeline.fwhm == 5.0 | ||
assert pipeline.team_id == '4SZ2' | ||
|
||
# 2 - check workflows | ||
assert pipeline.get_preprocessing() is None | ||
assert isinstance(pipeline.get_run_level_analysis(), Workflow) | ||
assert pipeline.get_subject_level_analysis() is None | ||
assert isinstance(pipeline.get_group_level_analysis(), Workflow) | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_outputs(): | ||
""" Test the expected outputs of a PipelineTeam4SZ2 object """ | ||
|
||
pipeline = PipelineTeam4SZ2() | ||
|
||
# 1 - 1 subject outputs | ||
pipeline.subject_list = ['001'] | ||
helpers.test_pipeline_outputs(pipeline, [0, 2*4*1*4, 0, 2*9, 18]) | ||
|
||
# 2 - 4 subjects outputs | ||
pipeline.subject_list = ['001', '002', '003', '004'] | ||
helpers.test_pipeline_outputs(pipeline, [0, 2*4*4*4, 0, 2*9, 18]) | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_subject_information(): | ||
""" Test the get_subject_information method """ | ||
|
||
# Get test files | ||
test_file = join(Configuration()['directories']['test_data'], 'pipelines', 'events.tsv') | ||
|
||
# Prepare several scenarii | ||
info_missed = PipelineTeam4SZ2.get_subject_information(test_file) | ||
|
||
# Compare bunches to expected | ||
bunch = info_missed[0] | ||
assert isinstance(bunch, Bunch) | ||
assert bunch.conditions == ['gain', 'loss'] | ||
helpers.compare_float_2d_arrays(bunch.onsets, [ | ||
[4.071, 11.834, 19.535, 27.535, 36.435], | ||
[4.071, 11.834, 19.535, 27.535, 36.435] | ||
]) | ||
helpers.compare_float_2d_arrays(bunch.durations, [ | ||
[4.0, 4.0, 4.0, 4.0, 4.0], | ||
[4.0, 4.0, 4.0, 4.0, 4.0] | ||
]) | ||
helpers.compare_float_2d_arrays(bunch.amplitudes, [ | ||
[14.0, 34.0, 38.0, 10.0, 16.0], | ||
[6.0, 14.0, 19.0, 15.0, 17.0] | ||
]) | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_get_group_level_regressors(): | ||
""" Test the get_group_level_regressors method """ | ||
|
||
regressors = PipelineTeam4SZ2.get_group_level_regressors( | ||
['001', '002', '003', '004'], | ||
['01', '02']) | ||
|
||
for k1, k2 in zip(regressors.keys(), ['equalIndifference', 'equalRange', 'age', 'gender']): | ||
assert k1 == k2 | ||
assert regressors['equalIndifference'] == [1, 1, 0, 0, 1, 1, 0, 0] | ||
assert regressors['equalRange'] == [0, 0, 1, 1, 0, 0, 1, 1] | ||
assert regressors['age'] == [24, 24, 25, 25, 27, 27, 25, 25] | ||
assert regressors['gender'] == [0, 0, 0, 0, 1, 1, 0, 0] | ||
|
||
@staticmethod | ||
@mark.pipeline_test | ||
def test_execution(): | ||
""" Test the execution of a PipelineTeam4SZ2 and compare results """ | ||
helpers.test_pipeline_evaluation('4SZ2') |
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,127 @@ | ||
#!/usr/bin/python | ||
# coding: utf-8 | ||
|
||
""" Tests of the 'narps_open.pipelines.team_B23O' module. | ||
Launch this test with PyTest | ||
Usage: | ||
====== | ||
pytest -q test_team_B23O.py | ||
pytest -q test_team_B23O.py -k <selected_test> | ||
""" | ||
from os.path import join, exists, abspath | ||
from filecmp import cmp | ||
|
||
from pytest import helpers, mark | ||
from nipype import Workflow, Node, Function | ||
from nipype.interfaces.base import Bunch | ||
|
||
from narps_open.utils.configuration import Configuration | ||
from narps_open.pipelines.team_B23O import PipelineTeamB23O | ||
|
||
class TestPipelinesTeamB23O: | ||
""" A class that contains all the unit tests for the PipelineTeamB23O class.""" | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_create(): | ||
""" Test the creation of a PipelineTeamB23O object """ | ||
|
||
pipeline = PipelineTeamB23O() | ||
|
||
# 1 - check the parameters | ||
assert pipeline.team_id == 'B23O' | ||
|
||
# 2 - check workflows | ||
assert pipeline.get_preprocessing() is None | ||
assert isinstance(pipeline.get_run_level_analysis(), Workflow) | ||
assert isinstance(pipeline.get_subject_level_analysis(), Workflow) | ||
group_level = pipeline.get_group_level_analysis() | ||
assert len(group_level) == 3 | ||
for sub_workflow in group_level: | ||
assert isinstance(sub_workflow, Workflow) | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_outputs(): | ||
""" Test the expected outputs of a PipelineTeamB23O object """ | ||
|
||
pipeline = PipelineTeamB23O() | ||
|
||
# 1 - 1 subject outputs | ||
pipeline.subject_list = ['001'] | ||
helpers.test_pipeline_outputs(pipeline, [0, 4*2*4*1, 4*2*1, 6*2*2 + 3*2, 18]) | ||
|
||
# 2 - 4 subjects outputs | ||
pipeline.subject_list = ['001', '002', '003', '004'] | ||
helpers.test_pipeline_outputs(pipeline, [0, 4*2*4*4, 4*2*4, 6*2*2 + 3*2, 18]) | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_subject_information(): | ||
""" Test the get_subject_information method """ | ||
|
||
# Get test files | ||
test_file = join(Configuration()['directories']['test_data'], 'pipelines', 'events.tsv') | ||
|
||
# Prepare several scenarii | ||
info = PipelineTeamB23O.get_subject_information(test_file) | ||
|
||
# Compare bunches to expected | ||
bunch = info[0] | ||
assert isinstance(bunch, Bunch) | ||
assert bunch.conditions == ['trial', 'gain', 'loss'] | ||
helpers.compare_float_2d_arrays(bunch.onsets, [ | ||
[4.071, 11.834, 19.535, 27.535, 36.435], | ||
[4.071, 11.834, 19.535, 27.535, 36.435], | ||
[4.071, 11.834, 19.535, 27.535, 36.435], | ||
]) | ||
helpers.compare_float_2d_arrays(bunch.durations, [ | ||
[4.0, 4.0, 4.0, 4.0, 4.0], | ||
[4.0, 4.0, 4.0, 4.0, 4.0], | ||
[4.0, 4.0, 4.0, 4.0, 4.0], | ||
]) | ||
helpers.compare_float_2d_arrays(bunch.amplitudes, [ | ||
[1.0, 1.0, 1.0, 1.0, 1.0], | ||
[14.0, 34.0, 38.0, 10.0, 16.0], | ||
[6.0, 14.0, 19.0, 15.0, 17.0], | ||
]) | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_confounds_file(temporary_data_dir): | ||
""" Test the get_confounds_file method """ | ||
|
||
# Get input and reference output file | ||
confounds_file = join( | ||
Configuration()['directories']['test_data'], 'pipelines', 'confounds.tsv') | ||
reference_file = join( | ||
Configuration()['directories']['test_data'], | ||
'pipelines', 'team_B23O', 'confounds.tsv') | ||
|
||
# Create new confounds file | ||
confounds_node = Node(Function( | ||
input_names = ['filepath', 'subject_id', 'run_id'], | ||
output_names = ['confounds_file'], | ||
function = PipelineTeamB23O.get_confounds_file), | ||
name = 'confounds_node') | ||
confounds_node.base_dir = temporary_data_dir | ||
confounds_node.inputs.filepath = confounds_file | ||
confounds_node.inputs.subject_id = 'sid' | ||
confounds_node.inputs.run_id = 'rid' | ||
confounds_node.run() | ||
|
||
# Check confounds file was created | ||
created_confounds_file = abspath(join( | ||
temporary_data_dir, confounds_node.name, 'confounds_file_sub-sid_run-rid.tsv')) | ||
assert exists(created_confounds_file) | ||
|
||
# Check contents | ||
assert cmp(reference_file, created_confounds_file) | ||
|
||
@staticmethod | ||
@mark.pipeline_test | ||
def test_execution(): | ||
""" Test the execution of a PipelineTeamB23O and compare results """ | ||
helpers.test_pipeline_evaluation('B23O') |
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,3 @@ | ||
6551.281999999999 6476.4653 9874.576 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 -0.0 0.0 | ||
6484.7285 6473.4890000000005 9830.212 0.0263099209 -0.0673065879 0.0934882554 -0.0079328884 0.0338007737 -0.0114910839999999 -0.0424113470999999 0.0277364229 0.0453303087 -0.0702260949 0.0963618709 -0.0200867957 0.0665186088 0.0665174038 0.0665153954 0.0665125838 0.0665089688 0.0665045505999999 0.0 -0.00996895 -0.0313444 -3.00931e-06 0.00132687 -0.000384193 -0.00016819 | ||
6441.5337 6485.7256 9821.212 -0.0404820317 0.034150583 0.1366118421 0.0745358691 -0.0054829985999999 -0.0217322686 0.0462141151999999 0.005774624 -0.0439093598 -0.075619539 0.1754689153999999 -0.0345256763 0.0665153954 0.0665045505999999 0.0664864771999999 0.0664611772 0.0664286533 0.0663889091 0.0 -2.56954e-05 -0.00923735 0.0549667 0.000997278 -0.00019745 -0.000398988 |