Skip to content

Commit deceb95

Browse files
committed
revise in accordance with @effigies review
1 parent 518a489 commit deceb95

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

nipype/algorithms/confounds.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,12 +1224,26 @@ def compute_noise_components(imgseries, mask_images, components_criterion=0.5,
12241224
'polynomial' - Legendre polynomial basis
12251225
'cosine' - Discrete cosine (DCT) basis
12261226
False - None (mean-removal only)
1227+
failure_mode: str
1228+
Action to be taken in the event that any decomposition fails to
1229+
identify any components. `error` indicates that the routine should
1230+
raise an exception and exit, while any other value indicates that the
1231+
routine should return a matrix of NaN values equal in size to the
1232+
requested decomposition matrix.
1233+
mask_names: list or None
1234+
List of names for each image in `mask_images`. This should be equal in
1235+
length to `mask_images`, with the ith element of `mask_names` naming
1236+
the ith element of `mask_images`.
12271237
12281238
Filter options:
12291239
1230-
degree: order of polynomial used to remove trends from the timeseries
1231-
period_cut: minimum period (in sec) for DCT high-pass filter
1232-
repetition_time: time (in sec) between volume acquisitions
1240+
degree: int
1241+
Order of polynomial used to remove trends from the timeseries
1242+
period_cut: float
1243+
Minimum period (in sec) for DCT high-pass filter
1244+
repetition_time: float
1245+
Time (in sec) between volume acquisitions. This must be defined if
1246+
the `filter_type` is `cosine`.
12331247
12341248
Returns
12351249
-------
@@ -1262,6 +1276,9 @@ def compute_noise_components(imgseries, mask_images, components_criterion=0.5,
12621276
# Currently support Legendre-polynomial or cosine or detrending
12631277
# With no filter, the mean is nonetheless removed (poly w/ degree 0)
12641278
if filter_type == 'cosine':
1279+
if repetition_time is None:
1280+
raise ValueError(
1281+
'Repetition time must be provided for cosine filter')
12651282
voxel_timecourses, basis = cosine_filter(
12661283
voxel_timecourses, repetition_time, period_cut)
12671284
elif filter_type in ('polynomial', False):
@@ -1286,8 +1303,8 @@ def compute_noise_components(imgseries, mask_images, components_criterion=0.5,
12861303
if failure_mode == 'error':
12871304
raise
12881305
if components_criterion >= 1:
1289-
u = np.empty((M.shape[0], components_criterion),
1290-
dtype=np.float32) * np.nan
1306+
u = np.full((M.shape[0], components_criterion),
1307+
np.nan, dtype=np.float32)
12911308
else:
12921309
continue
12931310

@@ -1329,7 +1346,7 @@ def compute_noise_components(imgseries, mask_images, components_criterion=0.5,
13291346
if components is None:
13301347
if failure_mode == 'error':
13311348
raise ValueError('No components found')
1332-
components = np.full((M.shape[0], num_components), np.NaN)
1349+
components = np.full((M.shape[0], num_components), np.nan)
13331350
return components, basis, metadata
13341351

13351352

nipype/workflows/rsfmri/fsl/tests/test_resting.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,14 @@ def test_create_resting_preproc(self, mock_node, mock_realign_wf):
9292
components_data = [line.split()
9393
for line in components_file.read().splitlines()]
9494
num_got_components = len(components_data)
95-
if not (num_got_components == self.num_noise_components or
96-
num_got_components == self.fake_data.shape[3]):
97-
raise AssertionError()
95+
assert (num_got_components == self.num_noise_components or
96+
num_got_components == self.fake_data.shape[3])
9897
first_two = [row[:2] for row in components_data[1:]]
99-
if first_two != [['-0.5172356654', '-0.6973053243'],
100-
['0.2574722644', '0.1645270737'],
101-
['-0.0806469590', '0.5156853779'],
102-
['0.7187176051', '-0.3235820287'],
103-
['-0.3783072450', '0.3406749013']]:
104-
raise AssertionError()
98+
assert first_two == [['-0.5172356654', '-0.6973053243'],
99+
['0.2574722644', '0.1645270737'],
100+
['-0.0806469590', '0.5156853779'],
101+
['0.7187176051', '-0.3235820287'],
102+
['-0.3783072450', '0.3406749013']]
105103

106104
fake_data = np.array([[[[2, 4, 3, 9, 1], [3, 6, 4, 7, 4]],
107105
[[8, 3, 4, 6, 2], [4, 0, 4, 4, 2]]],

0 commit comments

Comments
 (0)