nimare 0.4.2rc4__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.
Files changed (119) hide show
  1. benchmarks/__init__.py +0 -0
  2. benchmarks/bench_cbma.py +57 -0
  3. nimare/__init__.py +45 -0
  4. nimare/_version.py +21 -0
  5. nimare/annotate/__init__.py +21 -0
  6. nimare/annotate/cogat.py +213 -0
  7. nimare/annotate/gclda.py +924 -0
  8. nimare/annotate/lda.py +147 -0
  9. nimare/annotate/text.py +75 -0
  10. nimare/annotate/utils.py +87 -0
  11. nimare/base.py +217 -0
  12. nimare/cli.py +124 -0
  13. nimare/correct.py +462 -0
  14. nimare/dataset.py +685 -0
  15. nimare/decode/__init__.py +33 -0
  16. nimare/decode/base.py +115 -0
  17. nimare/decode/continuous.py +462 -0
  18. nimare/decode/discrete.py +753 -0
  19. nimare/decode/encode.py +110 -0
  20. nimare/decode/utils.py +44 -0
  21. nimare/diagnostics.py +510 -0
  22. nimare/estimator.py +139 -0
  23. nimare/extract/__init__.py +19 -0
  24. nimare/extract/extract.py +466 -0
  25. nimare/extract/utils.py +295 -0
  26. nimare/generate.py +331 -0
  27. nimare/io.py +635 -0
  28. nimare/meta/__init__.py +39 -0
  29. nimare/meta/cbma/__init__.py +6 -0
  30. nimare/meta/cbma/ale.py +951 -0
  31. nimare/meta/cbma/base.py +947 -0
  32. nimare/meta/cbma/mkda.py +1361 -0
  33. nimare/meta/cbmr.py +970 -0
  34. nimare/meta/ibma.py +1683 -0
  35. nimare/meta/kernel.py +501 -0
  36. nimare/meta/models.py +1199 -0
  37. nimare/meta/utils.py +494 -0
  38. nimare/nimads.py +492 -0
  39. nimare/reports/__init__.py +24 -0
  40. nimare/reports/base.py +664 -0
  41. nimare/reports/default.yml +123 -0
  42. nimare/reports/figures.py +651 -0
  43. nimare/reports/report.tpl +160 -0
  44. nimare/resources/__init__.py +1 -0
  45. nimare/resources/atlases/Harvard-Oxford-LICENSE +93 -0
  46. nimare/resources/atlases/HarvardOxford-cort-maxprob-thr25-2mm.nii.gz +0 -0
  47. nimare/resources/database_file_manifest.json +142 -0
  48. nimare/resources/english_spellings.csv +1738 -0
  49. nimare/resources/filenames.json +32 -0
  50. nimare/resources/neurosynth_laird_studies.json +58773 -0
  51. nimare/resources/neurosynth_stoplist.txt +396 -0
  52. nimare/resources/nidm_pain_dset.json +1349 -0
  53. nimare/resources/references.bib +541 -0
  54. nimare/resources/semantic_knowledge_children.txt +325 -0
  55. nimare/resources/semantic_relatedness_children.txt +249 -0
  56. nimare/resources/templates/MNI152_2x2x2_brainmask.nii.gz +0 -0
  57. nimare/resources/templates/tpl-MNI152NLin6Asym_res-01_T1w.nii.gz +0 -0
  58. nimare/resources/templates/tpl-MNI152NLin6Asym_res-01_desc-brain_mask.nii.gz +0 -0
  59. nimare/resources/templates/tpl-MNI152NLin6Asym_res-02_T1w.nii.gz +0 -0
  60. nimare/resources/templates/tpl-MNI152NLin6Asym_res-02_desc-brain_mask.nii.gz +0 -0
  61. nimare/results.py +225 -0
  62. nimare/stats.py +276 -0
  63. nimare/tests/__init__.py +1 -0
  64. nimare/tests/conftest.py +229 -0
  65. nimare/tests/data/amygdala_roi.nii.gz +0 -0
  66. nimare/tests/data/data-neurosynth_version-7_coordinates.tsv.gz +0 -0
  67. nimare/tests/data/data-neurosynth_version-7_metadata.tsv.gz +0 -0
  68. nimare/tests/data/data-neurosynth_version-7_vocab-terms_source-abstract_type-tfidf_features.npz +0 -0
  69. nimare/tests/data/data-neurosynth_version-7_vocab-terms_vocabulary.txt +100 -0
  70. nimare/tests/data/neurosynth_dset.json +2868 -0
  71. nimare/tests/data/neurosynth_laird_studies.json +58773 -0
  72. nimare/tests/data/nidm_pain_dset.json +1349 -0
  73. nimare/tests/data/nimads_annotation.json +1 -0
  74. nimare/tests/data/nimads_studyset.json +1 -0
  75. nimare/tests/data/test_baseline.txt +2 -0
  76. nimare/tests/data/test_pain_dataset.json +1278 -0
  77. nimare/tests/data/test_pain_dataset_multiple_contrasts.json +1242 -0
  78. nimare/tests/data/test_sleuth_file.txt +18 -0
  79. nimare/tests/data/test_sleuth_file2.txt +10 -0
  80. nimare/tests/data/test_sleuth_file3.txt +5 -0
  81. nimare/tests/data/test_sleuth_file4.txt +5 -0
  82. nimare/tests/data/test_sleuth_file5.txt +5 -0
  83. nimare/tests/test_annotate_cogat.py +32 -0
  84. nimare/tests/test_annotate_gclda.py +86 -0
  85. nimare/tests/test_annotate_lda.py +27 -0
  86. nimare/tests/test_dataset.py +99 -0
  87. nimare/tests/test_decode_continuous.py +132 -0
  88. nimare/tests/test_decode_discrete.py +92 -0
  89. nimare/tests/test_diagnostics.py +168 -0
  90. nimare/tests/test_estimator_performance.py +385 -0
  91. nimare/tests/test_extract.py +46 -0
  92. nimare/tests/test_generate.py +247 -0
  93. nimare/tests/test_io.py +240 -0
  94. nimare/tests/test_meta_ale.py +298 -0
  95. nimare/tests/test_meta_cbmr.py +295 -0
  96. nimare/tests/test_meta_ibma.py +240 -0
  97. nimare/tests/test_meta_kernel.py +209 -0
  98. nimare/tests/test_meta_mkda.py +234 -0
  99. nimare/tests/test_nimads.py +21 -0
  100. nimare/tests/test_reports.py +110 -0
  101. nimare/tests/test_stats.py +101 -0
  102. nimare/tests/test_transforms.py +272 -0
  103. nimare/tests/test_utils.py +200 -0
  104. nimare/tests/test_workflows.py +221 -0
  105. nimare/tests/utils.py +126 -0
  106. nimare/transforms.py +907 -0
  107. nimare/utils.py +1367 -0
  108. nimare/workflows/__init__.py +14 -0
  109. nimare/workflows/base.py +189 -0
  110. nimare/workflows/cbma.py +165 -0
  111. nimare/workflows/ibma.py +108 -0
  112. nimare/workflows/macm.py +77 -0
  113. nimare/workflows/misc.py +65 -0
  114. nimare-0.4.2rc4.dist-info/LICENSE +21 -0
  115. nimare-0.4.2rc4.dist-info/METADATA +124 -0
  116. nimare-0.4.2rc4.dist-info/RECORD +119 -0
  117. nimare-0.4.2rc4.dist-info/WHEEL +5 -0
  118. nimare-0.4.2rc4.dist-info/entry_points.txt +2 -0
  119. nimare-0.4.2rc4.dist-info/top_level.txt +2 -0
@@ -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
@@ -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