Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Output data where `S` is samples, `E` is echos, and `T` is time
ref_img : :obj:`str` or :obj:`numpy.ndarray`
Filepath to reference image for saving output files or NIFTI-like array
"""
if n_echos is None:
raise ValueError('Number of echos must be specified. '
'Confirm that TE times are provided with the `-e` argument.')
if isinstance(data, list):
if len(data) == 1: # a z-concatenated file was provided
data = data[0]
elif len(data) == 2: # inviable -- need more than 2 echos
raise ValueError('Cannot run `tedana` with only two echos: '
'{}'.format(data))
else: # individual echo files were provided (surface or volumetric)
fdata = np.stack([utils.load_image(f) for f in data], axis=1)
ref_img = check_niimg(data[0])
ref_img.header.extensions = []
return np.atleast_3d(fdata), ref_img
img = check_niimg(data)
(nx, ny), nz = img.shape[:2], img.shape[2] // n_echos
fdata = utils.load_image(img.get_data().reshape(nx, ny, nz, n_echos, -1, order='F'))
# create reference image
ref_img = img.__class__(np.zeros((nx, ny, nz, 1)), affine=img.affine,
header=img.header, extra=img.extra)
ref_img.header.extensions = []
ref_img.header.set_sform(ref_img.header.get_sform(), code=1)
return fdata, ref_img
if isinstance(data, list):
if len(data) == 1: # a z-concatenated file was provided
data = data[0]
elif len(data) == 2: # inviable -- need more than 2 echos
raise ValueError('Cannot run `tedana` with only two echos: '
'{}'.format(data))
else: # individual echo files were provided (surface or volumetric)
fdata = np.stack([utils.load_image(f) for f in data], axis=1)
ref_img = check_niimg(data[0])
ref_img.header.extensions = []
return np.atleast_3d(fdata), ref_img
img = check_niimg(data)
(nx, ny), nz = img.shape[:2], img.shape[2] // n_echos
fdata = utils.load_image(img.get_data().reshape(nx, ny, nz, n_echos, -1, order='F'))
# create reference image
ref_img = img.__class__(np.zeros((nx, ny, nz, 1)), affine=img.affine,
header=img.header, extra=img.extra)
ref_img.header.extensions = []
ref_img.header.set_sform(ref_img.header.get_sform(), code=1)
return fdata, ref_img
Output data where `S` is samples, `E` is echos, and `T` is time
ref_img : :obj:`str` or :obj:`numpy.ndarray`
Filepath to reference image for saving output files or NIFTI-like array
"""
if n_echos is None:
raise ValueError('Number of echos must be specified. '
'Confirm that TE times are provided with the `-e` argument.')
if isinstance(data, list):
if len(data) == 1: # a z-concatenated file was provided
data = data[0]
elif len(data) == 2: # inviable -- need more than 2 echos
raise ValueError('Cannot run `tedana` with only two echos: '
'{}'.format(data))
else: # individual echo files were provided (surface or volumetric)
fdata = np.stack([utils.load_image(f) for f in data], axis=1)
ref_img = check_niimg(data[0])
ref_img.header.extensions = []
return np.atleast_3d(fdata), ref_img
img = check_niimg(data)
(nx, ny), nz = img.shape[:2], img.shape[2] // n_echos
fdata = utils.load_image(img.get_data().reshape(nx, ny, nz, n_echos, -1, order='F'))
# create reference image
ref_img = img.__class__(np.zeros((nx, ny, nz)), affine=img.affine,
header=img.header, extra=img.extra)
ref_img.header.extensions = []
ref_img.header.set_sform(ref_img.header.get_sform(), code=1)
return fdata, ref_img
if infile is None:
data = data.copy()
data[data < thr] = 0
infile = filewrite(unmask(data, mask), '__clin.nii.gz', ref_img, gzip=True)
addopts = ''
if data is not None and data.squeeze().ndim > 1 and dindex + tindex == 0:
addopts = '-doall'
else:
addopts = '-1dindex {0} -1tindex {1}'.format(str(dindex), str(tindex))
cmd_str = '3dmerge -overwrite {0} -dxyz=1 -1clust 1 {1:d} ' \
'-1thresh {2:.02f} -prefix __clout.nii.gz {3}'
os.system(cmd_str.format(addopts, int(csize), float(thr), infile))
clustered = load_image('__clout.nii.gz')[mask] != 0
return clustered
continue # TODO: pass through GIFTI file data as below
os.system('3drefit -sublabel 0 PSC -sublabel 1 F_R2 -sublabel 2 F_SO '
'-sublabel 3 Z_sn {} 2> /dev/null > /dev/null'.format(ccname))
csize = np.max([int(n_voxels * 0.0005) + 5, 20])
# Do simple clustering on F
# TODO: can be replaced with nilearn.image.threshold_img
# TODO: fmin is being cast to an integer here -- is that purposeful?!
os.system('3dcalc -overwrite -a {}[1..2] -expr \'a*step(a-{:0d})\' -prefix '
'.fcl_in.nii.gz -overwrite'.format(ccname, int(fmin)))
# TODO: can be replaced with nilearn.regions.connected_regions
os.system('3dmerge -overwrite -dxyz=1 -1clust 1 {:0d} -doall '
'-prefix .fcl_out.nii.gz .fcl_in.nii.gz'.format(int(csize)))
sel = load_image('.fcl_out.nii.gz')[t2s != 0]
sel = np.array(sel != 0, dtype=np.int)
F_R2_clmaps[:, i] = sel[:, 0]
F_S0_clmaps[:, i] = sel[:, 1]
# Do simple clustering on Z at p<0.05
sel = spatclust(None, mask, csize, 1.95, ref_img,
infile=ccname, dindex=3, tindex=3)
Z_clmaps[:, i] = sel
# Do simple clustering on ranked signal-change map
countsigFR2 = F_R2_clmaps[:, i].sum()
countsigFS0 = F_S0_clmaps[:, i].sum()
spclust_input = stats.rankdata(tsoc_Babs[:, i])
Br_clmaps_R2[:, i] = spatclust(spclust_input, mask,
csize, max(tsoc_Babs.shape)-countsigFR2,
ref_img)