From 6baeb3d13e33ef2f762236989a67579f47bc48e0 Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Fri, 29 Nov 2024 11:40:10 -0500 Subject: [PATCH] Add DWSx layer options --- leafmap/toolbar.py | 50 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/leafmap/toolbar.py b/leafmap/toolbar.py index 3f3493f1d5..87ff8a5ba9 100644 --- a/leafmap/toolbar.py +++ b/leafmap/toolbar.py @@ -6775,6 +6775,13 @@ def get_temp_creds(): layout=widgets.Layout(width=widget_width, padding=padding), ) + layer = widgets.Dropdown( + value=None, + description="Layer:", + style=style, + layout=widgets.Layout(width=widget_width, padding=padding), + ) + buttons = widgets.ToggleButtons( value=None, options=["Search", "Display", "Reset", "Close"], @@ -6803,6 +6810,7 @@ def change_dataset(change): widgets.HBox([max_items, bbox]), widgets.HBox([start_date, end_date]), dataset, + layer, buttons, output, ] @@ -6927,6 +6935,25 @@ def button_clicked(change): setattr(m, "_NASA_DATA_GDF", gdf) setattr(m, "_NASA_DATA_RESULTS", results) + + if short_name.value == "OPERA_L3_DSWX-HLS_V1": + layer.options = [ + "B01_WTR: Water classification", + "B02_BWTR: Binary water", + "B03_CONF: Confidence", + "B04_DIAG: Diagnostic layer", + "B05_WTR-1: Interpretation of diagnostic layer", + "B06_WTR-2: Interpreted layer refined using land cover", + "B07_LAND: Land cover classification", + "B08_SHAD: Terrain shadow layer", + "B09_CLOUD: Input HLS Fmask cloud classification", + "B10_DEM: Digital elevation model", + ] + layer.value = "B01_WTR: Water classification" + else: + layer.options = [] + layer.value = None + output.clear_output() except Exception as e: @@ -6935,13 +6962,20 @@ def button_clicked(change): elif change["new"] == "Display": output.clear_output() with output: - print("Loading...") - links = m._NASA_DATA_RESULTS[ - dataset.options.index(dataset.value) - ].data_links() - ds = xr.open_dataset(links[0], engine="rasterio") - image = array_to_image(ds["band_data"]) - m.add_raster(image, zoom_to_layer=False) + if ( + short_name.value == "OPERA_L3_DSWX-HLS_V1" + and dataset.value is not None + ): + print("Loading...") + links = m._NASA_DATA_RESULTS[ + dataset.options.index(dataset.value) + ].data_links() + ds = xr.open_dataset(links[layer.index], engine="rasterio") + image = array_to_image(ds["band_data"]) + name_prefix = dataset.value.split("_")[4][:8] + name_suffix = layer.value.split(":")[0][4:] + layer_name = f"{name_prefix}_{name_suffix}" + m.add_raster(image, zoom_to_layer=False, layer_name=layer_name) output.clear_output() elif change["new"] == "Reset": @@ -6955,6 +6989,8 @@ def button_clicked(change): end_date.value = None dataset.options = [] dataset.value = None + layer.options = [] + layer.value = None output.clear_output() if "Footprints" in m.get_layer_names():