giswqs commited on
Commit
2daf2f9
·
1 Parent(s): c63dc1e

Add landsat image

Browse files
Files changed (1) hide show
  1. pages/03_landsat.py +82 -9
pages/03_landsat.py CHANGED
@@ -21,24 +21,42 @@ class Map(geemap.Map):
21
  style = {"description_width": "initial"}
22
  padding = "0px 5px 0px 5px"
23
  pre_start_date = widgets.DatePicker(
24
- description="Start", layout=layout, style=style
 
 
 
 
 
 
 
25
  )
26
- pre_end_date = widgets.DatePicker(description="End", layout=layout, style=style)
27
  pre_cloud_cover = widgets.IntSlider(
28
  description="Cloud",
29
  min=0,
30
  max=100,
31
  value=25,
32
  step=1,
 
33
  style=style,
34
- layout=widgets.Layout(padding=padding, width="200px"),
35
  )
36
- pre_widget.children = [pre_start_date, pre_end_date, pre_cloud_cover]
 
 
 
 
 
 
 
37
  post_start_date = widgets.DatePicker(
38
- description="Start", layout=layout, style=style
 
 
39
  )
40
  post_end_date = widgets.DatePicker(
41
- description="End", layout=layout, style=style
 
 
42
  )
43
  post_cloud_cover = widgets.IntSlider(
44
  description="Cloud",
@@ -46,20 +64,75 @@ class Map(geemap.Map):
46
  max=100,
47
  value=30,
48
  step=1,
 
49
  style=style,
50
- layout=widgets.Layout(padding=padding, width="200px"),
51
  )
52
- post_widget.children = [post_start_date, post_end_date, post_cloud_cover]
 
 
 
 
 
 
 
53
 
54
  apply_btn = widgets.Button(description="Apply", layout=layout)
55
  split_btn = widgets.Button(description="Split", layout=layout)
56
  reset_btn = widgets.Button(description="Reset", layout=layout)
57
  close_btn = widgets.Button(description="Close", layout=layout)
58
  buttons = widgets.HBox([apply_btn, split_btn, reset_btn, close_btn])
 
59
 
60
- widget.children = [pre_widget, post_widget, buttons]
61
  self.add_widget(widget, position=position, **kwargs)
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  @solara.component
65
  def Page():
 
21
  style = {"description_width": "initial"}
22
  padding = "0px 5px 0px 5px"
23
  pre_start_date = widgets.DatePicker(
24
+ description="Start",
25
+ style=style,
26
+ layout=widgets.Layout(padding=padding, width="160px"),
27
+ )
28
+ pre_end_date = widgets.DatePicker(
29
+ description="End",
30
+ style=style,
31
+ layout=widgets.Layout(padding=padding, width="160px"),
32
  )
 
33
  pre_cloud_cover = widgets.IntSlider(
34
  description="Cloud",
35
  min=0,
36
  max=100,
37
  value=25,
38
  step=1,
39
+ readout=False,
40
  style=style,
41
+ layout=widgets.Layout(padding=padding, width="130px"),
42
  )
43
+ pre_cloud_label = widgets.Label(value=str(pre_cloud_cover.value))
44
+ geemap.jslink_slider_label(pre_cloud_cover, pre_cloud_label)
45
+ pre_widget.children = [
46
+ pre_start_date,
47
+ pre_end_date,
48
+ pre_cloud_cover,
49
+ pre_cloud_label,
50
+ ]
51
  post_start_date = widgets.DatePicker(
52
+ description="Start",
53
+ style=style,
54
+ layout=widgets.Layout(padding=padding, width="160px"),
55
  )
56
  post_end_date = widgets.DatePicker(
57
+ description="End",
58
+ style=style,
59
+ layout=widgets.Layout(padding=padding, width="160px"),
60
  )
61
  post_cloud_cover = widgets.IntSlider(
62
  description="Cloud",
 
64
  max=100,
65
  value=30,
66
  step=1,
67
+ readout=False,
68
  style=style,
69
+ layout=widgets.Layout(padding=padding, width="130px"),
70
  )
71
+ post_cloud_label = widgets.Label(value=str(post_cloud_cover.value))
72
+ geemap.jslink_slider_label(post_cloud_cover, post_cloud_label)
73
+ post_widget.children = [
74
+ post_start_date,
75
+ post_end_date,
76
+ post_cloud_cover,
77
+ post_cloud_label,
78
+ ]
79
 
80
  apply_btn = widgets.Button(description="Apply", layout=layout)
81
  split_btn = widgets.Button(description="Split", layout=layout)
82
  reset_btn = widgets.Button(description="Reset", layout=layout)
83
  close_btn = widgets.Button(description="Close", layout=layout)
84
  buttons = widgets.HBox([apply_btn, split_btn, reset_btn, close_btn])
85
+ output = widgets.Output()
86
 
87
+ widget.children = [pre_widget, post_widget, buttons, output]
88
  self.add_widget(widget, position=position, **kwargs)
89
 
90
+ def apply_btn_click(b):
91
+
92
+ if self.user_roi is None:
93
+ output.clear_output()
94
+ output.append_stdout("Please draw a ROI first.")
95
+ elif (
96
+ pre_start_date.value is None
97
+ or pre_end_date.value is None
98
+ or post_start_date.value is None
99
+ or post_end_date.value is None
100
+ ):
101
+ output.clear_output()
102
+ output.append_stdout("Please select start and end dates.")
103
+
104
+ elif self.user_roi is not None:
105
+ output.clear_output()
106
+ output.append_stdout("Computing... Please wait.")
107
+ roi = ee.FeatureCollection(self.user_roi)
108
+ pre_col = (
109
+ ee.ImageCollection("NASA/HLS/HLSL30/v002")
110
+ .filterBounds(roi)
111
+ .filterDate(
112
+ pre_start_date.value.strftime("%Y-%m-%d"),
113
+ pre_end_date.value.strftime("%Y-%m-%d"),
114
+ )
115
+ .filter(ee.Filter.lt("CLOUD_COVERAGE", pre_cloud_cover.value))
116
+ )
117
+ post_col = (
118
+ ee.ImageCollection("NASA/HLS/HLSL30/v002")
119
+ .filterBounds(roi)
120
+ .filterDate(
121
+ post_start_date.value.strftime("%Y-%m-%d"),
122
+ post_end_date.value.strftime("%Y-%m-%d"),
123
+ )
124
+ .filter(ee.Filter.lt("CLOUD_COVERAGE", post_cloud_cover.value))
125
+ )
126
+
127
+ pre_img = pre_col.median().clip(roi)
128
+ post_img = post_col.median().clip(roi)
129
+ vis_params = {"bands": ["B6", "B5", "B4"], "min": 0, "max": 0.4}
130
+ self.add_layer(pre_img, vis_params, "Pre-event Image")
131
+ self.add_layer(post_img, vis_params, "Post-event Image")
132
+ output.clear_output()
133
+
134
+ apply_btn.on_click(apply_btn_click)
135
+
136
 
137
  @solara.component
138
  def Page():