Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import nimare
from nimare.tests.utils import get_test_data_path
###############################################################################
# Load Dataset
# --------------------------------------------------
dset_file = os.path.join(get_test_data_path(), 'nidm_pain_dset.json')
dset = nimare.dataset.Dataset(dset_file)
mask_img = dset.masker.mask_img
###############################################################################
# MKDA density analysis
# --------------------------------------------------
mkda = nimare.meta.cbma.MKDADensity(kernel__r=10)
mkda.fit(dset)
corr = nimare.correct.FWECorrector(method='permutation', n_iters=10, n_cores=1)
cres = corr.transform(mkda.results)
plot_stat_map(cres.get_map('logp_level-voxel_corr-FWE_method-permutation'),
cut_coords=[0, 0, -8], draw_cross=False, cmap='RdBu_r')
###############################################################################
# MKDA Chi2 with FDR correction
# --------------------------------------------------
mkda = nimare.meta.cbma.MKDAChi2(kernel__r=10)
dset1 = dset.slice(dset.ids)
dset2 = dset.slice(dset.ids)
mkda.fit(dset1, dset2)
corr = nimare.correct.FDRCorrector(method='fdr_bh', alpha=0.001)
cres = corr.transform(mkda.results)
plot_stat_map(cres.get_map('consistency_z_FDR_corr-FDR_method-fdr_bh'),
mask_img = dset.masker.mask_img
###############################################################################
# MKDA density analysis
# --------------------------------------------------
mkda = nimare.meta.cbma.MKDADensity(kernel__r=10)
mkda.fit(dset)
corr = nimare.correct.FWECorrector(method='permutation', n_iters=10, n_cores=1)
cres = corr.transform(mkda.results)
plot_stat_map(cres.get_map('logp_level-voxel_corr-FWE_method-permutation'),
cut_coords=[0, 0, -8], draw_cross=False, cmap='RdBu_r')
###############################################################################
# MKDA Chi2 with FDR correction
# --------------------------------------------------
mkda = nimare.meta.cbma.MKDAChi2(kernel__r=10)
dset1 = dset.slice(dset.ids)
dset2 = dset.slice(dset.ids)
mkda.fit(dset1, dset2)
corr = nimare.correct.FDRCorrector(method='fdr_bh', alpha=0.001)
cres = corr.transform(mkda.results)
plot_stat_map(cres.get_map('consistency_z_FDR_corr-FDR_method-fdr_bh'),
threshold=1.65, cut_coords=[0, 0, -8], draw_cross=False,
cmap='RdBu_r')
###############################################################################
# MKDA Chi2 with FWE correction
# --------------------------------------------------
corr = nimare.correct.FWECorrector(method='permutation', n_iters=10, n_cores=1)
cres = corr.transform(mkda.results)
plot_stat_map(cres.get_map('consistency_z'), threshold=1.65,
cut_coords=[0, 0, -8], draw_cross=False, cmap='RdBu_r')
'data/nidm_pain_dset_with_subpeaks.json')
db = nimare.dataset.Database(database_file)
ds = db.get_dataset()
###############################################################################
# KDA
# --------------------------------
kernel = nimare.meta.cbma.KDAKernel(ds.coordinates, ds.mask)
kda_res = kernel.transform(ids=ds.ids, r=10)
max_conv = np.max(kda_res[2].get_data())
plot_stat_map(kda_res[2], cut_coords=[-2, -10, -4], title='KDA', vmax=max_conv)
###############################################################################
# MKDA
# --------------------------------
kernel = nimare.meta.cbma.MKDAKernel(ds.coordinates, ds.mask)
mkda_res = kernel.transform(ids=ds.ids, r=10)
plot_stat_map(mkda_res[2], cut_coords=[-2, -10, -4], title='MKDA', vmax=max_conv)
###############################################################################
# ALE
# --------------------------------
kernel = nimare.meta.cbma.ALEKernel(ds.coordinates, ds.mask)
ale_res = kernel.transform(ids=ds.ids, n=20)
plot_stat_map(ale_res[2], cut_coords=[-2, -10, -4], title='ALE')
from nilearn.plotting import plot_stat_map
import nimare
###############################################################################
# Load data
# --------------------------------
database_file = op.join(nimare.utils.get_resource_path(),
'data/nidm_pain_dset_with_subpeaks.json')
db = nimare.dataset.Database(database_file)
ds = db.get_dataset()
###############################################################################
# KDA
# --------------------------------
kernel = nimare.meta.cbma.KDAKernel(ds.coordinates, ds.mask)
kda_res = kernel.transform(ids=ds.ids, r=10)
max_conv = np.max(kda_res[2].get_data())
plot_stat_map(kda_res[2], cut_coords=[-2, -10, -4], title='KDA', vmax=max_conv)
###############################################################################
# MKDA
# --------------------------------
kernel = nimare.meta.cbma.MKDAKernel(ds.coordinates, ds.mask)
mkda_res = kernel.transform(ids=ds.ids, r=10)
plot_stat_map(mkda_res[2], cut_coords=[-2, -10, -4], title='MKDA', vmax=max_conv)
###############################################################################
# ALE
# --------------------------------
kernel = nimare.meta.cbma.ALEKernel(ds.coordinates, ds.mask)
ale_res = kernel.transform(ids=ds.ids, n=20)
import matplotlib.pyplot as plt
from nilearn.plotting import plot_stat_map
import nimare
from nimare.tests.utils import get_test_data_path
###############################################################################
# Load Dataset
# --------------------------------------------------
dset_file = os.path.join(get_test_data_path(), 'nidm_pain_dset.json')
dset = nimare.dataset.Dataset(dset_file)
###############################################################################
# MKDA kernel maps
# --------------------------------------------------
kernel = nimare.meta.cbma.MKDAKernel(r=8)
mkda_r08 = kernel.transform(dset)
kernel = nimare.meta.cbma.MKDAKernel(r=9)
mkda_r09 = kernel.transform(dset)
kernel = nimare.meta.cbma.MKDAKernel(r=10)
mkda_r10 = kernel.transform(dset)
kernel = nimare.meta.cbma.MKDAKernel(r=11)
mkda_r11 = kernel.transform(dset)
fig, axes = plt.subplots(nrows=4, ncols=1, figsize=(10, 17.5))
plot_stat_map(mkda_r08[2], cut_coords=[-2, -10, -4],
title='r=8mm', vmax=2, axes=axes[0],
draw_cross=False)
plot_stat_map(mkda_r09[2], cut_coords=[-2, -10, -4],
title='r=9mm', vmax=2, axes=axes[1],
draw_cross=False)
plot_stat_map(mkda_r10[2], cut_coords=[-2, -10, -4],
plot_stat_map(mkda_r10[2], cut_coords=[-2, -10, -4],
title='r=10mm', vmax=2, axes=axes[2],
draw_cross=False)
plot_stat_map(mkda_r11[2], cut_coords=[-2, -10, -4],
title='r=11mm', vmax=2, axes=axes[3],
draw_cross=False)
fig.show()
###############################################################################
# Show different kernel types together
# --------------------------------------------------
kernel = nimare.meta.cbma.MKDAKernel(r=10)
mkda_res = kernel.transform(dset)
kernel = nimare.meta.cbma.KDAKernel(r=10)
kda_res = kernel.transform(dset)
kernel = nimare.meta.cbma.ALEKernel(n=20)
ale_res = kernel.transform(dset)
max_conv = np.max(kda_res[2].get_data())
plot_stat_map(ale_res[2], cut_coords=[-2, -10, -4], title='ALE')
plot_stat_map(mkda_res[2], cut_coords=[-2, -10, -4], title='MKDA', vmax=max_conv)
plot_stat_map(kda_res[2], cut_coords=[-2, -10, -4], title='KDA', vmax=max_conv)