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

[BUG] issue with masker.region_names_ #4359

Open
3 of 9 tasks
mtorabi59 opened this issue Apr 4, 2024 · 1 comment · May be fixed by #4360
Open
3 of 9 tasks

[BUG] issue with masker.region_names_ #4359

mtorabi59 opened this issue Apr 4, 2024 · 1 comment · May be fixed by #4360
Assignees
Labels
Bug for bug reports

Comments

@mtorabi59
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Operating system

  • Linux
  • Mac
  • Windows

Operating system version

Mac OS Version 13.4 Ventura

Python version

  • 3.12
  • 3.11
  • 3.10
  • 3.9
  • 3.8

nilearn version

0.10.3

Expected behavior

the output of print(masker.region_names_) in the following code must be {0: 'Frontal Pole', 1: 'Insular Cortex', 2: 'Inferior Frontal Gyrus, pars triangularis'}, because the region id 5 corresponds to region name "Inferior Frontal Gyrus, pars triangularis" based on the output of print(initial_region_id_names).

The issue with region names was addressed in #4289 (this was mostly due to non-standard atlas outputs.), but it seems the issue is a bit more complicated.

Current behavior & error messages

This is what I got instead:

# Paste the error message here
{0: 'Frontal Pole', 1: 'Insular Cortex', 2: 'Superior Frontal Gyrus'}

Steps and code to reproduce bug

# Paste your code here
import numpy as np
from nilearn.regions.tests.test_signal_extraction import get_data
from nilearn import datasets
from nilearn.maskers import NiftiLabelsMasker
from nibabel import Nifti1Image

# func data
dataset = datasets.fetch_development_fmri(n_subjects=1)
func_filename = dataset.func[0]

# atlas data
atlas = datasets.fetch_atlas_harvard_oxford('cort-maxprob-thr25-2mm')

# create a mask with 3 regions
labels_data = get_data(atlas.maps)
mask_data = (labels_data == 1) + (labels_data == 2) + (labels_data == 5)
mask_img = Nifti1Image(mask_data.astype(np.int8), atlas.maps.affine)

# Instantiate the masker with label image and label values
masker = NiftiLabelsMasker(atlas.maps,
                           labels=atlas.labels,
                           mask_img=mask_img,
                           standardize=True,
                           keep_masked_labels=False
                           )

# fit and transform the masker
_ = masker.fit_transform(func_filename)

# get the region ids and names before and after masking
initial_region_ids = np.unique(labels_data)
initial_region_id_names = {region_id: atlas.labels[i] for i, region_id in enumerate(initial_region_ids)}
print(initial_region_id_names)

region_ids_after_masking = masker.region_ids_
region_names_after_masking = masker.region_names_
print(masker.region_ids_)
print(masker.region_names_)
@mtorabi59 mtorabi59 added the Bug for bug reports label Apr 4, 2024
@mtorabi59
Copy link
Contributor Author

I like to work on this issue myself since I'm already familiar with the issue.

@mtorabi59 mtorabi59 linked a pull request Apr 5, 2024 that will close this issue
@Remi-Gau Remi-Gau added this to the Release 0.11.0 milestone Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug for bug reports
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants