malcolmSQ commited on
Commit ·
8d81017
1
Parent(s): 866f52b
feat: add mortality inputs for years 1-10 and subsequent, update both species, and fix UI assignment
Browse files- dashboard/app.py +24 -3
- dashboard/inputs.py +11 -15
dashboard/app.py
CHANGED
|
@@ -255,8 +255,25 @@ This version is smoother and may yield slightly different results than the discr
|
|
| 255 |
# --- Adjustable Model Inputs ---
|
| 256 |
model_inputs, model_defaults = get_model_inputs(config)
|
| 257 |
with gr.Accordion("Adjust Model Inputs", open=True):
|
| 258 |
-
|
| 259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
# Update the update_declining_increment callback to use these new inputs
|
| 261 |
def update_declining_increment(y1, y2, y3, y4, y5,
|
| 262 |
planting_density_A, r0_dbh_A, tm_dbh_A, r0_height_A, tm_height_A,
|
|
@@ -322,7 +339,11 @@ This version is smoother and may yield slightly different results than the discr
|
|
| 322 |
return (plots[0], plots[1], plots[2], growth_fig, summary, results_fmt, species_results_fmt, survival_table, biomass_debug_df, key_metrics_md)
|
| 323 |
update_btn.click(
|
| 324 |
update_declining_increment,
|
| 325 |
-
inputs=[year_1, year_2, year_3, year_4, year_5
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
outputs=[carbon_plot, biomass_plot, annual_plot, growth_plot, summary_box, results_box, species_box, survival_box, biomass_debug_table, key_metrics]
|
| 327 |
)
|
| 328 |
# Show initial results
|
|
|
|
| 255 |
# --- Adjustable Model Inputs ---
|
| 256 |
model_inputs, model_defaults = get_model_inputs(config)
|
| 257 |
with gr.Accordion("Adjust Model Inputs", open=True):
|
| 258 |
+
planting_density_A = model_inputs['planting_density_A']
|
| 259 |
+
r0_dbh_A = model_inputs['r0_dbh_A']
|
| 260 |
+
tm_dbh_A = model_inputs['tm_dbh_A']
|
| 261 |
+
r0_height_A = model_inputs['r0_height_A']
|
| 262 |
+
tm_height_A = model_inputs['tm_height_A']
|
| 263 |
+
planting_density_B = model_inputs['planting_density_B']
|
| 264 |
+
r0_dbh_B = model_inputs['r0_dbh_B']
|
| 265 |
+
tm_dbh_B = model_inputs['tm_dbh_B']
|
| 266 |
+
r0_height_B = model_inputs['r0_height_B']
|
| 267 |
+
tm_height_B = model_inputs['tm_height_B']
|
| 268 |
+
mort_1 = model_inputs['mort_1']
|
| 269 |
+
mort_2 = model_inputs['mort_2']
|
| 270 |
+
mort_3 = model_inputs['mort_3']
|
| 271 |
+
mort_4 = model_inputs['mort_4']
|
| 272 |
+
mort_5 = model_inputs['mort_5']
|
| 273 |
+
mort_sub = model_inputs['mort_sub']
|
| 274 |
+
project_duration = model_inputs['project_duration']
|
| 275 |
+
buffer_pct = model_inputs['buffer_pct']
|
| 276 |
+
soil_carbon = model_inputs['soil_carbon']
|
| 277 |
# Update the update_declining_increment callback to use these new inputs
|
| 278 |
def update_declining_increment(y1, y2, y3, y4, y5,
|
| 279 |
planting_density_A, r0_dbh_A, tm_dbh_A, r0_height_A, tm_height_A,
|
|
|
|
| 339 |
return (plots[0], plots[1], plots[2], growth_fig, summary, results_fmt, species_results_fmt, survival_table, biomass_debug_df, key_metrics_md)
|
| 340 |
update_btn.click(
|
| 341 |
update_declining_increment,
|
| 342 |
+
inputs=[year_1, year_2, year_3, year_4, year_5,
|
| 343 |
+
planting_density_A, r0_dbh_A, tm_dbh_A, r0_height_A, tm_height_A,
|
| 344 |
+
planting_density_B, r0_dbh_B, tm_dbh_B, r0_height_B, tm_height_B,
|
| 345 |
+
mort_1, mort_2, mort_3, mort_4, mort_5, mort_sub,
|
| 346 |
+
project_duration, buffer_pct, soil_carbon],
|
| 347 |
outputs=[carbon_plot, biomass_plot, annual_plot, growth_plot, summary_box, results_box, species_box, survival_box, biomass_debug_table, key_metrics]
|
| 348 |
)
|
| 349 |
# Show initial results
|
dashboard/inputs.py
CHANGED
|
@@ -15,13 +15,15 @@ def get_model_inputs(config):
|
|
| 15 |
tm_dbh_B = gr.Number(value=spB['declining_increment']['dbh']['T_m'], label=f"{spB['name']} Tm (DBH, yrs)")
|
| 16 |
r0_height_B = gr.Number(value=spB['declining_increment']['height']['r0'], label=f"{spB['name']} r0 (Height, m/yr)")
|
| 17 |
tm_height_B = gr.Number(value=spB['declining_increment']['height']['T_m'], label=f"{spB['name']} Tm (Height, yrs)")
|
| 18 |
-
# Mortality (one set, mirrored)
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
# Project/Carbon
|
| 26 |
project_duration = gr.Number(value=config['project']['duration_years'], label="Project Duration (years)")
|
| 27 |
buffer_pct = gr.Number(value=config['carbon']['buffer_percentage'], label="Buffer %")
|
|
@@ -38,12 +40,7 @@ def get_model_inputs(config):
|
|
| 38 |
'tm_dbh_B': tm_dbh_B,
|
| 39 |
'r0_height_B': r0_height_B,
|
| 40 |
'tm_height_B': tm_height_B,
|
| 41 |
-
|
| 42 |
-
'mort_2': mort_2,
|
| 43 |
-
'mort_3': mort_3,
|
| 44 |
-
'mort_4': mort_4,
|
| 45 |
-
'mort_5': mort_5,
|
| 46 |
-
'mort_sub': mort_sub,
|
| 47 |
'project_duration': project_duration,
|
| 48 |
'buffer_pct': buffer_pct,
|
| 49 |
'soil_carbon': soil_carbon
|
|
@@ -53,8 +50,7 @@ def get_model_inputs(config):
|
|
| 53 |
spA['declining_increment']['height']['r0'], spA['declining_increment']['height']['T_m'],
|
| 54 |
spB['planting_density'], spB['declining_increment']['dbh']['r0'], spB['declining_increment']['dbh']['T_m'],
|
| 55 |
spB['declining_increment']['height']['r0'], spB['declining_increment']['height']['T_m'],
|
| 56 |
-
|
| 57 |
-
spA['mortality_rates']['year_4'], spA['mortality_rates']['year_5'], spA['mortality_rates']['subsequent'],
|
| 58 |
config['project']['duration_years'], config['carbon']['buffer_percentage'], config['carbon']['soil_carbon_per_ha_per_year']
|
| 59 |
]
|
| 60 |
return components, defaults
|
|
|
|
| 15 |
tm_dbh_B = gr.Number(value=spB['declining_increment']['dbh']['T_m'], label=f"{spB['name']} Tm (DBH, yrs)")
|
| 16 |
r0_height_B = gr.Number(value=spB['declining_increment']['height']['r0'], label=f"{spB['name']} r0 (Height, m/yr)")
|
| 17 |
tm_height_B = gr.Number(value=spB['declining_increment']['height']['T_m'], label=f"{spB['name']} Tm (Height, yrs)")
|
| 18 |
+
# Mortality (one set, mirrored, years 1-10 + subsequent)
|
| 19 |
+
mort_inputs = {}
|
| 20 |
+
mort_defaults = []
|
| 21 |
+
for yr in range(1, 11):
|
| 22 |
+
key = f"year_{yr}"
|
| 23 |
+
mort_inputs[key] = gr.Number(value=spA['mortality_rates'][key], label=f"Year {yr} Mortality (%)")
|
| 24 |
+
mort_defaults.append(spA['mortality_rates'][key])
|
| 25 |
+
mort_inputs['subsequent'] = gr.Number(value=spA['mortality_rates']['subsequent'], label="Subsequent Years Mortality (%)")
|
| 26 |
+
mort_defaults.append(spA['mortality_rates']['subsequent'])
|
| 27 |
# Project/Carbon
|
| 28 |
project_duration = gr.Number(value=config['project']['duration_years'], label="Project Duration (years)")
|
| 29 |
buffer_pct = gr.Number(value=config['carbon']['buffer_percentage'], label="Buffer %")
|
|
|
|
| 40 |
'tm_dbh_B': tm_dbh_B,
|
| 41 |
'r0_height_B': r0_height_B,
|
| 42 |
'tm_height_B': tm_height_B,
|
| 43 |
+
**mort_inputs,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
'project_duration': project_duration,
|
| 45 |
'buffer_pct': buffer_pct,
|
| 46 |
'soil_carbon': soil_carbon
|
|
|
|
| 50 |
spA['declining_increment']['height']['r0'], spA['declining_increment']['height']['T_m'],
|
| 51 |
spB['planting_density'], spB['declining_increment']['dbh']['r0'], spB['declining_increment']['dbh']['T_m'],
|
| 52 |
spB['declining_increment']['height']['r0'], spB['declining_increment']['height']['T_m'],
|
| 53 |
+
*mort_defaults,
|
|
|
|
| 54 |
config['project']['duration_years'], config['carbon']['buffer_percentage'], config['carbon']['soil_carbon_per_ha_per_year']
|
| 55 |
]
|
| 56 |
return components, defaults
|