@@ -18,7 +18,8 @@ To remove noise from your data, you can regress the "bad" components out of it,
1818
1919Let's start by loading the necessary data.
2020
21- ```` {tab} Python
21+ :::::{tab-set}
22+ ::::{tab-item} Python
2223``` python
2324import numpy as np
2425import pandas as pd
@@ -44,30 +45,32 @@ arr = arr.T
4445# The first dimension should be time
4546assert arr.shape[1 ] == mixing.shape[0 ]
4647```
47- ````
48- ```` {tab} FSL
48+ ::::
49+ :::: {tab-item } FSL
4950``` bash
5051data_file=preprocessed_data.nii.gz
5152mixing_file=mixing.tsv
5253mask_file=mask.nii.gz
5354den_idx=(0, 1, 2, 3, 4, 5)
5455```
55- ````
56- ```` {tab} AFNI
56+ ::::
57+ :::: {tab-item } AFNI
5758``` bash
5859data_file=preprocessed_data.nii.gz
5960mixing_file=mixing.tsv
6061mask_file=mask.nii.gz
6162den_idx=(0, 1, 2, 3, 4, 5)
6263```
63- ````
64+ ::::
65+ :::::
6466
6567## Aggressive Denoising
6668
6769If you regress just nuisance regressors (i.e., rejected components) out of your data,
6870then retain the residuals for further analysis, you are doing aggressive denoising.
6971
70- ```` {tab} Python
72+ :::::{tab-set}
73+ ::::{tab-item} Python
7174``` python
7275# Fit GLM to bad components only
7376betas = np.linalg.lstsq(motion_components, arr, rcond = None )[0 ]
@@ -80,24 +83,26 @@ arr_denoised = arr - pred_arr
8083img_denoised = masking.unmask(arr_denoised.T, data[' mask' ])
8184img_denoised.to_filename(" denoised.nii.gz" )
8285```
83- ````
84- ```` {tab} FSL
86+ ::::
87+ :::: {tab-item } FSL
8588``` bash
86893dcalc --input stuff
8790```
88- ````
89- ```` {tab} AFNI
91+ ::::
92+ :::: {tab-item } AFNI
9093``` bash
91943dcalc --input stuff
9295```
93- ````
96+ ::::
97+ :::::
9498
9599## Non-Aggressive Denoising
96100
97101If you include both nuisance regressors and regressors of interest in your regression,
98102you are doing nonaggressive denoising.
99103
100- ```` {tab} Python
104+ :::::{tab-set}
105+ ::::{tab-item} Python
101106``` python
102107# Fit GLM to all components
103108betas = np.linalg.lstsq(mixing, arr, rcond = None )[0 ]
@@ -110,17 +115,18 @@ arr_denoised = arr - pred_arr
110115img_denoised = masking.unmask(arr_denoised.T, data[' mask' ])
111116img_denoised.to_filename(" denoised.nii.gz" )
112117```
113- ````
114- ```` {tab} FSL
118+ ::::
119+ :::: {tab-item } FSL
115120``` bash
1161213dcalc --input stuff
117122```
118- ````
119- ```` {tab} AFNI
123+ ::::
124+ :::: {tab-item } AFNI
120125``` bash
1211263dcalc --input stuff
122127```
123- ````
128+ ::::
129+ :::::
124130
125131## Component orthogonalization
126132
@@ -130,7 +136,8 @@ If you want to ensure that variance shared between the accepted and rejected com
130136you may wish to orthogonalize the rejected components with respect to the accepted components.
131137This way, you can regress the rejected components out of the data in the form of, what we call, "pure evil" components.
132138
133- ```` {tab} Python
139+ :::::{tab-set}
140+ ::::{tab-item} Python
134141``` python
135142good_idx = np.setdiff1d(np.arange(mixing.shape[1 ]), den_idx)
136143
@@ -146,21 +153,23 @@ orth_motion_components = bad_mixing - pred_bad_mixing
146153# Replace the old component time series in the mixing matrix with the new ones
147154mixing[:, den_idx] = orth_motion_components
148155```
149- ````
150- ```` {tab} FSL
156+ ::::
157+ :::: {tab-item } FSL
151158``` bash
1521593dcalc --input stuff
153160```
154- ````
155- ```` {tab} AFNI
161+ ::::
162+ :::: {tab-item } AFNI
156163``` bash
1571643dcalc --input stuff
158165```
159- ````
166+ ::::
167+ :::::
160168
161169Once you have these "pure evil" components, you can perform aggressive denoising on the data.
162170
163- ```` {tab} Python
171+ :::::{tab-set}
172+ ::::{tab-item} Python
164173``` python
165174# Fit GLM to bad components only
166175betas = np.linalg.lstsq(orth_motion_components, arr, rcond = None )[0 ]
@@ -173,14 +182,15 @@ arr_denoised = arr - pred_arr
173182img_denoised = masking.unmask(arr_denoised.T, data[' mask' ])
174183img_denoised.to_filename(" denoised.nii.gz" )
175184```
176- ````
177- ```` {tab} FSL
185+ ::::
186+ :::: {tab-item } FSL
178187``` bash
1791883dcalc --input stuff
180189```
181- ````
182- ```` {tab} AFNI
190+ ::::
191+ :::: {tab-item } AFNI
183192``` bash
1841933dcalc --input stuff
185194```
186- ````
195+ ::::
196+ :::::
0 commit comments