tedana.utils.utils

Utilities for tedana package

Functions

andb(arrs) Sums arrays in arrs
dice(arr1, arr2) Compute Dice’s similarity index between two numpy arrays.
filewrite(data, filename, ref_img[, gzip, …]) Writes data to filename in format of ref_img
fitgaussian(data) Returns estimated gaussian parameters of a 2D distribution found by a fit
gaussian(height, center_x, center_y, …) Returns gaussian function
get_dtype(data) Determines neuroimaging format of data
getfbounds(n_echos) Gets estimated F-statistic boundaries based on number of echos
load_data(data[, n_echos]) Coerces input data files to required 3D array output
load_image(data) Takes input data and returns a sample x time array
make_adaptive_mask(data[, mask, minimum, getsum]) Makes map of data specifying longest echo a voxel can be sampled with
make_min_mask(data[, roi]) Generates a 3D mask of data
moments(data) Returns gaussian parameters of a 2D distribution by calculating its moments
new_nii_like(ref_img, data[, affine, …]) Coerces data into NiftiImage format like ref_img
unmask(data, mask) Unmasks data using non-zero entries of mask
andb(arrs)[source]

Sums arrays in arrs

Parameters:arrs (list) – List of boolean or integer arrays to be summed
Returns:result – Integer array of summed arrs
Return type:numpy.ndarray
dice(arr1, arr2)[source]

Compute Dice’s similarity index between two numpy arrays. Arrays will be binarized before comparison.

Parameters:arr2 (arr1,) – Input arrays, arrays to binarize and compare.
Returns:dsi – Dice-Sorenson index.
Return type:float

References

REF

filewrite(data, filename, ref_img, gzip=False, copy_header=True)[source]

Writes data to filename in format of ref_img

Parameters:
  • data ((S [x T]) array_like) – Data to be saved
  • filename (str) – Filepath where data should be saved to
  • ref_img (str or img_like) – Reference image
  • gzip (bool, optional) – Whether to gzip output (if not specified in filename). Only applies if output dtype is NIFTI. Default: False
  • copy_header (bool, optional) – Whether to copy header from ref_img to new image. Default: True
Returns:

name – Path of saved image (with added extensions, as appropriate)

Return type:

str

fitgaussian(data)[source]

Returns estimated gaussian parameters of a 2D distribution found by a fit

Parameters:data (array_like) – 2D data array
Returns:p – Array with height, center_x, center_y, width_x, width_y of data
Return type:array_like

References

Scipy Cookbook

gaussian(height, center_x, center_y, width_x, width_y)[source]

Returns gaussian function

Parameters:
Returns:

Gaussian function with provided parameters

Return type:

lambda

References

Scipy Cookbook

get_dtype(data)[source]

Determines neuroimaging format of data

Parameters:data (list of str or str or img_like) – Data to determine format of
Returns:dtype – Format of input data
Return type:{‘NIFTI’, ‘OTHER’} str
getfbounds(n_echos)[source]

Gets estimated F-statistic boundaries based on number of echos

Parameters:n_echos (int) – Number of echoes
Returns:fmin, fmid, fmax – Minimum, mid, and max F bounds
Return type:float
load_data(data, n_echos=None)[source]

Coerces input data files to required 3D array output

Parameters:
  • data ((X x Y x M x T) array_like or list of img_like) – Input multi-echo data array, where X and Y are spatial dimensions, M is the Z-spatial dimensions with all the input echos concatenated, and T is time. A list of image-like objects (e.g., .nii) are accepted, as well
  • n_echos (int, optional) – Number of echos in provided data array. Only necessary if data is array_like. Default: None
Returns:

  • fdata ((S x E x T) numpy.ndarray) – Output data where S is samples, E is echos, and T is time
  • ref_img (str or numpy.ndarray) – Filepath to reference image for saving output files or NIFTI-like array

load_image(data)[source]

Takes input data and returns a sample x time array

Parameters:data ((X x Y x Z [x T]) array_like or img_like object) – Data array or data file to be loaded and reshaped
Returns:fdata – Reshaped data, where S is samples and T is time
Return type:(S [x T]) numpy.ndarray
make_adaptive_mask(data, mask=None, minimum=True, getsum=False)[source]

Makes map of data specifying longest echo a voxel can be sampled with

Parameters:
  • data ((S x E x T) array_like) – Multi-echo data array, where S is samples, E is echos, and T is time
  • mask (str or img_like, optional) – Binary mask for voxels to consider in TE Dependent ANAlysis. Default is to generate mask from data with good signal across echoes
  • minimum (bool, optional) – Use make_min_mask() instead of generating a map with echo-specific times. Default: True
  • getsum (bool, optional) – Return masksum in addition to mask. Default: False
Returns:

  • mask ((S,) numpy.ndarray) – Boolean array of voxels that have sufficient signal in at least one echo
  • masksum ((S,) numpy.ndarray) – Valued array indicating the number of echos with sufficient signal in a given voxel. Only returned if getsum = True

make_min_mask(data, roi=None)[source]

Generates a 3D mask of data

Only samples that are consistently (i.e., across time AND echoes) non-zero in data are True in output

Parameters:
  • data ((S x E x T) array_like) – Multi-echo data array, where S is samples, E is echos, and T is time
  • roi (str, optional) – Binary mask for region-of-interest to consider in TE Dependent ANAlysis
Returns:

mask – Boolean array

Return type:

(S,) numpy.ndarray

moments(data)[source]

Returns gaussian parameters of a 2D distribution by calculating its moments

Parameters:data (array_like) – 2D data array
Returns:

References

Scipy Cookbook

new_nii_like(ref_img, data, affine=None, copy_header=True)[source]

Coerces data into NiftiImage format like ref_img

Parameters:
  • ref_img (str or img_like) – Reference image
  • data ((S [x T]) array_like) – Data to be saved
  • affine ((4 x 4) array_like, optional) – Transformation matrix to be used. Default: ref_img.affine
  • copy_header (bool, optional) – Whether to copy header from ref_img to new image. Default: True
Returns:

nii – NiftiImage

Return type:

nibabel.nifti1.Nifti1Image

unmask(data, mask)[source]

Unmasks data using non-zero entries of mask

Parameters:
  • data ((M [x E [x T]]) array_like) – Masked array, where M is the number of True values in mask
  • mask ((S,) array_like) – Boolean array of S samples that was used to mask data. It should have exactly M True values.
Returns:

out – Unmasked data array

Return type:

(S [x E [x T]]) numpy.ndarray