Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Component table with components classified as 'accepted', 'rejected',
or 'ignored'.
"""
eigenvalue_elbow = getelbow(comptable['normalized variance explained'],
return_val=True)
diff_varex_norm = np.abs(np.diff(comptable['normalized variance explained']))
lower_diff_varex_norm = diff_varex_norm[(len(diff_varex_norm) // 2):]
varex_norm_thr = np.mean([lower_diff_varex_norm.max(),
diff_varex_norm.min()])
varex_norm_min = comptable['normalized variance explained'][
(len(diff_varex_norm) // 2) +
np.arange(len(lower_diff_varex_norm))[lower_diff_varex_norm >= varex_norm_thr][0] + 1]
varex_norm_cum = np.cumsum(comptable['normalized variance explained'])
fmin, fmid, fmax = utils.getfbounds(n_echos)
if int(kdaw) == -1:
lim_idx = utils.andb([comptable['kappa'] < fmid,
comptable['kappa'] > fmin]) == 2
kappa_lim = comptable.loc[lim_idx, 'kappa'].values
kappa_thr = kappa_lim[getelbow(kappa_lim)]
lim_idx = utils.andb([comptable['rho'] < fmid, comptable['rho'] > fmin]) == 2
rho_lim = comptable.loc[lim_idx, 'rho'].values
rho_thr = rho_lim[getelbow(rho_lim)]
stabilize = True
LGR.info('kdaw set to -1. Switching TEDPCA method to '
'kundu-stabilize')
elif int(rdaw) == -1:
lim_idx = utils.andb([comptable['rho'] < fmid, comptable['rho'] > fmin]) == 2
rho_lim = comptable.loc[lim_idx, 'rho'].values
rho_thr = rho_lim[getelbow(rho_lim)]
Component table with components classified as 'accepted', 'rejected',
or 'ignored'.
"""
eigenvalue_elbow = getelbow(ct_df['normalized variance explained'],
return_val=True)
diff_varex_norm = np.abs(np.diff(ct_df['normalized variance explained']))
lower_diff_varex_norm = diff_varex_norm[(len(diff_varex_norm)//2):]
varex_norm_thr = np.mean([lower_diff_varex_norm.max(),
diff_varex_norm.min()])
varex_norm_min = ct_df['normalized variance explained'][
(len(diff_varex_norm)//2) +
np.arange(len(lower_diff_varex_norm))[lower_diff_varex_norm >= varex_norm_thr][0] + 1]
varex_norm_cum = np.cumsum(ct_df['normalized variance explained'])
fmin, fmid, fmax = utils.getfbounds(n_echos)
if int(kdaw) == -1:
lim_idx = utils.andb([ct_df['kappa'] < fmid,
ct_df['kappa'] > fmin]) == 2
kappa_lim = ct_df.loc[lim_idx, 'kappa'].values
kappa_thr = kappa_lim[getelbow(kappa_lim)]
lim_idx = utils.andb([ct_df['rho'] < fmid, ct_df['rho'] > fmin]) == 2
rho_lim = ct_df.loc[lim_idx, 'rho'].values
rho_thr = rho_lim[getelbow(rho_lim)]
stabilize = True
LGR.info('kdaw set to -1. Switching TEDPCA method to '
'kundu-stabilize')
elif int(rdaw) == -1:
lim_idx = utils.andb([ct_df['rho'] < fmid, ct_df['rho'] > fmin]) == 2
rho_lim = ct_df.loc[lim_idx, 'rho'].values
rho_thr = rho_lim[getelbow(rho_lim)]
for i_loop in range(3):
temp_comptable = comptable.loc[ncls].sort_values(by=['variance explained'],
ascending=False)
ncls = temp_comptable.loc[
temp_comptable['variance explained'].diff() < varex_upper_p].index.values
# Compute elbows from other elbows
kappas_under_f01 = (comptable.loc[comptable['kappa'] <
utils.getfbounds(n_echos)[-1], 'kappa'])
# NOTE: Would an elbow from all Kappa values *ever* be lower than one from
# a subset of lower values?
kappa_elbow = np.min((getelbow(kappas_under_f01, return_val=True),
getelbow(comptable['kappa'], return_val=True)))
rho_elbow = np.mean((getelbow(comptable.loc[ncls, 'rho'], return_val=True),
getelbow(comptable['rho'], return_val=True),
utils.getfbounds(n_echos)[0]))
# Provisionally accept components based on Kappa and Rho elbows
acc_prov = ncls[(comptable.loc[ncls, 'kappa'] >= kappa_elbow) &
(comptable.loc[ncls, 'rho'] < rho_elbow)]
if len(acc_prov) == 0:
LGR.warning('No BOLD-like components detected')
ign = sorted(np.setdiff1d(all_comps, rej))
comptable.loc[ign, 'classification'] = 'ignored'
comptable.loc[ign, 'rationale'] += 'I006;'
# Move decision columns to end
comptable = comptable[[c for c in comptable if c not in cols_at_end] +
[c for c in cols_at_end if c in comptable]]
comptable['rationale'] = comptable['rationale'].str.rstrip(';')
return comptable