Skip to content

Commit 10d8992

Browse files
committed
Map.get_colormap(): allow_random_colors -> fill_uncolored. Display colorless regions
1 parent 9f5cbcf commit 10d8992

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

siibra/volumes/parcellationmap.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -690,15 +690,16 @@ def colorize(self, values: dict, **kwargs) -> _volume.Volume:
690690
name=f"Custom colorization of {self}"
691691
)
692692

693-
def get_colormap(self, region_specs: Iterable = None, *, allow_random_colors: bool = False):
693+
def get_colormap(self, region_specs: Iterable = None, *, fill_uncolored: bool = False):
694694
"""
695695
Generate a matplotlib colormap from known rgb values of label indices.
696696
697697
Parameters
698698
----------
699699
region_specs: iterable(regions), optional
700700
Optional parameter to only color the desired regions.
701-
allow_random_colors: bool , optional
701+
fill_uncolored: bool , optional
702+
If a region has no preconfigured color, a color will be randomly (reproducible) created.
702703
703704
Returns
704705
-------
@@ -711,7 +712,7 @@ def get_colormap(self, region_specs: Iterable = None, *, allow_random_colors: bo
711712
"matplotlib not available. Please install matplotlib to create a matplotlib colormap."
712713
)
713714
raise e
714-
if allow_random_colors:
715+
if fill_uncolored:
715716
seed = len(self.regions)
716717
np.random.seed(seed)
717718
logger.info(f"Random colors are allowed for regions without preconfgirued colors. Random seee: {seed}.")
@@ -724,6 +725,7 @@ def get_colormap(self, region_specs: Iterable = None, *, allow_random_colors: bo
724725
else:
725726
include_region_names = None
726727

728+
no_predefined_color = []
727729
for regionname, indices in self._indices.items():
728730
for index in indices:
729731
if index.label is None:
@@ -735,16 +737,25 @@ def get_colormap(self, region_specs: Iterable = None, *, allow_random_colors: bo
735737
region = self.get_region(index=index)
736738
if region.rgb is not None:
737739
colors[index.label] = region.rgb
738-
elif allow_random_colors:
740+
elif fill_uncolored:
739741
random_clr = [np.random.randint(0, 255) for r in range(3)]
740742
while random_clr in list(colors.values()):
741743
random_clr = [np.random.randint(0, 255) for r in range(3)]
742744
colors[index.label] = random_clr
745+
else:
746+
no_predefined_color.append(region.name)
743747

744748
if len(colors) == 0:
745749
raise exceptions.NoPredifinedColormapException(
746750
f"There is no predefined/preconfigured colormap for '{self}'."
747-
"Set `allow_random_colors=True` to a colormap with random values"
751+
"Set `fill_uncolored=True` to get a reproducible colormap."
752+
)
753+
754+
if no_predefined_color:
755+
logger.info(
756+
f"No preconfigured color found for the follwing regions."
757+
"Use `fill_uncolored=True` to display with a non-background color.\n"
758+
f"{no_predefined_color}"
748759
)
749760

750761
palette = np.array(

0 commit comments

Comments
 (0)