malcolmSQ commited on
Commit ·
866f52b
1
Parent(s): 43a1446
fix: correct initial call to update_declining_increment to match new input signature
Browse files- dashboard/app.py +6 -33
dashboard/app.py
CHANGED
|
@@ -19,6 +19,7 @@ from dashboard.plots import check_complex, create_growth_increment_plots, create
|
|
| 19 |
from dashboard.tables import create_survival_table, create_biomass_table, create_project_results_table
|
| 20 |
import yaml
|
| 21 |
import tempfile
|
|
|
|
| 22 |
|
| 23 |
MODEL_CONFIGS = {
|
| 24 |
"Declining Increment": "configs/declining_increment.yaml"
|
|
@@ -252,34 +253,10 @@ This version is smoother and may yield slightly different results than the discr
|
|
| 252 |
biomass_debug_table = gr.Dataframe(label="Biomass Table (inputs & outputs per year)")
|
| 253 |
# --- End tabbed tables ---
|
| 254 |
# --- Adjustable Model Inputs ---
|
| 255 |
-
|
| 256 |
-
spA = config["species"][0]
|
| 257 |
-
spB = config["species"][1]
|
| 258 |
with gr.Accordion("Adjust Model Inputs", open=True):
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
r0_dbh_A = gr.Number(value=spA['declining_increment']['dbh']['r0'], label=f"{spA['name']} r0 (DBH, cm/yr)")
|
| 262 |
-
tm_dbh_A = gr.Number(value=spA['declining_increment']['dbh']['T_m'], label=f"{spA['name']} Tm (DBH, yrs)")
|
| 263 |
-
r0_height_A = gr.Number(value=spA['declining_increment']['height']['r0'], label=f"{spA['name']} r0 (Height, m/yr)")
|
| 264 |
-
tm_height_A = gr.Number(value=spA['declining_increment']['height']['T_m'], label=f"{spA['name']} Tm (Height, yrs)")
|
| 265 |
-
with gr.Row():
|
| 266 |
-
planting_density_B = gr.Number(value=spB['planting_density'], label=f"{spB['name']} Planting Density (trees/ha)")
|
| 267 |
-
r0_dbh_B = gr.Number(value=spB['declining_increment']['dbh']['r0'], label=f"{spB['name']} r0 (DBH, cm/yr)")
|
| 268 |
-
tm_dbh_B = gr.Number(value=spB['declining_increment']['dbh']['T_m'], label=f"{spB['name']} Tm (DBH, yrs)")
|
| 269 |
-
r0_height_B = gr.Number(value=spB['declining_increment']['height']['r0'], label=f"{spB['name']} r0 (Height, m/yr)")
|
| 270 |
-
tm_height_B = gr.Number(value=spB['declining_increment']['height']['T_m'], label=f"{spB['name']} Tm (Height, yrs)")
|
| 271 |
-
with gr.Row():
|
| 272 |
-
mort_1 = gr.Number(value=spA['mortality_rates']['year_1'], label="Year 1 Mortality (%)")
|
| 273 |
-
mort_2 = gr.Number(value=spA['mortality_rates']['year_2'], label="Year 2 Mortality (%)")
|
| 274 |
-
mort_3 = gr.Number(value=spA['mortality_rates']['year_3'], label="Year 3 Mortality (%)")
|
| 275 |
-
mort_4 = gr.Number(value=spA['mortality_rates']['year_4'], label="Year 4 Mortality (%)")
|
| 276 |
-
mort_5 = gr.Number(value=spA['mortality_rates']['year_5'], label="Year 5 Mortality (%)")
|
| 277 |
-
mort_sub = gr.Number(value=spA['mortality_rates']['subsequent'], label="Subsequent Years Mortality (%)")
|
| 278 |
-
with gr.Row():
|
| 279 |
-
project_duration = gr.Number(value=config['project']['duration_years'], label="Project Duration (years)")
|
| 280 |
-
buffer_pct = gr.Number(value=config['carbon']['buffer_percentage'], label="Buffer %")
|
| 281 |
-
soil_carbon = gr.Number(value=config['carbon']['soil_carbon_per_ha_per_year'], label="Soil Carbon per ha per year (tCO2)")
|
| 282 |
-
# Remove hardcoded key model inputs from Markdown section
|
| 283 |
# Update the update_declining_increment callback to use these new inputs
|
| 284 |
def update_declining_increment(y1, y2, y3, y4, y5,
|
| 285 |
planting_density_A, r0_dbh_A, tm_dbh_A, r0_height_A, tm_height_A,
|
|
@@ -345,15 +322,11 @@ This version is smoother and may yield slightly different results than the discr
|
|
| 345 |
return (plots[0], plots[1], plots[2], growth_fig, summary, results_fmt, species_results_fmt, survival_table, biomass_debug_df, key_metrics_md)
|
| 346 |
update_btn.click(
|
| 347 |
update_declining_increment,
|
| 348 |
-
inputs=[year_1, year_2, year_3, year_4, year_5,
|
| 349 |
-
planting_density_A, r0_dbh_A, tm_dbh_A, r0_height_A, tm_height_A,
|
| 350 |
-
planting_density_B, r0_dbh_B, tm_dbh_B, r0_height_B, tm_height_B,
|
| 351 |
-
mort_1, mort_2, mort_3, mort_4, mort_5, mort_sub,
|
| 352 |
-
project_duration, buffer_pct, soil_carbon],
|
| 353 |
outputs=[carbon_plot, biomass_plot, annual_plot, growth_plot, summary_box, results_box, species_box, survival_box, biomass_debug_table, key_metrics]
|
| 354 |
)
|
| 355 |
# Show initial results
|
| 356 |
-
c, b, a, g, summary, r, s, surv, biomass_debug_df, key_metrics_md = update_declining_increment(2500, 2500, 0, 0, 0,
|
| 357 |
carbon_plot.value = c
|
| 358 |
biomass_plot.value = b
|
| 359 |
annual_plot.value = a
|
|
|
|
| 19 |
from dashboard.tables import create_survival_table, create_biomass_table, create_project_results_table
|
| 20 |
import yaml
|
| 21 |
import tempfile
|
| 22 |
+
from dashboard.inputs import get_model_inputs
|
| 23 |
|
| 24 |
MODEL_CONFIGS = {
|
| 25 |
"Declining Increment": "configs/declining_increment.yaml"
|
|
|
|
| 253 |
biomass_debug_table = gr.Dataframe(label="Biomass Table (inputs & outputs per year)")
|
| 254 |
# --- End tabbed tables ---
|
| 255 |
# --- Adjustable Model Inputs ---
|
| 256 |
+
model_inputs, model_defaults = get_model_inputs(config)
|
|
|
|
|
|
|
| 257 |
with gr.Accordion("Adjust Model Inputs", open=True):
|
| 258 |
+
for k, comp in model_inputs.items():
|
| 259 |
+
comp.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
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] + list(model_inputs.values()),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 329 |
+
c, b, a, g, summary, r, s, surv, biomass_debug_df, key_metrics_md = update_declining_increment(2500, 2500, 0, 0, 0, *model_defaults)
|
| 330 |
carbon_plot.value = c
|
| 331 |
biomass_plot.value = b
|
| 332 |
annual_plot.value = a
|