marco.renzi commited on
Commit
f6f0aea
·
1 Parent(s): 81ae6a8

WIP: update map and netcdf feature

Browse files
Files changed (1) hide show
  1. pages/01_dcascade.py +82 -131
pages/01_dcascade.py CHANGED
@@ -3,144 +3,93 @@ from pathlib import Path
3
  import shutil
4
  from typing import Callable, Optional, Union, cast
5
  # import leafmap
6
- import textwrap
7
- import leafmap.kepler as leafmap
8
  import solara
 
9
  from leafmap.toolbar import change_basemap
10
  from solara.components.file_drop import FileInfo
11
  from dcascade_py import dcascade_py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  zoom = solara.reactive(2)
14
  center = solara.reactive((20, 0))
15
- config = {'version': 'v1',
16
- 'config': {'visState': {'filters': [{'dataId': ['Discharge'],
17
- 'id': '58woufh3',
18
- 'name': ['ts'],
19
- 'type': 'range',
20
- 'value': [0, 1.68], ###time change here
21
- 'enlarged': False,
22
- 'plotType': 'histogram',
23
- 'animationWindow': 'free',
24
- 'yAxis': None,
25
- 'speed': 1}],
26
- 'layers': [{'id': 'lqz57i8',
27
- 'type': 'geojson',
28
- 'config': {'dataId': 'Discharge',
29
- 'label': 'Discharge',
30
- 'color': [18, 147, 154],
31
- 'highlightColor': [252, 242, 26, 255],
32
- 'columns': {'geojson': '_geojson'},
33
- 'isVisible': True,
34
- 'visConfig': {'opacity': 0.8,
35
- 'strokeOpacity': 0.3,
36
- 'thickness': 1,
37
- 'strokeColor': [210, 0, 0],
38
- 'colorRange': {'name': 'Global Warming',
39
- 'type': 'sequential',
40
- 'category': 'Uber',
41
- 'colors': ['#5A1846',
42
- '#900C3F',
43
- '#C70039',
44
- '#E3611C',
45
- '#F1920E',
46
- '#FFC300']},
47
- 'strokeColorRange': {'name': 'Ice And Fire',
48
- 'type': 'diverging',
49
- 'category': 'Uber',
50
- 'colors': ['#0198BD',
51
- '#49E3CE',
52
- '#E8FEB5',
53
- '#FEEDB1',
54
- '#FEAD54',
55
- '#D50255']},
56
- 'radius': 10,
57
- 'sizeRange': [0, 10],
58
- 'radiusRange': [0, 50],
59
- 'heightRange': [0, 500],
60
- 'elevationScale': 5,
61
- 'enableElevationZoomFactor': True,
62
- 'stroked': True,
63
- 'filled': False,
64
- 'enable3d': False,
65
- 'wireframe': False},
66
- 'hidden': False,
67
- 'textLabel': [{'field': None,
68
- 'color': [255, 255, 255],
69
- 'size': 18,
70
- 'offset': [0, 0],
71
- 'anchor': 'start',
72
- 'alignment': 'center'}]},
73
- 'visualChannels': {'colorField': None,
74
- 'colorScale': 'quantile',
75
- 'strokeColorField': {'name': 'Discharge', 'type': 'real'},
76
- 'strokeColorScale': 'quantize',
77
- 'sizeField': None,
78
- 'sizeScale': 'linear',
79
- 'heightField': None,
80
- 'heightScale': 'linear',
81
- 'radiusField': None,
82
- 'radiusScale': 'linear'}}],
83
- 'interactionConfig': {'tooltip': {'fieldsToShow': {'Discharge': [{'name': 'ts',
84
- 'format': None},
85
- {'name': 'Discharge', 'format': None}]},
86
- 'compareMode': False,
87
- 'compareType': 'absolute',
88
- 'enabled': True},
89
- 'brush': {'size': 0.5, 'enabled': False},
90
- 'geocoder': {'enabled': False},
91
- 'coordinate': {'enabled': False}},
92
- 'layerBlending': 'additive',
93
- 'splitMaps': [],
94
- 'animationConfig': {'currentTime': None, 'speed': 1}},
95
- 'mapState': {'bearing': 0,
96
- 'dragRotate': False,
97
- 'latitude': 40.24060796334474,
98
- 'longitude': 20.565835594966174,
99
- 'pitch': 0,
100
- 'zoom': 8.776177236597563,
101
- 'isSplit': False},
102
- 'mapStyle': {'styleType': 'dark',
103
- 'topLayerGroups': {},
104
- 'visibleLayerGroups': {'label': True,
105
- 'road': True,
106
- 'border': False,
107
- 'building': True,
108
- 'water': True,
109
- 'land': True,
110
- '3d building': False},
111
- 'threeDBuildingColor': [9.665468314072013,
112
- 17.18305478057247,
113
- 31.1442867897876],
114
- 'mapStyles': {}}}}
115
-
116
- class Map(leafmap.Map):
117
- def __init__(self, **kwargs):
118
- super().__init__(**kwargs)
119
- self.updateMap()
120
- # Add what you want below
121
- # self.add_basemap("OpenTopoMap")
122
- # change_basemap(self)
123
- # self.add_shp()
124
- def updateMap(self):
125
- self.add_shp("public/deposito.shp", "Discharge")
126
- self.config = config
127
- # self.add_basemap("OpenTopoMap")
128
- # change_basemap(self)
129
 
 
 
 
 
 
 
 
130
 
131
  @solara.component
132
  def MapComponent():
133
- m = Map()
134
- m.element( # type: ignore
135
- zoom=zoom.value,
136
- on_zoom=zoom.set,
137
- center=center.value,
138
- on_center=center.set,
139
- scroll_wheel_zoom=True,
140
- toolbar_ctrl=False,
141
- data_ctrl=False,
142
- )
143
- m.config = config
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
 
146
  @solara.component
@@ -165,7 +114,7 @@ def Page():
165
  partitionings = ["Direct", "Bed material fraction (BMF)", "Transport capacity function (TCF)", "Shear stress correction approach"]
166
  partitioning = solara.reactive("Shear stress correction approach")
167
  timescale = solara.reactive("20")
168
- sed_range = solara.reactive("-8,4")
169
  class_size = solara.reactive(2.5)
170
  deposit = solara.reactive(50.0)
171
  continuous_update = solara.reactive(True)
@@ -234,9 +183,9 @@ def Page():
234
  river = river_filename
235
  q = q_filename
236
  out = os.getcwd()+"/public/deposito"
237
- out_shp = out+".shp"
238
- out_prj = out+".prj"
239
- shutil.copyfile(river,out_prj)
240
  dcascade_py(river, q, sed_range=sed_range.value, class_size=class_size.value, deposit=deposit.value, timescale=sel_timescale, formula=sel_form, partitioning=sel_part, out=out_shp, version=False, verbose=False, debug=False, credits=False)
241
  set_map_loaded(True)
242
 
@@ -349,3 +298,5 @@ def Page():
349
  # dense=True,
350
  # icon=True,
351
  # )
 
 
 
3
  import shutil
4
  from typing import Callable, Optional, Union, cast
5
  # import leafmap
6
+ from ipyleaflet import Map, GeoData, basemaps, LayersControl, ScaleControl, FullScreenControl, WidgetControl, TileLayer, Marker
7
+ import geopandas as gpd
8
  import solara
9
+ from solara import FigureEcharts, display
10
  from leafmap.toolbar import change_basemap
11
  from solara.components.file_drop import FileInfo
12
  from dcascade_py import dcascade_py
13
+ import xarray as xr
14
+
15
+ # Define a callback function for the click event
16
+ def on_feature_click(feature, **kwargs):
17
+ properties = feature['properties']
18
+ print("Clicked on:", properties)
19
+ # ds_disk = xr.open_dataset(os.getcwd()+'/public/deposito.nc')
20
+ # with xr.open_dataset(os.getcwd()+'/public/deposito.nc') as ds:
21
+ # print(ds.keys())
22
+ filename = os.getcwd()+'/public/deposito.nc'
23
+ ds = xr.open_dataset(filename, decode_times=False)
24
+ print("-----")
25
+ print(ds.keys())
26
+ print(ds["Qout"].values)
27
+ # print(ds)
28
+ ds_dec = xr.decode_cf(ds,decode_timedelta=False)
29
+ print("-----")
30
+ print(ds_dec.keys())
31
+ # print(ds_dec)
32
+
33
+
34
+
35
 
36
  zoom = solara.reactive(2)
37
  center = solara.reactive((20, 0))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
+ maps = {
40
+ "OpenStreetMap.Mapnik": basemaps.OpenStreetMap.Mapnik,
41
+ "OpenTopoMap": basemaps.OpenTopoMap,
42
+ "Esri.WorldTopoMap": basemaps.Esri.WorldTopoMap,
43
+ }
44
+
45
+ map_name = solara.reactive(list(maps)[0])
46
 
47
  @solara.component
48
  def MapComponent():
49
+ # Isolation is required to prevent the map from overlapping navigation (when screen width < 960px)
50
+ with solara.Column(style={"isolation": "isolate"}):
51
+ m = Map(center=center.value, zoom = zoom.value, basemap= basemaps.Esri.WorldTopoMap)
52
+ map_type = maps[map_name.value]
53
+ url = map_type.build_url()
54
+
55
+ sel_df = gpd.read_file(os.getcwd()+'/public/deposito.shp')
56
+ geo_df = sel_df.to_crs(4326) #32634
57
+ geo_data = GeoData(geo_dataframe=geo_df, style={'color': 'black', 'fillColor': '#3366cc', 'opacity':0.5, 'weight':3.9, 'dashArray':'2', 'fillOpacity':0.1},
58
+ hover_style={'fillColor': 'red' , 'fillOpacity': 5.2}, name="deposito")
59
+ geo_data.on_click(on_feature_click)
60
+ m.add(geo_data)
61
+ m.add(LayersControl())
62
+ m.element( # type: ignore
63
+ zoom=zoom.value,
64
+ on_zoom=zoom.set,
65
+ center=center.value,
66
+ on_center=center.set,
67
+ scroll_wheel_zoom=True,
68
+ layers=[
69
+ TileLayer.element(url=url),
70
+ # Marker.element(location=marker_location.value, draggable=True, on_location=location_changed),
71
+ geo_data
72
+ ]
73
+ )
74
+ options = {
75
+ "line": {
76
+ "title": {"text": "EAD"},
77
+ "tooltip": {},
78
+ "legend": {"data": ["EAD"]},
79
+ "xAxis": {"data":[1,2,3,4,5,6,7,8]}, # {"type": "category"},
80
+ "yAxis": {"name": "€/year","nameLocation": "middle","nameGap": 40},
81
+ "emphasis": {"itemStyle": {"shadowBlur":10}},
82
+ "series": [{
83
+ "type": "line",
84
+ "universalTransition": True,
85
+ "data":[
86
+ 0,1,4,6
87
+ ]
88
+ }]
89
+ }
90
+ }
91
+ FigureEcharts(option=options["line"])
92
+
93
 
94
 
95
  @solara.component
 
114
  partitionings = ["Direct", "Bed material fraction (BMF)", "Transport capacity function (TCF)", "Shear stress correction approach"]
115
  partitioning = solara.reactive("Shear stress correction approach")
116
  timescale = solara.reactive("20")
117
+ sed_range = solara.reactive("-8,5")
118
  class_size = solara.reactive(2.5)
119
  deposit = solara.reactive(50.0)
120
  continuous_update = solara.reactive(True)
 
183
  river = river_filename
184
  q = q_filename
185
  out = os.getcwd()+"/public/deposito"
186
+ out_shp = out+".nc" #".shp"
187
+ # out_prj = out+".prj"
188
+ # shutil.copyfile(river,out_prj)
189
  dcascade_py(river, q, sed_range=sed_range.value, class_size=class_size.value, deposit=deposit.value, timescale=sel_timescale, formula=sel_form, partitioning=sel_part, out=out_shp, version=False, verbose=False, debug=False, credits=False)
190
  set_map_loaded(True)
191
 
 
298
  # dense=True,
299
  # icon=True,
300
  # )
301
+
302
+