From b1cff576e15c5fd5c2f2001f07433eccd34ab8dd Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Sat, 14 Dec 2024 15:22:06 -0500 Subject: [PATCH] Improve NASA OPERA colormap --- docs/notebooks/103_raster_colormap.ipynb | 5 +++-- leafmap/toolbar.py | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/notebooks/103_raster_colormap.ipynb b/docs/notebooks/103_raster_colormap.ipynb index 6b7506d594..fa90cb18ec 100644 --- a/docs/notebooks/103_raster_colormap.ipynb +++ b/docs/notebooks/103_raster_colormap.ipynb @@ -29,7 +29,8 @@ "outputs": [], "source": [ "import leafmap\n", - "import rioxarray as rxr" + "import rioxarray as rxr\n", + "from leafmap.common import get_image_colormap" ] }, { @@ -87,7 +88,7 @@ "metadata": {}, "outputs": [], "source": [ - "colormap = leafmap.get_image_colormap(filepath)" + "colormap = get_image_colormap(filepath)" ] }, { diff --git a/leafmap/toolbar.py b/leafmap/toolbar.py index 4dbcc598d0..43301f8872 100644 --- a/leafmap/toolbar.py +++ b/leafmap/toolbar.py @@ -6789,7 +6789,7 @@ def get_temp_creds(): palette = widgets.Dropdown( options=cmap_options, - value="tab10", + value=None, description="Colormap:", style=style, layout=widgets.Layout(width="200px", padding=padding), @@ -6979,7 +6979,11 @@ def button_clicked(change): da = ds["band_data"] nodata = os.environ.get("NODATA", 0) da = da.fillna(nodata) - image = array_to_image(da) + try: + colormap = get_image_colormap(ds) + except Exception as e: + colormap = None + image = array_to_image(da, colormap=colormap) setattr(m, "_NASA_DATA_IMAGE", image) name_prefix = layer.value.split(".")[0] items = dataset.value.split("_") @@ -7013,7 +7017,7 @@ def button_clicked(change): dataset.value = None layer.options = [] layer.value = None - palette.value = "tab10" + palette.value = None output.clear_output() if "Footprints" in m.get_layer_names():