File size: 4,596 Bytes
42ce3bd
 
 
 
 
 
 
 
 
 
 
8b4903a
0cefa06
280f88c
8b4903a
 
280f88c
03038b8
 
280f88c
03038b8
280f88c
8b4903a
 
 
1524dc6
 
 
 
 
8b4903a
1524dc6
8b4903a
 
bc8f256
8b4903a
1524dc6
8b4903a
 
280f88c
 
 
 
03038b8
 
 
280f88c
8b4903a
 
03038b8
 
 
 
 
8b4903a
280f88c
 
 
 
 
 
 
 
 
 
03038b8
280f88c
 
 
 
 
 
 
 
0cefa06
 
 
 
 
03038b8
280f88c
03038b8
 
 
0cefa06
 
280f88c
 
 
0cefa06
 
 
 
280f88c
0cefa06
 
 
 
 
 
0dba6f7
 
280f88c
0cefa06
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
title: Mangrove ER Model Dashboard
emoji: 🌱
colorFrom: green
colorTo: blue
sdk: gradio
sdk_version: "5.29.0"
app_file: dashboard/app.py
pinned: false
---

# Mangrove Emissions Reduction Model & Dashboard

This project implements a flexible, modular dashboard for mangrove carbon sequestration and emissions reduction, supporting multiple growth models. **Currently, only the Declining Increment model is active; all other models are archived for reference.**

## Features
- Interactive Gradio dashboard for project simulation and analysis
- Updated: grouped accordions, tooltips as labels, reset-to-defaults button, and compact two-column mortality layout
- Modular growth model architecture (see `er_model_core/growth_models/`)
- All dashboard tables and plots are driven by model outputs (no redundant calculations)
- Editable planting schedule and all model parameters for Declining Increment model
- Robust, transparent, and reproducible calculations

## Usage

1. **Access the Dashboard (Recommended):**
   - The Mangrove ER Model Dashboard is hosted online.
   - **Access it here:** [https://huggingface.co/spaces/mowcom/er-model](https://huggingface.co/spaces/mowcom/er-model)

2. **(Optional) Run Locally for Development:**
   ```bash
   # Using conda (recommended)
   conda env create -f environment.yml
   conda activate er-model
   python dashboard/app.py
   ```
   - To stop the local server, press `Ctrl+C` in the terminal.

## Growth Models
- **Declining Increment (ACTIVE):**
  - Annual increment declines linearly to zero; total size is the sum of non-negative increments (never decreases or goes negative).
  - Both discrete and continuous versions are available (toggle via config).
- **Archived Models:**
  - **Chapman-Richards** (see `er_model_core/growth_models/chapman_richards.py`)
  - **Simple Linear** (see `er_model_core/growth_models/linear.py`)
  - **Linear Plateau** (see `er_model_core/growth_models/linear.py`)
  - **Jimenez-Lugo** (see `models/jimenez_lugo/README.md`)

## File Structure
- `dashboard/app.py` β€” Gradio dashboard UI and logic (now model-driven, with grouped accordions and tooltips)
- `er_model_core/er_model.py` β€” Core model logic, growth model selection, and all calculations
- `er_model_core/growth_models/` β€” Modular growth model implementations (active and archived)
- `er_model_core/types.py` β€” Shared dataclasses for model config
- `er_model_core/config_loader.py` β€” Config loading and parsing
- `configs/` β€” Model configuration YAMLs
- `models/` β€” Reference model folders and documentation
- `tests/` β€” Unit tests for model logic and outputs

## Model-Driven Dashboard
- All per-year, per-species metrics (surviving trees, DBH, height, biomass per tree, total biomass) are calculated and stored in the model (`model.species_metrics`).
- Dashboard tables and plots read directly from model outputs for speed, consistency, and maintainability.
- No redundant calculations in the dashboard.

## Adding or Re-enabling Models
1. **To add a new model:**
   - Implement the growth function in `er_model_core/growth_models/`.
   - Add a config YAML to `configs/`.
   - Add a tab/entry in `dashboard/app.py` (if you want it visible in the UI).
2. **To re-enable an archived model:**
   - Uncomment the relevant import and config entry.
   - Ensure the model is listed in `MODEL_CONFIGS` in `dashboard/app.py`.
   - Add or update documentation in `models/` as needed.

## Directory Structure
```
er-chapman-richards/
β”œβ”€β”€ README.md                # This file
β”œβ”€β”€ environment.yml          # Conda environment
β”œβ”€β”€ dashboard/               # Gradio dashboard app
β”œβ”€β”€ er_model_core/           # Core model code
β”‚   β”œβ”€β”€ er_model.py
β”‚   β”œβ”€β”€ growth_models/
β”‚   β”œβ”€β”€ types.py
β”‚   └── config_loader.py
β”œβ”€β”€ configs/                 # Model parameter YAMLs
β”œβ”€β”€ models/                  # Model-specific docs
β”‚   β”œβ”€β”€ original/README.md   # Archived
β”‚   β”œβ”€β”€ jimenez_lugo/README.md # Archived
β”‚   └── declining_increment/README.md # Active
β”œβ”€β”€ tests/                   # Pytest suite
└── ...
```

## Development & Testing
- Code style: [black](https://black.readthedocs.io/), [isort](https://pycqa.github.io/isort/)
- Type hints required for all public functions
- Run tests with:
  ```bash
  pytest
  ```
- Pre-commit hooks ensure code quality

## References
- Chapman-Richards growth model literature
- Jimenez, J.A. & Lugo, A.E. (1985, 1987)
- Zanvo et al. (2023) for allometric equations
- Field data from Nigeria mangrove sites (2024)