From 80af211220183ee1ace6487afc29cf33c2e65eaa Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Sun, 1 Sep 2024 23:13:31 -0400 Subject: [PATCH] Fix add hyperspectral data bug (#882) --- leafmap/map_widgets.py | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/leafmap/map_widgets.py b/leafmap/map_widgets.py index 4043dd502a..5ccb579113 100644 --- a/leafmap/map_widgets.py +++ b/leafmap/map_widgets.py @@ -867,10 +867,31 @@ def on_apply_click(self): self._host_map.remove(old_layer) - if self._layer_dict["type"] == "LOCAL": - self._host_map.add_raster( - self._filename, - indexes=vis["indexes"], + # Add support for hyperspectral data via HyperCoast + if self._xds is not None: + + r_index = self._band_1_dropdown.index + g_index = self._band_2_dropdown.index + b_index = self._band_3_dropdown.index + + if (r_index >= g_index and g_index >= b_index) or ( + r_index <= g_index and g_index <= b_index + ): + pass + else: + sorted_indexes = sorted([r_index, g_index, b_index], reverse=True) + self._band_1_dropdown.index = sorted_indexes[0] + self._band_2_dropdown.index = sorted_indexes[1] + self._band_3_dropdown.index = sorted_indexes[2] + vis["indexes"] = [ + self._band_1_dropdown.index + 1, + self._band_2_dropdown.index + 1, + self._band_3_dropdown.index + 1, + ] + self._host_map.add_hyper( + self._xds, + dtype=self._layer_dict["hyper"], + wvl_indexes=[index - 1 for index in vis["indexes"]], colormap=vis["colormap"], vmin=vis["vmin"], vmax=vis["vmax"], @@ -880,12 +901,11 @@ def on_apply_click(self): zoom_to_layer=False, layer_index=layer_index, ) - # Add support for hyperspectral data via HyperCoast - elif self._xds is not None: - self._host_map.add_hyper( - self._xds, - type=self._layer_dict["hyper"], - wvl_indexes=[index - 1 for index in vis["indexes"]], + + elif self._layer_dict["type"] == "LOCAL": + self._host_map.add_raster( + self._filename, + indexes=vis["indexes"], colormap=vis["colormap"], vmin=vis["vmin"], vmax=vis["vmax"], @@ -895,6 +915,7 @@ def on_apply_click(self): zoom_to_layer=False, layer_index=layer_index, ) + elif self._layer_dict["type"] == "COG": self._host_map.add_cog_layer( self._layer_dict["url"],