malcolmSQ commited on
Commit
68e63b4
·
1 Parent(s): 1a9cae5

fix: improve LaTeX formula compatibility for dashboard accordions

Browse files
Files changed (1) hide show
  1. dashboard/app.py +55 -41
dashboard/app.py CHANGED
@@ -223,38 +223,43 @@ The core of this dashboard is an emissions reduction (ER) model that projects ma
223
 
224
  This model assumes that the annual growth increment (for both Diameter at Breast Height - DBH, and Height) declines linearly over time, eventually reaching zero. The total size at any given age is the sum of all non-negative annual increments up to that age. This ensures that tree size never decreases.
225
 
226
- **1. Discrete Declining Increment:**
227
- The size at a given age $t$ (in years) is calculated by summing annual increments:
228
  $$
229
- \text{size}(t) = \text{initial\_size} + \sum_{i=1}^{t} \text{increment}(i)
230
  $$
 
231
  Where the increment for year $i$ is:
 
232
  $$
233
- \text{increment}(i) = \max\left(0, r_0 \cdot \left(1 - \frac{i - 0.5}{T_m}\right)\right)
234
  $$
235
- - $\text{initial\_size}$: The initial DBH (cm) or Height (m) at planting (age 0).
236
- - $r_0$: The initial annual growth increment (cm/year for DBH, m/year for Height).
237
- - $T_m$: The time (in years) at which the annual growth increment becomes zero.
238
 
239
- **2. Continuous Declining Increment (Analytical Formula):**
240
- For a smoother representation, the continuous version uses an analytical formula:
 
 
 
 
241
  $$
242
- \text{size}(t) = \text{initial\_size} + r_0 \cdot \left(t - \frac{t^2}{2T_m}\right), \quad \text{for } 0 \le t \le T_m
243
  $$
244
- If $t > T_m$, then $\text{size}(t) = \text{size}(T_m)$.
245
- This version may yield slightly different results from the discrete sum, especially for short time periods or small $T_m$ values. The dashboard configuration specifies which version is active.
246
 
247
  ### Survival and Mortality
248
  The number of surviving trees in a cohort is calculated annually. Mortality can be specified using either:
249
- 1. **Annual Mortality Rates**: A percentage mortality rate applied each year, potentially varying for the first few years and then stabilizing.
250
- 2. **DBH-Dependent Mortality (Optional, if configured)**: Mortality rate $m$ is a function of tree DBH:
 
 
251
  $$
252
- m = m_{\text{ref}} \cdot \left(\frac{\text{DBH}_{\text{ref}}}{\text{DBH}}\right)^p
253
  $$
254
- - $m_{\text{ref}}$: Reference mortality rate at $\text{DBH}_{\text{ref}}$.
255
- - $\text{DBH}_{\text{ref}}$: Reference DBH.
256
- - $p$: Exponent controlling the sensitivity of mortality to DBH.
257
- The calculated $m$ is capped (e.g., between 0 and 0.99).
258
  """)
259
  with gr.Accordion("How Emission Reductions (ERs) are Calculated", open=False):
260
  gr.Markdown(r"""
@@ -262,41 +267,50 @@ The calculated $m$ is capped (e.g., between 0 and 0.99).
262
 
263
  The model follows these steps to estimate net CO2 emission reductions:
264
 
265
- **1. Biomass Calculation:**
266
- Total above-ground and below-ground biomass per tree is calculated using allometric equations, which typically relate DBH and Height to biomass. For example, using equations from Zanvo et al. (2023):
267
- - For *Rhizophora spp.* (Species A): $\text{Biomass}_{\text{total}} = 1.938 \times (\text{DBH}^2 \cdot H)^{0.67628}$ (kg)
268
- - For *Avicennia germinans* (Species B): $\text{Biomass}_{\text{total}} = 1.486 \times (\text{DBH}^2 \cdot H)^{0.55864}$ (kg)
269
- *(Note: The specific equations are defined in the model configuration.)*
 
 
 
 
 
 
 
270
 
271
- **2. Carbon Stock Calculation:**
272
- The total carbon stock in living biomass per hectare is calculated:
273
  $$
274
- \text{Carbon Stock (tC/ha)} = \frac{\text{Biomass per tree (kg)} \times \text{Surviving Trees per ha} \times \text{Biomass to Carbon ratio}}{1000}
275
  $$
276
- - The Biomass to Carbon ratio (e.g., 0.47) converts biomass to carbon mass.
277
 
278
- **3. Gross CO2 Sequestration:**
279
- The carbon stock is then converted to tons of CO2 equivalent:
 
 
280
  $$
281
- \text{Gross CO2eq (tCO2/ha)} = \text{Carbon Stock (tC/ha)} \times \text{Carbon to CO2 ratio}
282
  $$
283
- - The Carbon to CO2 ratio (typically 3.67) is based on molecular weights.
284
 
285
- **4. Soil Carbon (Optional):**
286
- If configured, annual soil carbon sequestration is added:
 
 
287
  $$
288
- \text{Soil Carbon CO2eq (tCO2/ha/yr)} = \text{User Defined Value (e.g. 1.0 tCO2/ha/yr)}
289
  $$
 
290
  This is added to the gross CO2 sequestration from biomass.
291
 
292
- **5. Net Emission Reductions (ERs):**
293
- Adjustments are made to the gross CO2 sequestration (including soil carbon, if applicable) to determine net ERs eligible for crediting:
294
  $$
295
- \text{Net ERs} = (\text{Gross CO2eq}_{\text{biomass + soil}}) \times (1 - \text{Buffer \%}) - (\text{Gross CO2eq}_{\text{biomass + soil}} \times \text{Leakage \%}) - (\text{Baseline Emissions per ha} \times \text{Area})
296
  $$
297
- - **Buffer Pool**: A percentage deduction to account for risks like project failure or natural disturbances.
298
- - **Leakage**: Emissions occurring outside the project boundary due to project activities (often assumed to be 0% for mangrove projects if activities are self-contained).
299
- - **Baseline Emissions**: Emissions that would have occurred in the absence of the project (e.g., from degrading land).
 
300
 
301
  This dashboard visualizes these values annually over the project duration, providing insights into the project's carbon sequestration potential.
302
  """)
 
223
 
224
  This model assumes that the annual growth increment (for both Diameter at Breast Height - DBH, and Height) declines linearly over time, eventually reaching zero. The total size at any given age is the sum of all non-negative annual increments up to that age. This ensures that tree size never decreases.
225
 
226
+ **1. Discrete Declining Increment:** The size at a given age $t$ (in years) is calculated by summing annual increments:
227
+
228
  $$
229
+ \mathrm{size}(t) = \mathrm{initial\_size} + \sum_{i=1}^{t} \mathrm{increment}(i)
230
  $$
231
+
232
  Where the increment for year $i$ is:
233
+
234
  $$
235
+ \mathrm{increment}(i) = \max \left(0, r_0 \cdot \left(1 - \frac{i - 0.5}{T_m}\right) \right)
236
  $$
 
 
 
237
 
238
+ - $\mathrm{initial\_size}$: The initial DBH (cm) or Height (m) at planting (age 0).
239
+ - $r_0$: The initial annual growth increment (cm/year for DBH, m/year for Height).
240
+ - $T_m$: The time (in years) at which the annual growth increment becomes zero.
241
+
242
+ **2. Continuous Declining Increment (Analytical Formula):** For a smoother representation, the continuous version uses an analytical formula:
243
+
244
  $$
245
+ \mathrm{size}(t) = \mathrm{initial\_size} + r_0 \cdot \left(t - \frac{t^2}{2T_m}\right), \quad 0 \leq t \leq T_m
246
  $$
247
+
248
+ If $t > T_m$, then $\mathrm{size}(t) = \mathrm{size}(T_m)$. This version may yield slightly different results from the discrete sum, especially for short time periods or small $T_m$ values. The dashboard configuration specifies which version is active.
249
 
250
  ### Survival and Mortality
251
  The number of surviving trees in a cohort is calculated annually. Mortality can be specified using either:
252
+
253
+ 1. **Annual Mortality Rates:** A percentage mortality rate applied each year, potentially varying for the first few years and then stabilizing.
254
+ 2. **DBH-Dependent Mortality (Optional, if configured):** Mortality rate $m$ is a function of tree DBH:
255
+
256
  $$
257
+ m = m_\mathrm{ref} \cdot \left( \frac{\mathrm{DBH}_\mathrm{ref}}{\mathrm{DBH}} \right)^p
258
  $$
259
+
260
+ - $m_\mathrm{ref}$: Reference mortality rate at $\mathrm{DBH}_\mathrm{ref}$.
261
+ - $\mathrm{DBH}_\mathrm{ref}$: Reference DBH.
262
+ - $p$: Exponent controlling the sensitivity of mortality to DBH. The calculated $m$ is capped (e.g., between 0 and 0.99).
263
  """)
264
  with gr.Accordion("How Emission Reductions (ERs) are Calculated", open=False):
265
  gr.Markdown(r"""
 
267
 
268
  The model follows these steps to estimate net CO2 emission reductions:
269
 
270
+ **1. Biomass Calculation:** Total above-ground and below-ground biomass per tree is calculated using allometric equations, which typically relate DBH and Height to biomass. For example, using equations from Zanvo et al. (2023):
271
+ - For *Rhizophora spp.* (Species A):
272
+ $$
273
+ \mathrm{Biomass}_{\mathrm{total}} = 1.938 \times (\mathrm{DBH}^2 \cdot H)^{0.67628}
274
+ $$
275
+ - For *Avicennia germinans* (Species B):
276
+ $$
277
+ \mathrm{Biomass}_{\mathrm{total}} = 1.486 \times (\mathrm{DBH}^2 \cdot H)^{0.55864}
278
+ $$
279
+ *(Note: The specific equations are defined in the model configuration.)*
280
+
281
+ **2. Carbon Stock Calculation:** The total carbon stock in living biomass per hectare is calculated:
282
 
 
 
283
  $$
284
+ \mathrm{Carbon\ Stock\ (tC/ha)} = \frac{\mathrm{Biomass\ per\ tree\ (kg)} \times \mathrm{Surviving\ Trees\ per\ ha} \times \mathrm{Biomass\ to\ Carbon\ ratio}}{1000}
285
  $$
 
286
 
287
+ - The Biomass to Carbon ratio (e.g., 0.47) converts biomass to carbon mass.
288
+
289
+ **3. Gross CO2 Sequestration:** The carbon stock is then converted to tons of CO2 equivalent:
290
+
291
  $$
292
+ \mathrm{Gross\ CO2eq\ (tCO2/ha)} = \mathrm{Carbon\ Stock\ (tC/ha)} \times \mathrm{Carbon\ to\ CO2\ ratio}
293
  $$
 
294
 
295
+ - The Carbon to CO2 ratio (typically 3.67) is based on molecular weights.
296
+
297
+ **4. Soil Carbon (Optional):** If configured, annual soil carbon sequestration is added:
298
+
299
  $$
300
+ \mathrm{Soil\ Carbon\ CO2eq\ (tCO2/ha/yr)} = \mathrm{User\ Defined\ Value\ (e.g.\ 1.0\ tCO2/ha/yr)}
301
  $$
302
+
303
  This is added to the gross CO2 sequestration from biomass.
304
 
305
+ **5. Net Emission Reductions (ERs):** Adjustments are made to the gross CO2 sequestration (including soil carbon, if applicable) to determine net ERs eligible for crediting:
306
+
307
  $$
308
+ \mathrm{Net\ ERs} = (\mathrm{Gross\ CO2eq}_{\mathrm{biomass + soil}}) \times (1 - \mathrm{Buffer\ \%}) - (\mathrm{Gross\ CO2eq}_{\mathrm{biomass + soil}} \times \mathrm{Leakage\ \%}) - (\mathrm{Baseline\ Emissions\ per\ ha} \times \mathrm{Area})
309
  $$
310
+
311
+ - **Buffer Pool**: A percentage deduction to account for risks like project failure or natural disturbances.
312
+ - **Leakage**: Emissions occurring outside the project boundary due to project activities (often assumed to be 0% for mangrove projects if activities are self-contained).
313
+ - **Baseline Emissions**: Emissions that would have occurred in the absence of the project (e.g., from degrading land).
314
 
315
  This dashboard visualizes these values annually over the project duration, providing insights into the project's carbon sequestration potential.
316
  """)