Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] only download group maps when creating dataset and raise error if no images are found for a contrast #580

Merged
merged 4 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"
)
Comment on lines +537 to +540
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not have strong feelings about this being a warning instead, but I chose to raise an error since it could lead to errors down the line if you were trying to run a meta-analysis for a contrast with no images.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an error is reasonable. If we see users complain about it a lot, we can revisit, but I agree that downgrading to a warning sounds problematic.

# 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