Spaces:
Running
Running
Add JRC app
Browse files- pages/01_jrc.py +85 -0
- pages/02_inspector.py +0 -53
- pages/03_plotting.py +0 -5
- pages/04_split_map.py +0 -5
pages/01_jrc.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import ee
|
3 |
+
import geemap
|
4 |
+
import ipywidgets as widgets
|
5 |
+
from IPython.display import display
|
6 |
+
import solara
|
7 |
+
|
8 |
+
|
9 |
+
class Map(geemap.Map):
|
10 |
+
def __init__(self, **kwargs):
|
11 |
+
super().__init__(**kwargs)
|
12 |
+
url = "https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}"
|
13 |
+
self.add_tile_layer(url, name="Google Satellite", attribution="Google")
|
14 |
+
self.add_ee_data()
|
15 |
+
self.add_buttons(add_header=True)
|
16 |
+
|
17 |
+
def add_ee_data(self):
|
18 |
+
|
19 |
+
dataset = ee.Image("JRC/GSW1_4/GlobalSurfaceWater")
|
20 |
+
image = dataset.select(["occurrence"])
|
21 |
+
vis_params = {
|
22 |
+
"min": 0.0,
|
23 |
+
"max": 100.0,
|
24 |
+
"palette": ["ffffff", "ffbbbb", "0000ff"],
|
25 |
+
}
|
26 |
+
self.addLayer(image, vis_params, "Occurrence")
|
27 |
+
self.add_colorbar(
|
28 |
+
vis_params, label="Water occurrence (%)", layer_name="Occurrence"
|
29 |
+
)
|
30 |
+
|
31 |
+
def add_buttons(self, position="topright", **kwargs):
|
32 |
+
widget = widgets.VBox()
|
33 |
+
layout = layout = widgets.Layout(width="auto")
|
34 |
+
hist_btn = widgets.Button(description="Show histogram", layout=layout)
|
35 |
+
bar_btn = widgets.Button(description="Show bar chart", layout=layout)
|
36 |
+
reset_btn = widgets.Button(description="Reset", layout=layout)
|
37 |
+
scale = widgets.IntSlider(min=30, max=1000, value=90, description="Scale")
|
38 |
+
widget.children = [widgets.HBox([hist_btn, bar_btn, reset_btn]), scale]
|
39 |
+
self.add_widget(widget, position=position, **kwargs)
|
40 |
+
output = widgets.Output()
|
41 |
+
self.add_widget(output, position="bottomleft", add_header=False)
|
42 |
+
|
43 |
+
def hist_btn_click(b):
|
44 |
+
region = self.user_roi
|
45 |
+
if region is not None:
|
46 |
+
image = ee.Image("JRC/GSW1_4/GlobalSurfaceWater").select(["occurrence"])
|
47 |
+
self.default_style = {"cursor": "wait"}
|
48 |
+
hist = geemap.image_histogram(
|
49 |
+
image,
|
50 |
+
region,
|
51 |
+
scale=60,
|
52 |
+
height=350,
|
53 |
+
width=550,
|
54 |
+
x_label="Water Occurrence (%)",
|
55 |
+
y_label="Pixel Count",
|
56 |
+
layout_args={
|
57 |
+
"title": dict(x=0.5),
|
58 |
+
"margin": dict(l=0, r=0, t=10, b=0),
|
59 |
+
},
|
60 |
+
return_df=False,
|
61 |
+
)
|
62 |
+
output.clear_output()
|
63 |
+
with output:
|
64 |
+
display(hist)
|
65 |
+
self.default_style = {"cursor": "default"}
|
66 |
+
|
67 |
+
hist_btn.on_click(hist_btn_click)
|
68 |
+
|
69 |
+
def reset_btn_click(b):
|
70 |
+
self._draw_control.clear()
|
71 |
+
output.clear_output()
|
72 |
+
|
73 |
+
reset_btn.on_click(reset_btn_click)
|
74 |
+
|
75 |
+
|
76 |
+
@solara.component
|
77 |
+
def Page():
|
78 |
+
with solara.Column(style={"min-width": "500px"}):
|
79 |
+
Map.element(
|
80 |
+
center=[20, -0],
|
81 |
+
zoom=2,
|
82 |
+
height="800px",
|
83 |
+
zoom_ctrl=False,
|
84 |
+
measure_ctrl=False,
|
85 |
+
)
|
pages/02_inspector.py
DELETED
@@ -1,53 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import ee
|
3 |
-
import geemap
|
4 |
-
|
5 |
-
import solara
|
6 |
-
|
7 |
-
# service_account = os.environ.get("EARTHENGINE_SERVICE_ACCOUNT", False)
|
8 |
-
# if isinstance(service_account, str):
|
9 |
-
# service_account = True
|
10 |
-
# geemap.ee_initialize(service_account=service_account)
|
11 |
-
|
12 |
-
|
13 |
-
class Map(geemap.Map):
|
14 |
-
def __init__(self, **kwargs):
|
15 |
-
super().__init__(**kwargs)
|
16 |
-
self.add_ee_data()
|
17 |
-
self.add("layer_manager")
|
18 |
-
self.add("inspector")
|
19 |
-
|
20 |
-
def add_ee_data(self):
|
21 |
-
# Add Earth Engine dataset
|
22 |
-
dem = ee.Image("USGS/SRTMGL1_003")
|
23 |
-
landsat7 = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003").select(
|
24 |
-
["B1", "B2", "B3", "B4", "B5", "B7"]
|
25 |
-
)
|
26 |
-
states = ee.FeatureCollection("TIGER/2018/States")
|
27 |
-
|
28 |
-
# Set visualization parameters.
|
29 |
-
vis_params = {
|
30 |
-
"min": 0,
|
31 |
-
"max": 4000,
|
32 |
-
"palette": ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"],
|
33 |
-
}
|
34 |
-
|
35 |
-
# Add Earth Engine layers to Map
|
36 |
-
self.addLayer(
|
37 |
-
landsat7,
|
38 |
-
{"bands": ["B4", "B3", "B2"], "min": 20, "max": 200, "gamma": 2.0},
|
39 |
-
"Landsat 7",
|
40 |
-
True,
|
41 |
-
)
|
42 |
-
self.addLayer(dem, vis_params, "SRTM DEM", True, 1)
|
43 |
-
self.addLayer(states, {}, "US States")
|
44 |
-
|
45 |
-
|
46 |
-
@solara.component
|
47 |
-
def Page():
|
48 |
-
with solara.Column(style={"min-width": "500px"}):
|
49 |
-
Map.element(
|
50 |
-
center=[40, -100],
|
51 |
-
zoom=4,
|
52 |
-
height="600px",
|
53 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/03_plotting.py
CHANGED
@@ -4,11 +4,6 @@ import geemap
|
|
4 |
|
5 |
import solara
|
6 |
|
7 |
-
# service_account = os.environ.get("EARTHENGINE_SERVICE_ACCOUNT", False)
|
8 |
-
# if isinstance(service_account, str):
|
9 |
-
# service_account = True
|
10 |
-
# geemap.ee_initialize(service_account=service_account)
|
11 |
-
|
12 |
|
13 |
class Map(geemap.Map):
|
14 |
def __init__(self, **kwargs):
|
|
|
4 |
|
5 |
import solara
|
6 |
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
class Map(geemap.Map):
|
9 |
def __init__(self, **kwargs):
|
pages/04_split_map.py
CHANGED
@@ -4,11 +4,6 @@ import geemap
|
|
4 |
|
5 |
import solara
|
6 |
|
7 |
-
# service_account = os.environ.get("EARTHENGINE_SERVICE_ACCOUNT", False)
|
8 |
-
# if isinstance(service_account, str):
|
9 |
-
# service_account = True
|
10 |
-
# geemap.ee_initialize(service_account=service_account)
|
11 |
-
|
12 |
|
13 |
class Map(geemap.Map):
|
14 |
def __init__(self, **kwargs):
|
|
|
4 |
|
5 |
import solara
|
6 |
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
class Map(geemap.Map):
|
9 |
def __init__(self, **kwargs):
|