Skip to content
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

[ENH] Remove accepted and rejected outputs #822

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/approach.rst
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ presented at MRITogether 2022 for a hands-on tutorial.
Removal of spatially diffuse noise (optional)
*********************************************

:func:`tedana.gscontrol.gscontrol_raw`, :func:`tedana.gscontrol.gscontrol_mmix`
:func:`tedana.gscontrol.gscontrol_raw`, :func:`tedana.gscontrol.minimum_image_regression`

Due to the constraints of ICA, TEDICA is able to identify and remove spatially
localized noise components, but it cannot identify components that are spread
Expand Down
14 changes: 2 additions & 12 deletions docs/outputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ future processing. ``tedana`` allows for multiple file naming conventions. The k
and naming options for each convention that can be set using the ``--convention`` option
are in `outputs.json`_. The output of ``tedana`` also includes a file called
``registry.json`` or ``desc-tedana_registry.json`` that includes the keys and the matching
file names for the output. The table below lists both these keys and the default
file names for the output. The table below lists both these keys and the default
"BIDS Derivatives" file names.

.. _outputs.json: https://github.com/ME-ICA/tedana/blob/main/tedana/resources/config/outputs.json
Expand Down Expand Up @@ -107,14 +107,8 @@ tedana_report.html The
status of each component after each node was run.
Columns are only added for runs where component
statuses can change.
"ICA accepted components img": desc-ICAAccepted_components.nii.gz High-kappa ICA coefficient feature set
"z-scored ICA accepted components img": desc-ICAAcceptedZ_components.nii.gz Z-normalized spatial component maps
report.txt A summary report for the workflow with relevant
citations.
"low kappa ts img": desc-optcomRejected_bold.nii.gz Combined time series from rejected components.
"high kappa ts img": desc-optcomAccepted_bold.nii.gz High-kappa time series. This dataset does not
include thermal noise or low variance components.
Not the recommended dataset for analysis.
references.bib The BibTeX entries for references cited in
report.txt.

Expand All @@ -133,7 +127,7 @@ Key: Filename
"limited s0 img": desc-limited_S0map.nii.gz Limited S0 map/time series.
Unlike the full S0 maps, if only one 1 echo contains
good data the limited map will have NaN
"whitened img": desc-optcom_whitened_bold The optimally combined data after whitening
"whitened img": desc-optcomWhitened_bold The optimally combined data after whitening
"echo weight [PCA|ICA] maps split img": echo-[echo]_desc-[PCA|ICA]_components.nii.gz Echo-wise PCA/ICA component weight maps.
"echo T2 [PCA|ICA] split img": echo-[echo]_desc-[PCA|ICA]T2ModelPredictions_components.nii.gz Component- and voxel-wise R2-model predictions,
separated by echo.
Expand All @@ -145,8 +139,6 @@ Key: Filename
"[PCA|ICA] component F-T2 img": desc-[PCA|ICA]T2_stat-F_statmap.nii.gz F-statistic map for each component, for the T2 model.
"PCA reduced img": desc-optcomPCAReduced_bold.nii.gz Optimally combined data after dimensionality
reduction with PCA. This is the input to the ICA.
"high kappa ts split img": echo-[echo]_desc-Accepted_bold.nii.gz High-Kappa time series for echo number ``echo``
"low kappa ts split img": echo-[echo]_desc-Rejected_bold.nii.gz Low-Kappa time series for echo number ``echo``
"denoised ts split img": echo-[echo]_desc-Denoised_bold.nii.gz Denoised time series for echo number ``echo``
============================================================================================= =====================================================

Expand Down Expand Up @@ -187,8 +179,6 @@ Key: Filename
"t1 like img": desc-T1likeEffect_min.nii.gz T1-like effect
"mir denoised img": desc-optcomMIRDenoised_bold.nii.gz Denoised time series after MIR
"ICA MIR mixing tsv": desc-ICAMIRDenoised_mixing.tsv ICA mixing matrix after MIR
"ICA accepted mir component weights img": desc-ICAAcceptedMIRDenoised_components.nii.gz high-kappa components after MIR
"ICA accepted mir denoised img": desc-optcomAcceptedMIRDenoised_bold.nii.gz high-kappa time series after MIR
======================================================================================= =====================================================

.. _classification-output-descriptions:
Expand Down
42 changes: 18 additions & 24 deletions tedana/decomposition/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,55 +124,49 @@ def tedpca(

Notes
-----
====================== =================================================
====================== ===================================================================
Notation Meaning
====================== =================================================
:math:`\\kappa` Component pseudo-F statistic for TE-dependent
(BOLD) model.
:math:`\\rho` Component pseudo-F statistic for TE-independent
(artifact) model.
====================== ===================================================================
:math:`\\kappa` Component pseudo-F statistic for TE-dependent (BOLD) model.
:math:`\\rho` Component pseudo-F statistic for TE-independent (artifact) model.
:math:`v` Voxel
:math:`V` Total number of voxels in mask
:math:`\\zeta` Something
:math:`c` Component
:math:`p` Something else
====================== =================================================
====================== ===================================================================

Steps:

1. Variance normalize either multi-echo or optimally combined data,
depending on settings.
1. Variance normalize either multi-echo or optimally combined data, depending on settings.
2. Decompose normalized data using PCA or SVD.
3. Compute :math:`{\\kappa}` and :math:`{\\rho}`:
3. Compute :math:`{\\kappa}` and :math:`{\\rho}`.

.. math::
{\\kappa}_c = \\frac{\\sum_{v}^V {\\zeta}_{c,v}^p * \
F_{c,v,R_2^*}}{\\sum {\\zeta}_{c,v}^p}
.. math::
{\\kappa}_c = \\frac{\\sum_{v}^V {\\zeta}_{c,v}^p * \
F_{c,v,R_2^*}}{\\sum {\\zeta}_{c,v}^p}

{\\rho}_c = \\frac{\\sum_{v}^V {\\zeta}_{c,v}^p * \
F_{c,v,S_0}}{\\sum {\\zeta}_{c,v}^p}
{\\rho}_c = \\frac{\\sum_{v}^V {\\zeta}_{c,v}^p * \
F_{c,v,S_0}}{\\sum {\\zeta}_{c,v}^p}

4. Some other stuff. Something about elbows.
5. Classify components as thermal noise if they meet both of the
following criteria:
5. Classify components as thermal noise if they meet both of the following criteria.

- Nonsignificant :math:`{\\kappa}` and :math:`{\\rho}`.
- Nonsignificant variance explained.

Generated Files
---------------

=========================== =============================================
=========================== ======================================================
Default Filename Content
=========================== =============================================
=========================== ======================================================
desc-PCA_metrics.tsv PCA component table
desc-PCA_metrics.json Metadata sidecar file describing the
component table
desc-PCA_metrics.json Metadata sidecar file describing the component table
desc-PCA_mixing.tsv PCA mixing matrix
desc-PCA_components.nii.gz Component weight maps
desc-PCA_decomposition.json Metadata sidecar file describing the PCA
decomposition
=========================== =============================================
desc-PCA_decomposition.json Metadata sidecar file describing the PCA decomposition
=========================== ======================================================

References
----------
Expand Down
21 changes: 7 additions & 14 deletions tedana/gscontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def gscontrol_raw(catd, optcom, n_echos, io_generator, dtrank=4):
Input `catd` with global signal removed from time series
dm_optcom : (S x T) array_like
Input `optcom` with global signal removed from time series

Warning
-------
This GSR approach is rather dissimilar to the more common approach of extracting global signal
using a gray matter or whole brain mask, and regressing the mean of that signal from the rest
of the brain.
"""
LGR.info("Applying amplitude-based T1 equilibration correction")
RepLGR.info(
Expand Down Expand Up @@ -160,9 +166,7 @@ def minimum_image_regression(optcom_ts, mmix, mask, comptable, io_generator):
Filename Content
====================== =================================================
sphis_hik.nii T1-like effect
hik_ts_OC_MIR.nii T1-corrected BOLD (high-Kappa) time series
dn_ts_OC_MIR.nii Denoised version of T1-corrected time series
betas_hik_OC_MIR.nii T1 global signal-corrected components
meica_mix_MIR.1D T1 global signal-corrected mixing matrix
====================== =================================================

Expand Down Expand Up @@ -204,25 +208,14 @@ def minimum_image_regression(optcom_ts, mmix, mask, comptable, io_generator):
mehk_noT1gs = mehk_ts - np.dot(
np.linalg.lstsq(glob_sig.T, mehk_ts.T, rcond=None)[0].T, glob_sig
)
hik_ts = mehk_noT1gs * optcom_std # rescale
io_generator.save_file(utils.unmask(hik_ts, mask), "ICA accepted mir denoised img")

# Make denoised version of T1-corrected time series
medn_ts = optcom_mean + ((mehk_noT1gs + resid) * optcom_std)
io_generator.save_file(utils.unmask(medn_ts, mask), "mir denoised img")

# Orthogonalize mixing matrix w.r.t. T1-GS
mmix_noT1gs = mmix.T - np.dot(np.linalg.lstsq(glob_sig.T, mmix, rcond=None)[0].T, glob_sig)
mmix_noT1gs_z = stats.zscore(mmix_noT1gs, axis=-1)
mmix_noT1gs_z = np.vstack(
(np.atleast_2d(np.ones(max(glob_sig.shape))), glob_sig, mmix_noT1gs_z)
)

# Write T1-corrected components and mixing matrix
comp_pes_norm = np.linalg.lstsq(mmix_noT1gs_z.T, optcom_z.T, rcond=None)[0].T
io_generator.save_file(
utils.unmask(comp_pes_norm[:, 2:], mask),
"ICA accepted mir component weights img",
)
# Write T1-corrected mixing matrix
mixing_df = pd.DataFrame(data=mmix_noT1gs.T, columns=comptable["Component"].values)
io_generator.save_file(mixing_df, "ICA MIR mixing tsv")
Loading