giswqs commited on
Commit
0c0e9ec
·
1 Parent(s): 55b2b6f

Add date filter

Browse files
Files changed (3) hide show
  1. pages/01_morocco.py +51 -3
  2. pages/02_libya.py +51 -3
  3. pages/03_maui.py +51 -3
pages/01_morocco.py CHANGED
@@ -33,6 +33,14 @@ def get_catalogs(name):
33
  return catalog_ids
34
 
35
 
 
 
 
 
 
 
 
 
36
  def add_widgets(m):
37
  datasets = get_datasets()['dataset'].tolist()
38
  setattr(m, 'zoom_to_layer', True)
@@ -49,6 +57,13 @@ def add_widgets(m):
49
  catalog_ids = get_catalogs(dataset.value)
50
  setattr(m, 'catalog_ids', catalog_ids)
51
 
 
 
 
 
 
 
 
52
  image = widgets.Dropdown(
53
  value=None,
54
  options=m.catalog_ids,
@@ -78,6 +93,8 @@ def add_widgets(m):
78
  layout=widgets.Layout(width="75px", padding='0px'),
79
  )
80
 
 
 
81
  def reset_map(change):
82
  if change.new:
83
  image.value = None
@@ -85,6 +102,14 @@ def add_widgets(m):
85
  m.layers = m.layers[:3]
86
  m.zoom_to_layer = True
87
  reset.value = False
 
 
 
 
 
 
 
 
88
 
89
  reset.observe(reset_map, names='value')
90
 
@@ -106,11 +131,28 @@ def add_widgets(m):
106
 
107
  dataset.observe(change_dataset, names='value')
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  def change_image(change):
110
  if change.new:
111
  if change.new not in m.get_layer_names():
112
  mosaic = f'{url}/datasets/{dataset.value}/{image.value}.json'
113
  m.add_stac_layer(mosaic, name=image.value, fit_bounds=m.zoom_to_layer)
 
 
 
114
 
115
  image.observe(change_image, names='value')
116
 
@@ -162,7 +204,9 @@ def add_widgets(m):
162
 
163
  m.on_interaction(handle_click)
164
 
165
- box = widgets.VBox([dataset, image, widgets.HBox([checkbox, split, reset])])
 
 
166
  m.add_widget(box, position='topright', add_header=False)
167
 
168
 
@@ -190,8 +234,12 @@ class Map(leafmap.Map):
190
  default_geojson = tmp_geojson
191
  else:
192
  leafmap.download_file(default_geojson, tmp_geojson, quiet=True)
193
- self.add_geojson(default_geojson, layer_name='Footprint', zoom_to_layer=True)
194
- setattr(self, 'gdf', gpd.read_file(default_geojson))
 
 
 
 
195
 
196
 
197
  @solara.component
 
33
  return catalog_ids
34
 
35
 
36
+ def get_image_date(catalog_id, m):
37
+ gdf = m.footprint
38
+ image_date = pd.Timestamp(
39
+ gdf[gdf['catalog_id'] == catalog_id]['datetime'].values[0]
40
+ ).strftime('%Y-%m-%d %H:%M:%S')
41
+ return image_date
42
+
43
+
44
  def add_widgets(m):
45
  datasets = get_datasets()['dataset'].tolist()
46
  setattr(m, 'zoom_to_layer', True)
 
57
  catalog_ids = get_catalogs(dataset.value)
58
  setattr(m, 'catalog_ids', catalog_ids)
59
 
60
+ date_picker = widgets.DatePicker(
61
+ description='Start date:',
62
+ value=pd.to_datetime('2021-01-01').date(),
63
+ style=style,
64
+ layout=widgets.Layout(width="270px", padding=padding),
65
+ )
66
+
67
  image = widgets.Dropdown(
68
  value=None,
69
  options=m.catalog_ids,
 
93
  layout=widgets.Layout(width="75px", padding='0px'),
94
  )
95
 
96
+ output = widgets.Output()
97
+
98
  def reset_map(change):
99
  if change.new:
100
  image.value = None
 
102
  m.layers = m.layers[:3]
103
  m.zoom_to_layer = True
104
  reset.value = False
105
+ date_picker.value = pd.to_datetime('2021-01-01').date()
106
+ m.remove_layer(m.find_layer('Footprint'))
107
+ m.add_gdf(
108
+ m.footprint, layer_name='Footprint', zoom_to_layer=False, info_mode=None
109
+ )
110
+ satellite_layer = m.find_layer('Google Satellite')
111
+ satellite_layer.visible = False
112
+ output.outputs = ()
113
 
114
  reset.observe(reset_map, names='value')
115
 
 
131
 
132
  dataset.observe(change_dataset, names='value')
133
 
134
+ def change_date(change):
135
+ if change.new:
136
+ start_date = change.new.strftime('%Y-%m-%d')
137
+ sub_gdf = m.gdf[m.gdf['datetime'] >= start_date]
138
+ sub_catalog_ids = sub_gdf['catalog_id'].values.tolist()
139
+ image.options = sub_catalog_ids
140
+ m.remove_layer(m.find_layer('Footprint'))
141
+ m.add_gdf(
142
+ sub_gdf, layer_name='Footprint', zoom_to_layer=False, info_mode=None
143
+ )
144
+ m.gdf = sub_gdf
145
+
146
+ date_picker.observe(change_date, names='value')
147
+
148
  def change_image(change):
149
  if change.new:
150
  if change.new not in m.get_layer_names():
151
  mosaic = f'{url}/datasets/{dataset.value}/{image.value}.json'
152
  m.add_stac_layer(mosaic, name=image.value, fit_bounds=m.zoom_to_layer)
153
+ image_date = get_image_date(image.value, m)
154
+ output.outputs = ()
155
+ output.append_stdout(f"Image date: {image_date}\n")
156
 
157
  image.observe(change_image, names='value')
158
 
 
204
 
205
  m.on_interaction(handle_click)
206
 
207
+ box = widgets.VBox(
208
+ [dataset, date_picker, image, widgets.HBox([checkbox, split, reset]), output]
209
+ )
210
  m.add_widget(box, position='topright', add_header=False)
211
 
212
 
 
234
  default_geojson = tmp_geojson
235
  else:
236
  leafmap.download_file(default_geojson, tmp_geojson, quiet=True)
237
+ self.add_geojson(
238
+ default_geojson, layer_name='Footprint', zoom_to_layer=True, info_mode=None
239
+ )
240
+ gdf = gpd.read_file(default_geojson)
241
+ setattr(self, 'gdf', gdf)
242
+ setattr(self, 'footprint', gdf)
243
 
244
 
245
  @solara.component
pages/02_libya.py CHANGED
@@ -33,6 +33,14 @@ def get_catalogs(name):
33
  return catalog_ids
34
 
35
 
 
 
 
 
 
 
 
 
36
  def add_widgets(m):
37
  datasets = get_datasets()['dataset'].tolist()
38
  setattr(m, 'zoom_to_layer', True)
@@ -49,6 +57,13 @@ def add_widgets(m):
49
  catalog_ids = get_catalogs(dataset.value)
50
  setattr(m, 'catalog_ids', catalog_ids)
51
 
 
 
 
 
 
 
 
52
  image = widgets.Dropdown(
53
  value=None,
54
  options=m.catalog_ids,
@@ -78,6 +93,8 @@ def add_widgets(m):
78
  layout=widgets.Layout(width="75px", padding='0px'),
79
  )
80
 
 
 
81
  def reset_map(change):
82
  if change.new:
83
  image.value = None
@@ -85,6 +102,14 @@ def add_widgets(m):
85
  m.layers = m.layers[:3]
86
  m.zoom_to_layer = True
87
  reset.value = False
 
 
 
 
 
 
 
 
88
 
89
  reset.observe(reset_map, names='value')
90
 
@@ -106,11 +131,28 @@ def add_widgets(m):
106
 
107
  dataset.observe(change_dataset, names='value')
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  def change_image(change):
110
  if change.new:
111
  if change.new not in m.get_layer_names():
112
  mosaic = f'{url}/datasets/{dataset.value}/{image.value}.json'
113
  m.add_stac_layer(mosaic, name=image.value, fit_bounds=m.zoom_to_layer)
 
 
 
114
 
115
  image.observe(change_image, names='value')
116
 
@@ -162,7 +204,9 @@ def add_widgets(m):
162
 
163
  m.on_interaction(handle_click)
164
 
165
- box = widgets.VBox([dataset, image, widgets.HBox([checkbox, split, reset])])
 
 
166
  m.add_widget(box, position='topright', add_header=False)
167
 
168
 
@@ -190,8 +234,12 @@ class Map(leafmap.Map):
190
  default_geojson = tmp_geojson
191
  else:
192
  leafmap.download_file(default_geojson, tmp_geojson, quiet=True)
193
- self.add_geojson(default_geojson, layer_name='Footprint', zoom_to_layer=True)
194
- setattr(self, 'gdf', gpd.read_file(default_geojson))
 
 
 
 
195
 
196
 
197
  @solara.component
 
33
  return catalog_ids
34
 
35
 
36
+ def get_image_date(catalog_id, m):
37
+ gdf = m.footprint
38
+ image_date = pd.Timestamp(
39
+ gdf[gdf['catalog_id'] == catalog_id]['datetime'].values[0]
40
+ ).strftime('%Y-%m-%d %H:%M:%S')
41
+ return image_date
42
+
43
+
44
  def add_widgets(m):
45
  datasets = get_datasets()['dataset'].tolist()
46
  setattr(m, 'zoom_to_layer', True)
 
57
  catalog_ids = get_catalogs(dataset.value)
58
  setattr(m, 'catalog_ids', catalog_ids)
59
 
60
+ date_picker = widgets.DatePicker(
61
+ description='Start date:',
62
+ value=pd.to_datetime('2021-01-01').date(),
63
+ style=style,
64
+ layout=widgets.Layout(width="270px", padding=padding),
65
+ )
66
+
67
  image = widgets.Dropdown(
68
  value=None,
69
  options=m.catalog_ids,
 
93
  layout=widgets.Layout(width="75px", padding='0px'),
94
  )
95
 
96
+ output = widgets.Output()
97
+
98
  def reset_map(change):
99
  if change.new:
100
  image.value = None
 
102
  m.layers = m.layers[:3]
103
  m.zoom_to_layer = True
104
  reset.value = False
105
+ date_picker.value = pd.to_datetime('2021-01-01').date()
106
+ m.remove_layer(m.find_layer('Footprint'))
107
+ m.add_gdf(
108
+ m.footprint, layer_name='Footprint', zoom_to_layer=False, info_mode=None
109
+ )
110
+ satellite_layer = m.find_layer('Google Satellite')
111
+ satellite_layer.visible = False
112
+ output.outputs = ()
113
 
114
  reset.observe(reset_map, names='value')
115
 
 
131
 
132
  dataset.observe(change_dataset, names='value')
133
 
134
+ def change_date(change):
135
+ if change.new:
136
+ start_date = change.new.strftime('%Y-%m-%d')
137
+ sub_gdf = m.gdf[m.gdf['datetime'] >= start_date]
138
+ sub_catalog_ids = sub_gdf['catalog_id'].values.tolist()
139
+ image.options = sub_catalog_ids
140
+ m.remove_layer(m.find_layer('Footprint'))
141
+ m.add_gdf(
142
+ sub_gdf, layer_name='Footprint', zoom_to_layer=False, info_mode=None
143
+ )
144
+ m.gdf = sub_gdf
145
+
146
+ date_picker.observe(change_date, names='value')
147
+
148
  def change_image(change):
149
  if change.new:
150
  if change.new not in m.get_layer_names():
151
  mosaic = f'{url}/datasets/{dataset.value}/{image.value}.json'
152
  m.add_stac_layer(mosaic, name=image.value, fit_bounds=m.zoom_to_layer)
153
+ image_date = get_image_date(image.value, m)
154
+ output.outputs = ()
155
+ output.append_stdout(f"Image date: {image_date}\n")
156
 
157
  image.observe(change_image, names='value')
158
 
 
204
 
205
  m.on_interaction(handle_click)
206
 
207
+ box = widgets.VBox(
208
+ [dataset, date_picker, image, widgets.HBox([checkbox, split, reset]), output]
209
+ )
210
  m.add_widget(box, position='topright', add_header=False)
211
 
212
 
 
234
  default_geojson = tmp_geojson
235
  else:
236
  leafmap.download_file(default_geojson, tmp_geojson, quiet=True)
237
+ self.add_geojson(
238
+ default_geojson, layer_name='Footprint', zoom_to_layer=True, info_mode=None
239
+ )
240
+ gdf = gpd.read_file(default_geojson)
241
+ setattr(self, 'gdf', gdf)
242
+ setattr(self, 'footprint', gdf)
243
 
244
 
245
  @solara.component
pages/03_maui.py CHANGED
@@ -33,6 +33,14 @@ def get_catalogs(name):
33
  return catalog_ids
34
 
35
 
 
 
 
 
 
 
 
 
36
  def add_widgets(m):
37
  datasets = get_datasets()['dataset'].tolist()
38
  setattr(m, 'zoom_to_layer', True)
@@ -49,6 +57,13 @@ def add_widgets(m):
49
  catalog_ids = get_catalogs(dataset.value)
50
  setattr(m, 'catalog_ids', catalog_ids)
51
 
 
 
 
 
 
 
 
52
  image = widgets.Dropdown(
53
  value=None,
54
  options=m.catalog_ids,
@@ -78,6 +93,8 @@ def add_widgets(m):
78
  layout=widgets.Layout(width="75px", padding='0px'),
79
  )
80
 
 
 
81
  def reset_map(change):
82
  if change.new:
83
  image.value = None
@@ -85,6 +102,14 @@ def add_widgets(m):
85
  m.layers = m.layers[:3]
86
  m.zoom_to_layer = True
87
  reset.value = False
 
 
 
 
 
 
 
 
88
 
89
  reset.observe(reset_map, names='value')
90
 
@@ -106,11 +131,28 @@ def add_widgets(m):
106
 
107
  dataset.observe(change_dataset, names='value')
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  def change_image(change):
110
  if change.new:
111
  if change.new not in m.get_layer_names():
112
  mosaic = f'{url}/datasets/{dataset.value}/{image.value}.json'
113
  m.add_stac_layer(mosaic, name=image.value, fit_bounds=m.zoom_to_layer)
 
 
 
114
 
115
  image.observe(change_image, names='value')
116
 
@@ -162,7 +204,9 @@ def add_widgets(m):
162
 
163
  m.on_interaction(handle_click)
164
 
165
- box = widgets.VBox([dataset, image, widgets.HBox([checkbox, split, reset])])
 
 
166
  m.add_widget(box, position='topright', add_header=False)
167
 
168
 
@@ -190,8 +234,12 @@ class Map(leafmap.Map):
190
  default_geojson = tmp_geojson
191
  else:
192
  leafmap.download_file(default_geojson, tmp_geojson, quiet=True)
193
- self.add_geojson(default_geojson, layer_name='Footprint', zoom_to_layer=True)
194
- setattr(self, 'gdf', gpd.read_file(default_geojson))
 
 
 
 
195
 
196
 
197
  @solara.component
 
33
  return catalog_ids
34
 
35
 
36
+ def get_image_date(catalog_id, m):
37
+ gdf = m.footprint
38
+ image_date = pd.Timestamp(
39
+ gdf[gdf['catalog_id'] == catalog_id]['datetime'].values[0]
40
+ ).strftime('%Y-%m-%d %H:%M:%S')
41
+ return image_date
42
+
43
+
44
  def add_widgets(m):
45
  datasets = get_datasets()['dataset'].tolist()
46
  setattr(m, 'zoom_to_layer', True)
 
57
  catalog_ids = get_catalogs(dataset.value)
58
  setattr(m, 'catalog_ids', catalog_ids)
59
 
60
+ date_picker = widgets.DatePicker(
61
+ description='Start date:',
62
+ value=pd.to_datetime('2021-01-01').date(),
63
+ style=style,
64
+ layout=widgets.Layout(width="270px", padding=padding),
65
+ )
66
+
67
  image = widgets.Dropdown(
68
  value=None,
69
  options=m.catalog_ids,
 
93
  layout=widgets.Layout(width="75px", padding='0px'),
94
  )
95
 
96
+ output = widgets.Output()
97
+
98
  def reset_map(change):
99
  if change.new:
100
  image.value = None
 
102
  m.layers = m.layers[:3]
103
  m.zoom_to_layer = True
104
  reset.value = False
105
+ date_picker.value = pd.to_datetime('2021-01-01').date()
106
+ m.remove_layer(m.find_layer('Footprint'))
107
+ m.add_gdf(
108
+ m.footprint, layer_name='Footprint', zoom_to_layer=False, info_mode=None
109
+ )
110
+ satellite_layer = m.find_layer('Google Satellite')
111
+ satellite_layer.visible = False
112
+ output.outputs = ()
113
 
114
  reset.observe(reset_map, names='value')
115
 
 
131
 
132
  dataset.observe(change_dataset, names='value')
133
 
134
+ def change_date(change):
135
+ if change.new:
136
+ start_date = change.new.strftime('%Y-%m-%d')
137
+ sub_gdf = m.gdf[m.gdf['datetime'] >= start_date]
138
+ sub_catalog_ids = sub_gdf['catalog_id'].values.tolist()
139
+ image.options = sub_catalog_ids
140
+ m.remove_layer(m.find_layer('Footprint'))
141
+ m.add_gdf(
142
+ sub_gdf, layer_name='Footprint', zoom_to_layer=False, info_mode=None
143
+ )
144
+ m.gdf = sub_gdf
145
+
146
+ date_picker.observe(change_date, names='value')
147
+
148
  def change_image(change):
149
  if change.new:
150
  if change.new not in m.get_layer_names():
151
  mosaic = f'{url}/datasets/{dataset.value}/{image.value}.json'
152
  m.add_stac_layer(mosaic, name=image.value, fit_bounds=m.zoom_to_layer)
153
+ image_date = get_image_date(image.value, m)
154
+ output.outputs = ()
155
+ output.append_stdout(f"Image date: {image_date}\n")
156
 
157
  image.observe(change_image, names='value')
158
 
 
204
 
205
  m.on_interaction(handle_click)
206
 
207
+ box = widgets.VBox(
208
+ [dataset, date_picker, image, widgets.HBox([checkbox, split, reset]), output]
209
+ )
210
  m.add_widget(box, position='topright', add_header=False)
211
 
212
 
 
234
  default_geojson = tmp_geojson
235
  else:
236
  leafmap.download_file(default_geojson, tmp_geojson, quiet=True)
237
+ self.add_geojson(
238
+ default_geojson, layer_name='Footprint', zoom_to_layer=True, info_mode=None
239
+ )
240
+ gdf = gpd.read_file(default_geojson)
241
+ setattr(self, 'gdf', gdf)
242
+ setattr(self, 'footprint', gdf)
243
 
244
 
245
  @solara.component