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

failures to generate reports with several atlases #4331

Open
Remi-Gau opened this issue Mar 20, 2024 · 2 comments
Open

failures to generate reports with several atlases #4331

Remi-Gau opened this issue Mar 20, 2024 · 2 comments
Labels
Atlas Bug for bug reports Report

Comments

@Remi-Gau
Copy link
Collaborator

Remi-Gau commented Mar 20, 2024

it turns out that we get failures to generate reports with several atlases.

  • fetch_atlas_destrieux_2009
  • fetch_atlas_aal
  • fetch_atlas_basc_multiscale_2015
  • fetch_atlas_yeo_2011
  File "/home/remi/github/nilearn/nilearn/../tmp.py", line 80, in main
    report = masker.generate_report()
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/nilearn/nilearn/nilearn/maskers/nifti_labels_masker.py", line 350, in generate_report
    return generate_report(self)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/nilearn/nilearn/nilearn/reporting/html_report.py", line 236, in generate_report
    return _create_report(estimator, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/nilearn/nilearn/nilearn/reporting/html_report.py", line 241, in _create_report
    overlay, image = _define_overlay(estimator)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/nilearn/nilearn/nilearn/reporting/html_report.py", line 164, in _define_overlay
    displays = estimator._reporting()
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/remi/github/nilearn/nilearn/nilearn/maskers/nifti_labels_masker.py", line 387, in _reporting
    self._check_mismatch_labels_regions(label_values, tolerant=False)
  File "/home/remi/github/nilearn/nilearn/nilearn/maskers/nifti_labels_masker.py", line 333, in _check_mismatch_labels_regions
    raise ValueError(msg)
ValueError: Mismatch between the number of provided labels (151) and the number of regions in provided label image (149).

Originally posted by @Remi-Gau in #4289 (comment)

@Remi-Gau
Copy link
Collaborator Author

Code to reproduce:

"""Test atlases masking."""

import numpy as np
from rich import print

from nilearn import datasets
from nilearn.datasets import (
    fetch_atlas_aal,
    fetch_atlas_basc_multiscale_2015,
    fetch_atlas_destrieux_2009,
    fetch_atlas_harvard_oxford,
    fetch_atlas_juelich,
    fetch_atlas_schaefer_2018,
    fetch_atlas_talairach,
    fetch_atlas_yeo_2011,
)
from nilearn.maskers import NiftiLabelsMasker

functions = {
    fetch_atlas_destrieux_2009: None,
    fetch_atlas_harvard_oxford: ["cort-maxprob-thr0-1mm"],
    fetch_atlas_juelich: ["maxprob-thr0-1mm"],
    fetch_atlas_talairach: ["gyrus"],
    fetch_atlas_aal: None,
    fetch_atlas_schaefer_2018: None,
    fetch_atlas_basc_multiscale_2015: [None, None, True, 1, 64, "sym"],
    fetch_atlas_yeo_2011: None,
}

failing_atlas = []


def main():
    """Test atlases masking."""
    dataset = datasets.fetch_development_fmri(n_subjects=1)
    func_filename = dataset.func[0]

    for f, args in functions.items():
        print(f)

        atlas = f(*args) if args else f()

        if "labels" in atlas:
            labels = atlas.labels
        elif "rsn_indices" in atlas:
            labels = atlas.rsn_indices
        elif f == fetch_atlas_basc_multiscale_2015:
            labels = range(64)
        elif f == fetch_atlas_yeo_2011:
            labels = range(17)

        if f == fetch_atlas_schaefer_2018:
            labels = np.insert(labels, 0, "Background")

        labels_img = atlas["thick_17"] if f == fetch_atlas_yeo_2011 else atlas.maps

        resampling_target = "data"
        # resampling_target="labels"

        masker = NiftiLabelsMasker(
            labels_img=labels_img,
            labels=labels,
            standardize="zscore_sample",
            resampling_target=resampling_target,
        )

        masker.fit_transform(func_filename)
        
        try:
            report = masker.generate_report()
            report.save_as_html("foo.html")
        except ValueError:
            print("\n[red]" + "Could not generate report".upper() + "\n")
            failing_atlas.append(f)

    print(failing_atlas)

if __name__ == "__main__":
    exit(main())

@Remi-Gau Remi-Gau changed the title Actually was also checking what the reports would look with these "misnamed" regions and it turns out that we get failures to generate reports with several atlases. failures to generate reports with several atlases Mar 20, 2024
@Remi-Gau Remi-Gau added Bug for bug reports Atlas Report labels Mar 20, 2024
@Remi-Gau
Copy link
Collaborator Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Atlas Bug for bug reports Report
Projects
None yet
Development

No branches or pull requests

1 participant