malcolmSQ commited on
Commit
fa68af3
·
1 Parent(s): 9be5734

Fix: Use cumulative soil carbon for all tables and outputs; remove cumsum from table logic

Browse files
dashboard/tables/__init__.py CHANGED
@@ -71,8 +71,7 @@ def create_survival_table(model):
71
 
72
  def create_project_results_table(results: pd.DataFrame) -> pd.DataFrame:
73
  df = results.copy()
74
- # Replace soil_carbon with its cumulative sum
75
- df['soil_carbon'] = df['soil_carbon'].cumsum()
76
  # Optionally format numbers for display
77
  for col in df.columns:
78
  if df[col].dtype in [float, int]:
 
71
 
72
  def create_project_results_table(results: pd.DataFrame) -> pd.DataFrame:
73
  df = results.copy()
74
+ # No need to cumsum soil_carbon; model now provides cumulative values
 
75
  # Optionally format numbers for display
76
  for col in df.columns:
77
  if df[col].dtype in [float, int]:
er_model_core/er_model.py CHANGED
@@ -249,6 +249,7 @@ class ERModel:
249
  results = []
250
  species_results = []
251
  species_metrics_rows = [] # For new per-year, per-species metrics
 
252
  for year in years:
253
  year_results = {"year": year}
254
  species_year_results = {"Year": year}
@@ -318,15 +319,17 @@ class ERModel:
318
  soil_carbon = 0
319
  if hasattr(self.carbon, 'soil_carbon_per_ha_per_year'):
320
  soil_carbon = self.carbon.soil_carbon_per_ha_per_year * cumulative_area
321
- gross_carbon_with_soil = gross_carbon + soil_carbon
322
- buffer_carbon_with_soil = buffer_carbon + (soil_carbon * (1 - self.carbon.buffer_percentage / 100))
 
323
  year_results.update({
324
  "gross_carbon": gross_carbon,
325
  "buffer_carbon": buffer_carbon,
326
  "cumulative_area": cumulative_area,
327
  "gross_carbon_with_soil": gross_carbon_with_soil,
328
  "buffer_carbon_with_soil": buffer_carbon_with_soil,
329
- "soil_carbon": soil_carbon
 
330
  })
331
  results.append(year_results)
332
  species_results.append(species_year_results)
 
249
  results = []
250
  species_results = []
251
  species_metrics_rows = [] # For new per-year, per-species metrics
252
+ cumulative_soil_carbon = 0
253
  for year in years:
254
  year_results = {"year": year}
255
  species_year_results = {"Year": year}
 
319
  soil_carbon = 0
320
  if hasattr(self.carbon, 'soil_carbon_per_ha_per_year'):
321
  soil_carbon = self.carbon.soil_carbon_per_ha_per_year * cumulative_area
322
+ cumulative_soil_carbon += soil_carbon
323
+ gross_carbon_with_soil = gross_carbon + cumulative_soil_carbon
324
+ buffer_carbon_with_soil = buffer_carbon + (cumulative_soil_carbon * (1 - self.carbon.buffer_percentage / 100))
325
  year_results.update({
326
  "gross_carbon": gross_carbon,
327
  "buffer_carbon": buffer_carbon,
328
  "cumulative_area": cumulative_area,
329
  "gross_carbon_with_soil": gross_carbon_with_soil,
330
  "buffer_carbon_with_soil": buffer_carbon_with_soil,
331
+ "soil_carbon": soil_carbon,
332
+ "cumulative_soil_carbon": cumulative_soil_carbon
333
  })
334
  results.append(year_results)
335
  species_results.append(species_year_results)