Skip to content

Commit

Permalink
ENH: Add NaN failure mode to CompCor interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Dec 12, 2018
1 parent 35b58cd commit 16af71e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions nipype/algorithms/confounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ class CompCorInputSpec(BaseInterfaceInputSpec):
low=0,
usedefault=True,
desc='Number of volumes at start of series to ignore')
failure_mode = traits.Enum(
'error', 'NaN',
usedefault=True,
desc='When no components are found or convergence fails, raise an error '
'or silently return columns of NaNs.')


class CompCorOutputSpec(TraitedSpec):
Expand Down Expand Up @@ -1185,13 +1190,20 @@ def compute_noise_components(imgseries, mask_images, num_components,

# "The covariance matrix C = MMT was constructed and decomposed into its
# principal components using a singular value decomposition."
u, _, _ = np.linalg.svd(M, full_matrices=False)
try:
u, _, _ = np.linalg.svd(M, full_matrices=False)
except np.linalg.LinAlgError:
if self.inputs.failure_mode == 'error':
raise
u = np.ones((M.shape[0], num_components), dtype=np.float32) * np.nan
if components is None:
components = u[:, :num_components]
else:
components = np.hstack((components, u[:, :num_components]))
if components is None and num_components > 0:
raise ValueError('No components found')
if self.inputs.failure_mode == 'error':
raise ValueError('No components found')
components = np.ones((M.shape[0], num_components), dtype=np.float32) * np.nan
return components, basis


Expand Down

0 comments on commit 16af71e

Please sign in to comment.