本文整理汇总了Python中nilearn.input_data.NiftiLabelsMasker方法的典型用法代码示例。如果您正苦于以下问题:Python input_data.NiftiLabelsMasker方法的具体用法?Python input_data.NiftiLabelsMasker怎么用?Python input_data.NiftiLabelsMasker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nilearn.input_data
的用法示例。
在下文中一共展示了input_data.NiftiLabelsMasker方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run_interface
# 需要导入模块: from nilearn import input_data [as 别名]
# 或者: from nilearn.input_data import NiftiLabelsMasker [as 别名]
def _run_interface(self, runtime):
fname = self.inputs.fmri_denoised
bold_img = nb.load(fname)
masker = NiftiLabelsMasker(labels_img=self.inputs.parcellation, standardize=True)
time_series = masker.fit_transform(bold_img, confounds=None)
corr_measure = ConnectivityMeasure(kind='correlation')
corr_mat = corr_measure.fit_transform([time_series])[0]
_, base, _ = split_filename(fname)
conn_file = f'{self.inputs.output_dir}/{base}_conn_mat.npy'
carpet_plot_file = join(self.inputs.output_dir, f'{base}_carpet_plot.png')
matrix_plot_file = join(self.inputs.output_dir, f'{base}_matrix_plot.png')
create_carpetplot(time_series, carpet_plot_file)
mplot = plot_matrix(corr_mat, vmin=-1, vmax=1)
mplot.figure.savefig(matrix_plot_file)
np.save(conn_file, corr_mat)
self._results['corr_mat'] = conn_file
self._results['carpet_plot'] = carpet_plot_file
self._results['matrix_plot'] = matrix_plot_file
return runtime
示例2: create_carpetplot
# 需要导入模块: from nilearn import input_data [as 别名]
# 或者: from nilearn.input_data import NiftiLabelsMasker [as 别名]
def create_carpetplot(time_series: np.ndarray, out_fname: str,
dpi=300, figsize=(8, 3), format='png'):
"""Generates and saves carpet plot for rois timecourses.
Args:
time_series: Timecourse array of size N_timepoints x N_rois. Output of
fit_transform() NiftiLabelsMasker method.
out_fname: Carpetplot output filename.
dpi (:obj:`int`, optional): Dots per inch (default 300).
figsize (:obj:`tuple`, optional): Size of the figure in inches
(default (3,8))
format (:obj:`str`, optional): Image format. Available options include
'png', 'pdf', 'ps', 'eps' and 'svg'.
"""
if not isinstance(time_series, np.ndarray):
raise TypeError('time series should be np.ndarray')
fig = plt.figure(figsize=figsize, dpi=dpi)
ax = fig.add_subplot(111)
ax.imshow(time_series.T, cmap='gray')
ax.set_xlabel('volume')
ax.set_ylabel('roi')
ax.set_yticks([])
try:
fig.savefig(out_fname, format=format,
transparent=True, bbox_inches='tight')
except FileNotFoundError:
print(f'{out_fname} directory not found')
示例3: test_ibma_with_custom_masker
# 需要导入模块: from nilearn import input_data [as 别名]
# 或者: from nilearn.input_data import NiftiLabelsMasker [as 别名]
def test_ibma_with_custom_masker(testdata):
""" Ensure voxel-to-ROI reduction works. """
atlas = op.join(get_resource_path(), 'atlases',
'HarvardOxford-cort-maxprob-thr25-2mm.nii.gz')
masker = NiftiLabelsMasker(atlas)
meta = ibma.Fishers(mask=masker)
meta.fit(testdata['dset_z'])
assert isinstance(meta.results, nimare.base.MetaResult)
assert meta.results.maps['z'].shape == (48, )
示例4: correlation_matrix
# 需要导入模块: from nilearn import input_data [as 别名]
# 或者: from nilearn.input_data import NiftiLabelsMasker [as 别名]
def correlation_matrix(ts,atlas,
confounds=None,
mask=None,
loud=False,
structure_names=[],
save_as='',
low_pass=0.25,
high_pass=0.004,
smoothing_fwhm=.3,
):
"""Return a CSV file containing correlations between ROIs.
Parameters
----------
ts : str
Path to the 4D NIfTI timeseries file on which to perform the connectivity analysis.
confounds : 2D array OR path to CSV file
Array/CSV file containing confounding time-series to be regressed out before FC analysis.
atlas : str, optional
Path to a 3D NIfTI-like binary label file designating ROIs.
structure_names : list, optional
Ordered list of all structure names in atlas (length N).
save_as : str
Path under which to save the Pandas DataFrame conttaining the NxN correlation matrix.
"""
ts = path.abspath(path.expanduser(ts))
if isinstance(atlas,str):
atlas = path.abspath(path.expanduser(atlas))
if mask:
mask = path.abspath(path.expanduser(mask))
tr = nib.load(ts).header['pixdim'][0]
labels_masker = NiftiLabelsMasker(
labels_img=atlas,
mask_img=mask,
standardize=True,
memory='nilearn_cache',
verbose=5,
low_pass=low_pass,
high_pass = high_pass,
smoothing_fwhm=smoothing_fwhm,
t_r=tr,
)
#TODO: test confounds with physiological signals
if(confounds):
confounds = path.abspath(path.expanduser(confounds))
timeseries = labels_masker.fit_transform(ts, confounds=confounds)
else:
timeseries = labels_masker.fit_transform(ts)
correlation_measure = ConnectivityMeasure(kind='correlation')
correlation_matrix = correlation_measure.fit_transform([timeseries])[0]
if structure_names:
df = pd.DataFrame(columns=structure_names, index=structure_names, data=correlation_matrix)
else:
df = pd.DataFrame(data=correlation_matrix)
if save_as:
save_dir = path.dirname(save_as)
if not path.exists(save_dir):
makedirs(save_dir)
df.to_csv(save_as)