malcolmSQ commited on
Commit
e0a99b2
·
1 Parent(s): bd976f6

Add editable planting schedule to Declining Increment tab with live dashboard updates

Browse files
Files changed (1) hide show
  1. dashboard/app.py +52 -11
dashboard/app.py CHANGED
@@ -275,16 +275,57 @@ with gr.Blocks() as demo:
275
  gr.Markdown("# Mangrove ER Model Dashboard\nDeclining Increment Model Only")
276
  with gr.Tabs():
277
  with gr.Tab("Declining Increment"):
278
- gr.Markdown("## Declining Increment Model Results (base config)")
279
- carbon_plot, annual_plot, biomass_plot, summary, results, species, survival = run_model(MODEL_CONFIGS["Declining Increment"])
280
- growth_fig = create_growth_increment_plots(yaml.safe_load(open(MODEL_CONFIGS["Declining Increment"])), model_type="declining_increment")
 
 
 
 
281
  with gr.Row():
282
- carbon_plot_comp = gr.Plot(value=carbon_plot)
283
- biomass_plot_comp = gr.Plot(value=biomass_plot)
284
- annual_plot_comp = gr.Plot(value=annual_plot)
285
- gr.Textbox(value=summary, label="Summary", lines=12)
286
- gr.Dataframe(value=results, label="Project Results (Annual)")
287
- gr.Dataframe(value=species, label="Species Results (Annual)")
288
- gr.Dataframe(value=survival, label="Surviving Trees Table")
289
- # gr.Plot(value=growth_fig, label="Growth & Increment Curves")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  demo.launch(share=True)
 
275
  gr.Markdown("# Mangrove ER Model Dashboard\nDeclining Increment Model Only")
276
  with gr.Tabs():
277
  with gr.Tab("Declining Increment"):
278
+ gr.Markdown("## Planting Schedule (ha per year)")
279
+ year_1 = gr.Number(value=2500, label="Year 1 Area (ha)")
280
+ year_2 = gr.Number(value=2500, label="Year 2 Area (ha)")
281
+ year_3 = gr.Number(value=0, label="Year 3 Area (ha)")
282
+ year_4 = gr.Number(value=0, label="Year 4 Area (ha)")
283
+ year_5 = gr.Number(value=0, label="Year 5 Area (ha)")
284
+ update_btn = gr.Button("Update Results", variant="primary")
285
  with gr.Row():
286
+ carbon_plot = gr.Plot()
287
+ biomass_plot = gr.Plot()
288
+ annual_plot = gr.Plot()
289
+ summary_box = gr.Textbox(label="Summary", lines=12)
290
+ results_box = gr.Dataframe(label="Project Results (Annual)")
291
+ species_box = gr.Dataframe(label="Species Results (Annual)")
292
+ survival_box = gr.Dataframe(label="Surviving Trees Table")
293
+
294
+ def update_declining_increment(y1, y2, y3, y4, y5):
295
+ config = update_planting_schedule(MODEL_CONFIGS["Declining Increment"], [y1, y2, y3, y4, y5])
296
+ import tempfile
297
+ import yaml
298
+ with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as tmp:
299
+ yaml.dump(config, tmp)
300
+ tmp_path = tmp.name
301
+ model = ERModel(Path(tmp_path))
302
+ results, species_results = model.run()
303
+ plots = create_all_plots(results, species_results, config)
304
+ summary = create_summary(results, species_results, config, model)
305
+ survival_table = create_survival_table(model)
306
+ results_fmt = results.copy()
307
+ species_results_fmt = species_results.copy()
308
+ for col in results_fmt.columns:
309
+ if results_fmt[col].dtype in [float, int]:
310
+ results_fmt[col] = results_fmt[col].apply(lambda x: f"{x:,.2f}" if isinstance(x, float) else f"{x:,}")
311
+ for col in species_results_fmt.columns:
312
+ if species_results_fmt[col].dtype in [float, int]:
313
+ species_results_fmt[col] = species_results_fmt[col].apply(lambda x: f"{x:,.2f}" if isinstance(x, float) else f"{x:,}")
314
+ return plots[0], plots[2], plots[1], summary, results_fmt.head(30), species_results_fmt.head(30), survival_table.head(30)
315
+
316
+ update_btn.click(
317
+ update_declining_increment,
318
+ inputs=[year_1, year_2, year_3, year_4, year_5],
319
+ outputs=[carbon_plot, biomass_plot, annual_plot, summary_box, results_box, species_box, survival_box]
320
+ )
321
+
322
+ # Show initial results
323
+ c, b, a, summary, r, s, surv = update_declining_increment(2500, 2500, 0, 0, 0)
324
+ carbon_plot.value = c
325
+ biomass_plot.value = b
326
+ annual_plot.value = a
327
+ summary_box.value = summary
328
+ results_box.value = r
329
+ species_box.value = s
330
+ survival_box.value = surv
331
  demo.launch(share=True)