Skip to content

ENH: Add NaN failure mode to CompCor interfaces #2819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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