giswqs commited on
Commit
3272eed
·
1 Parent(s): c4cec6d

Add monthly history

Browse files
Files changed (1) hide show
  1. pages/01_jrc.py +65 -8
pages/01_jrc.py CHANGED
@@ -29,13 +29,30 @@ class Map(geemap.Map):
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)
@@ -43,12 +60,14 @@ class Map(geemap.Map):
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 (%)",
@@ -59,13 +78,51 @@ class Map(geemap.Map):
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()
 
29
  )
30
 
31
  def add_buttons(self, position="topright", **kwargs):
32
+ padding = "0px 5px 0px 5px"
33
+ widget = widgets.VBox(layout=widgets.Layout(padding=padding))
34
+ layout = widgets.Layout(width="auto")
35
+ style = {"description_width": "initial"}
36
+ hist_btn = widgets.Button(description="Occurrence", layout=layout)
37
+ bar_btn = widgets.Button(description="Monthly history", layout=layout)
38
  reset_btn = widgets.Button(description="Reset", layout=layout)
39
+ scale = widgets.IntSlider(
40
+ min=30, max=1000, value=90, description="Scale", layout=layout, style=style
41
+ )
42
+ month_slider = widgets.IntRangeSlider(
43
+ description="Months",
44
+ value=[5, 10],
45
+ min=1,
46
+ max=12,
47
+ step=1,
48
+ layout=layout,
49
+ style=style,
50
+ )
51
+ widget.children = [
52
+ widgets.HBox([hist_btn, bar_btn, reset_btn]),
53
+ month_slider,
54
+ scale,
55
+ ]
56
  self.add_widget(widget, position=position, **kwargs)
57
  output = widgets.Output()
58
  self.add_widget(output, position="bottomleft", add_header=False)
 
60
  def hist_btn_click(b):
61
  region = self.user_roi
62
  if region is not None:
63
+ output.clear_output()
64
+ output.append_stdout("Computing histogram...")
65
  image = ee.Image("JRC/GSW1_4/GlobalSurfaceWater").select(["occurrence"])
66
  self.default_style = {"cursor": "wait"}
67
  hist = geemap.image_histogram(
68
  image,
69
  region,
70
+ scale=scale.value,
71
  height=350,
72
  width=550,
73
  x_label="Water Occurrence (%)",
 
78
  },
79
  return_df=False,
80
  )
81
+
82
  with output:
83
+ output.clear_output()
84
  display(hist)
85
  self.default_style = {"cursor": "default"}
86
+ else:
87
+ output.clear_output()
88
+ with output:
89
+ output.append_stdout("Please draw a region of interest first.")
90
 
91
  hist_btn.on_click(hist_btn_click)
92
 
93
+ def bar_btn_click(b):
94
+ region = self.user_roi
95
+ if region is not None:
96
+ self.default_style = {"cursor": "wait"}
97
+ output.clear_output()
98
+ output.append_stdout("Computing monthly history...")
99
+ bar = geemap.jrc_hist_monthly_history(
100
+ region=region,
101
+ scale=scale.value,
102
+ height=350,
103
+ width=550,
104
+ layout_args={
105
+ "title": dict(x=0.5),
106
+ "margin": dict(l=0, r=0, t=10, b=0),
107
+ },
108
+ frequency="month",
109
+ start_month=month_slider.value[0],
110
+ end_month=month_slider.value[1],
111
+ denominator=1e4,
112
+ y_label="Area (ha)",
113
+ )
114
+
115
+ with output:
116
+ output.clear_output()
117
+ display(bar)
118
+ self.default_style = {"cursor": "default"}
119
+ else:
120
+ output.clear_output()
121
+ with output:
122
+ output.append_stdout("Please draw a region of interest first.")
123
+
124
+ bar_btn.on_click(bar_btn_click)
125
+
126
  def reset_btn_click(b):
127
  self._draw_control.clear()
128
  output.clear_output()