Skip to content

Commit

Permalink
[REF] Remove the sourceTEs option (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo authored Dec 12, 2019
1 parent 2e6e3cb commit feddfcb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 43 deletions.
35 changes: 7 additions & 28 deletions tedana/decomposition/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def low_mem_pca(data):


def tedpca(data_cat, data_oc, combmode, mask, t2s, t2sG,
ref_img, tes, algorithm='mdl', source_tes=-1, kdaw=10., rdaw=1.,
ref_img, tes, algorithm='mdl', kdaw=10., rdaw=1.,
out_dir='.', verbose=False, low_mem=False):
"""
Use principal components analysis (PCA) to identify and remove thermal
Expand Down Expand Up @@ -119,12 +119,6 @@ def tedpca(data_cat, data_oc, combmode, mask, t2s, t2sG,
decomposition with the mdl, kic and aic options are based on a Moving Average
(stationary Gaussian) process and are ordered from most to least aggresive.
See (Li et al., 2007).
source_tes : :obj:`int` or :obj:`list` of :obj:`int`, optional
Which echos to use in PCA. Values -1 and 0 are special, where a value
of -1 will indicate using the optimal combination of the echos
and 0 will indicate using all the echos. A list can be provided
to indicate a subset of echos.
Default: -1
kdaw : :obj:`float`, optional
Dimensionality augmentation weight for Kappa calculations. Must be a
non-negative float, or -1 (a special value). Default is 10.
Expand Down Expand Up @@ -232,28 +226,14 @@ def tedpca(data_cat, data_oc, combmode, mask, t2s, t2sG,
"functional magnetic resonance imaging data. "
"Human brain mapping, 28(11), pp.1251-1266.")

if source_tes == -1:
dat_str = "the optimally combined data"
elif source_tes == 0:
dat_str = "the z-concatenated multi-echo data"
else:
dat_str = "a z-concatenated subset of echoes from the input data"

RepLGR.info("Principal component analysis {0} was applied to "
"{1} for dimensionality reduction.".format(alg_str, dat_str))
"the optimally combined data for dimensionality "
"reduction.".format(alg_str))

n_samp, n_echos, n_vols = data_cat.shape
source_tes = np.array([int(ee) for ee in str(source_tes).split(',')])

if len(source_tes) == 1 and source_tes[0] == -1:
LGR.info('Computing PCA of optimally combined multi-echo data')
data = data_oc[mask, :][:, np.newaxis, :]
elif len(source_tes) == 1 and source_tes[0] == 0:
LGR.info('Computing PCA of spatially concatenated multi-echo data')
data = data_cat[mask, ...]
else:
LGR.info('Computing PCA of echo #{0}'.format(','.join([str(ee) for ee in source_tes])))
data = np.stack([data_cat[mask, ee, :] for ee in source_tes - 1], axis=1)

LGR.info('Computing PCA of optimally combined multi-echo data')
data = data_oc[mask, :][:, np.newaxis, :]

eim = np.squeeze(_utils.eimask(data))
data = np.squeeze(data[eim])
Expand Down Expand Up @@ -340,8 +320,7 @@ def tedpca(data_cat, data_oc, combmode, mask, t2s, t2sG,
mixing_df = pd.DataFrame(data=comp_ts, columns=comp_names)
mixing_df.to_csv(op.join(out_dir, 'pca_mixing.tsv'), sep='\t', index=False)

data_type = 'optimally combined data' if source_tes == -1 else 'z-concatenated data'
comptable['Description'] = 'PCA fit to {0}.'.format(data_type)
comptable['Description'] = 'PCA fit to optimally combined data.'
mmix_dict = {}
mmix_dict['Method'] = ('Principal components analysis implemented by '
'sklearn. Components are sorted by variance '
Expand Down
18 changes: 3 additions & 15 deletions tedana/workflows/tedana.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ def _get_parser():
help=('Comma separated list of manually '
'accepted components'),
default=None)
optional.add_argument('--sourceTEs',
dest='source_tes',
type=str,
help=('Source TEs for models. E.g., 0 for all, '
'-1 for opt. com., and 1,2 for just TEs 1 and '
'2. Default=-1.'),
default=-1)
optional.add_argument('--combmode',
dest='combmode',
action='store',
Expand Down Expand Up @@ -216,7 +209,7 @@ def _get_parser():

def tedana_workflow(data, tes, mask=None, mixm=None, ctab=None, manacc=None,
tedort=False, gscontrol=None, tedpca='mle',
source_tes=-1, combmode='t2s', verbose=False, stabilize=False,
combmode='t2s', verbose=False, stabilize=False,
out_dir='.', fixed_seed=42, maxit=500, maxrestart=10,
debug=False, quiet=False, no_png=False,
png_cmap='coolwarm',
Expand Down Expand Up @@ -254,9 +247,6 @@ def tedana_workflow(data, tes, mask=None, mixm=None, ctab=None, manacc=None,
is None.
tedpca : {'mle', 'kundu', 'kundu-stabilize', 'mdl', 'aic', 'kic'}, optional
Method with which to select components in TEDPCA. Default is 'mdl'.
source_tes : :obj:`int`, optional
Source TEs for models. 0 for all, -1 for optimal combination.
Default is -1.
combmode : {'t2s'}, optional
Combination scheme for TEs: 't2s' (Posse 1999, default).
fittype : {'loglin', 'curvefit'}, optional
Expand Down Expand Up @@ -474,15 +464,14 @@ def tedana_workflow(data, tes, mask=None, mixm=None, ctab=None, manacc=None,
dd, n_components = decomposition.tedpca(catd, data_oc, combmode, mask,
t2s_limited, t2s_full, ref_img,
tes=tes, algorithm=tedpca,
source_tes=source_tes,
kdaw=10., rdaw=1.,
out_dir=out_dir,
verbose=verbose,
low_mem=low_mem)
mmix_orig = decomposition.tedica(dd, n_components, fixed_seed,
maxit, maxrestart)

if verbose and (source_tes == -1):
if verbose:
io.filewrite(utils.unmask(dd, mask),
op.join(out_dir, 'ts_OC_whitened.nii'), ref_img)

Expand Down Expand Up @@ -525,8 +514,7 @@ def tedana_workflow(data, tes, mask=None, mixm=None, ctab=None, manacc=None,
comptable = selection.manual_selection(comptable, acc=manacc)

# Save decomposition
data_type = 'optimally combined data' if source_tes == -1 else 'z-concatenated data'
comptable['Description'] = 'ICA fit to dimensionally reduced {0}.'.format(data_type)
comptable['Description'] = 'ICA fit to dimensionally-reduced optimally combined data.'
mmix_dict = {}
mmix_dict['Method'] = ('Independent components analysis with FastICA '
'algorithm implemented by sklearn. Components '
Expand Down

0 comments on commit feddfcb

Please sign in to comment.