compose-runner 0.14.0__tar.gz → 0.14.2__tar.gz
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.
- compose_runner-0.14.2/.gitignore +15 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/PKG-INFO +2 -2
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/_version.py +2 -2
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/coverage.py +25 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/images.py +46 -1
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/run.py +72 -7
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/test_apply_filter.py +8 -3
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/test_coverage.py +62 -15
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/test_ibma_dispatch.py +87 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/test_ibma_end_to_end.py +36 -17
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/test_images.py +23 -2
- {compose_runner-0.14.0 → compose_runner-0.14.2}/pyproject.toml +1 -7
- compose_runner-0.14.0/.gitignore +0 -5
- compose_runner-0.14.0/docs/ibma.md +0 -229
- {compose_runner-0.14.0 → compose_runner-0.14.2}/Dockerfile +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/LICENSE +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/README.md +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/aws_lambda/.dockerignore +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/aws_lambda/Dockerfile +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/__init__.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/aws_lambda/__init__.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/aws_lambda/common.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/aws_lambda/cost_check_handler.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/aws_lambda/log_poll_handler.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/aws_lambda/results_handler.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/aws_lambda/run_handler.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/aws_lambda/status_handler.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/cli.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/ecs_task.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/metadata.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/sentry.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_cli/test_cli.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_lambda_handlers/test_select_task_size_uses_large_for_montecarlo.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_lambda_handlers/test_select_task_size_uses_standard_for_fdr.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_run/test_download_bundle.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_run/test_download_bundle_dev_meta_analysis_shape.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_run/test_download_bundle_dev_string_id_shape.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_run/test_download_bundle_production_cached_snapshot_shape.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_run/test_incorrect_id.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_run/test_missing_column_workflow.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_run/test_mkdachis_comparison_workflow.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_run/test_mkdachis_no_corrector_workflow.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_run/test_run_database_workflow.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_run/test_run_group_comparison_workflow.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_run/test_run_string_group_comparison_workflow.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/cassettes/test_run/test_run_workflow.yaml +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/conftest.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/test_cli.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/test_ecs_task.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/test_lambda_handlers.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/test_metadata.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/test_reference_studyset.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/test_run.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/infra/cdk/app.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/infra/cdk/cdk.json +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/infra/cdk/requirements.txt +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/infra/cdk/stacks/__init__.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/infra/cdk/stacks/compose_runner_stack.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/infra/cdk/stacks/image_repositories_stack.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/infra/cdk/tests/test_compose_runner_stack.py +0 -0
- {compose_runner-0.14.0 → compose_runner-0.14.2}/scripts/simulate_ibma_bundle.py +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.nsc
|
|
2
|
+
.runner
|
|
3
|
+
.pytest_cache
|
|
4
|
+
_version.py
|
|
5
|
+
__pycache__
|
|
6
|
+
|
|
7
|
+
# Working directories of scripts/staging_matrix
|
|
8
|
+
scripts/staging_matrix/raw/
|
|
9
|
+
scripts/staging_matrix/bundles/
|
|
10
|
+
scripts/staging_matrix/specs/
|
|
11
|
+
scripts/staging_matrix/images/
|
|
12
|
+
scripts/staging_matrix/runs/
|
|
13
|
+
scripts/staging_matrix/probes/
|
|
14
|
+
scripts/staging_matrix/*.log
|
|
15
|
+
scripts/staging_matrix/prefetch_report.json
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: compose-runner
|
|
3
|
-
Version: 0.14.
|
|
3
|
+
Version: 0.14.2
|
|
4
4
|
Summary: A package for running neurosynth-compose analyses
|
|
5
5
|
Project-URL: Repository, https://github.com/neurostuff/compose-runner
|
|
6
6
|
Author-email: James Kent <jamesdkent21@gmail.com>
|
|
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
12
12
|
Requires-Dist: click
|
|
13
13
|
Requires-Dist: neurostore-sdk>=1.1
|
|
14
14
|
Requires-Dist: neurosynth-compose-sdk>=1.2
|
|
15
|
-
Requires-Dist: nimare[parquet]==0.21.
|
|
15
|
+
Requires-Dist: nimare[parquet]==0.21.0
|
|
16
16
|
Requires-Dist: numpy
|
|
17
17
|
Requires-Dist: requests
|
|
18
18
|
Requires-Dist: sentry-sdk
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '0.14.
|
|
22
|
-
__version_tuple__ = version_tuple = (0, 14,
|
|
21
|
+
__version__ = version = '0.14.2'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 14, 2)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -262,6 +262,31 @@ def describe_result(results, studyset, dropped_maps=None):
|
|
|
262
262
|
)
|
|
263
263
|
|
|
264
264
|
|
|
265
|
+
def describe_estimator(studyset, estimator, dropped_maps=None):
|
|
266
|
+
"""Report coverage from an estimator that collected its inputs but failed.
|
|
267
|
+
|
|
268
|
+
Between ``describe_result``, which needs a ``MetaResult``, and
|
|
269
|
+
``describe_submission``, which assumes nothing was transformed: a fit that
|
|
270
|
+
raises after ``_preprocess_input`` has both answers on the estimator
|
|
271
|
+
already, and describing it as an untransformed submission would report
|
|
272
|
+
every converted analysis as one NiMARE could not convert.
|
|
273
|
+
"""
|
|
274
|
+
fitted_ids = {
|
|
275
|
+
str(image_id)
|
|
276
|
+
for image_id in (getattr(estimator, "inputs_", None) or {}).get("id", [])
|
|
277
|
+
}
|
|
278
|
+
transformed = getattr(estimator, "dataset", None)
|
|
279
|
+
|
|
280
|
+
return _build(
|
|
281
|
+
studyset,
|
|
282
|
+
estimator,
|
|
283
|
+
before=_held_types(studyset.images),
|
|
284
|
+
after=_held_types(getattr(transformed, "images", None)),
|
|
285
|
+
fitted_ids=fitted_ids,
|
|
286
|
+
dropped_maps=dropped_maps,
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
|
|
265
290
|
def describe_submission(studyset, estimator, dropped_maps=None):
|
|
266
291
|
"""Report what was submitted, for when the fit never got far enough to ask.
|
|
267
292
|
|
|
@@ -13,6 +13,7 @@ from concurrent.futures import ThreadPoolExecutor
|
|
|
13
13
|
from pathlib import Path
|
|
14
14
|
from urllib.parse import urlparse
|
|
15
15
|
|
|
16
|
+
import nibabel as nib
|
|
16
17
|
import requests
|
|
17
18
|
|
|
18
19
|
LGR = logging.getLogger(__name__)
|
|
@@ -238,7 +239,12 @@ def download_studyset_images(
|
|
|
238
239
|
def _fetch(job):
|
|
239
240
|
_, image, _, source_url = job
|
|
240
241
|
destination = image_dir / _local_name(image, source_url)
|
|
241
|
-
|
|
242
|
+
# Absolute: NiMARE resolves a relative image reference against the
|
|
243
|
+
# studyset's base path, which is this same directory, so a relative path
|
|
244
|
+
# would be joined onto itself.
|
|
245
|
+
return _download(
|
|
246
|
+
source_url, destination, session=session, timeout=timeout
|
|
247
|
+
).resolve()
|
|
242
248
|
|
|
243
249
|
with ThreadPoolExecutor(max_workers=max_workers) as pool:
|
|
244
250
|
for job, result in zip(jobs, pool.map(_safe(_fetch), jobs)):
|
|
@@ -246,6 +252,15 @@ def download_studyset_images(
|
|
|
246
252
|
resolved[id(job[1])] = result
|
|
247
253
|
|
|
248
254
|
attempted = {id(image) for _, image, _, _ in jobs}
|
|
255
|
+
# A file that does not parse as a NIfTI would otherwise reach nibabel from
|
|
256
|
+
# inside the fit, where nothing attributes it to the analysis it came from.
|
|
257
|
+
unusable = {
|
|
258
|
+
key: reason
|
|
259
|
+
for key, reason in (
|
|
260
|
+
(key, _unusable_reason(path)) for key, path in resolved.items()
|
|
261
|
+
)
|
|
262
|
+
if reason is not None
|
|
263
|
+
}
|
|
249
264
|
for study in studyset_dict.get("studies") or []:
|
|
250
265
|
for analysis in study.get("analyses") or []:
|
|
251
266
|
kept = []
|
|
@@ -255,6 +270,9 @@ def download_studyset_images(
|
|
|
255
270
|
if id(image) in attempted:
|
|
256
271
|
_record(analysis, image, "could not be downloaded")
|
|
257
272
|
continue
|
|
273
|
+
if id(image) in unusable:
|
|
274
|
+
_record(analysis, image, unusable[id(image)])
|
|
275
|
+
continue
|
|
258
276
|
image = dict(image)
|
|
259
277
|
image["filename"] = str(local_path)
|
|
260
278
|
image["url"] = str(local_path)
|
|
@@ -275,6 +293,33 @@ def download_studyset_images(
|
|
|
275
293
|
return studyset_dict, {k: tuple(v) for k, v in dropped.items()}
|
|
276
294
|
|
|
277
295
|
|
|
296
|
+
#: Verdicts from :func:`_unusable_reason`, which reads a whole volume and is
|
|
297
|
+
#: asked the same question once per analysis the map is reached from.
|
|
298
|
+
_UNUSABLE_CACHE = {}
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def _unusable_reason(path):
|
|
302
|
+
"""Why a downloaded map cannot be used, or None if it can.
|
|
303
|
+
|
|
304
|
+
Only unreadable files. A map that parses but holds no finite non-zero voxel
|
|
305
|
+
is NiMARE's to drop, and it does; a file that is not a NIfTI at all reaches
|
|
306
|
+
nibabel mid-fit instead, which is neither caught nor attributed there.
|
|
307
|
+
"""
|
|
308
|
+
key = str(path)
|
|
309
|
+
if key in _UNUSABLE_CACHE:
|
|
310
|
+
return _UNUSABLE_CACHE[key]
|
|
311
|
+
|
|
312
|
+
try:
|
|
313
|
+
nib.load(key)
|
|
314
|
+
except Exception as exc: # noqa: BLE001 - an unreadable map is just dropped
|
|
315
|
+
reason = f"could not be read as a NIfTI ({exc.__class__.__name__})"
|
|
316
|
+
else:
|
|
317
|
+
reason = None
|
|
318
|
+
|
|
319
|
+
_UNUSABLE_CACHE[key] = reason
|
|
320
|
+
return reason
|
|
321
|
+
|
|
322
|
+
|
|
278
323
|
def _safe(func):
|
|
279
324
|
"""Wrap a fetch so one failure drops an image instead of the whole run."""
|
|
280
325
|
|
|
@@ -209,10 +209,14 @@ class Runner:
|
|
|
209
209
|
self.nv_key = nv_key # neurovault key to upload to neurovault
|
|
210
210
|
|
|
211
211
|
# result directory
|
|
212
|
+
# Resolved: the studyset records where its downloaded maps are, and
|
|
213
|
+
# NiMARE treats a relative reference as relative to the studyset's base
|
|
214
|
+
# path -- so a relative result_dir has the base path prepended to a path
|
|
215
|
+
# that already contains it, and every map goes missing.
|
|
212
216
|
if result_dir is None:
|
|
213
217
|
self.result_dir = Path.cwd() / "results"
|
|
214
218
|
else:
|
|
215
|
-
self.result_dir = Path(result_dir)
|
|
219
|
+
self.result_dir = Path(result_dir).expanduser().resolve()
|
|
216
220
|
|
|
217
221
|
# Where image-based meta-analyses stage their maps. Kept alongside the
|
|
218
222
|
# results so it doubles as a cache across reruns, and so NiMARE has
|
|
@@ -584,7 +588,14 @@ class Runner:
|
|
|
584
588
|
lost along with the study grouping the dependence correction needs.
|
|
585
589
|
"""
|
|
586
590
|
column = self.cached_specification["filter"]
|
|
587
|
-
|
|
591
|
+
note_keys = (self.cached_annotation or {}).get("note_keys") or {}
|
|
592
|
+
if column not in note_keys:
|
|
593
|
+
# Otherwise a bare KeyError, which names the column but nothing else.
|
|
594
|
+
raise ValueError(
|
|
595
|
+
f"The specification selects analyses by {column!r}, which this "
|
|
596
|
+
f"annotation does not record. It has: {sorted(note_keys)}."
|
|
597
|
+
)
|
|
598
|
+
column_type = note_keys[column]
|
|
588
599
|
conditions = self.cached_specification.get("conditions", [])
|
|
589
600
|
database_studyset = self.cached_specification.get("database_studyset")
|
|
590
601
|
weights = self.cached_specification.get("weights", [])
|
|
@@ -610,6 +621,19 @@ class Runner:
|
|
|
610
621
|
else:
|
|
611
622
|
raise ValueError(f"Column type {column_type} not supported.")
|
|
612
623
|
|
|
624
|
+
if not analysis_ids:
|
|
625
|
+
# NiMARE would report this as a missing image type, which sends
|
|
626
|
+
# whoever reads it looking at the maps rather than at the selection.
|
|
627
|
+
raise ValueError(
|
|
628
|
+
f"No analysis is selected: none of the {len(analysis_id)} "
|
|
629
|
+
f"analyses in the studyset has a {column!r} note that "
|
|
630
|
+
+ (
|
|
631
|
+
"is true."
|
|
632
|
+
if column_type == "boolean"
|
|
633
|
+
else f"equals {weight_conditions[1]!r}."
|
|
634
|
+
)
|
|
635
|
+
)
|
|
636
|
+
|
|
613
637
|
first_studyset = studyset.slice(analyses=analysis_ids)
|
|
614
638
|
if combine:
|
|
615
639
|
first_studyset = first_studyset.combine_analyses()
|
|
@@ -746,6 +770,24 @@ class Runner:
|
|
|
746
770
|
self.staged_studyset = apply_sample_sizes(staged, self.cached_annotation)
|
|
747
771
|
return self.staged_studyset
|
|
748
772
|
|
|
773
|
+
def _reject_image_based_comparison(self):
|
|
774
|
+
"""Refuse an image-based group comparison while it is still cheap.
|
|
775
|
+
|
|
776
|
+
``run_meta_analysis`` catches this too, but only after the maps are
|
|
777
|
+
staged and, for a database comparison, after the whole reference
|
|
778
|
+
studyset has been downloaded -- tens of megabytes to reach a conclusion
|
|
779
|
+
the specification already carried.
|
|
780
|
+
"""
|
|
781
|
+
spec = self.cached_specification or {}
|
|
782
|
+
if len(spec.get("conditions") or []) <= 1 and not spec.get("database_studyset"):
|
|
783
|
+
return
|
|
784
|
+
raise ValueError(
|
|
785
|
+
"A group comparison was requested, but no image-based estimator "
|
|
786
|
+
f"supports one. {spec['estimator']['type']} takes a single studyset. "
|
|
787
|
+
"Choose a single-group selection, or a pairwise coordinate-based "
|
|
788
|
+
"estimator."
|
|
789
|
+
)
|
|
790
|
+
|
|
749
791
|
def process_bundle(self, n_cores=None):
|
|
750
792
|
self.n_cores = n_cores
|
|
751
793
|
image_based = self._is_image_based()
|
|
@@ -754,7 +796,19 @@ class Runner:
|
|
|
754
796
|
# nothing rather than a studyset's worth of downloads.
|
|
755
797
|
estimator, corrector = self.load_specification(n_cores=n_cores)
|
|
756
798
|
|
|
757
|
-
|
|
799
|
+
if image_based:
|
|
800
|
+
self._reject_image_based_comparison()
|
|
801
|
+
studyset_dict = self.prepare_images()
|
|
802
|
+
else:
|
|
803
|
+
# A coordinate-based kernel needs a sample size per experiment as
|
|
804
|
+
# much as an image-based estimator does -- ALE sizes its Gaussian
|
|
805
|
+
# from it, and one experiment without one fails the whole run --
|
|
806
|
+
# and compose records it on the annotation note rather than on the
|
|
807
|
+
# analysis. Copied, since cached_studyset is uploaded as the
|
|
808
|
+
# result's snapshot and must keep what Neurostore served.
|
|
809
|
+
studyset_dict = apply_sample_sizes(
|
|
810
|
+
deepcopy(self.cached_studyset), self.cached_annotation
|
|
811
|
+
)
|
|
758
812
|
# The annotation is attached to the studyset rather than wrapped in an
|
|
759
813
|
# object of its own: it is the studyset that owns the notes, and reading
|
|
760
814
|
# them back gives the full analysis ids that ``slice`` selects on.
|
|
@@ -812,9 +866,11 @@ class Runner:
|
|
|
812
866
|
if not finite or any(finite.values()):
|
|
813
867
|
return
|
|
814
868
|
|
|
869
|
+
fitted = list((getattr(self.estimator, "inputs_", None) or {}).get("id", []))
|
|
815
870
|
message = [
|
|
816
871
|
"The meta-analysis produced no value at any voxel: every map is "
|
|
817
|
-
"entirely NaN."
|
|
872
|
+
f"entirely NaN. {len(fitted)} analysis/analyses reached the "
|
|
873
|
+
f"estimator, of {len(self.first_studyset.analyses)} submitted."
|
|
818
874
|
]
|
|
819
875
|
empty = self._empty_input_maps()
|
|
820
876
|
aggressive = getattr(self.estimator, "aggressive_mask", False)
|
|
@@ -869,9 +925,18 @@ class Runner:
|
|
|
869
925
|
try:
|
|
870
926
|
self.meta_results = workflow.fit(self.first_studyset)
|
|
871
927
|
except ValueError as exc:
|
|
872
|
-
report
|
|
873
|
-
|
|
874
|
-
|
|
928
|
+
# Which report is right depends on how far the fit got. Once the
|
|
929
|
+
# estimator has inputs, the transform ran and describing the
|
|
930
|
+
# submission instead would report every converted analysis as one
|
|
931
|
+
# NiMARE could not convert.
|
|
932
|
+
if (getattr(self.estimator, "inputs_", None) or {}).get("id") is not None:
|
|
933
|
+
report = coverage.describe_estimator(
|
|
934
|
+
self.first_studyset, self.estimator, dropped_maps=self.dropped_maps
|
|
935
|
+
)
|
|
936
|
+
else:
|
|
937
|
+
report = coverage.describe_submission(
|
|
938
|
+
self.first_studyset, self.estimator, dropped_maps=self.dropped_maps
|
|
939
|
+
)
|
|
875
940
|
self._describe_coverage(report)
|
|
876
941
|
raise ValueError(f"{exc}\n\n{report.summary()}") from exc
|
|
877
942
|
|
|
@@ -95,15 +95,20 @@ def test_an_absent_note_is_not_selected():
|
|
|
95
95
|
|
|
96
96
|
|
|
97
97
|
def test_a_filter_column_no_note_carries_selects_nothing():
|
|
98
|
+
"""An un-noted column must select nothing -- and say so rather than proceed.
|
|
99
|
+
|
|
100
|
+
Selecting nothing is the safe half: a null note is truthy, so a bare test
|
|
101
|
+
would take every analysis the column says nothing about. Saying so is the
|
|
102
|
+
other half, since NiMARE reports an empty selection as a missing image type.
|
|
103
|
+
"""
|
|
98
104
|
runner, studyset = _runner(
|
|
99
105
|
{"filter": "missing", "conditions": [True], "weights": [1]},
|
|
100
106
|
{"missing": "boolean"},
|
|
101
107
|
[_note("a1", True)],
|
|
102
108
|
)
|
|
103
109
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
assert list(first.ids) == []
|
|
110
|
+
with pytest.raises(ValueError, match="No analysis is selected.*'missing'"):
|
|
111
|
+
runner.apply_filter(studyset, combine=False)
|
|
107
112
|
|
|
108
113
|
|
|
109
114
|
def test_boolean_column_splits_into_two_groups():
|
|
@@ -96,11 +96,13 @@ def test_requirements_read_off_the_estimator():
|
|
|
96
96
|
|
|
97
97
|
def test_a_derived_map_is_reported_as_derived(write_map):
|
|
98
98
|
"""A t-map plus a sample size becomes a z-map, and the report says so."""
|
|
99
|
-
studyset = _studyset(
|
|
99
|
+
studyset = _studyset(
|
|
100
|
+
write_map, {"s1": (["T map"], 20), "s2": (["T map"], 20), "s3": (["T map"], 20)}
|
|
101
|
+
)
|
|
100
102
|
|
|
101
103
|
_, report = _fit_and_describe(studyset, Stouffers(aggressive_mask=True))
|
|
102
104
|
|
|
103
|
-
|
|
105
|
+
analysis = {a.study_id: a for a in report.analyses}["s1"]
|
|
104
106
|
assert analysis.included
|
|
105
107
|
assert analysis.derived == {"z"}
|
|
106
108
|
assert "converted z" in analysis.reason
|
|
@@ -112,7 +114,15 @@ def test_an_analysis_nimare_cannot_transform_is_excluded_with_a_reason(write_map
|
|
|
112
114
|
Paired with a usable study, so the run succeeds and reports the exclusion
|
|
113
115
|
rather than failing.
|
|
114
116
|
"""
|
|
115
|
-
studyset = _studyset(
|
|
117
|
+
studyset = _studyset(
|
|
118
|
+
write_map,
|
|
119
|
+
{
|
|
120
|
+
"ok": (["Z map"], None),
|
|
121
|
+
"ok2": (["Z map"], None),
|
|
122
|
+
"ok3": (["Z map"], None),
|
|
123
|
+
"s1": (["T map"], None),
|
|
124
|
+
},
|
|
125
|
+
)
|
|
116
126
|
|
|
117
127
|
_, report = _fit_and_describe(studyset, Stouffers(aggressive_mask=True))
|
|
118
128
|
|
|
@@ -121,7 +131,7 @@ def test_an_analysis_nimare_cannot_transform_is_excluded_with_a_reason(write_map
|
|
|
121
131
|
assert analysis.missing_images == {"z"}
|
|
122
132
|
assert "could not produce z" in analysis.reason
|
|
123
133
|
assert "from t" in analysis.reason
|
|
124
|
-
assert len(report.included) ==
|
|
134
|
+
assert len(report.included) == 3
|
|
125
135
|
|
|
126
136
|
|
|
127
137
|
def test_nothing_usable_is_described_from_the_submission(write_map):
|
|
@@ -134,7 +144,7 @@ def test_nothing_usable_is_described_from_the_submission(write_map):
|
|
|
134
144
|
report = coverage.describe_submission(studyset, Stouffers())
|
|
135
145
|
|
|
136
146
|
assert report.included == []
|
|
137
|
-
|
|
147
|
+
analysis = {a.study_id: a for a in report.analyses}["s1"]
|
|
138
148
|
assert analysis.supplied == {"t"}
|
|
139
149
|
assert "could not produce z" in analysis.reason
|
|
140
150
|
|
|
@@ -145,7 +155,15 @@ def test_an_analysis_with_the_map_but_no_metadata_is_explained(write_map):
|
|
|
145
155
|
The map is there, so the report has to reach for the metadata requirement to
|
|
146
156
|
explain the exclusion.
|
|
147
157
|
"""
|
|
148
|
-
studyset = _studyset(
|
|
158
|
+
studyset = _studyset(
|
|
159
|
+
write_map,
|
|
160
|
+
{
|
|
161
|
+
"ok": (["T map"], 20),
|
|
162
|
+
"ok2": (["T map"], 20),
|
|
163
|
+
"ok3": (["T map"], 20),
|
|
164
|
+
"s1": (["T map"], None),
|
|
165
|
+
},
|
|
166
|
+
)
|
|
149
167
|
|
|
150
168
|
_, report = _fit_and_describe(studyset, FixedEffectsHedges(aggressive_mask=True))
|
|
151
169
|
|
|
@@ -162,6 +180,7 @@ def test_partial_coverage_still_yields_a_usable_studyset(write_map):
|
|
|
162
180
|
write_map,
|
|
163
181
|
{
|
|
164
182
|
"supplied": (["Z map"], None),
|
|
183
|
+
"supplied2": (["Z map"], None),
|
|
165
184
|
"derivable": (["T map"], 20),
|
|
166
185
|
"hopeless": (["T map"], None),
|
|
167
186
|
"unusable": (["univariate-beta map"], None),
|
|
@@ -170,28 +189,45 @@ def test_partial_coverage_still_yields_a_usable_studyset(write_map):
|
|
|
170
189
|
|
|
171
190
|
_, report = _fit_and_describe(studyset, Stouffers(aggressive_mask=True))
|
|
172
191
|
|
|
173
|
-
assert len(report.included) ==
|
|
192
|
+
assert len(report.included) == 3
|
|
174
193
|
assert len(report.excluded) == 2
|
|
175
|
-
assert report.n_studies_included ==
|
|
176
|
-
assert {a.study_id for a in report.included} == {
|
|
194
|
+
assert report.n_studies_included == 3
|
|
195
|
+
assert {a.study_id for a in report.included} == {
|
|
196
|
+
"supplied",
|
|
197
|
+
"supplied2",
|
|
198
|
+
"derivable",
|
|
199
|
+
}
|
|
177
200
|
|
|
178
201
|
|
|
179
202
|
def test_summary_names_the_excluded_analyses(write_map):
|
|
180
203
|
studyset = _studyset(
|
|
181
|
-
write_map,
|
|
204
|
+
write_map,
|
|
205
|
+
{
|
|
206
|
+
"good": (["Z map"], None),
|
|
207
|
+
"good2": (["Z map"], None),
|
|
208
|
+
"good3": (["Z map"], None),
|
|
209
|
+
"bad": (["univariate-beta map"], None),
|
|
210
|
+
},
|
|
182
211
|
)
|
|
183
212
|
|
|
184
213
|
_, report = _fit_and_describe(studyset, Stouffers(aggressive_mask=True))
|
|
185
214
|
summary = report.summary()
|
|
186
215
|
|
|
187
|
-
assert "Used
|
|
216
|
+
assert "Used 3 of 4 analyses" in summary
|
|
188
217
|
assert "Left out 1 analysis/analyses" in summary
|
|
189
218
|
assert "bad" in summary
|
|
190
219
|
|
|
191
220
|
|
|
192
221
|
def test_dropped_maps_are_carried_into_the_report(write_map):
|
|
193
222
|
"""What never reached the transform still belongs in the account."""
|
|
194
|
-
studyset = _studyset(
|
|
223
|
+
studyset = _studyset(
|
|
224
|
+
write_map,
|
|
225
|
+
{
|
|
226
|
+
"s1": (["univariate-beta map"], None),
|
|
227
|
+
"s2": (["univariate-beta map"], None),
|
|
228
|
+
"s3": (["univariate-beta map"], None),
|
|
229
|
+
},
|
|
230
|
+
)
|
|
195
231
|
|
|
196
232
|
report = coverage.describe_submission(
|
|
197
233
|
studyset,
|
|
@@ -199,17 +235,24 @@ def test_dropped_maps_are_carried_into_the_report(write_map):
|
|
|
199
235
|
dropped_maps={"s1-a": ("ROI/mask (not a map type NiMARE can use)",)},
|
|
200
236
|
)
|
|
201
237
|
|
|
202
|
-
|
|
238
|
+
analysis = {a.study_id: a for a in report.analyses}["s1"]
|
|
203
239
|
assert "ROI/mask" in analysis.reason
|
|
204
240
|
|
|
205
241
|
|
|
206
242
|
def test_varcope_is_derived_from_beta_and_t(write_map):
|
|
207
243
|
"""DerSimonianLaird needs beta and varcope; t + beta yields the varcope."""
|
|
208
|
-
studyset = _studyset(
|
|
244
|
+
studyset = _studyset(
|
|
245
|
+
write_map,
|
|
246
|
+
{
|
|
247
|
+
"s1": (["univariate-beta map", "T map"], None),
|
|
248
|
+
"s2": (["univariate-beta map", "T map"], None),
|
|
249
|
+
"s3": (["univariate-beta map", "T map"], None),
|
|
250
|
+
},
|
|
251
|
+
)
|
|
209
252
|
|
|
210
253
|
_, report = _fit_and_describe(studyset, DerSimonianLaird(aggressive_mask=True))
|
|
211
254
|
|
|
212
|
-
|
|
255
|
+
analysis = {a.study_id: a for a in report.analyses}["s1"]
|
|
213
256
|
assert analysis.included
|
|
214
257
|
assert analysis.derived == {"varcope"}
|
|
215
258
|
|
|
@@ -227,6 +270,10 @@ def test_supplied_maps_are_reported_per_analysis(write_map):
|
|
|
227
270
|
"has_t": (["T map"], None),
|
|
228
271
|
"has_beta": (["univariate-beta map"], None),
|
|
229
272
|
"has_z": (["Z map"], None),
|
|
273
|
+
# Two more usable studies: rc4 refuses a fit that reaches the
|
|
274
|
+
# estimator with fewer than three analyses once the jackknife runs.
|
|
275
|
+
"has_z2": (["Z map"], None),
|
|
276
|
+
"has_z3": (["Z map"], None),
|
|
230
277
|
},
|
|
231
278
|
)
|
|
232
279
|
|
|
@@ -186,3 +186,90 @@ def test_ibma_estimator_rejects_group_comparison(runner):
|
|
|
186
186
|
|
|
187
187
|
with pytest.raises(ValueError, match="no image-based estimator supports one"):
|
|
188
188
|
runner.run_meta_analysis()
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
@pytest.mark.parametrize(
|
|
192
|
+
("key", "value"),
|
|
193
|
+
[("conditions", [True, False]), ("database_studyset", "neurostore")],
|
|
194
|
+
ids=["two-conditions", "database"],
|
|
195
|
+
)
|
|
196
|
+
def test_an_image_based_comparison_is_refused_before_the_work(
|
|
197
|
+
runner, monkeypatch, key, value
|
|
198
|
+
):
|
|
199
|
+
"""The specification already says this cannot run, so nothing should be fetched.
|
|
200
|
+
|
|
201
|
+
``run_meta_analysis`` catches it too, but only after the maps are staged
|
|
202
|
+
and, for a database comparison, after the reference studyset has been
|
|
203
|
+
downloaded.
|
|
204
|
+
"""
|
|
205
|
+
monkeypatch.setattr(
|
|
206
|
+
Runner, "load_specification", lambda self, n_cores=None: (Stouffers(), None)
|
|
207
|
+
)
|
|
208
|
+
monkeypatch.setattr(
|
|
209
|
+
Runner,
|
|
210
|
+
"prepare_images",
|
|
211
|
+
lambda self: pytest.fail("images must not be staged"),
|
|
212
|
+
)
|
|
213
|
+
runner.cached_specification.update(
|
|
214
|
+
{"type": "IBMA", "estimator": {"type": "Stouffers"}, key: value}
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
with pytest.raises(ValueError, match="no image-based estimator supports one"):
|
|
218
|
+
runner.process_bundle()
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def test_a_coordinate_based_run_gets_its_sample_sizes(runner, monkeypatch):
|
|
222
|
+
"""ALE's kernel needs one per experiment, and compose records it on the note.
|
|
223
|
+
|
|
224
|
+
One analysis without a sample size fails the whole run, so the copy that
|
|
225
|
+
``apply_sample_sizes`` makes has to happen on this path too -- and on a
|
|
226
|
+
copy, since ``cached_studyset`` is uploaded as the result's snapshot.
|
|
227
|
+
"""
|
|
228
|
+
captured = {}
|
|
229
|
+
|
|
230
|
+
monkeypatch.setattr(
|
|
231
|
+
Runner, "load_specification", lambda self, n_cores=None: (None, None)
|
|
232
|
+
)
|
|
233
|
+
monkeypatch.setattr(Runner, "apply_filter", lambda *a, **kw: (FakeStudyset(), None))
|
|
234
|
+
|
|
235
|
+
def fake_studyset(payload, **kwargs):
|
|
236
|
+
captured["studyset"] = payload
|
|
237
|
+
return FakeStudyset()
|
|
238
|
+
|
|
239
|
+
monkeypatch.setattr("compose_runner.run.Studyset", fake_studyset)
|
|
240
|
+
runner.cached_specification["type"] = "CBMA"
|
|
241
|
+
runner.cached_studyset = {
|
|
242
|
+
"studies": [
|
|
243
|
+
{
|
|
244
|
+
"id": "s1",
|
|
245
|
+
"metadata": {},
|
|
246
|
+
"analyses": [{"id": "a1", "metadata": {}, "points": []}],
|
|
247
|
+
}
|
|
248
|
+
]
|
|
249
|
+
}
|
|
250
|
+
runner.cached_annotation = {
|
|
251
|
+
"note_keys": {"include": "boolean", "sample_size": "number"},
|
|
252
|
+
"notes": [{"study": "s1", "analysis": "a1", "note": {"sample_size": 25}}],
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
runner.process_bundle()
|
|
256
|
+
|
|
257
|
+
analysis = captured["studyset"]["studies"][0]["analyses"][0]
|
|
258
|
+
assert analysis["metadata"]["sample_sizes"] == [25.0]
|
|
259
|
+
# The uploaded snapshot keeps what Neurostore served.
|
|
260
|
+
assert runner.cached_studyset["studies"][0]["analyses"][0]["metadata"] == {}
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def test_a_relative_result_dir_is_resolved(tmp_path, monkeypatch):
|
|
264
|
+
"""Staged maps are recorded as paths, and NiMARE resolves relative ones.
|
|
265
|
+
|
|
266
|
+
The base path it resolves against is the image directory itself, so a
|
|
267
|
+
relative result_dir has that directory prepended to a path already holding
|
|
268
|
+
it and every map goes missing.
|
|
269
|
+
"""
|
|
270
|
+
monkeypatch.chdir(tmp_path)
|
|
271
|
+
|
|
272
|
+
runner = Runner(meta_analysis_id="meta-id", result_dir="results/run1")
|
|
273
|
+
|
|
274
|
+
assert runner.result_dir.is_absolute()
|
|
275
|
+
assert runner.image_dir == tmp_path / "results" / "run1" / "images"
|
{compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/test_ibma_end_to_end.py
RENAMED
|
@@ -403,26 +403,45 @@ def test_nothing_usable_fails_with_the_account_attached(tmp_path):
|
|
|
403
403
|
assert (runner.result_dir / "ibma_coverage.tsv").is_file()
|
|
404
404
|
|
|
405
405
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
"""A run that computes nothing must not pass as a success.
|
|
406
|
+
def test_an_unreadable_upload_is_dropped_rather_than_failing_the_run(tmp_path):
|
|
407
|
+
"""A file that is not a NIfTI costs its own analysis, not the meta-analysis.
|
|
409
408
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
a more liberal mask.
|
|
409
|
+
It passes the magic-byte check that guards the download, so nothing notices
|
|
410
|
+
until nibabel opens it from inside the fit, where it is neither caught nor
|
|
411
|
+
attributed to the analysis it came from. A map that parses but holds no
|
|
412
|
+
finite non-zero voxel is NiMARE's to drop, and is not covered here.
|
|
415
413
|
"""
|
|
416
|
-
runner = _prepared_runner(
|
|
417
|
-
|
|
414
|
+
runner = _prepared_runner(tmp_path, "Stouffers")
|
|
415
|
+
corrupt = tmp_path / "corrupt.nii.gz"
|
|
416
|
+
corrupt.write_bytes(b"\x1f\x8b" + b"not actually a nifti" * 8)
|
|
417
|
+
analysis = runner.cached_studyset["studies"][0]["analyses"][0]
|
|
418
|
+
analysis["images"][0]["filename"] = str(corrupt)
|
|
419
|
+
analysis["images"][0]["url"] = str(corrupt)
|
|
420
|
+
|
|
421
|
+
runner.process_bundle()
|
|
422
|
+
runner.run_meta_analysis()
|
|
423
|
+
|
|
424
|
+
assert "could not be read as a NIfTI" in " ".join(
|
|
425
|
+
runner.dropped_maps[analysis["id"]]
|
|
418
426
|
)
|
|
427
|
+
assert analysis["id"] in {a.analysis_id for a in runner.coverage_report.excluded}
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
def test_an_all_nan_result_is_rejected(tmp_path):
|
|
431
|
+
"""A run that computes nothing must not pass as a success.
|
|
432
|
+
|
|
433
|
+
Every analysis here comes from one study, so the studyset clears NiMARE's
|
|
434
|
+
floor on the analysis count but holds a single dependence group. Every bag
|
|
435
|
+
of voxels is then skipped for want of independent replication, the fit
|
|
436
|
+
succeeds, and every output map is NaN.
|
|
437
|
+
"""
|
|
438
|
+
runner = _prepared_runner(tmp_path, "Stouffers")
|
|
419
439
|
studyset = runner.cached_studyset
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
studyset["studies"][0]["analyses"][0]["images"][0]["url"] = str(degenerate)
|
|
440
|
+
analyses = [a for study in studyset["studies"] for a in study["analyses"]]
|
|
441
|
+
studyset["studies"] = [
|
|
442
|
+
{"id": "study0", "name": "study 0", "metadata": {}, "analyses": analyses}
|
|
443
|
+
]
|
|
444
|
+
runner.cached_annotation = _make_annotation(studyset)
|
|
426
445
|
|
|
427
446
|
runner.process_bundle()
|
|
428
447
|
with pytest.raises(ValueError) as excinfo:
|
|
@@ -430,4 +449,4 @@ def test_an_all_nan_result_is_rejected(tmp_path, fill):
|
|
|
430
449
|
|
|
431
450
|
message = str(excinfo.value)
|
|
432
451
|
assert "no value at any voxel" in message
|
|
433
|
-
assert "
|
|
452
|
+
assert f"{len(analyses)} analysis/analyses reached the estimator" in message
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"""Tests for staging a studyset's images locally."""
|
|
2
2
|
|
|
3
|
+
import gzip
|
|
4
|
+
import io
|
|
5
|
+
|
|
6
|
+
import nibabel as nib
|
|
7
|
+
import numpy as np
|
|
3
8
|
import pytest
|
|
4
9
|
|
|
5
10
|
from compose_runner.images import (
|
|
@@ -9,8 +14,24 @@ from compose_runner.images import (
|
|
|
9
14
|
select_image_url,
|
|
10
15
|
)
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
|
|
18
|
+
def _gzipped_nifti():
|
|
19
|
+
"""A real, tiny NIfTI: staging opens what it downloaded and drops what it cannot.
|
|
20
|
+
|
|
21
|
+
A map with no finite non-zero voxel is dropped, so the canned one carries a
|
|
22
|
+
value.
|
|
23
|
+
"""
|
|
24
|
+
data = np.zeros((2, 2, 2), dtype=np.float32)
|
|
25
|
+
data[0, 0, 0] = 1.0
|
|
26
|
+
image = nib.Nifti1Image(data, np.eye(4))
|
|
27
|
+
buffer = io.BytesIO()
|
|
28
|
+
with gzip.GzipFile(fileobj=buffer, mode="wb") as handle:
|
|
29
|
+
handle.write(image.to_bytes())
|
|
30
|
+
return buffer.getvalue()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# Canned responses have to be a NIfTI, or they are rejected.
|
|
34
|
+
GZIPPED_NIFTI = _gzipped_nifti()
|
|
14
35
|
|
|
15
36
|
|
|
16
37
|
class FakeResponse:
|
|
@@ -15,13 +15,7 @@ classifiers = [
|
|
|
15
15
|
]
|
|
16
16
|
dynamic = ["version"]
|
|
17
17
|
dependencies = [
|
|
18
|
-
|
|
19
|
-
# runner reads a studyset's annotations off the studyset itself, which the
|
|
20
|
-
# columnar rewrite (NiMARE #1103) introduced. All of it releases as NiMARE
|
|
21
|
-
# 0.21.0. Replace with `nimare[parquet]>=0.21.0` once it is on PyPI, which
|
|
22
|
-
# publishing this package requires anyway: PyPI rejects direct references.
|
|
23
|
-
# The `parquet` extra is pyarrow, which reading a studyset release needs.
|
|
24
|
-
"nimare[parquet]==0.21.0rc3",
|
|
18
|
+
"nimare[parquet]==0.21.0",
|
|
25
19
|
"click",
|
|
26
20
|
"requests",
|
|
27
21
|
"sentry-sdk",
|
compose_runner-0.14.0/.gitignore
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
# Image-based meta-analysis
|
|
2
|
-
|
|
3
|
-
Compose cannot yet create an image-based meta-analysis, so this describes the
|
|
4
|
-
bundle the frontend *will* produce, what this runner does with it, and what still
|
|
5
|
-
has to change upstream. `scripts/simulate_ibma_bundle.py` assembles such a bundle
|
|
6
|
-
out of real Neurostore studies and real NeuroVault maps and pushes it through
|
|
7
|
-
`Runner`.
|
|
8
|
-
|
|
9
|
-
## Versions this is written against
|
|
10
|
-
|
|
11
|
-
| Package | Version | Why |
|
|
12
|
-
| --- | --- | --- |
|
|
13
|
-
| NiMARE | `main`, pinned in `pyproject.toml` until 0.21.0 ships | `groupby`, IBMA dependence handling, `aggressive_mask=False` by default, `Stouffers` without `normalize_contrast_weights`, [#1102](https://github.com/neurostuff/NiMARE/pull/1102) for the jackknife, [#1099](https://github.com/neurostuff/NiMARE/pull/1099) for the `logp` maps, and [#1103](https://github.com/neurostuff/NiMARE/pull/1103) for the columnar studyset |
|
|
14
|
-
| PyMARE | 0.0.11rc1 | `Dataset(g=...)`, `encode_groups`, `group_mean`, `estimate_null_correlation`; required by NiMARE 0.21.0 |
|
|
15
|
-
| Neurostore | [PR #1695](https://github.com/neurostuff/neurostore/pull/1695) | the IBMA algorithm config and the `IBMA` specification type |
|
|
16
|
-
|
|
17
|
-
## What the bundle looks like
|
|
18
|
-
|
|
19
|
-
The studyset and annotation are the same shape as for a coordinate-based run.
|
|
20
|
-
Only the specification differs:
|
|
21
|
-
|
|
22
|
-
```json
|
|
23
|
-
{
|
|
24
|
-
"type": "IBMA",
|
|
25
|
-
"estimator": {
|
|
26
|
-
"type": "Stouffers",
|
|
27
|
-
"args": {
|
|
28
|
-
"aggressive_mask": false,
|
|
29
|
-
"use_sample_size": false,
|
|
30
|
-
"two_sided": true,
|
|
31
|
-
"**kwargs": {}
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"corrector": {"type": "FDRCorrector", "args": {"method": "indep", "alpha": 0.05}},
|
|
35
|
-
"filter": "included",
|
|
36
|
-
"conditions": [true],
|
|
37
|
-
"weights": [1.0],
|
|
38
|
-
"database_studyset": null
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Two things about the studyset matter more for IBMA than for CBMA.
|
|
43
|
-
|
|
44
|
-
**An image's location is split across two fields, inconsistently.** Which of
|
|
45
|
-
`url` and `filename` holds the downloadable NIfTI depends on how the image
|
|
46
|
-
reached Neurostore, and both shapes are live in production:
|
|
47
|
-
|
|
48
|
-
| Provenance | `url` | `filename` |
|
|
49
|
-
| --- | --- | --- |
|
|
50
|
-
| Ingested from NeuroVault | `https://neurovault.org/media/images/4248/spmT_0001_2.nii.gz` | `spmT_0001_2.nii.gz` |
|
|
51
|
-
| Uploaded by compose | `http://neurovault.org/images/1040266/` | `http://neurovault.org/media/images/24371/z.nii.gz` |
|
|
52
|
-
|
|
53
|
-
So neither field can be trusted by position. `compose_runner.images` chooses the
|
|
54
|
-
candidate that is both fetchable and named like a NIfTI, and drops the image when
|
|
55
|
-
neither is — a landing page downloads happily as HTML, and a `.nii.gz` full of
|
|
56
|
-
HTML fails much later and much less legibly.
|
|
57
|
-
|
|
58
|
-
**`value_type` is a human-readable NeuroVault label**, not a NiMARE image type:
|
|
59
|
-
`"Z map"`, `"T map"`, `"univariate-beta map"`, `"variance"`,
|
|
60
|
-
`"P map (given null hypothesis)"`. `compose_runner.images` maps these onto
|
|
61
|
-
NiMARE's `z`/`t`/`beta`/`varcope`/`p` and drops the labels NiMARE has no use for
|
|
62
|
-
(`ROI/mask`, `parcellation`, `anatomical`, `F map`, `Chi squared map`, `other`).
|
|
63
|
-
|
|
64
|
-
## What the runner does differently for `type: "IBMA"`
|
|
65
|
-
|
|
66
|
-
| Step | Behaviour |
|
|
67
|
-
| --- | --- |
|
|
68
|
-
| `prepare_images` | Downloads every usable map into `<result_dir>/images` and returns a studyset pointing at the local files, caching across reruns. NiMARE hands paths to nibabel, which cannot read over HTTP. Staged on a copy, since `cached_studyset` is uploaded as the result's studyset snapshot. Records which maps it dropped and why, per analysis. |
|
|
69
|
-
| `apply_sample_sizes` | Copies a sample size onto each analysis's `metadata["sample_sizes"]`, preferring the annotation note, then analysis metadata, then study metadata. |
|
|
70
|
-
| `apply_filter(combine=False)` | Keeps each analysis separate. `combine_analyses()` is right for CBMA, where the point is pooling foci, but for IBMA it concatenates a study's images into one analysis and the conversion to a Dataset keeps only one map per type, silently discarding every extra contrast — and destroying the study grouping the dependence correction needs. |
|
|
71
|
-
| `load_specification` | Runs before any download, so a specification NiMARE rejects costs nothing. Drops the injected `n_cores`, which no image-based estimator takes, or passes it as `n_jobs` to `PermutedOLS`, the only one that parallelizes its fit. |
|
|
72
|
-
| `run_meta_analysis` | Dispatches to `IBMAWorkflow` with `diagnostics="jackknife"`. Group comparisons are rejected: no image-based estimator is pairwise. Needs a NiMARE carrying [#1102](https://github.com/neurostuff/NiMARE/pull/1102) — before it, `Studyset.slice` dropped the maps `ImageTransformer` derived, so every leave-one-out refit lost every converted analysis rather than the one being left out, which made the diagnostic table this runner uploads meaningless. |
|
|
73
|
-
| `upload_results` | Also publishes the `logp` maps [#1099](https://github.com/neurostuff/NiMARE/pull/1099) adds. They matter because the maps are float32: `p` loses precision below 1.18e-38 and reaches exactly 0 at \|z\| >= 14.17, which real studysets approach. `logp` carries the tail past that. |
|
|
74
|
-
| `_fit_image_based` | Fits the workflow, then reports what it used. On the failure NiMARE raises when nothing survives, describes the submitted studyset instead and appends that to the message. |
|
|
75
|
-
| `_describe_coverage` | Logs the account and writes `ibma_coverage.tsv` beside the results. |
|
|
76
|
-
| `_check_result_is_not_empty` | Rejects a result that is NaN at every voxel, naming the input maps that have no finite non-zero value. |
|
|
77
|
-
|
|
78
|
-
Task sizing is unchanged: `_requires_large_task` escalates a run to the large ECS
|
|
79
|
-
task for a montecarlo FWE corrector whatever the specification type, which for an
|
|
80
|
-
image-based run means `PermutedOLS`'s permutation test — the only image-based
|
|
81
|
-
path where the extra cores are worth paying for. Everything else fits the
|
|
82
|
-
standard task comfortably. Note that the choice is made in
|
|
83
|
-
`aws_lambda/run_handler.py`, so invoking `compose_runner.ecs_task` or the CLI
|
|
84
|
-
directly bypasses it.
|
|
85
|
-
|
|
86
|
-
## Uneven input, and what gets left out
|
|
87
|
-
|
|
88
|
-
Real studysets are not tidy. A base-study search for image data on "language"
|
|
89
|
-
returns 27 studies carrying nine distinct `value_type` labels between them:
|
|
90
|
-
|
|
91
|
-
```
|
|
92
|
-
Z map, T map, univariate-beta map, P map (given null hypothesis),
|
|
93
|
-
F map, 1-P map ("inverted" probability), ROI/mask, anatomical, other
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
NiMARE closes the gap between that and what an estimator needs on its own.
|
|
97
|
-
`IBMAWorkflow.fit` runs `ImageTransformer` over the estimator's
|
|
98
|
-
`_required_inputs`, converting what it can — a z-map from a t-map and a sample
|
|
99
|
-
size, a varcope from a t-map and a beta map — and `drop_invalid` discards
|
|
100
|
-
whatever is still incomplete. Both steps are silent, and that is the only
|
|
101
|
-
problem: a meta-analysis can rest on a third of the studies the user selected and
|
|
102
|
-
say nothing.
|
|
103
|
-
|
|
104
|
-
`compose_runner.coverage` does none of that work and owns no transform rules. It
|
|
105
|
-
introspects the fitted estimator, which already holds both answers:
|
|
106
|
-
|
|
107
|
-
| | |
|
|
108
|
-
| --- | --- |
|
|
109
|
-
| `estimator.inputs_["id"]` | the analyses that made it in, after everything was dropped |
|
|
110
|
-
| `estimator.dataset.images` | the image table *after* the transform, so comparing it with the table submitted says which maps were converted rather than supplied |
|
|
111
|
-
|
|
112
|
-
Each analysis is named in `<result_dir>/ibma_coverage.tsv`, one row each:
|
|
113
|
-
|
|
114
|
-
```
|
|
115
|
-
study_name analysis_name included supplied converted reason
|
|
116
|
-
The neural basis of free language… Figure 2a true t z converted z
|
|
117
|
-
Functional organisation for verb… DLD: VG> Rest false ... dropped other
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
Partial coverage is not an error — it is the normal case, and the run proceeds.
|
|
121
|
-
Two things do stop it:
|
|
122
|
-
|
|
123
|
-
* **Nothing usable at all.** NiMARE raises `The collection has no data for
|
|
124
|
-
'z_maps'`, which does not say which studies were unusable. There is no fitted
|
|
125
|
-
estimator to introspect at that point, so the submitted studyset is described
|
|
126
|
-
instead and the account is appended to NiMARE's message.
|
|
127
|
-
* **A result that is empty everywhere.** An image-based meta-analysis can finish
|
|
128
|
-
with every map entirely NaN. The run looks successful and the maps it would
|
|
129
|
-
upload hold no values, so this is rejected with the cause named.
|
|
130
|
-
|
|
131
|
-
The cause is worth stating precisely, because it is not what it looks like.
|
|
132
|
-
NiMARE counts a voxel as valid only where it is finite *and* non-zero, and
|
|
133
|
-
`aggressive_mask` is the intersection of that across inputs. So a single map
|
|
134
|
-
that is exactly zero everywhere — an empty NeuroVault upload, which does occur
|
|
135
|
-
— empties the mask on its own, however well the rest overlap. The error names
|
|
136
|
-
the empty maps rather than only suggesting `aggressive_mask=False`, since
|
|
137
|
-
excluding an empty upload is the real fix.
|
|
138
|
-
|
|
139
|
-
## Changes needed in Neurostore
|
|
140
|
-
|
|
141
|
-
Neurostore PR #1695 is merged, and its `meta_analysis_params.json` carries
|
|
142
|
-
`weight_scheme`/`rho` with legal defaults, no `dependence`, and no
|
|
143
|
-
`normalize_contrast_weights`. `groupby` is deliberately left out, so every run
|
|
144
|
-
takes NiMARE's default of grouping images by the study that contributed them: a
|
|
145
|
-
JSON form cannot express the array and `False` forms, and `False` inflates
|
|
146
|
-
significance.
|
|
147
|
-
|
|
148
|
-
1. **Give sample size a real home.** Two estimators require it
|
|
149
|
-
(`FixedEffectsHedges`, `SampleSizeBasedLikelihood`), `Stouffers` and `Fishers`
|
|
150
|
-
can weight by it, and NiMARE needs it to derive a `z` map from a `t` map —
|
|
151
|
-
the common case, since most NeuroVault maps are T maps. On the "language"
|
|
152
|
-
corpus, having it is worth 17 analyses and 9 studies out of 27. Today it is a
|
|
153
|
-
free-form study-level metadata key (a string, `"42"`). NiMARE wants one value
|
|
154
|
-
per *analysis*, and a study contributing several contrasts with different `n`
|
|
155
|
-
cannot be described study-level. A typed, analysis-level field would also let
|
|
156
|
-
the frontend tell a user up front which studies an estimator will drop.
|
|
157
|
-
|
|
158
|
-
2. **Distinguish `se`/`sd` from `varcope`.** Four estimators need `beta` +
|
|
159
|
-
`varcope`. Neurostore inherits NeuroVault's vocabulary, whose only
|
|
160
|
-
variance-ish map type is `"variance"` — ambiguous between a variance of the
|
|
161
|
-
contrast estimate and a standard error or standard deviation. NiMARE can
|
|
162
|
-
derive `varcope` from `se`, from `sd` + `sample_sizes`, or from `t` + `beta`,
|
|
163
|
-
but only if it is told which it has. Without the distinction, `"variance"` is
|
|
164
|
-
taken as `varcope` and a study that actually published a standard error is
|
|
165
|
-
silently analysed with the wrong scale.
|
|
166
|
-
|
|
167
|
-
3. **Drop the hardcoded `aggressive_mask` override.** The config generator sets
|
|
168
|
-
it to `False` explicitly, which now restates NiMARE's own default and will go
|
|
169
|
-
stale the moment upstream reconsiders. Regenerating picks up `False` on its
|
|
170
|
-
own.
|
|
171
|
-
|
|
172
|
-
## Changes needed in NiMARE
|
|
173
|
-
|
|
174
|
-
1. **`Studyset.slice` silently returns nothing for an id it cannot resolve.**
|
|
175
|
-
[#1103](https://github.com/neurostuff/NiMARE/pull/1103) closed most of this:
|
|
176
|
-
a full `<study_id>-<analysis_id>` id is now matched whole rather than split
|
|
177
|
-
back on the hyphen, so `slice(analyses=["mixed-a-b"])` resolves where it used
|
|
178
|
-
to return nothing. Two pieces are left:
|
|
179
|
-
|
|
180
|
-
```python
|
|
181
|
-
ss.slice(analyses=["a-b"]) # -> no analyses: the short id of "mixed-a-b"
|
|
182
|
-
ss.slice(analyses=["nope"]) # -> no analyses, no error
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
The short-id path derives its keys with `rsplit("-", 1)[-1]`, so a hyphenated
|
|
186
|
-
*analysis* id is unreachable by its short form, and an id matching nothing at
|
|
187
|
-
either level is still an empty studyset rather than an error. This runner now
|
|
188
|
-
selects on the full ids `annotations_df` reports, so neither bites it, but
|
|
189
|
-
raising on an unresolvable id would make the failure visible to whoever hits
|
|
190
|
-
it next.
|
|
191
|
-
|
|
192
|
-
2. **`_persist_meta_results` spends far more disk than the results need.** Most
|
|
193
|
-
of a pickled `MetaResult` is `estimator.inputs_`, which for an IBMA holds
|
|
194
|
-
every input map — data already on disk under `images/`. Dropping `inputs_`
|
|
195
|
-
before pickling would reclaim almost all of it, if nothing downstream reads
|
|
196
|
-
it.
|
|
197
|
-
|
|
198
|
-
## Running the simulation
|
|
199
|
-
|
|
200
|
-
```bash
|
|
201
|
-
# Which estimators the config exposes, and what each needs
|
|
202
|
-
python scripts/simulate_ibma_bundle.py --list
|
|
203
|
-
|
|
204
|
-
# Build a bundle and print it without running
|
|
205
|
-
python scripts/simulate_ibma_bundle.py --estimator Fishers --dry-run
|
|
206
|
-
|
|
207
|
-
# Build and run, picking studies that already carry the estimator's maps
|
|
208
|
-
python scripts/simulate_ibma_bundle.py --estimator Stouffers --n-studies 6
|
|
209
|
-
|
|
210
|
-
# The messy case: take a real search as-is, whatever it returns
|
|
211
|
-
python scripts/simulate_ibma_bundle.py --estimator Stouffers --search language \
|
|
212
|
-
--n-studies 30
|
|
213
|
-
|
|
214
|
-
# The same search with no sample size recorded, which is what stops NiMARE
|
|
215
|
-
# converting a t-map into a z-map
|
|
216
|
-
python scripts/simulate_ibma_bundle.py --estimator Stouffers --search language \
|
|
217
|
-
--n-studies 30 --sample-size 0
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
Point `--config` (or `COMPOSE_PARAMS_CONFIG`) at a Neurostore checkout's
|
|
221
|
-
`compose/neurosynth-frontend/src/assets/config/meta_analysis_params.json`.
|
|
222
|
-
|
|
223
|
-
`--search` is the one worth reaching for when testing behaviour on uneven input:
|
|
224
|
-
it takes a `/base-studies/` query and uses whatever comes back, rather than
|
|
225
|
-
selecting for studies the estimator can already use.
|
|
226
|
-
|
|
227
|
-
`--dry-run` is enough to check that a config change produces a specification this
|
|
228
|
-
runner accepts. A full run is not fast, and `Jackknife` dominates it — one refit
|
|
229
|
-
per image.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/aws_lambda/cost_check_handler.py
RENAMED
|
File without changes
|
{compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/aws_lambda/log_poll_handler.py
RENAMED
|
File without changes
|
{compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/aws_lambda/results_handler.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/test_lambda_handlers.py
RENAMED
|
File without changes
|
|
File without changes
|
{compose_runner-0.14.0 → compose_runner-0.14.2}/compose_runner/tests/test_reference_studyset.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{compose_runner-0.14.0 → compose_runner-0.14.2}/infra/cdk/stacks/image_repositories_stack.py
RENAMED
|
File without changes
|
{compose_runner-0.14.0 → compose_runner-0.14.2}/infra/cdk/tests/test_compose_runner_stack.py
RENAMED
|
File without changes
|
|
File without changes
|