Skip to content

Commit 61da367

Browse files
author
Shoshana Berleant
committed
testing skeleton for tsnr
1 parent 9a88a11 commit 61da367

File tree

1 file changed

+22
-59
lines changed

1 file changed

+22
-59
lines changed

nipype/algorithms/tests/test_tsnr.py

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,49 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
import nipype
4-
from nipype.testing import assert_equal, assert_true, assert_false, skipif
5-
from nipype.algorithms.compcor import CompCor, TCompCor, ACompCor
4+
from nipype.testing import assert_equal, assert_true, skipif, utils
5+
from nipype.algorithms.misc import TSNR
66

77
import unittest
88
import mock
99
import nibabel as nb
1010
import numpy as np
1111
import os
1212

13-
class TestCompCor(unittest.TestCase):
13+
class TestTSNR(unittest.TestCase):
1414
''' Note: Tests currently do a poor job of testing functionality '''
15-
16-
functionalnii = 'compcorfunc.nii'
17-
masknii = 'compcormask.nii'
18-
components_file = None
15+
'''
16+
in_file = InputMultiPath(File(exists=True), mandatory=True,
17+
regress_poly = traits.Range(low=1, desc='Remove polynomials')
18+
'''
19+
in_file_name = 'tsnrinfile.nii'
1920

2021
def setUp(self):
2122
# setup
22-
noise = np.fromfunction(self.fake_noise_fun, self.fake_data.shape)
23-
self.realigned_file = self.make_toy(self.fake_data + noise,
24-
self.functionalnii)
25-
26-
def test_compcor(self):
27-
mask = np.ones(self.fake_data.shape[:3])
28-
mask[0,0,0] = 0
29-
mask[0,0,1] = 0
30-
mask_file = self.make_toy(mask, self.masknii)
31-
32-
ccresult = self.run_cc(CompCor(realigned_file=self.realigned_file,
33-
mask_file=mask_file))
34-
35-
accresult = self.run_cc(ACompCor(realigned_file=self.realigned_file,
36-
mask_file=mask_file,
37-
components_file='acc_components_file'))
38-
39-
assert_equal(os.path.getsize(ccresult.outputs.components_file),
40-
os.path.getsize(accresult.outputs.components_file))
41-
42-
def test_tcompcor(self):
43-
ccinterface = TCompCor(realigned_file=self.realigned_file)
44-
self.run_cc(ccinterface)
23+
utils.save_toy_nii(self.fake_data, self.in_file_name)
4524

46-
def run_cc(self, ccinterface):
25+
def test_tsnr(self):
26+
# setup
4727
# run
48-
ccresult = ccinterface.run()
49-
28+
tsnrresult = TSNR(in_file=self.in_file_name, regress_poly=1)
5029
# assert
51-
expected_file = ccinterface._list_outputs()['components_file']
52-
assert_equal(ccresult.outputs.components_file, expected_file)
53-
assert_true(os.path.exists(expected_file))
54-
assert_true(os.path.getsize(expected_file) > 0)
55-
assert_equal(ccinterface.inputs.num_components, 6)
56-
57-
return ccresult
30+
# cleanup
5831

5932
def tearDown(self):
6033
# remove temporary nifti files
6134
try:
62-
os.remove(self.functionalnii)
63-
os.remove(self.components_file)
64-
os.remove(self.masknii)
35+
os.remove(self.in_file_name)
6536
except (OSError, TypeError) as e:
6637
print(e)
6738

68-
def make_toy(self, ndarray, filename):
69-
toy = nb.Nifti1Image(ndarray, np.eye(4))
70-
nb.nifti1.save(toy, filename)
71-
return filename
72-
73-
def fake_noise_fun(self, i, j, l, m):
74-
return m*i + l - j
75-
76-
fake_data = np.array([[[[8, 5, 3, 8, 0],
77-
[6, 7, 4, 7, 1]],
39+
fake_data = np.array([[[[2, 4, 3, 9, 1],
40+
[3, 6, 4, 7, 4]],
7841

79-
[[7, 9, 1, 6, 5],
80-
[0, 7, 4, 7, 7]]],
42+
[[8, 3, 4, 6, 2],
43+
[4, 0, 4, 4, 2]]],
8144

82-
[[[2, 4, 5, 7, 0],
83-
[1, 7, 0, 5, 4]],
45+
[[[9, 7, 5, 5, 7],
46+
[7, 8, 4, 8, 4]],
8447

85-
[[7, 3, 9, 0, 4],
86-
[9, 4, 1, 5, 0]]]])
48+
[[0, 4, 7, 1, 7],
49+
[6, 8, 8, 8, 7]]]])

0 commit comments

Comments
 (0)