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

Allow random cmap creation for map.get_color_map #641

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

AhmetNSimsek
Copy link
Collaborator

import siibra
from nilearn import plotting
mp = siibra.get_map("deep bundles", "mni152")
cmap = mp.get_colormap(allow_random_colors=True)  # keyword has to be specified
plotting.view_img(mp.fetch(), cmap=cmap, symmetric_cmap=False).open_in_browser()

Uses the number of regions to determine the random seed for reproducibility.

@AhmetNSimsek AhmetNSimsek added the enhancement New feature or request label Feb 5, 2025
Copy link

codecov bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 10.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 45.34%. Comparing base (bc7c1d5) to head (f88a7d5).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
siibra/volumes/parcellationmap.py 10.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #641      +/-   ##
==========================================
- Coverage   45.41%   45.34%   -0.07%     
==========================================
  Files          75       75              
  Lines        7212     7229      +17     
==========================================
+ Hits         3275     3278       +3     
- Misses       3937     3951      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@dickscheid dickscheid left a comment

Choose a reason for hiding this comment

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

I would not return random colors if a colormap is absent. I think it is sufficient if siibra fails, but with a readable Exception which catches this case. An alternative would be to return a commonly used map, so that at least the result is always the same.

@AhmetNSimsek
Copy link
Collaborator Author

I would not return random colors if a colormap is absent. I think it is sufficient if siibra fails, but with a readable Exception which catches this case. An alternative would be to return a commonly used map, so that at least the result is always the same.

@dickscheid I disagree. When plotting, the user can use a default colormap themselves. This is an instance method which implicitly suggests there is a preconfigured colormap for this specific ParcellationMap.

Using a random seed, as the pr does, ensures reproducibility too. And we inform the user it is a non native colormap. Additionally, there are maps that are not fully covered. This PR also ensures a reproducible way to color them instead of setting to them the background.

@xgui3783
Copy link
Member

xgui3783 commented Feb 6, 2025

I think the flag should be renamed to fill_uncolored or fill_unset or fill_undefined, and defaults to False (which it already does)

This indicates the action, fill color map, and the target, areas without a color.

This flag also implies that this action is not random, but deterministic. (though it may change from version to version of siibra-python)

@dickscheid
Copy link
Contributor

@AhmetNSimsek I agree with you that a default colormap is not needed, but I also think that a random colormap is not useful either. I definitely prefer to raise a well defined exception if we don't have a parcellaion-specific colormap to provide.

@AhmetNSimsek
Copy link
Collaborator Author

@AhmetNSimsek I agree with you that a default colormap is not needed, but I also think that a random colormap is not useful either. I definitely prefer to raise a well defined exception if we don't have a parcellaion-specific colormap to provide.

This is already done, please see 400520d.
However, this does not address the issue that if a map has only partial coverage, some regions have no color values but others do, the regions without colors will have the color of the background. I don't think this is correct.

Also, a reproducible random map is better than a standard colormap, IMO, since the odds that neighbor regions have similar colors are very slim. Not the mention, the user has to explicitly set it to True, in order to obtain such a colormap.

@dickscheid
Copy link
Contributor

@AhmetNSimsek I agree with you that a default colormap is not needed, but I also think that a random colormap is not useful either. I definitely prefer to raise a well defined exception if we don't have a parcellaion-specific colormap to provide.

This is already done, please see 400520d. However, this does not address the issue that if a map has only partial coverage, some regions have no color values but others do, the regions without colors will have the color of the background. I don't think this is correct.

Also, a reproducible random map is better than a standard colormap, IMO, since the odds that neighbor regions have similar colors are very slim. Not the mention, the user has to explicitly set it to True, in order to obtain such a colormap.

I was not aware that this should actually solve the missing region problem. Agreed then. Regarding optimal contrast of neighboring region colors, it is a complicated optimization problem so let's hope the random solution is sufficient.

@AhmetNSimsek AhmetNSimsek merged commit c298bff into main Feb 6, 2025
36 of 40 checks passed
@AhmetNSimsek AhmetNSimsek deleted the enh_allow_random_cmap branch February 6, 2025 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants