Spaces:
Runtime error
Runtime error
Commit
·
ec4dcfc
1
Parent(s):
f54fc00
ui: migrated population_displacement_consensus
Browse files
tomorrowcities/pages/engine.py
CHANGED
|
@@ -23,8 +23,7 @@ import pickle
|
|
| 23 |
import datetime
|
| 24 |
from . import storage, user, session_storage, store_in_session_storage, read_from_session_storage, config
|
| 25 |
from .settings import landslide_max_trials
|
| 26 |
-
from .settings import threshold_flood_ds2, threshold_flood_ds3, threshold_flood_ds4, threshold_flood_distance, threshold_road_water_height, threshold_culvert_water_height
|
| 27 |
-
population_displacement_consensus
|
| 28 |
from ..backend.engine import compute, compute_power_infra, compute_road_infra, generate_exposure, \
|
| 29 |
create_tally, generate_metrics
|
| 30 |
from ..backend.utils import building_preprocess, identity_preprocess, ParameterFile, read_gem_xml, read_gem_xml_fragility, read_gem_xml_vulnerability, getText
|
|
@@ -41,6 +40,7 @@ tally_filter = solara.reactive(None)
|
|
| 41 |
building_filter = solara.reactive(None)
|
| 42 |
landuse_filter = solara.reactive(None)
|
| 43 |
center_default = (41.01,28.98)
|
|
|
|
| 44 |
def create_new_app_state():
|
| 45 |
return solara.reactive({
|
| 46 |
'infra': solara.reactive(["building"]),
|
|
@@ -1637,7 +1637,13 @@ def ExecutePanel():
|
|
| 1637 |
# values=['low','medium','high'],
|
| 1638 |
# on_value=layers.value['implementation_capacity_score'].set,
|
| 1639 |
# )
|
| 1640 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1641 |
solara.ProgressLinear(value=False)
|
| 1642 |
with solara.Columns([70,30]):
|
| 1643 |
with solara.Column():
|
|
|
|
| 23 |
import datetime
|
| 24 |
from . import storage, user, session_storage, store_in_session_storage, read_from_session_storage, config
|
| 25 |
from .settings import landslide_max_trials
|
| 26 |
+
from .settings import threshold_flood_ds2, threshold_flood_ds3, threshold_flood_ds4, threshold_flood_distance, threshold_road_water_height, threshold_culvert_water_height
|
|
|
|
| 27 |
from ..backend.engine import compute, compute_power_infra, compute_road_infra, generate_exposure, \
|
| 28 |
create_tally, generate_metrics
|
| 29 |
from ..backend.utils import building_preprocess, identity_preprocess, ParameterFile, read_gem_xml, read_gem_xml_fragility, read_gem_xml_vulnerability, getText
|
|
|
|
| 40 |
building_filter = solara.reactive(None)
|
| 41 |
landuse_filter = solara.reactive(None)
|
| 42 |
center_default = (41.01,28.98)
|
| 43 |
+
population_displacement_consensus = solara.reactive(2)
|
| 44 |
def create_new_app_state():
|
| 45 |
return solara.reactive({
|
| 46 |
'infra': solara.reactive(["building"]),
|
|
|
|
| 1637 |
# values=['low','medium','high'],
|
| 1638 |
# on_value=layers.value['implementation_capacity_score'].set,
|
| 1639 |
# )
|
| 1640 |
+
solara.Markdown("#### Metric Parameters")
|
| 1641 |
+
# preserve_edge_directions is only used for graph-based inputs (power and road)
|
| 1642 |
+
with solara.Row(justify="left", style="min-height: 0px"):
|
| 1643 |
+
solara.Select(label='population displacement consensus (default:2)', values=[1,2,3,4], value=population_displacement_consensus)
|
| 1644 |
+
with solara.Tooltip('Minimum number of conditions to claim a population displacement. Click for more info.'):
|
| 1645 |
+
solara.Button(icon_name="mdi-help-box", attributes={"href": "https://github.com/TomorrowsCities/tomorrowscities/wiki/4%E2%80%90Engine#parameters", "target": "_blank"}, text=True, outlined=False)
|
| 1646 |
+
|
| 1647 |
solara.ProgressLinear(value=False)
|
| 1648 |
with solara.Columns([70,30]):
|
| 1649 |
with solara.Column():
|
tomorrowcities/pages/explore.py
CHANGED
|
@@ -32,7 +32,6 @@ from .engine import landuse_colors, generic_layer_colors, building_colors, road_
|
|
| 32 |
power_edge_colors, ds_to_color, ds_to_color_approx, create_tally
|
| 33 |
from .engine import MetricWidget, create_new_app_state
|
| 34 |
from ..backend.engine import generate_metrics
|
| 35 |
-
from .settings import population_displacement_consensus
|
| 36 |
|
| 37 |
def get_session_list():
|
| 38 |
if storage.value is not None:
|
|
@@ -49,6 +48,7 @@ tally_counter = solara.reactive(0)
|
|
| 49 |
tally_filter = solara.reactive(None)
|
| 50 |
building_filter = solara.reactive(None)
|
| 51 |
landuse_filter = solara.reactive(None)
|
|
|
|
| 52 |
|
| 53 |
layers = create_new_app_state()
|
| 54 |
|
|
@@ -185,7 +185,12 @@ def assign_nested_value(dictionary, keys, value):
|
|
| 185 |
def get_nested_value(dictionary, keys):
|
| 186 |
for key in keys[:-1]:
|
| 187 |
dictionary = dictionary[key]
|
| 188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
def load_from_state(source_dict):
|
| 191 |
stack = [((), layers.value)]
|
|
@@ -196,11 +201,12 @@ def load_from_state(source_dict):
|
|
| 196 |
stack.append((path + (key,), value))
|
| 197 |
else:
|
| 198 |
keys = list(path + (key,))
|
| 199 |
-
src_value = get_nested_value(source_dict, keys)
|
| 200 |
-
if
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
| 204 |
|
| 205 |
|
| 206 |
|
|
@@ -369,6 +375,7 @@ def generate_metrics_local():
|
|
| 369 |
metrics = {name: {'value':0, 'max_value':0, 'desc': metric['desc']} for name, metric in layers.value['metrics'].items()}
|
| 370 |
|
| 371 |
tally_geo = read_from_session_storage('explore_tally_geo')
|
|
|
|
| 372 |
if tally_geo is not None and layers.value['bounds'].value is not None:
|
| 373 |
((ymin,xmin),(ymax,xmax)) = layers.value['bounds'].value
|
| 374 |
tally_filtered = tally_geo.cx[xmin:xmax,ymin:ymax]
|
|
@@ -395,6 +402,7 @@ def MetricPanel():
|
|
| 395 |
solara.use_memo(generate_metrics_local,
|
| 396 |
[tally_counter.value,
|
| 397 |
layers.value['bounds'].value,
|
|
|
|
| 398 |
tally_filter.value], debug_name="generate_metrics_loca")
|
| 399 |
if generate_metrics_local.finished:
|
| 400 |
filtered_metrics = generate_metrics_local.value
|
|
@@ -511,6 +519,12 @@ def FilterPanel():
|
|
| 511 |
solara.CrossFilterSelect(tally_minimal, col, multiple=True)
|
| 512 |
print(f"fiter panel render count {render_count.value}")
|
| 513 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
|
| 515 |
@solara.component
|
| 516 |
def Page():
|
|
|
|
| 32 |
power_edge_colors, ds_to_color, ds_to_color_approx, create_tally
|
| 33 |
from .engine import MetricWidget, create_new_app_state
|
| 34 |
from ..backend.engine import generate_metrics
|
|
|
|
| 35 |
|
| 36 |
def get_session_list():
|
| 37 |
if storage.value is not None:
|
|
|
|
| 48 |
tally_filter = solara.reactive(None)
|
| 49 |
building_filter = solara.reactive(None)
|
| 50 |
landuse_filter = solara.reactive(None)
|
| 51 |
+
population_displacement_consensus = solara.reactive(2)
|
| 52 |
|
| 53 |
layers = create_new_app_state()
|
| 54 |
|
|
|
|
| 185 |
def get_nested_value(dictionary, keys):
|
| 186 |
for key in keys[:-1]:
|
| 187 |
dictionary = dictionary[key]
|
| 188 |
+
if keys[-1] in dictionary.keys():
|
| 189 |
+
is_available = True
|
| 190 |
+
return (dictionary[keys[-1]], is_available)
|
| 191 |
+
else:
|
| 192 |
+
is_available = False
|
| 193 |
+
return (None, is_available)
|
| 194 |
|
| 195 |
def load_from_state(source_dict):
|
| 196 |
stack = [((), layers.value)]
|
|
|
|
| 201 |
stack.append((path + (key,), value))
|
| 202 |
else:
|
| 203 |
keys = list(path + (key,))
|
| 204 |
+
src_value, is_available = get_nested_value(source_dict, keys)
|
| 205 |
+
if is_available:
|
| 206 |
+
if isinstance(value,solara.toestand.Reactive):
|
| 207 |
+
assign_nested_value(layers.value, keys, solara.reactive(src_value))
|
| 208 |
+
else:
|
| 209 |
+
assign_nested_value(layers.value, keys, src_value)
|
| 210 |
|
| 211 |
|
| 212 |
|
|
|
|
| 375 |
metrics = {name: {'value':0, 'max_value':0, 'desc': metric['desc']} for name, metric in layers.value['metrics'].items()}
|
| 376 |
|
| 377 |
tally_geo = read_from_session_storage('explore_tally_geo')
|
| 378 |
+
print('population_displacement_consensus explore', population_displacement_consensus.value)
|
| 379 |
if tally_geo is not None and layers.value['bounds'].value is not None:
|
| 380 |
((ymin,xmin),(ymax,xmax)) = layers.value['bounds'].value
|
| 381 |
tally_filtered = tally_geo.cx[xmin:xmax,ymin:ymax]
|
|
|
|
| 402 |
solara.use_memo(generate_metrics_local,
|
| 403 |
[tally_counter.value,
|
| 404 |
layers.value['bounds'].value,
|
| 405 |
+
population_displacement_consensus.value,
|
| 406 |
tally_filter.value], debug_name="generate_metrics_loca")
|
| 407 |
if generate_metrics_local.finished:
|
| 408 |
filtered_metrics = generate_metrics_local.value
|
|
|
|
| 519 |
solara.CrossFilterSelect(tally_minimal, col, multiple=True)
|
| 520 |
print(f"fiter panel render count {render_count.value}")
|
| 521 |
|
| 522 |
+
# preserve_edge_directions is only used for graph-based inputs (power and road)
|
| 523 |
+
with solara.Row(justify="left", style="min-height: 0px"):
|
| 524 |
+
solara.Select(label='population displacement consensus (default:2)', values=[1,2,3,4], value=population_displacement_consensus)
|
| 525 |
+
with solara.Tooltip('Minimum number of conditions to claim a population displacement. Click for more info.'):
|
| 526 |
+
solara.Button(icon_name="mdi-help-box", attributes={"href": "https://github.com/TomorrowsCities/tomorrowscities/wiki/4%E2%80%90Engine#parameters", "target": "_blank"}, text=True, outlined=False)
|
| 527 |
+
|
| 528 |
|
| 529 |
@solara.component
|
| 530 |
def Page():
|
tomorrowcities/pages/settings.py
CHANGED
|
@@ -13,15 +13,10 @@ threshold_flood_ds4 = solara.reactive(0.50)
|
|
| 13 |
threshold_flood_distance = solara.reactive(10)
|
| 14 |
threshold_road_water_height = solara.reactive(0.3)
|
| 15 |
threshold_culvert_water_height = solara.reactive(1.5)
|
| 16 |
-
population_displacement_consensus = solara.reactive(2)
|
| 17 |
|
| 18 |
@solara.component
|
| 19 |
def Page(name: Optional[str] = None, page: int = 0, page_size=100):
|
| 20 |
|
| 21 |
-
with solara.Card(title='Metric-related Parameters',
|
| 22 |
-
subtitle='Minimum number of direct damage, inaccessibility or power lost should be observed to claim a population displacement.'):
|
| 23 |
-
solara.Select(label='population displacement consensus', values=[1,2,3,4], value=population_displacement_consensus)
|
| 24 |
-
|
| 25 |
with solara.Card(title='Landslide Parameters',subtitle='Choose the parameters for the landslide simulation'):
|
| 26 |
solara.SliderInt(label='Number of Monte-Carlo Trials', value=landslide_max_trials, min=1,max=100)
|
| 27 |
|
|
|
|
| 13 |
threshold_flood_distance = solara.reactive(10)
|
| 14 |
threshold_road_water_height = solara.reactive(0.3)
|
| 15 |
threshold_culvert_water_height = solara.reactive(1.5)
|
|
|
|
| 16 |
|
| 17 |
@solara.component
|
| 18 |
def Page(name: Optional[str] = None, page: int = 0, page_size=100):
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
with solara.Card(title='Landslide Parameters',subtitle='Choose the parameters for the landslide simulation'):
|
| 21 |
solara.SliderInt(label='Number of Monte-Carlo Trials', value=landslide_max_trials, min=1,max=100)
|
| 22 |
|