Skip to content

Commit

Permalink
[FIX] only download group maps when creating dataset and raise error …
Browse files Browse the repository at this point in the history
…if no images are found for a contrast (#580)

* only download group maps

* fix and test case where no images are found for a contrast

* fix indent

* run black
  • Loading branch information
jdkent authored Oct 20, 2021
1 parent 05bbd89 commit 48fbae0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions nimare/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions nimare/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down

0 comments on commit 48fbae0

Please sign in to comment.