Skip to content

Commit 79e840d

Browse files
committed
integrate @effigies review comments
1 parent 82a25c2 commit 79e840d

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

nipype/algorithms/confounds.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212
import os.path as op
1313
from collections import OrderedDict
14+
from itertools import chain
1415

1516
import nibabel as nb
1617
import numpy as np
@@ -1262,11 +1263,18 @@ def compute_noise_components(imgseries, mask_images, components_criterion=0.5,
12621263
Dictionary of eigenvalues, fractional explained variances, and
12631264
cumulative explained variances.
12641265
"""
1265-
components = None
12661266
basis = np.array([])
12671267
if components_criterion == 'all':
12681268
components_criterion = -1
12691269
mask_names = mask_names or range(len(mask_images))
1270+
1271+
comp_list = []
1272+
md_mask = []
1273+
md_sv = []
1274+
md_var = []
1275+
md_cumvar = []
1276+
md_retained = []
1277+
12701278
for name, img in zip(mask_names, mask_images):
12711279
mask = nb.squeeze_image(img).get_data().astype(np.bool)
12721280
if imgseries.shape[:3] != mask.shape:
@@ -1331,32 +1339,30 @@ def compute_noise_components(imgseries, mask_images, components_criterion=0.5,
13311339
num_components = int(num_components)
13321340
if num_components == 0:
13331341
break
1334-
if components is None:
1335-
components = u[:, :num_components]
1336-
metadata = OrderedDict()
1337-
metadata['mask'] = [name] * len(s)
1338-
metadata['singular_value'] = s
1339-
metadata['variance_explained'] = variance_explained
1340-
metadata['cumulative_variance_explained'] = (
1341-
cumulative_variance_explained)
1342-
metadata['retained'] = [i < num_components for i in range(len(s))]
1343-
else:
1344-
components = np.hstack((components, u[:, :num_components]))
1345-
metadata['mask'] = metadata['mask'] + [name] * len(s)
1346-
metadata['singular_value'] = (
1347-
np.hstack((metadata['singular_value'], s)))
1348-
metadata['variance_explained'] = (
1349-
np.hstack((metadata['variance_explained'],
1350-
variance_explained)))
1351-
metadata['cumulative_variance_explained'] = (
1352-
np.hstack((metadata['cumulative_variance_explained'],
1353-
cumulative_variance_explained)))
1354-
metadata['retained'] = (
1355-
metadata['retained'] + [i < num_components for i in range(len(s))])
1356-
if components is None:
1342+
1343+
components.append(u[:, :num_components])
1344+
md_mask.append([name] * len(s))
1345+
md_sv.append(s)
1346+
md_var.append(variance_explained)
1347+
md_cumvar.append(cumulative_variance_explained)
1348+
md_retained.append(i < num_components for i in range(len(s)))
1349+
1350+
if len(components) > 0:
1351+
components = np.hstack(components)
1352+
else:
13571353
if failure_mode == 'error':
13581354
raise ValueError('No components found')
1359-
components = np.full((M.shape[0], num_components), np.nan)
1355+
components = np.full((M.shape[0], num_components),
1356+
np.nan, dtype=np.float32)
1357+
1358+
metadata = OrderedDict(
1359+
('mask', list(chain(*md_mask))),
1360+
('singular_value', np.hstack(md_sv)),
1361+
('variance_explained', np.hstack(md_var)),
1362+
('cumulative_variance_explained', np.hstack(md_cumvar)),
1363+
('retained', list(chain(*md_retained)))
1364+
)
1365+
13601366
return components, basis, metadata
13611367

13621368

nipype/algorithms/tests/test_CompCor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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 os
4-
import re
54

65
import nibabel as nb
76
import numpy as np
@@ -198,7 +197,7 @@ def run_cc(self,
198197
expected_n_components = min(ccinterface.inputs.num_components,
199198
self.fake_data.shape[3])
200199

201-
components_data = [re.sub('\n', '', line).split('\t')
200+
components_data = [line.rstrip().split('\t')
202201
for line in components_file]
203202

204203
# the first item will be '#', we can throw it out
@@ -224,7 +223,7 @@ def run_cc(self,
224223
assert os.path.getsize(expected_metadata_file) > 0
225224

226225
with open(ccresult.outputs.metadata_file, 'r') as metadata_file:
227-
components_metadata = [re.sub('\n', '', line).split('\t')
226+
components_metadata = [line.rstrip().split('\t')
228227
for line in metadata_file]
229228
components_metadata = {i: j for i, j in
230229
zip(components_metadata[0],

nipype/info.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ def get_nipype_gitversion():
141141
'numpy>=%s ; python_version >= "3.7"' % NUMPY_MIN_VERSION_37,
142142
'python-dateutil>=%s' % DATEUTIL_MIN_VERSION,
143143
'scipy>=%s' % SCIPY_MIN_VERSION,
144-
'traits>=%s,<%s ; python_version == "2.7"' % (TRAITS_MIN_VERSION, '5.0.0'),
145-
'traits>=%s ; python_version >= "3.0"' % TRAITS_MIN_VERSION,
144+
'traits>=%s,!=5.0' % TRAITS_MIN_VERSION,
146145
'future>=%s' % FUTURE_MIN_VERSION,
147146
'simplejson>=%s' % SIMPLEJSON_MIN_VERSION,
148147
'prov>=%s' % PROV_VERSION,

0 commit comments

Comments
 (0)