How to use the nimare.dataset function in NiMARE

To help you get started, we’ve selected a few NiMARE examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neurostuff / NiMARE / examples / 03_annotation / run_gclda.py View on Github external
###############################################################################
# Start with the necessary imports
# --------------------------------
import os

import numpy as np
import nibabel as nib

import nimare
from nimare import annotate, decode
from nimare.tests.utils import get_test_data_path

###############################################################################
# Load dataset with abstracts
# ---------------------------
dset = nimare.dataset.Dataset.load(
    os.path.join(get_test_data_path(), 'neurosynth_laird_studies.pkl.gz'))

###############################################################################
# Generate term counts
# --------------------
counts_df = annotate.text.generate_counts(
    dset.texts, text_column='abstract', tfidf=False, max_df=0.99, min_df=0)

###############################################################################
# Run model
# ---------
# Five iterations will take ~10 minutes
model = annotate.topic.GCLDAModel(
    counts_df, dset.coordinates, mask=dset.masker.mask_img)
model.fit(n_iters=5, loglikely_freq=5)
model.save('gclda_model.pkl.gz')
github neurostuff / NiMARE / examples / 02_meta-analyses / run_cbmas.py View on Github external
import numpy as np
import pandas as pd
import nibabel as nib
from scipy.stats import t
from nilearn.masking import apply_mask
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)

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
# --------------------------------------------------
github neurostuff / NiMARE / examples / 03_annotation / run_lda.py View on Github external
using abstracts from Neurosynth.

"""
###############################################################################
# Start with the necessary imports
# --------------------------------
import os

import nimare
from nimare import annotate
from nimare.tests.utils import get_test_data_path

###############################################################################
# Load dataset with abstracts
# ---------------------------
dset = nimare.dataset.Dataset.load(
    os.path.join(get_test_data_path(), 'neurosynth_laird_studies.pkl.gz'))

###############################################################################
# Download MALLET
# ---------------
# LDAModel will do this automatically.
mallet_dir = nimare.extract.download_mallet()

###############################################################################
# Run model
# ---------
# Five iterations will take ~10 minutes
model = annotate.topic.LDAModel(dset.texts, text_column='abstract', n_iters=5)
model.fit()
model.save('lda_model.pkl.gz')
github neurostuff / NiMARE / examples / 02_meta-analyses / run_ibmas.py View on Github external
import nimare
from nimare.tests.utils import get_test_data_path
from nimare.meta.esma import fishers
from nimare.meta.ibma import (Fishers, Stouffers, WeightedStouffers,
                              RFX_GLM, FFX_GLM, ffx_glm)

###############################################################################
# Download data
# --------------------------------
dset_dir = nimare.extract.download_nidm_pain()

###############################################################################
# Load Dataset
# --------------------------------------------------
dset_file = os.path.join(get_test_data_path(), 'nidm_pain_dset.json')
dset = nimare.dataset.Dataset(dset_file)
dset.update_path(dset_dir)

mask_img = dset.masker.mask_img

logp_thresh = -np.log(.05)

###############################################################################
# Fisher's (using functions)
# --------------------------------------------------
# Get images for analysis
files = dset.get_images(imtype='z')
files = [f for f in files if f]
z_imgs = [nib.load(f) for f in files]
z_data = apply_mask(z_imgs, mask_img)
print('{0} studies found.'.format(z_data.shape[0]))
github neurostuff / NiMARE / examples / 02_meta-analyses / generate_ma_maps.py View on Github external
# Start with the necessary imports
# --------------------------------
import os

import numpy as np
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],
github neurostuff / NiMARE / examples / 01_meta-analyses / plot_generate_ma_maps.py View on Github external
"""
###############################################################################
# Start with the necessary imports
# --------------------------------
import os.path as op
import numpy as np
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)