Skip to content

Commit addb0e9

Browse files
committed
return metadata for all components regardless of retention criterion
1 parent 94bea4a commit addb0e9

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

nipype/algorithms/confounds.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -652,11 +652,15 @@ def _run_interface(self, runtime):
652652
metadata_file = os.path.abspath('component_metadata.tsv')
653653
else:
654654
metadata_file = save_metadata
655+
components_names = np.array(dtype='object_',
656+
object=['dropped' for i in range(len(metadata['mask']))])
657+
components_names[np.where(metadata['retained'])] = (
658+
components_header)
655659
self._results['metadata_file'] = metadata_file
656660
with open(metadata_file, 'w') as f:
657661
f.write('{}\t{}\t{}\t{}\t{}\n'.format('component',
658662
*list(metadata.keys())))
659-
for i in zip(components_header, *metadata.values()):
663+
for i in zip(components_names, *metadata.values()):
660664
f.write('{0[0]}\t{0[1]}\t{0[2]:.10f}\t'
661665
'{0[3]:.10f}\t{0[4]:.10f}\n'.format(i))
662666

@@ -1296,23 +1300,30 @@ def compute_noise_components(imgseries, mask_images, components_criterion=0.5,
12961300
if components is None:
12971301
components = u[:, :num_components]
12981302
metadata = OrderedDict()
1299-
metadata['mask'] = np.array([i] * num_components)
1300-
metadata['singular_value'] = s[:num_components]
1301-
metadata['variance_explained'] = variance_explained[:num_components]
1303+
metadata['mask'] = np.array([i] * len(s))
1304+
metadata['singular_value'] = s
1305+
metadata['variance_explained'] = variance_explained
13021306
metadata['cumulative_variance_explained'] = (
1303-
cumulative_variance_explained[:num_components])
1307+
cumulative_variance_explained)
1308+
metadata['retained'] = np.array(
1309+
[True if i < num_components
1310+
else False for i in range(len(s))], dtype='bool')
13041311
else:
13051312
components = np.hstack((components, u[:, :num_components]))
13061313
metadata['mask'] = np.hstack((metadata['mask'],
1307-
[i] * num_components))
1314+
[i] * len(s)))
13081315
metadata['singular_value'] = (
1309-
np.hstack((metadata['singular_value'], s[:num_components])))
1316+
np.hstack((metadata['singular_value'], s)))
13101317
metadata['variance_explained'] = (
13111318
np.hstack((metadata['variance_explained'],
1312-
variance_explained[:num_components])))
1319+
variance_explained)))
13131320
metadata['cumulative_variance_explained'] = (
13141321
np.hstack((metadata['cumulative_variance_explained'],
1315-
cumulative_variance_explained[:num_components])))
1322+
cumulative_variance_explained)))
1323+
metadata['retained'] = np.hstack((metadata['retained'],
1324+
[True if i < num_components
1325+
else False
1326+
for i in range(len(s))]))
13161327
if components is None and num_components != 0:
13171328
if self.inputs.failure_mode == 'error':
13181329
raise ValueError('No components found')

0 commit comments

Comments
 (0)