-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial demo code for viewer extensions
- Loading branch information
Showing
4 changed files
with
242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import xarray as xr | ||
|
||
|
||
def compute_indexes(dataset): | ||
b04 = dataset.B04 | ||
b05 = dataset.B05 | ||
b06 = dataset.B06 | ||
b08 = dataset.B08 | ||
b11 = dataset.B11 | ||
scl = dataset.SCL | ||
|
||
# See https://gisgeography.com/sentinel-2-bands-combinations/ | ||
|
||
# moisture_index | ||
# | ||
moisture_index = (b08 - b11) / (b08 + b11) | ||
moisture_index.attrs.update( | ||
color_value_min=0.0, | ||
color_value_max=0.5, | ||
color_bar_name="Blues", | ||
units="-", | ||
description="Simple moisture index: (B08-B11) / (B08+B11)", | ||
) | ||
# where valid and not cloud | ||
moisture_index = moisture_index.where((scl >= 2) & (scl <= 7)) | ||
|
||
# vegetation_index | ||
# | ||
vegetation_index = (b08 - b04) / (b08 + b04) | ||
vegetation_index.attrs.update( | ||
color_value_min=0.0, | ||
color_value_max=0.25, | ||
color_bar_name="Greens", | ||
units="-", | ||
description="Simple vegetation index or NDVI: (B08-B04) / (B08+B04)", | ||
) | ||
# where water | ||
vegetation_index = vegetation_index.where(scl == 6) | ||
|
||
# chlorophyll_index | ||
# | ||
b_from, b_peek, b_to = b04, b05, b06 | ||
wlen_from = b04.attrs["wavelength"] | ||
wlen_peek = b05.attrs["wavelength"] | ||
wlen_to = b06.attrs["wavelength"] | ||
f = (wlen_peek - wlen_from) / (wlen_to - wlen_from) | ||
chlorophyll_index = (b_peek - b_from) - f * (b_to - b_from) | ||
chlorophyll_index.attrs.update( | ||
color_value_min=0.0, | ||
color_value_max=0.025, | ||
color_bar_name="viridis", | ||
units="-", | ||
description="Maximum chlorophyll index: (B05-B04) - f * (B06-B04)", | ||
) | ||
# where water | ||
chlorophyll_index = chlorophyll_index.where(scl == 6) | ||
|
||
return xr.Dataset( | ||
dict( | ||
moisture_index=moisture_index, | ||
vegetation_index=vegetation_index, | ||
chlorophyll_index=chlorophyll_index, | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
DatasetAttribution: | ||
- "© by Brockmann Consult GmbH 2024, contains modified Copernicus Data 2019, processed by ESA" | ||
|
||
DatasetChunkCacheSize: 100M | ||
|
||
DataStores: | ||
- Identifier: opensr-test | ||
StoreId: s3 | ||
StoreParams: | ||
root: opensr-test | ||
Datasets: | ||
- Path: openSR_musselbeds_use_case_waddensea_S2L2A_2018-2022.levels | ||
Identifier: waddensea | ||
Title: Wadden Sea | ||
Style: S2L2A | ||
Augmentation: | ||
Path: compute_indexes.py | ||
Function: compute_indexes | ||
|
||
Styles: | ||
- Identifier: S2L2A | ||
ColorMappings: | ||
B01: | ||
ColorBar: "Greys_r" | ||
ValueRange: [0., 0.25] | ||
B02: | ||
ColorBar: "Greys_r" | ||
ValueRange: [0., 0.25] | ||
B03: | ||
ColorBar: "Greys_r" | ||
ValueRange: [0., 0.25] | ||
B04: | ||
ColorBar: "Greys_r" | ||
ValueRange: [0., 0.25] | ||
B05: | ||
ColorBar: "Greys_r" | ||
ValueRange: [0., 0.25] | ||
B06: | ||
ColorBar: "Greys_r" | ||
ValueRange: [0., 0.25] | ||
B07: | ||
ColorBar: "Greys_r" | ||
ValueRange: [0., 0.25] | ||
B08: | ||
ColorBar: "Greys_r" | ||
ValueRange: [0., 0.25] | ||
B8A: | ||
ColorBar: "Greys_r" | ||
ValueRange: [0., 0.25] | ||
B09: | ||
ColorBar: "Greys_r" | ||
ValueRange: [0., 0.25] | ||
B10: | ||
ColorBar: "Greys_r" | ||
ValueRange: [0., 0.25] | ||
B11: | ||
ColorBar: "Greys_r" | ||
ValueRange: [0., 0.25] | ||
B12: | ||
ColorBar: "Greys_r" | ||
ValueRange: [0., 0.25] | ||
SCL: | ||
ColorBar: "Accent" | ||
ValueRange: [ 0, 255 ] | ||
rgb: | ||
Red: | ||
Variable: B04 | ||
ValueRange: [0., 0.25] | ||
Green: | ||
Variable: B03 | ||
ValueRange: [0., 0.25] | ||
Blue: | ||
Variable: B02 | ||
ValueRange: [0., 0.25] | ||
|
||
Viewer: | ||
Extensions: | ||
- Path: my_viewer_ext.ext | ||
|
||
ServiceProvider: | ||
ProviderName: "Brockmann Consult GmbH" | ||
ProviderSite: "https://www.brockmann-consult.de" | ||
ServiceContact: | ||
IndividualName: "Norman Fomferra" | ||
PositionName: "Senior Software Engineer" | ||
ContactInfo: | ||
Phone: | ||
Voice: "+49 4152 889 303" | ||
Facsimile: "+49 4152 889 330" | ||
Address: | ||
DeliveryPoint: "HZG / GITZ" | ||
City: "Geesthacht" | ||
AdministrativeArea: "Herzogtum Lauenburg" | ||
PostalCode: "21502" | ||
Country: "Germany" | ||
ElectronicMailAddress: "[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from dashipy import Extension | ||
from .my_panel_1 import panel as my_panel_1 | ||
|
||
ext = Extension(__name__) | ||
ext.add(my_panel_1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from dashipy import Component, Input, State, Output | ||
from dashipy.components import Box, Dropdown, Checkbox, Typography | ||
from dashipy.demo.contribs import Panel | ||
from dashipy.demo.context import Context | ||
|
||
|
||
panel = Panel(__name__, title="Panel B") | ||
|
||
|
||
COLORS = [("red", 0), ("green", 1), ("blue", 2), ("yellow", 3)] | ||
|
||
|
||
@panel.layout( | ||
Input(source="app", property="control.selectedDatasetId"), | ||
) | ||
def render_panel( | ||
ctx: Context, | ||
dataset_id: str = "", | ||
) -> Component: | ||
|
||
opaque = False | ||
color = 0 | ||
|
||
opaque_checkbox = Checkbox( | ||
id="opaque", | ||
value=opaque, | ||
label="Opaque", | ||
) | ||
|
||
color_dropdown = Dropdown( | ||
id="color", | ||
value=color, | ||
label="Color", | ||
options=COLORS, | ||
style={"flexGrow": 0, "minWidth": 80}, | ||
) | ||
|
||
info_text = Typography( | ||
id="info_text", text=update_info_text(ctx, dataset_id, opaque, color) | ||
) | ||
|
||
return Box( | ||
style={ | ||
"display": "flex", | ||
"flexDirection": "column", | ||
"width": "100%", | ||
"height": "100%", | ||
"gap": "6px", | ||
}, | ||
children=[opaque_checkbox, color_dropdown, info_text], | ||
) | ||
|
||
|
||
# noinspection PyUnusedLocal | ||
@panel.callback( | ||
Input(source="app", property="control.selectedDatasetId"), | ||
Input("opaque"), | ||
Input("color"), | ||
State("info_text", "text"), | ||
Output("info_text", "text"), | ||
) | ||
def update_info_text( | ||
ctx: Context, | ||
dataset_id: str = "", | ||
opaque: bool = False, | ||
color: int = 0, | ||
info_text: str = "", | ||
) -> str: | ||
opaque = opaque or False | ||
color = color if color is not None else 0 | ||
return ( | ||
f"The dataset is {dataset_id}," | ||
f" the color is {COLORS[color][0]} and" | ||
f" it {'is' if opaque else 'is not'} opaque." | ||
f" The length of the last info text" | ||
f" was {len(info_text or "")}." | ||
) |