Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions 000-config.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ pecan_outdir <- file.path(ccmmf_dir, "modelout", "ccmmf_phase_2b_mixed_pfts_2025
# PEcAn model output to be analyzed
pecan_archive_tgz <- file.path(ccmmf_dir, "lebauer_agu_2025_20251210.tgz")

# -----Management scenarios config -----
# set to TRUE to use Phase 3 management scenario outputs
USE_PHASE_3_SCENARIOS <- TRUE

phase_3_outdir <- file.path(ccmmf_dir, "modelout", "ccmmf_phase_3_scenarios_20251210")

management_scenarios <- c(
"baseline",
"compost",
"reduced_till",
"zero_till",
"reduced_irrig_drip",
"stacked"
)

# override paths if using Phase 3
if (USE_PHASE_3_SCENARIOS) {
pecan_outdir <- phase_3_outdir
}

# **Variables to extract**
# see docs/workflow_documentation.qmd for complete list of outputs
outputs_to_extract <- c("TotSoilCarb", "AGB")
Expand Down
15 changes: 13 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,31 @@ Once a new release is made this file will be updated to create a new `Unreleased

For more information about this file see also [Keep a Changelog](http://keepachangelog.com/) .

<!--

sections to include in release notes:

## [Unreleased]

### Added

- Management scenario support for comparing agricultural practices
- Configuration flag `USE_PHASE_3_SCENARIOS` in `000-config.R`
- Six scenarios: baseline, compost, reduced_till, zero_till, reduced_irrig_drip, stacked
- Scenario-aware extraction from pre-aggregated `.Rdata` files
- `scenario` column added to all output CSVs
- `scenarios` array in metadata JSON
- Early exit in `031_aggregate_sipnet_output.R` for single-PFT runs
- Parquet output for large files (>100k rows) via `write_output()` helper

### Fixed

- Empty vector handling in mixed-scenario logic (`040_downscale.R`)

### Changed

### Removed

-->


## 0.2.0-2a

Expand Down
35 changes: 30 additions & 5 deletions docs/workflow_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ git clone git@github.com:ccmmf/downscaling
- detect and use resources for parallel processing (with future package); default is `available cores - 1`
- PRODUCTION mode setting. For testing, set `PRODUCTION` to `FALSE`. This is _much_ faster and requires fewer computing resources because it subsets large datasets. Once a test run is successful, set `PRODUCTION` to `TRUE` to run the full workflow.

#### Management Scenario Configuration

To compare carbon outcomes under different agricultural practices, enable management scenario mode:
```r
USE_PHASE_3_SCENARIOS <- TRUE
```

When enabled, the workflow processes multiple management scenarios in a single run. Each scenario represents a different combination of practices applied to annual croplands.

**Available Management Scenarios:**

| Scenario | Description |
|----------|-------------|
| baseline | Conventional management practices |
| compost | Compost application replacing mineral N fertilizer |
| reduced_till | Reduced tillage intensity (0.10) |
| zero_till | No tillage (0.00) |
| reduced_irrig_drip | Drip irrigation replacing canopy irrigation |
| stacked | Combined: compost + reduced tillage + drip irrigation |

### 1. Data Preparation

```sh
Expand Down Expand Up @@ -235,9 +255,13 @@ Extracts and formats SIPNET outputs for downscaling:

**Inputs:**
- `out/ENS-<ensemble_number>-<site_id>/YYYY.nc`
- `results_monthly_<variable>.Rdata` (management scenario mode)
- `site_info.csv` (management scenario mode)

**Outputs:**
- `out/ensemble_output.csv`: Long format data
- `out/ensemble_output.csv`: Long format data with columns:
- `scenario`: Management scenario identifier (when scenarios enabled)
- `datetime`, `site_id`, `lat`, `lon`, `pft`, `parameter`, `variable`, `prediction`

### 5. Mixed Cropping Systems

Expand Down Expand Up @@ -277,12 +301,13 @@ Builds Random Forest models to predict carbon pools for all fields; aggregates t
- `data/site_covariates.csv`: Environmental covariates

**Outputs from `040_downscale.R`:**
- `model_outdir/downscaled_preds.csv`: Per-site, per-ensemble predictions with totals and densities
- `model_outdir/downscaled_preds_metadata.json`: Metadata for predictions
- `model_outdir/training_sites.csv`: Training site list per PFT and pool
- `model_outdir/downscaled_preds.csv`: Per-site, per-ensemble predictions with columns:
- `site_id`, `scenario`, `pft`, `ensemble`, `c_density_Mg_ha`, `total_c_Mg`, `area_ha`, `county`, `model_output`
- `model_outdir/downscaled_preds_metadata.json`: Metadata including scenarios list
- `model_outdir/downscaled_deltas.csv`: Carbon change from simulation start to end per scenario
- `model_outdir/training_sites.csv`: Training site list per scenario, PFT, and pool
- `cache/models/*_models.rds`: Saved RF models per spec
- `cache/training_data/*_training.csv`: Training covariate matrices per spec
- `model_outdir/downscaled_deltas.csv`: Optional start→end deltas when available

**Outputs from `041_aggregate_to_county.R`:**
- `model_outdir/county_summaries.csv`: County statistics (means/SDs across ensembles for stocks and densities)
Expand Down
Loading