Skip to content

Commit

Permalink
Add DWSx layer options
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Nov 29, 2024
1 parent 36ae301 commit 6baeb3d
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions leafmap/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -6803,6 +6810,7 @@ def change_dataset(change):
widgets.HBox([max_items, bbox]),
widgets.HBox([start_date, end_date]),
dataset,
layer,
buttons,
output,
]
Expand Down Expand Up @@ -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:
Expand All @@ -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":
Expand All @@ -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():
Expand Down

0 comments on commit 6baeb3d

Please sign in to comment.