-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from tsalo/refactor
[RF] Reorganize package further.
- Loading branch information
Showing
16 changed files
with
522 additions
and
465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
Utility functions for tedana decomposition | ||
""" | ||
import logging | ||
|
||
import numpy as np | ||
from scipy import stats | ||
|
||
logging.basicConfig(format='[%(levelname)s]: %(message)s', level=logging.INFO) | ||
LGR = logging.getLogger(__name__) | ||
|
||
F_MAX = 500 | ||
Z_MAX = 8 | ||
|
||
|
||
def eimask(dd, ees=None): | ||
""" | ||
Returns mask for data between [0.001, 5] * 98th percentile of dd | ||
Parameters | ||
---------- | ||
dd : (S x E x T) array_like | ||
Input data, where `S` is samples, `E` is echos, and `T` is time | ||
ees : (N,) list | ||
Indices of echos to assess from `dd` in calculating output | ||
Returns | ||
------- | ||
imask : (S x N) np.ndarray | ||
Boolean array denoting | ||
""" | ||
|
||
if ees is None: | ||
ees = range(dd.shape[1]) | ||
imask = np.zeros([dd.shape[0], len(ees)], dtype=bool) | ||
for ee in ees: | ||
LGR.info('++ Creating eimask for echo {}'.format(ee)) | ||
perc98 = stats.scoreatpercentile(dd[:, ee, :].flatten(), 98, | ||
interpolation_method='lower') | ||
lthr, hthr = 0.001 * perc98, 5 * perc98 | ||
LGR.info('++ Eimask threshold boundaries: ' | ||
'{:.03f} {:.03f}'.format(lthr, hthr)) | ||
m = dd[:, ee, :].mean(axis=1) | ||
imask[np.logical_and(m > lthr, m < hthr), ee] = True | ||
|
||
return imask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
""" | ||
Functions to optimally combine data across echoes. | ||
""" | ||
import logging | ||
|
||
import numpy as np | ||
|
||
from tedana import utils | ||
|
||
logging.basicConfig(format='[%(levelname)s]: %(message)s', level=logging.INFO) | ||
LGR = logging.getLogger(__name__) | ||
|
||
|
||
def make_optcom(data, t2s, tes, mask, combmode): | ||
""" | ||
Optimally combine BOLD data across TEs. | ||
Parameters | ||
---------- | ||
data : (S x E x T) :obj:`numpy.ndarray` | ||
Concatenated BOLD data. | ||
t2 : (S,) :obj:`numpy.ndarray` | ||
Estimated T2* values. | ||
tes : :obj:`numpy.ndarray` | ||
Array of TEs, in seconds. | ||
mask : (S,) :obj:`numpy.ndarray` | ||
Brain mask in 3D array. | ||
combmode : :obj:`str` | ||
How to combine data. Either 'ste' or 't2s'. | ||
useG : :obj:`bool`, optional | ||
Use G. Default is False. | ||
Returns | ||
------- | ||
combined : (S x T) :obj:`numpy.ndarray` | ||
Optimally combined data. | ||
""" | ||
|
||
_, _, n_vols = data.shape | ||
mdata = data[mask] | ||
tes = np.array(tes)[np.newaxis] # (1 x E) array_like | ||
|
||
if t2s.ndim == 1: | ||
LGR.info('++ Optimally combining data with voxel-wise T2 estimates') | ||
ft2s = t2s[mask, np.newaxis] | ||
else: | ||
LGR.info('++ Optimally combining data with voxel- and volume-wise T2 ' | ||
'estimates') | ||
ft2s = t2s[mask, :, np.newaxis] | ||
|
||
if combmode == 'ste': | ||
alpha = mdata.mean(axis=-1) * tes | ||
else: | ||
alpha = tes * np.exp(-tes / ft2s) | ||
|
||
if t2s.ndim == 1: | ||
alpha = np.tile(alpha[:, :, np.newaxis], (1, 1, n_vols)) | ||
else: | ||
alpha = np.swapaxes(alpha, 1, 2) | ||
ax0_idx, ax2_idx = np.where(np.all(alpha == 0, axis=1)) | ||
alpha[ax0_idx, :, ax2_idx] = 1. | ||
|
||
combined = np.average(mdata, axis=1, weights=alpha) | ||
combined = utils.unmask(combined, mask) | ||
|
||
return combined |
Oops, something went wrong.