forked from chicham/snapearth_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
117 lines (100 loc) · 2.55 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# ---
# jupyter:
# jupytext:
# cell_metadata_filter: -all
# formats: ipynb,py:percent
# text_representation:
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.13.4
# ---
# %%
from datetime import datetime, timedelta
import ipywidgets as widgets
import nest_asyncio
from IPython.display import clear_output, display
from ipywidgets.widgets.widget_box import GridBox, HBox
from ipywidgets.widgets.widget_layout import Layout
from utils import EUROPE_COORDINATES, DemoConfig, plot_responses
nest_asyncio.apply()
cfg: DemoConfig = DemoConfig.from_environ(
{
"SNAPEARTH_GRPC_HOST": "earthsignature.snapearth.eu",
"SNAPEARTH_GRPC_PORT": 443,
"SNAPEARTH_GRPC_USE_SSL": True,
"SNAPEARTH_GRPC_KEEPALIVE_TIMEOUT_MS": 60000,
"SNAPEARTH_GRPC_MAX_RECEIVE_MESSAGE_LENGTH": 10**20,
"SNAPEARTH_GRPC_MAX_SEND_MESSAGE_LENGTH": 10**20,
},
)
style = {"description_width": "initial"}
geom = widgets.Text(
value=str(EUROPE_COORDINATES),
placeholder="",
description="WKT polygon of the area of interest",
disabled=False,
)
start_date = widgets.DatePicker(
value=datetime.now() - timedelta(1),
description="Start date",
disabled=False,
)
end_date = widgets.DatePicker(
value=datetime.now() - timedelta(1),
description="Stop date",
disabled=False,
)
product_ids = widgets.Text(
value="",
placeholder="",
description="Product IDs (comma separated)",
disabled=False,
style=style,
)
categories = widgets.Text(
value="",
description="Categories (comma separated)",
disabled=False,
style=style,
)
n_results = widgets.IntSlider(
value=cfg.grpc.max_results,
min=1,
max=20,
step=1,
description="Max results",
disabled=False,
)
submit = widgets.Button(description="Submit")
output = widgets.Output()
def on_click(_):
output.clear_output()
with output:
map_ = plot_responses(
cfg.grpc.host,
cfg.grpc.port,
cfg.grpc.use_ssl,
geom,
start_date,
end_date,
product_ids,
categories,
n_results,
)
display(map_)
submit.on_click(on_click)
# %%
form = widgets.VBox(
children=[geom, start_date, end_date, product_ids, categories, n_results, submit],
)
display(
GridBox(
children=[form, output],
layout=Layout(
grid_template_rows="auto",
grid_template_columns="30% auto",
grid_gap="5px 10px",
),
),
)