nimare 0.4.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- benchmarks/__init__.py +0 -0
- benchmarks/bench_cbma.py +57 -0
- nimare/__init__.py +45 -0
- nimare/_version.py +21 -0
- nimare/annotate/__init__.py +21 -0
- nimare/annotate/cogat.py +213 -0
- nimare/annotate/gclda.py +924 -0
- nimare/annotate/lda.py +147 -0
- nimare/annotate/text.py +75 -0
- nimare/annotate/utils.py +87 -0
- nimare/base.py +217 -0
- nimare/cli.py +124 -0
- nimare/correct.py +462 -0
- nimare/dataset.py +685 -0
- nimare/decode/__init__.py +33 -0
- nimare/decode/base.py +115 -0
- nimare/decode/continuous.py +462 -0
- nimare/decode/discrete.py +753 -0
- nimare/decode/encode.py +110 -0
- nimare/decode/utils.py +44 -0
- nimare/diagnostics.py +510 -0
- nimare/estimator.py +139 -0
- nimare/extract/__init__.py +19 -0
- nimare/extract/extract.py +466 -0
- nimare/extract/utils.py +295 -0
- nimare/generate.py +331 -0
- nimare/io.py +667 -0
- nimare/meta/__init__.py +39 -0
- nimare/meta/cbma/__init__.py +6 -0
- nimare/meta/cbma/ale.py +951 -0
- nimare/meta/cbma/base.py +947 -0
- nimare/meta/cbma/mkda.py +1361 -0
- nimare/meta/cbmr.py +970 -0
- nimare/meta/ibma.py +1683 -0
- nimare/meta/kernel.py +501 -0
- nimare/meta/models.py +1199 -0
- nimare/meta/utils.py +494 -0
- nimare/nimads.py +492 -0
- nimare/reports/__init__.py +24 -0
- nimare/reports/base.py +664 -0
- nimare/reports/default.yml +123 -0
- nimare/reports/figures.py +651 -0
- nimare/reports/report.tpl +160 -0
- nimare/resources/__init__.py +1 -0
- nimare/resources/atlases/Harvard-Oxford-LICENSE +93 -0
- nimare/resources/atlases/HarvardOxford-cort-maxprob-thr25-2mm.nii.gz +0 -0
- nimare/resources/database_file_manifest.json +142 -0
- nimare/resources/english_spellings.csv +1738 -0
- nimare/resources/filenames.json +32 -0
- nimare/resources/neurosynth_laird_studies.json +58773 -0
- nimare/resources/neurosynth_stoplist.txt +396 -0
- nimare/resources/nidm_pain_dset.json +1349 -0
- nimare/resources/references.bib +541 -0
- nimare/resources/semantic_knowledge_children.txt +325 -0
- nimare/resources/semantic_relatedness_children.txt +249 -0
- nimare/resources/templates/MNI152_2x2x2_brainmask.nii.gz +0 -0
- nimare/resources/templates/tpl-MNI152NLin6Asym_res-01_T1w.nii.gz +0 -0
- nimare/resources/templates/tpl-MNI152NLin6Asym_res-01_desc-brain_mask.nii.gz +0 -0
- nimare/resources/templates/tpl-MNI152NLin6Asym_res-02_T1w.nii.gz +0 -0
- nimare/resources/templates/tpl-MNI152NLin6Asym_res-02_desc-brain_mask.nii.gz +0 -0
- nimare/results.py +225 -0
- nimare/stats.py +276 -0
- nimare/tests/__init__.py +1 -0
- nimare/tests/conftest.py +229 -0
- nimare/tests/data/amygdala_roi.nii.gz +0 -0
- nimare/tests/data/data-neurosynth_version-7_coordinates.tsv.gz +0 -0
- nimare/tests/data/data-neurosynth_version-7_metadata.tsv.gz +0 -0
- nimare/tests/data/data-neurosynth_version-7_vocab-terms_source-abstract_type-tfidf_features.npz +0 -0
- nimare/tests/data/data-neurosynth_version-7_vocab-terms_vocabulary.txt +100 -0
- nimare/tests/data/neurosynth_dset.json +2868 -0
- nimare/tests/data/neurosynth_laird_studies.json +58773 -0
- nimare/tests/data/nidm_pain_dset.json +1349 -0
- nimare/tests/data/nimads_annotation.json +1 -0
- nimare/tests/data/nimads_studyset.json +1 -0
- nimare/tests/data/test_baseline.txt +2 -0
- nimare/tests/data/test_pain_dataset.json +1278 -0
- nimare/tests/data/test_pain_dataset_multiple_contrasts.json +1242 -0
- nimare/tests/data/test_sleuth_file.txt +18 -0
- nimare/tests/data/test_sleuth_file2.txt +10 -0
- nimare/tests/data/test_sleuth_file3.txt +5 -0
- nimare/tests/data/test_sleuth_file4.txt +5 -0
- nimare/tests/data/test_sleuth_file5.txt +5 -0
- nimare/tests/test_annotate_cogat.py +32 -0
- nimare/tests/test_annotate_gclda.py +86 -0
- nimare/tests/test_annotate_lda.py +27 -0
- nimare/tests/test_dataset.py +99 -0
- nimare/tests/test_decode_continuous.py +132 -0
- nimare/tests/test_decode_discrete.py +92 -0
- nimare/tests/test_diagnostics.py +168 -0
- nimare/tests/test_estimator_performance.py +385 -0
- nimare/tests/test_extract.py +46 -0
- nimare/tests/test_generate.py +247 -0
- nimare/tests/test_io.py +294 -0
- nimare/tests/test_meta_ale.py +298 -0
- nimare/tests/test_meta_cbmr.py +295 -0
- nimare/tests/test_meta_ibma.py +240 -0
- nimare/tests/test_meta_kernel.py +209 -0
- nimare/tests/test_meta_mkda.py +234 -0
- nimare/tests/test_nimads.py +21 -0
- nimare/tests/test_reports.py +110 -0
- nimare/tests/test_stats.py +101 -0
- nimare/tests/test_transforms.py +272 -0
- nimare/tests/test_utils.py +200 -0
- nimare/tests/test_workflows.py +221 -0
- nimare/tests/utils.py +126 -0
- nimare/transforms.py +907 -0
- nimare/utils.py +1367 -0
- nimare/workflows/__init__.py +14 -0
- nimare/workflows/base.py +189 -0
- nimare/workflows/cbma.py +165 -0
- nimare/workflows/ibma.py +108 -0
- nimare/workflows/macm.py +77 -0
- nimare/workflows/misc.py +65 -0
- nimare-0.4.2.dist-info/LICENSE +21 -0
- nimare-0.4.2.dist-info/METADATA +124 -0
- nimare-0.4.2.dist-info/RECORD +119 -0
- nimare-0.4.2.dist-info/WHEEL +5 -0
- nimare-0.4.2.dist-info/entry_points.txt +2 -0
- nimare-0.4.2.dist-info/top_level.txt +2 -0
nimare/tests/conftest.py
ADDED
@@ -0,0 +1,229 @@
|
|
1
|
+
"""Generate fixtures for tests."""
|
2
|
+
|
3
|
+
import json
|
4
|
+
import os
|
5
|
+
from shutil import copyfile
|
6
|
+
|
7
|
+
import nibabel as nib
|
8
|
+
import numpy as np
|
9
|
+
import pytest
|
10
|
+
from nilearn.image import resample_img
|
11
|
+
from requests import request
|
12
|
+
|
13
|
+
import nimare
|
14
|
+
from nimare.generate import create_coordinate_dataset
|
15
|
+
from nimare.tests.utils import get_test_data_path
|
16
|
+
from nimare.utils import get_resource_path
|
17
|
+
|
18
|
+
# Only enable the following once in a while for a check for SettingWithCopyWarnings
|
19
|
+
# pd.options.mode.chained_assignment = "raise"
|
20
|
+
|
21
|
+
|
22
|
+
@pytest.fixture(scope="session")
|
23
|
+
def testdata_ibma(tmp_path_factory):
|
24
|
+
"""Load data from dataset into global variables."""
|
25
|
+
tmpdir = tmp_path_factory.mktemp("testdata_ibma")
|
26
|
+
|
27
|
+
# Load dataset
|
28
|
+
dset_file = os.path.join(get_test_data_path(), "test_pain_dataset.json")
|
29
|
+
dset_dir = os.path.join(get_test_data_path(), "test_pain_dataset")
|
30
|
+
mask_file = os.path.join(dset_dir, "mask.nii.gz")
|
31
|
+
dset = nimare.dataset.Dataset(dset_file, mask=mask_file)
|
32
|
+
dset.update_path(dset_dir)
|
33
|
+
# Move image contents of Dataset to temporary directory
|
34
|
+
for c in dset.images.columns:
|
35
|
+
if c.endswith("__relative"):
|
36
|
+
continue
|
37
|
+
for f in dset.images[c].values:
|
38
|
+
if (f is None) or not os.path.isfile(f):
|
39
|
+
continue
|
40
|
+
new_f = f.replace(
|
41
|
+
dset_dir.rstrip(os.path.sep), str(tmpdir.absolute()).rstrip(os.path.sep)
|
42
|
+
)
|
43
|
+
dirname = os.path.dirname(new_f)
|
44
|
+
if not os.path.isdir(dirname):
|
45
|
+
os.makedirs(dirname)
|
46
|
+
copyfile(f, new_f)
|
47
|
+
dset.update_path(tmpdir)
|
48
|
+
return dset
|
49
|
+
|
50
|
+
|
51
|
+
@pytest.fixture(scope="session")
|
52
|
+
def testdata_cbma():
|
53
|
+
"""Generate coordinate-based dataset for tests."""
|
54
|
+
dset_file = os.path.join(get_test_data_path(), "test_pain_dataset.json")
|
55
|
+
dset = nimare.dataset.Dataset(dset_file)
|
56
|
+
|
57
|
+
# Only retain one peak in each study in coordinates
|
58
|
+
# Otherwise centers of mass will be obscured in kernel tests by overlapping
|
59
|
+
# kernels
|
60
|
+
dset.coordinates = dset.coordinates.drop_duplicates(subset=["id"])
|
61
|
+
return dset
|
62
|
+
|
63
|
+
|
64
|
+
@pytest.fixture(scope="session")
|
65
|
+
def testdata_cbma_full():
|
66
|
+
"""Generate more complete coordinate-based dataset for tests.
|
67
|
+
|
68
|
+
Same as above, except returns all coords, not just one per study.
|
69
|
+
"""
|
70
|
+
dset_file = os.path.join(get_test_data_path(), "test_pain_dataset.json")
|
71
|
+
dset = nimare.dataset.Dataset(dset_file)
|
72
|
+
return dset
|
73
|
+
|
74
|
+
|
75
|
+
@pytest.fixture(scope="session")
|
76
|
+
def testdata_cbmr_simulated():
|
77
|
+
"""Simulate coordinate-based dataset for tests."""
|
78
|
+
# simulate
|
79
|
+
ground_truth_foci, dset = create_coordinate_dataset(
|
80
|
+
foci=10, sample_size=(20, 40), n_studies=1000, seed=100
|
81
|
+
)
|
82
|
+
# set up group columns: diagnosis & drug_status
|
83
|
+
n_rows = dset.annotations.shape[0]
|
84
|
+
dset.annotations["diagnosis"] = [
|
85
|
+
"schizophrenia" if i % 2 == 0 else "depression" for i in range(n_rows)
|
86
|
+
]
|
87
|
+
dset.annotations["drug_status"] = ["Yes" if i % 2 == 0 else "No" for i in range(n_rows)]
|
88
|
+
dset.annotations["drug_status"] = (
|
89
|
+
dset.annotations["drug_status"].sample(frac=1).reset_index(drop=True)
|
90
|
+
) # random shuffle drug_status column
|
91
|
+
# set up moderators: sample sizes & avg_age
|
92
|
+
dset.annotations["sample_sizes"] = [dset.metadata.sample_sizes[i][0] for i in range(n_rows)]
|
93
|
+
dset.annotations["avg_age"] = np.arange(n_rows)
|
94
|
+
dset.annotations["schizophrenia_subtype"] = [
|
95
|
+
"type1",
|
96
|
+
"type2",
|
97
|
+
"type3",
|
98
|
+
"type4",
|
99
|
+
"type5",
|
100
|
+
] * int(n_rows / 5)
|
101
|
+
dset.annotations["schizophrenia_subtype"] = (
|
102
|
+
dset.annotations["schizophrenia_subtype"].sample(frac=1).reset_index(drop=True)
|
103
|
+
) # random shuffle drug_status column
|
104
|
+
|
105
|
+
return dset
|
106
|
+
|
107
|
+
|
108
|
+
@pytest.fixture(scope="session")
|
109
|
+
def testdata_laird():
|
110
|
+
"""Load data from dataset into global variables."""
|
111
|
+
testdata_laird = nimare.dataset.Dataset(
|
112
|
+
os.path.join(get_test_data_path(), "neurosynth_laird_studies.json")
|
113
|
+
)
|
114
|
+
return testdata_laird
|
115
|
+
|
116
|
+
|
117
|
+
@pytest.fixture(scope="session")
|
118
|
+
def mni_mask():
|
119
|
+
"""Load MNI mask for testing."""
|
120
|
+
return nib.load(
|
121
|
+
os.path.join(get_resource_path(), "templates", "MNI152_2x2x2_brainmask.nii.gz")
|
122
|
+
)
|
123
|
+
|
124
|
+
|
125
|
+
@pytest.fixture(scope="session")
|
126
|
+
def roi_img():
|
127
|
+
"""Load MNI mask for testing."""
|
128
|
+
return nib.load(os.path.join(get_test_data_path(), "amygdala_roi.nii.gz"))
|
129
|
+
|
130
|
+
|
131
|
+
@pytest.fixture(scope="session")
|
132
|
+
def testdata_ibma_resample(tmp_path_factory):
|
133
|
+
"""Create dataset for image-based resampling tests."""
|
134
|
+
tmpdir = tmp_path_factory.mktemp("testdata_ibma_resample")
|
135
|
+
|
136
|
+
# Load dataset
|
137
|
+
dset_file = os.path.join(get_test_data_path(), "test_pain_dataset.json")
|
138
|
+
dset_dir = os.path.join(get_test_data_path(), "test_pain_dataset")
|
139
|
+
mask_file = os.path.join(dset_dir, "mask.nii.gz")
|
140
|
+
dset = nimare.dataset.Dataset(dset_file, mask=mask_file)
|
141
|
+
dset.update_path(dset_dir)
|
142
|
+
|
143
|
+
# create reproducible random number generator for resampling
|
144
|
+
rng = np.random.default_rng(seed=123)
|
145
|
+
# Move image contents of Dataset to temporary directory
|
146
|
+
for c in dset.images.columns:
|
147
|
+
if c.endswith("__relative"):
|
148
|
+
continue
|
149
|
+
|
150
|
+
for f in dset.images[c].values:
|
151
|
+
if (f is None) or not os.path.isfile(f):
|
152
|
+
continue
|
153
|
+
|
154
|
+
new_f = f.replace(
|
155
|
+
dset_dir.rstrip(os.path.sep), str(tmpdir.absolute()).rstrip(os.path.sep)
|
156
|
+
)
|
157
|
+
dirname = os.path.dirname(new_f)
|
158
|
+
if not os.path.isdir(dirname):
|
159
|
+
os.makedirs(dirname)
|
160
|
+
|
161
|
+
# create random affine to make images different shapes
|
162
|
+
affine = np.eye(3)
|
163
|
+
np.fill_diagonal(affine, rng.choice([1, 2, 3]))
|
164
|
+
img = resample_img(
|
165
|
+
nib.load(f),
|
166
|
+
target_affine=affine,
|
167
|
+
interpolation="linear",
|
168
|
+
clip=True,
|
169
|
+
)
|
170
|
+
nib.save(img, new_f)
|
171
|
+
dset.update_path(tmpdir)
|
172
|
+
return dset
|
173
|
+
|
174
|
+
|
175
|
+
@pytest.fixture(scope="session")
|
176
|
+
def example_nimads_studyset():
|
177
|
+
"""Download/lookup example NiMADS studyset."""
|
178
|
+
out_file = os.path.join(get_test_data_path(), "nimads_studyset.json")
|
179
|
+
if not os.path.isfile(out_file):
|
180
|
+
url = "https://neurostore.org/api/studysets/Cv2LLUqG76W9?nested=true"
|
181
|
+
response = request("GET", url)
|
182
|
+
with open(out_file, "wb") as f:
|
183
|
+
f.write(response.content)
|
184
|
+
with open(out_file, "r") as f:
|
185
|
+
studyset = json.load(f)
|
186
|
+
return studyset
|
187
|
+
|
188
|
+
|
189
|
+
@pytest.fixture(scope="session")
|
190
|
+
def example_nimads_annotation():
|
191
|
+
"""Download/lookup example NiMADS annotation."""
|
192
|
+
out_file = os.path.join(get_test_data_path(), "nimads_annotation.json")
|
193
|
+
if not os.path.isfile(out_file):
|
194
|
+
url = "https://neurostore.org/api/annotations/76PyNqoTNEsE"
|
195
|
+
response = request("GET", url)
|
196
|
+
with open(out_file, "wb") as f:
|
197
|
+
f.write(response.content)
|
198
|
+
with open(out_file, "r") as f:
|
199
|
+
annotation = json.load(f)
|
200
|
+
return annotation
|
201
|
+
|
202
|
+
|
203
|
+
@pytest.fixture(scope="session")
|
204
|
+
def testdata_ibma_multiple_contrasts(tmp_path_factory):
|
205
|
+
"""Load data from dataset into global variables."""
|
206
|
+
tmpdir = tmp_path_factory.mktemp("testdata_ibma_multiple_contrasts")
|
207
|
+
|
208
|
+
# Load dataset
|
209
|
+
dset_file = os.path.join(get_test_data_path(), "test_pain_dataset_multiple_contrasts.json")
|
210
|
+
dset_dir = os.path.join(get_test_data_path(), "test_pain_dataset")
|
211
|
+
mask_file = os.path.join(dset_dir, "mask.nii.gz")
|
212
|
+
dset = nimare.dataset.Dataset(dset_file, mask=mask_file)
|
213
|
+
dset.update_path(dset_dir)
|
214
|
+
# Move image contents of Dataset to temporary directory
|
215
|
+
for c in dset.images.columns:
|
216
|
+
if c.endswith("__relative"):
|
217
|
+
continue
|
218
|
+
for f in dset.images[c].values:
|
219
|
+
if (f is None) or not os.path.isfile(f):
|
220
|
+
continue
|
221
|
+
new_f = f.replace(
|
222
|
+
dset_dir.rstrip(os.path.sep), str(tmpdir.absolute()).rstrip(os.path.sep)
|
223
|
+
)
|
224
|
+
dirname = os.path.dirname(new_f)
|
225
|
+
if not os.path.isdir(dirname):
|
226
|
+
os.makedirs(dirname)
|
227
|
+
copyfile(f, new_f)
|
228
|
+
dset.update_path(tmpdir)
|
229
|
+
return dset
|
Binary file
|
Binary file
|
Binary file
|
nimare/tests/data/data-neurosynth_version-7_vocab-terms_source-abstract_type-tfidf_features.npz
ADDED
Binary file
|
@@ -0,0 +1,100 @@
|
|
1
|
+
001
|
2
|
+
01
|
3
|
+
05
|
4
|
+
10
|
5
|
+
100
|
6
|
+
11
|
7
|
+
12
|
8
|
+
12 healthy
|
9
|
+
13
|
10
|
+
14
|
11
|
+
14 healthy
|
12
|
+
15
|
13
|
+
15 healthy
|
14
|
+
16
|
15
|
+
16 healthy
|
16
|
+
17
|
17
|
+
18
|
18
|
+
18 healthy
|
19
|
+
19
|
20
|
+
20
|
21
|
+
20 healthy
|
22
|
+
200
|
23
|
+
2014
|
24
|
+
21
|
25
|
+
22
|
26
|
+
23
|
27
|
+
24
|
28
|
+
25
|
29
|
+
26
|
30
|
+
27
|
31
|
+
28
|
32
|
+
29
|
33
|
+
30
|
34
|
+
31
|
35
|
+
32
|
36
|
+
33
|
37
|
+
34
|
38
|
+
35
|
39
|
+
36
|
40
|
+
37
|
41
|
+
38
|
42
|
+
39
|
43
|
+
3d
|
44
|
+
3t
|
45
|
+
40
|
46
|
+
41
|
47
|
+
42
|
48
|
+
43
|
49
|
+
44
|
50
|
+
45
|
51
|
+
46
|
52
|
+
47
|
53
|
+
48
|
54
|
+
49
|
55
|
+
50
|
56
|
+
60
|
57
|
+
70
|
58
|
+
75
|
59
|
+
80
|
60
|
+
90
|
61
|
+
aberrant
|
62
|
+
abilities
|
63
|
+
ability
|
64
|
+
able
|
65
|
+
abnormal
|
66
|
+
abnormalities
|
67
|
+
abnormality
|
68
|
+
absence
|
69
|
+
absent
|
70
|
+
abstract
|
71
|
+
abuse
|
72
|
+
acc
|
73
|
+
access
|
74
|
+
accompanied
|
75
|
+
accordance
|
76
|
+
according
|
77
|
+
accordingly
|
78
|
+
account
|
79
|
+
accounted
|
80
|
+
accounts
|
81
|
+
accumbens
|
82
|
+
accuracy
|
83
|
+
accurate
|
84
|
+
accurately
|
85
|
+
achieve
|
86
|
+
achieved
|
87
|
+
acoustic
|
88
|
+
acquired
|
89
|
+
acquisition
|
90
|
+
act
|
91
|
+
action
|
92
|
+
action observation
|
93
|
+
actions
|
94
|
+
activate
|
95
|
+
activates
|
96
|
+
activations
|
97
|
+
active
|
98
|
+
actively
|
99
|
+
activities
|
100
|
+
acts
|