diff --git a/nimare/io.py b/nimare/io.py index cf59c0cbc..c93f78971 100644 --- a/nimare/io.py +++ b/nimare/io.py @@ -505,13 +505,16 @@ def convert_neurovault_to_dataset( } sample_sizes = [] + no_images = True for img_dict in images["results"]: if not ( re.match(contrast_regex, img_dict["name"]) and img_dict["map_type"] in map_type_conversion + and img_dict["analysis_level"] == "group" ): continue + no_images = False filename = img_dir / ( f"collection-{nv_coll}_id-{img_dict['id']}_" + Path(img_dict["file"]).name ) @@ -530,6 +533,11 @@ def convert_neurovault_to_dataset( # aggregate sample sizes (should all be the same) sample_sizes.append(img_dict["number_of_subjects"]) + if no_images: + raise ValueError( + f"No images were found for contrast {contrast_name}. " + f"Please check the contrast regular expression: {contrast_regex}" + ) # take modal sample size (raise warning if there are multiple values) if len(set(sample_sizes)) > 1: sample_size = _resolve_sample_size(sample_sizes) diff --git a/nimare/tests/test_io.py b/nimare/tests/test_io.py index 7d51f4b3a..c65be81ae 100644 --- a/nimare/tests/test_io.py +++ b/nimare/tests/test_io.py @@ -168,6 +168,19 @@ def test_convert_neurosynth_to_json_smoke(): "map_type_conversion": {"univariate-beta map": "beta"}, } ), + ( + { + "collection_ids": (11303,), + "contrasts": {"rms": "rms"}, + "map_type_conversion": {"univariate-beta map": "beta"}, + } + ), + ( + { + "collection_ids": (8836,), + "contrasts": {"crab_people": "cannot hurt you because they do not exist"}, + } + ), ], ) def test_convert_neurovault_to_dataset(kwargs): @@ -177,6 +190,11 @@ def test_convert_neurovault_to_dataset(kwargs): dset = io.convert_neurovault_to_dataset(**kwargs) assert "Collection 778 not found." in str(excinfo.value) return + elif "crab_people" in kwargs["contrasts"].keys(): + with pytest.raises(ValueError) as excinfo: + dset = io.convert_neurovault_to_dataset(**kwargs) + assert "No images were found for contrast crab_people" in str(excinfo.value) + return else: dset = io.convert_neurovault_to_dataset(**kwargs)