Kelbec commited on
Commit
092753f
1 Parent(s): f6f0aea

WIP missing highlights on selection

Browse files
.dockerignore ADDED
@@ -0,0 +1 @@
 
 
1
+ venv
docker-compose.yml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # docker compose for dcascade image
2
+ # docker-compose up -d
3
+ services:
4
+ dcascade:
5
+ image: dcascade
6
+ build: .
7
+ ports:
8
+ - "8765:8765"
9
+ # volumes:
10
+ # - .:/dcascade
docker2ecr.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 901702069075.dkr.ecr.us-east-1.amazonaws.com
2
+ docker build -t dcascade-app --build-arg GITHUB_TOKEN=$GITHUB_TOKEN .
3
+ docker tag dcascade-app:latest 901702069075.dkr.ecr.us-east-1.amazonaws.com/dcascade-app:latest
4
+ docker push 901702069075.dkr.ecr.us-east-1.amazonaws.com/dcascade-app:latest
pages/01_dcascade.py CHANGED
@@ -12,30 +12,30 @@ 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,
@@ -44,52 +44,112 @@ maps = {
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
@@ -188,6 +248,9 @@ def Page():
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
 
192
  with solara.Div() as main:
193
 
 
12
  from dcascade_py import dcascade_py
13
  import xarray as xr
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
+ zoom = solara.reactive(6)
 
 
 
17
  center = solara.reactive((20, 0))
18
+ map_loaded = solara.reactive(False)
19
+ variables = solara.reactive([])
20
+ sel_var = solara.reactive("")
21
+ ds = solara.reactive(None)
22
+ feature_properties = solara.reactive(None)
23
+ geo_data = solara.reactive(None)
24
+ chart_options = solara.reactive({
25
+ "line": {
26
+ "title": {"text": "Variable"},
27
+ "tooltip": {},
28
+ "legend": {"data": ["Variable"]},
29
+ "xAxis": {"data":list(range(1, 21))}, # {"type": "category"},
30
+ "xAxis": {"name": "Time step","nameLocation": "middle","nameGap": 30, "data":list(range(1, 21))}, # {"type": "category"},
31
+ "yAxis": {"name": "Variable","nameLocation": "middle","nameGap": 60},
32
+ "series": [{
33
+ "type": "line",
34
+ "universalTransition": True,
35
+ "data":[]
36
+ }]
37
+ }
38
+ })
39
  maps = {
40
  "OpenStreetMap.Mapnik": basemaps.OpenStreetMap.Mapnik,
41
  "OpenTopoMap": basemaps.OpenTopoMap,
 
44
 
45
  map_name = solara.reactive(list(maps)[0])
46
 
47
+
48
+ def on_variable_change(variable):
49
+ print("feature",feature_properties.value)
50
+ if feature_properties.value is None:
51
+ solara.Warning(f"Select a feature on the map first",
52
+ text=True,
53
+ dense=True,
54
+ icon=True,
55
+ )
56
+ else:
57
+ chart_options.set({
58
+ "line": {
59
+ "title": {"text": variable+" "+str(feature_properties.value['FromN']-1)},
60
+ "tooltip": {},
61
+ "legend": {"data": [variable+" "+str(feature_properties.value['FromN']-1)]},
62
+ "xAxis": {"name": "Time step","nameLocation": "middle","nameGap": 30,"data":list(range(1, 21))}, # {"type": "category"},
63
+ "yAxis": {"name": variable+" "+str(feature_properties.value['FromN']-1),"nameLocation": "middle","nameGap": 60},
64
+ "emphasis": {"itemStyle": {"shadowBlur":10}},
65
+ "series": [{
66
+ "type": "line",
67
+ "universalTransition": True,
68
+ "data": ds.value[variable].values[:,0].tolist()
69
+ }]
70
+ }
71
+ })
72
+
73
+
74
+ # Define a callback function for the click event
75
+ def on_feature_click(feature, **kwargs):
76
+ properties = feature['properties']
77
+ print("Clicked on:", properties)
78
+ feature_properties.set(properties)
79
+
80
+ print("GD",geo_data.value.geo_dataframe)
81
+ for f in geo_data.value.geo_dataframe['FromN']:
82
+ if f == properties['FromN']:
83
+ print("FOUND f",f)
84
+ # geo_data.value.geo_dataframe.loc[geo_data.value.geo_dataframe['FromN'] == f, 'color'] = 'red'
85
+ else:
86
+ geo_data.value.geo_dataframe.loc[geo_data.value.geo_dataframe['FromN'] == f, 'color'] = '#3366cc'
87
+
88
+ # Highlight the clicked feature
89
+ # feature.style = {'color': 'red', 'fillColor': 'red', 'opacity':0.5, 'weight':3.9, 'dashArray':'2', 'fillOpacity':0.5}
90
+
91
+
92
+ filename = os.getcwd()+'/public/deposito.nc'
93
+ ds.set(xr.open_dataset(filename, decode_times=False))
94
+ variables.set(list(ds.value.keys()))
95
+
96
+ # ds_dec = xr.decode_cf(ds,decode_timedelta=False)
97
+ chart_options.set({
98
+ "line": {
99
+ "title": {"text": sel_var.value+" "+str(properties['FromN']-1)},
100
+ "tooltip": {},
101
+ "legend": {"data": [sel_var.value+" "+str(properties['FromN']-1)]},
102
+ "xAxis": {"name": "Time step","nameLocation": "middle","nameGap": 30,"data":list(range(1, 21))}, # {"type": "category"},
103
+ "yAxis": {"name": sel_var.value+" "+str(properties['FromN']-1),"nameLocation": "middle","nameGap": 60},
104
+ "emphasis": {"itemStyle": {"shadowBlur":10}},
105
+ "series": [{
106
+ "type": "line",
107
+ "universalTransition": True,
108
+ "data": ds.value[sel_var.value].values[:,properties['FromN']-1].tolist()
109
+ }]
110
+ }
111
+ })
112
+
113
+
114
  @solara.component
115
  def MapComponent():
116
  # Isolation is required to prevent the map from overlapping navigation (when screen width < 960px)
117
+ with solara.Column(style={"isolation": "isolate"}):
118
+
119
+
 
120
 
121
+ if not map_loaded.value:
122
  sel_df = gpd.read_file(os.getcwd()+'/public/deposito.shp')
123
  geo_df = sel_df.to_crs(4326) #32634
124
+ geo_data.set(GeoData(geo_dataframe=geo_df,
125
+ hover_style={'fillColor': 'red' , 'fillOpacity': 5.2}, name="deposito"))
126
+ geo_data.value.on_click(on_feature_click)
127
+ center.set((geo_df.total_bounds[1], geo_df.total_bounds[0]))
128
+ geo_data.value.style = {'color': 'black', 'fillColor': '#3366cc', 'opacity':0.5, 'weight':3.9, 'dashArray':'2', 'fillOpacity':0.1}
129
+
130
+ m = Map(center=center.value, zoom = zoom.value, basemap= basemaps.Esri.WorldTopoMap)
131
+ map_type = maps[map_name.value]
132
+ url = map_type.build_url()
133
+
134
+
135
+ m.add(geo_data.value)
136
+ m.add(LayersControl())
137
+ m.element( # type: ignore
138
+ zoom=zoom.value,
139
+ on_zoom=zoom.set,
140
+ center=center.value,
141
+ on_center=center.set,
142
+ scroll_wheel_zoom=True,
143
+ layers=[
144
+ TileLayer.element(url=url),
145
+ # Marker.element(location=marker_location.value, draggable=True, on_location=location_changed),
146
+ geo_data.value
147
+ ]
148
+ )
149
+ map_loaded.set(True)
150
+ solara.Select(label="Variable", value=sel_var, values=variables.value, on_value=on_variable_change)
151
+ FigureEcharts(option=chart_options.value["line"])
152
+
 
 
 
 
 
 
 
153
 
154
 
155
  @solara.component
 
248
  # shutil.copyfile(river,out_prj)
249
  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)
250
  set_map_loaded(True)
251
+ filename = os.getcwd()+'/public/deposito.nc'
252
+ ds.set(xr.open_dataset(filename, decode_times=False))
253
+ variables.set(list(ds.value.keys()))
254
 
255
  with solara.Div() as main:
256
 
pages/01_dcascade_OLD.py ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ 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
147
+ def Page():
148
+ with solara.Column(style={"min-width": "500px"}):
149
+
150
+ content, set_content = solara.use_state(b"")
151
+ uploaded, set_uploaded = solara.use_state(b"")
152
+ filename, set_filename = solara.use_state("")
153
+ river_filename, set_river_filename = solara.use_state("")
154
+ q_filename, set_q_filename = solara.use_state("")
155
+ error_select_csv, set_error_select_csv = solara.use_state("")
156
+ error_select_shp, set_error_select_shp = solara.use_state("")
157
+ no_file_selected, set_no_file_selected = solara.use_state("")
158
+ # removed_data, set_removed = solara.use_state("")
159
+ size, set_size = solara.use_state(0)
160
+ file_browser, set_file_browser = solara.use_state(cast(Optional[Path], None))
161
+ map_loaded, set_map_loaded = solara.use_state(False)
162
+
163
+ formulas = ["Parker and Klingeman 1982", "Wilkock and Crowe 2003", "Engelund and Hansen 1967", "Yang formula 1989", "Wong and Parker 2006", "Ackers and White formula 1973"]
164
+ formula = solara.reactive("Engelund and Hansen 1967")
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)
172
+
173
+
174
+
175
+ def on_file(file: FileInfo):
176
+ set_filename(file["name"])
177
+ set_size(file["size"])
178
+ f = file["file_obj"]
179
+ set_content(f.read())
180
+ set_uploaded(False)
181
+
182
+ def upload_file():
183
+ if content:
184
+
185
+ file_path = os.path.join("public",filename)
186
+ with open(file_path,"wb") as file:
187
+ file.write(content)
188
+ if filename.endswith(".zip"):
189
+ shutil.unpack_archive(os.getcwd()+"/public/"+filename,os.getcwd()+"/public")
190
+ os.remove(os.getcwd()+"/public/"+filename)
191
+
192
+ set_uploaded(True)
193
+
194
+ def open_river_file():
195
+ if file_browser:
196
+ file_path = os.path.join(os.getcwd(),file_browser)
197
+ if file_path.endswith(".shp"):
198
+ set_river_filename(file_path)
199
+ set_error_select_shp(False)
200
+ set_no_file_selected(False)
201
+ else:
202
+ set_error_select_shp(True)
203
+ else:
204
+ set_error_select_shp(True)
205
+
206
+
207
+ def open_q_file():
208
+ if file_browser:
209
+ file_path = os.path.join(os.getcwd(),file_browser)
210
+ if file_path.endswith(".csv"):
211
+ set_q_filename(file_path)
212
+ set_error_select_csv(False)
213
+ else:
214
+ set_error_select_csv(True)
215
+ else:
216
+ set_error_select_csv(True)
217
+
218
+ def remove_data():
219
+ for file in os.listdir(os.getcwd()+"/public"):
220
+ os.remove(os.getcwd()+"/public/"+file)
221
+
222
+
223
+ def run_dcascade():
224
+
225
+ if (river_filename == "" or q_filename == ""):
226
+ set_no_file_selected(True)
227
+ else:
228
+ set_no_file_selected(False)
229
+ sel_form = formulas.index(str(formula).replace("'",""))+1
230
+ sel_part = partitionings.index(str(partitioning).replace("'",""))+1
231
+ sel_timescale = int(str(timescale).replace("'",""))
232
+
233
+ set_map_loaded(False)
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
+ print("Calling dcascade_py with parameters: river: ", river, " q: ", 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)
241
+ 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)
242
+ set_map_loaded(True)
243
+
244
+ with solara.Div() as main:
245
+
246
+ with solara.Card("Dcascade"):
247
+ if map_loaded:
248
+ MapComponent()
249
+ with solara.Card("Upload files"):
250
+ solara.Markdown("Required \*.shp, \*.shx, \*.dbf and \*.prj files for **river** file and \*.csv for **q** file. Upload files one at the time or compressed in a *zip* archive.")
251
+ with solara.ColumnsResponsive(1, large=6):
252
+ solara.FileDrop(
253
+ label="Drag and drop a file here ",
254
+ on_file=on_file,
255
+ lazy=True,
256
+ )
257
+ solara.Button("Upload file",
258
+ color="primary",
259
+ on_click=upload_file)
260
+ if content and not uploaded:
261
+ solara.Info(f"File {filename} has total length: {size}\n",
262
+ text=True,
263
+ dense=True,
264
+ icon=True,
265
+ )
266
+ # solara.Preformatted("\n".join(textwrap.wrap(repr(content))))
267
+ # solara.Preformatted("\n".join(textwrap.wrap(repr(filename))))
268
+ elif uploaded:
269
+ solara.Success(
270
+ f"{filename} uploaded",
271
+ text=True,
272
+ dense=True,
273
+ icon=True,
274
+ )
275
+
276
+
277
+
278
+ with solara.Card("Select parameters"):
279
+ with solara.ColumnsResponsive(3, large=4):
280
+
281
+ solara.InputText("Timescale (days)", value=timescale, continuous_update=continuous_update.value)
282
+
283
+ solara.Select(label="Formula", value=formula, values=formulas)
284
+ # solara.Markdown(f"**Selected**: {formula.value}")
285
+
286
+ solara.Select(label="Partitioning ", value=partitioning, values=partitionings)
287
+ # solara.Markdown(f"**Selected**: {partitioning.value}")
288
+
289
+ solara.InputText(label="Sed range ", value=sed_range)
290
+
291
+ solara.InputFloat(label="Class size ", value=class_size)
292
+
293
+ solara.InputFloat(label="Deposit ", value=deposit)
294
+
295
+ with solara.Card("Select files"):
296
+ solara.Markdown("Select **river** and **q** files from file explorer below, the uploaded files can be found in /public folder. To select files click on the explorer the click on *SELECT RIVER FILE* or *SELECT Q FILE* based on the file selected.")
297
+ with solara.ColumnsResponsive(3, large=6):
298
+ solara.Markdown(f"**River file**: {river_filename}")
299
+
300
+ solara.Button("Select river file",
301
+ color="primary",
302
+ on_click=open_river_file)
303
+ with solara.ColumnsResponsive(3, large=6):
304
+ solara.Markdown(f"**Q file**: {q_filename}")
305
+
306
+ solara.Button("Select Q file",
307
+ color="primary",
308
+ on_click=open_q_file)
309
+ if error_select_csv:
310
+ solara.Warning(f"Q file must be csv",
311
+ text=True,
312
+ dense=True,
313
+ icon=True,
314
+ )
315
+ if error_select_shp:
316
+ solara.Warning(f"River file must be shp",
317
+ text=True,
318
+ dense=True,
319
+ icon=True,
320
+ )
321
+
322
+ solara.FileBrowser(
323
+ can_select=False,
324
+ on_file_open=set_file_browser,
325
+ directory="./public"
326
+ )
327
+ with solara.Card("Run model"):
328
+ with solara.ColumnsResponsive(3, large=6):
329
+ solara.Markdown("Click on DCASCADE button to run the model and generate the output map")
330
+ solara.Button("DCASCADE",
331
+ color="primary",
332
+ on_click=run_dcascade)
333
+ if no_file_selected:
334
+ solara.Warning(f"Select both River and Q files",
335
+ text=True,
336
+ dense=True,
337
+ icon=True,
338
+ )
339
+ # solara.Button("REMOVE DATA",
340
+ # color="secondary",
341
+ # on_click=remove_data)
342
+ # solara.Info(f"You are in directory: {directory}")
343
+ # solara.Info(f"You selected path: {path}")
344
+ # solara.Info(f"You opened file: {file}")
345
+ # if removed_data:
346
+
347
+ # solara.Success(
348
+ # f"Removed data",
349
+ # text=True,
350
+ # dense=True,
351
+ # icon=True,
352
+ # )