Kelbec commited on
Commit
b851993
1 Parent(s): 0ee5691

fix output charts

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. pages/01_dcascade.py +45 -15
Dockerfile CHANGED
@@ -9,7 +9,7 @@ RUN mamba install -c conda-forge leafmap geopandas localtileserver -y && \
9
  USER root
10
  RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
11
  RUN conda install -c conda-forge gdal
12
- RUN pip install git+https://${GITHUB_TOKEN}@github.com/saferplaces/dcascade_py.git@development
13
  RUN pip install keplergl
14
  RUN pip install xarray
15
  COPY requirements.txt .
 
9
  USER root
10
  RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
11
  RUN conda install -c conda-forge gdal
12
+ RUN pip install git+https://${GITHUB_TOKEN}@github.com/saferplaces/dcascade_py.git
13
  RUN pip install keplergl
14
  RUN pip install xarray
15
  COPY requirements.txt .
pages/01_dcascade.py CHANGED
@@ -4,6 +4,7 @@ import shutil
4
  from typing import Optional, cast
5
  from ipyleaflet import Map, GeoData, basemaps, LayersControl, TileLayer
6
  import geopandas as gpd
 
7
  import solara
8
  from solara import FigureEcharts
9
  from solara.components.file_drop import FileInfo
@@ -24,15 +25,32 @@ ds = solara.reactive(None)
24
  feature_properties = solara.reactive(None)
25
  geo_data = solara.reactive(None)
26
  sel_feature = solara.reactive(None)
27
- timescale = solara.reactive("20")
28
  sed_range = solara.reactive("-8,5")
29
  class_size = solara.reactive(2.5)
30
- deposit = solara.reactive(50.0)
31
  continuous_update = solara.reactive(True)
32
- 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"]
33
  formula = solara.reactive("Engelund and Hansen 1967")
34
- partitionings = ["Direct", "Bed material fraction (BMF)", "Transport capacity function (TCF)", "Shear stress correction approach"]
35
- partitioning = solara.reactive("Shear stress correction approach")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  chart_options = solara.reactive({
38
  "line": {
@@ -75,18 +93,23 @@ def on_variable_change(variable):
75
  icon=True,
76
  )
77
  else:
 
 
 
 
 
78
  chart_options.set({
79
  "line": {
80
- "title": {"text": sel_var.value+" "+str(feature_properties.value['FromN']-1)},
81
  "tooltip": {},
82
- "legend": {"data": [sel_var.value+" "+str(feature_properties.value['FromN']-1)]},
83
  "xAxis": {"name": "Time step","nameLocation": "middle","nameGap": 30,"data":list(range(1, int(timescale.value)+1))}, # {"type": "category"},
84
- "yAxis": {"name": sel_var.value+" "+str(feature_properties.value['FromN']-1),"nameLocation": "middle","nameGap": 60},
85
  "emphasis": {"itemStyle": {"shadowBlur":10}},
86
  "series": [{
87
  "type": "line",
88
  "universalTransition": True,
89
- "data": ds.value[sel_var.value].values[:,feature_properties.value['FromN']-1].tolist()
90
  }]
91
  }
92
  })
@@ -104,18 +127,23 @@ def on_feature_click(feature, **kwargs):
104
  variables.set(list(ds.value.keys()))
105
 
106
  # ds_dec = xr.decode_cf(ds,decode_timedelta=False)
 
 
 
 
 
107
  chart_options.set({
108
  "line": {
109
- "title": {"text": sel_var.value+" "+str(properties['FromN']-1)},
110
  "tooltip": {},
111
- "legend": {"data": [sel_var.value+" "+str(properties['FromN']-1)]},
112
  "xAxis": {"name": "Time step","nameLocation": "middle","nameGap": 30,"data":list(range(1, int(timescale.value)+1))}, # {"type": "category"},
113
- "yAxis": {"name": sel_var.value+" "+str(properties['FromN']-1),"nameLocation": "middle","nameGap": 60},
114
  "emphasis": {"itemStyle": {"shadowBlur":10}},
115
  "series": [{
116
  "type": "line",
117
  "universalTransition": True,
118
- "data": ds.value[sel_var.value].values[:,properties['FromN']-1].tolist()
119
  }]
120
  }
121
  })
@@ -291,8 +319,10 @@ def Page():
291
  if ds.value is not None:
292
  ds.value.close()
293
  set_no_file_selected(False)
294
- sel_form = formulas.index(str(formula).replace("'",""))+1
295
- sel_part = partitionings.index(str(partitioning).replace("'",""))+1
 
 
296
  # sel_timescale = int(str(timescale).replace("'",""))
297
  sel_timescale = int(timescale.value)
298
 
 
4
  from typing import Optional, cast
5
  from ipyleaflet import Map, GeoData, basemaps, LayersControl, TileLayer
6
  import geopandas as gpd
7
+ import numpy as np
8
  import solara
9
  from solara import FigureEcharts
10
  from solara.components.file_drop import FileInfo
 
25
  feature_properties = solara.reactive(None)
26
  geo_data = solara.reactive(None)
27
  sel_feature = solara.reactive(None)
28
+ timescale = solara.reactive("50")
29
  sed_range = solara.reactive("-8,5")
30
  class_size = solara.reactive(2.5)
31
+ deposit = solara.reactive(100000.0)
32
  continuous_update = solara.reactive(True)
33
+ formulas = ["Wilkock and Crowe 2003", "Engelund and Hansen 1967"] #,"Parker and Klingeman 1982", "Yang formula 1989", "Wong and Parker 2006", "Ackers and White formula 1973"]
34
  formula = solara.reactive("Engelund and Hansen 1967")
35
+ partitionings = ["Direct", "Bed material fraction (BMF)", "Transport capacity function (TCF)", "Shear stress correction approach"]
36
+ # - Engelund and Hansen with Direct approach\n
37
+ # - Engelund and Hansen with Bed material fraction (BMF) approach\n
38
+ # - Engelund and Hansen with Transport capacity function (TCF)\n
39
+ # - Wilkock and Crowe with Shear stress correction\n""")
40
+ partitioning = solara.reactive("Bed material fraction (BMF)")
41
+
42
+
43
+ part_mapping = {
44
+ "Direct": 1,
45
+ "Bed material fraction (BMF)": 2,
46
+ "Transport capacity function (TCF)": 3,
47
+ "Shear stress correction approach": 4
48
+ }
49
+
50
+ formula_mapping = {
51
+ "Wilkock and Crowe 2003": 2,
52
+ "Engelund and Hansen 1967": 3
53
+ }
54
 
55
  chart_options = solara.reactive({
56
  "line": {
 
93
  icon=True,
94
  )
95
  else:
96
+ fid = feature_properties.value['fromn']
97
+ reach = feature_properties.value['reach_id']
98
+ data = ds.value[sel_var.value].values[:,fid-1] # On nc file the index starts from 0, fromn starts from 1
99
+ # substitute nan values with False
100
+ data = np.where(np.isnan(data), None, data)
101
  chart_options.set({
102
  "line": {
103
+ "title": {"text": f"{sel_var.value} {reach} ({fid})"},
104
  "tooltip": {},
105
+ "legend": {"data": [f"{sel_var.value} {fid}"]},
106
  "xAxis": {"name": "Time step","nameLocation": "middle","nameGap": 30,"data":list(range(1, int(timescale.value)+1))}, # {"type": "category"},
107
+ "yAxis": {"name": f"{sel_var.value} {fid}","nameLocation": "middle","nameGap": 60},
108
  "emphasis": {"itemStyle": {"shadowBlur":10}},
109
  "series": [{
110
  "type": "line",
111
  "universalTransition": True,
112
+ "data": data.tolist()
113
  }]
114
  }
115
  })
 
127
  variables.set(list(ds.value.keys()))
128
 
129
  # ds_dec = xr.decode_cf(ds,decode_timedelta=False)
130
+ fid = properties['fromn']
131
+ reach = properties['reach_id']
132
+ data = ds.value[sel_var.value].values[:,fid-1] # On nc file the index starts from 0, fromn starts from 1
133
+ # substitute nan values with False
134
+ data = np.where(np.isnan(data), None, data)
135
  chart_options.set({
136
  "line": {
137
+ "title": {"text": f"{sel_var.value} {reach} ({fid})"},
138
  "tooltip": {},
139
+ "legend": {"data": f"{sel_var.value} {fid}"},
140
  "xAxis": {"name": "Time step","nameLocation": "middle","nameGap": 30,"data":list(range(1, int(timescale.value)+1))}, # {"type": "category"},
141
+ "yAxis": {"name": f"{sel_var.value} {fid}","nameLocation": "middle","nameGap": 60},
142
  "emphasis": {"itemStyle": {"shadowBlur":10}},
143
  "series": [{
144
  "type": "line",
145
  "universalTransition": True,
146
+ "data": data.tolist()
147
  }]
148
  }
149
  })
 
319
  if ds.value is not None:
320
  ds.value.close()
321
  set_no_file_selected(False)
322
+ # sel_form = formulas.index(str(formula).replace("'",""))+1
323
+ # sel_part = partitionings.index(str(partitioning).replace("'",""))+1
324
+ sel_form = formula_mapping[formula.value]
325
+ sel_part = part_mapping[partitioning.value]
326
  # sel_timescale = int(str(timescale).replace("'",""))
327
  sel_timescale = int(timescale.value)
328