Skip to content

Commit 73319c7

Browse files
authored
Merge branch 'develop' into automated-reporting-and-visualization
2 parents b77afa9 + a859541 commit 73319c7

14 files changed

Lines changed: 1255 additions & 372 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ For more information about this file see also [Keep a Changelog](http://keepacha
99
## Unreleased
1010

1111
### Added
12+
- Added ensemble calibration diagnostics to `inst/ilamb/` in PEcAn.benchmark (rank histogram, spread-skill ratio, coverage, reliability) for assessing whether an ensemble's spread is well calibrated against observations, complementing the ensemble-mean benchmarking.
1213
- Added `make_scorecard.sh` and documentation to `inst/ilamb/` in PEcAn.benchmark for generating and serving the ILAMB HTML scorecard.
1314
- New function `PEcAn.utils::netcdf2df()` flattens all dims and vars of a netCDF into a dataframe,
1415
with units attached as an attribute.

base/utils/data/standard_vars.csv

Lines changed: 122 additions & 121 deletions
Large diffs are not rendered by default.

models/peprmt/R/helpers.R

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# setEnsemblePaths leaves all path components other than siteid
2+
# identical across sites. This is an issue for our dataset, because
3+
# each site has a different location and date range.
4+
# To use site-specific grid id, we need to string-replace each siteid
5+
6+
#' Set grid cell names (not exported)
7+
#'
8+
#' @param s settings object
9+
#'
10+
#' @returns updated settings with met paths including grid cell
11+
#' @export
12+
#'
13+
#' @examples
14+
id2grid <- function(s) {
15+
# replacing in place to preserve names
16+
for (p in seq_along(s$run$inputs$met$path)) {
17+
s$run$inputs$met$path[[p]] <- gsub(
18+
pattern = s$run$site$id,
19+
replacement = s$run$site$ERA5_grid_cell,
20+
x = s$run$inputs$met$path[[p]]
21+
)
22+
}
23+
s
24+
}
25+
26+
#' Set start and end dates (not exported)
27+
#'
28+
#' @param s settings object
29+
#'
30+
#' @returns updated settings object with met path including correct years
31+
#'
32+
#' @examples
33+
dates2grid <- function(s) {
34+
for (p in seq_along(s$run$inputs$met$path)) {
35+
s$run$inputs$met$path[[p]] <- gsub(
36+
pattern = "DATES-HERE",
37+
replacement = paste0(s$run$site$met.start, ".",
38+
s$run$site$met.end),
39+
x = s$run$inputs$met$path[[p]]
40+
)
41+
}
42+
s
43+
}

models/peprmt/demo_run/run_pecan_peprmt.qmd renamed to models/peprmt/demo_run/01_run_pecan_peprmt.qmd

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
title: "Running PEPRMT Using PEcAn"
33
author:
44
- "Abby Lewis"
5-
- "Aritra Dey"
6-
- "David LeBauer"
75
format:
86
html: default
97
pdf: default
@@ -14,74 +12,71 @@ fig-height: 6
1412
fig-dpi: 300
1513
---
1614

17-
# Introduction {#introduction}
15+
# Introduction
1816

1917
Welcome to this PEcAn workflow notebook! This notebook will guide you through running the PEPRMT model using PEcAn's programmatic interface.
2018

2119
## What Is PEcAn?
2220

2321
PEcAn (Predictive Ecosystem Analyzer) is a scientific workflow system designed to make ecosystem modeling more transparent, repeatable, and accessible. It helps researchers:
2422

25-
- Run ecosystem models with standardized inputs and outputs
26-
- Perform uncertainty analysis on model parameters
27-
- Compare model predictions with observations
28-
- Share and reproduce scientific workflows
23+
- Run ecosystem models with standardized inputs and outputs
24+
- Perform uncertainty analysis on model parameters
25+
- Compare model predictions with observations
26+
- Share and reproduce scientific workflows
2927

3028
## What This Notebook Does
3129

32-
This notebook demonstrates how to:
30+
This notebook is patterned after [PEcAn demo 1](https://pecanproject.github.io/pecan-documentation/develop/run-demo-1.html), which was written by Aritra Dey and David LeBauer. It demonstrates how to:
3331

3432
1. Set up and configure a PEcAn workflow
35-
2. Run an ecosystem model simulation
33+
2. Run an ecosystem model simulation using the PEPRMT model
3634
3. Analyze and visualize the results
3735

3836
### The Scenario Being Modeled:
3937

40-
We are modeling greenhouse gas dynamics (gross primary productivity, ecosystem respiration, and methane emissions) at five sites. The model configuration uses the PEPRMT-Tidal process-based ecosystem model (Oikawa et al. 2024).
38+
We are modeling greenhouse gas dynamics (gross primary productivity, ecosystem respiration, and methane emissions) at five sites. The model configuration uses the PEPRMT-Tidal process-based ecosystem model (Oikawa et al. 2024).
4139

4240
The simulation is run for the duration of data at each site, which ranges from 2011 to 2021.
4341

44-
This scenario is designed to be a minimal, reproducible example to demonstrate how to run PEPRMT within the PEcAn workflow. In later steps, this same framework can be extended to include more ensemble members, longer time periods, or alternative meteorological inputs.
42+
This scenario is designed to be a minimal, reproducible example to demonstrate how to run PEPRMT within the PEcAn workflow. In later steps, this same framework can be extended to include more ensemble members, longer time periods, or alternative meteorological inputs (e.g., see `pecan/models/peprmt/demo_run/02_input_demo.qmd` and `pecan/models/peprmt/demo_run/03_event_demo.qmd`).
4543

4644
## Prerequisites
4745

4846
Before running this notebook, make sure you have:
4947

50-
- All the PEcAn packages installed. You can install all PEcAn packages and their dependencies by running the following command in the root of your PEcAn repository. This chunk does not run automatically since it will overwrite a version of PEcAn you installed by other methods. Run it by hand when needed.
48+
- All the PEcAn packages installed. You can install all PEcAn packages and their dependencies by running the following command in the root of your PEcAn repository. This chunk does not run automatically since it will overwrite a version of PEcAn you installed by other methods. Run it by hand when needed.
5149

52-
```{r, eval = FALSE}
50+
```{r packages, eval = FALSE}
5351
5452
# Enable repository from pecanproject
5553
options(repos = c(
5654
pecanproject = 'https://pecanproject.r-universe.dev',
5755
CRAN = 'https://cloud.r-project.org'))
5856
# Download and install PEcAn.all in R
5957
install.packages(c('PEcAn.all', 'PEcAn.PEPRMT'))
60-
```
61-
62-
- Alternatively, install from GitHub.
6358
64-
```{r, eval = FALSE}
59+
# Alternatively, install from GitHub
6560
remotes::install_github("pecanproject/pecan", subdir = "base/all",
6661
ref = "develop", force = T)
6762
remotes::install_github("pecanproject/pecan", subdir = "models/peprmt",
6863
ref = "develop")
6964
```
7065

71-
72-
```{r}
73-
#Set working directory
74-
here::i_am("models/peprmt/demo_run/run_pecan_peprmt.qmd")
75-
```
76-
77-
- A valid `pecan.xml` configuration file or use the example provided: `pecan/models/peprmt/demo_run/settings.xml`
66+
- You will also need a valid `pecan.xml` configuration file, such as the example provided: `pecan/models/peprmt/demo_run/settings.xml`
7867

7968
## How to Use This Notebook
8069

81-
1. Each section is clearly marked with a heading
70+
1. Each section is marked with a heading
8271
2. Code chunks are provided with explanations
8372
3. You can run the code chunks sequentially
8473
4. Once you have successfully run the demo, you can modify parameters to configure new runs and analyses
74+
5. By default, the demo runs within `pecan/models/peprmt/demo_run/`.
75+
76+
```{r wd}
77+
#Set working directory
78+
here::i_am("models/peprmt/demo_run/01_run_pecan_peprmt.qmd")
79+
```
8580

8681
**Objective:**
8782

@@ -103,8 +98,14 @@ First, we need to load the PEcAn R packages. These packages provide all the func
10398
# Load the PEcAn.all package, which includes all necessary PEcAn functionality
10499
library("PEcAn.all")
105100
library("PEcAn.PEPRMT")
106-
set.seed(20260326)
101+
102+
# Set "seed" to make outputs reproducible
103+
set.seed(20260326)
104+
105+
# prints logger messages into the notebook instead of to the terminal
107106
logger.setUseConsole(console = TRUE, stderr = FALSE)
107+
# prints messages with levels INFO or higher (WARNING, ERROR, SEVERE)
108+
# For even more detail, change to "DEBUG"
108109
logger.setLevel("INFO")
109110
```
110111

@@ -126,8 +127,8 @@ settings_path <- here::here("models/peprmt/demo_run/settings_inputdemo.xml")
126127

127128
After specifying the path to the `pecan.xml` file, the next step involves reading and preparing these settings. PEcAn provides utilities to process and validate the configurations before execution begins.
128129

129-
- `PEcAn.settings::read.settings(settings_path)`: Reads the `pecan.xml` file and converts it to an R list object.
130-
- `PEcAn.settings::prepare.settings(settings)`: Prepares and validates settings. It sets defaults for missing fields, changes file paths to absolute paths, and generally ensures consistency.
130+
- `PEcAn.settings::read.settings(settings_path)`: Reads the `pecan.xml` file and converts it to an R list object.
131+
- `PEcAn.settings::prepare.settings(settings)`: Prepares and validates settings. It sets defaults for missing fields, changes file paths to absolute paths, and generally ensures consistency.
131132

132133
```{r read-prepare-settings}
133134
# Read the settings from the pecan.xml file
@@ -141,7 +142,7 @@ settings <- PEcAn.settings::prepare.settings(settings)
141142

142143
Once the settings have been read and prepared, it is useful to inspect the structure of the `settings` object. This object is an R list containing all parameters and configurations for the PEcAn workflow.
143144

144-
- `str(settings)` displays the internal structure of the `settings` object. This shows how the settings are represented in R and is useful for debugging and verifying settings.
145+
- `str(settings)` displays the internal structure of the `settings` object. This shows how the settings are represented in R and is useful for debugging and verifying settings.
145146

146147
```{r explore-settings}
147148
str(settings)
@@ -165,22 +166,25 @@ Editing the more interesting settings to change the PFT (`settings$pfts`) or ext
165166

166167
The directory structure created by PEcAn for this demo run will look like this:
167168

168-
```
169+
```
169170
demo_outdir/ # Root output directory
171+
├── ensemble.samples.<ensemble_id>.Rdata # contains the selected parameter values for each ensemble member
170172
├── run/ # Configuration & execution metadata
171173
│ ├── runs.txt # List of run IDs (one per model realization)
172-
│ ├── <runid>/ # Model-specific config copies (sometimes)
173-
│ └── config.* # Generated model configs (e.g., SIPNET)
174+
│ └── <runid>/ # Model-specific configs, including run job and driver data
174175
├── out/ # Raw model outputs by run ID
175-
│ └── <runid>/ # E.g., daily PEPRMT output files
176+
│ └── <runid>/ # E.g., PEPRMT output files
177+
├── STATUS # timestamp and ok/error status of each workflow step
178+
├── pecan.*.xml # copies of the run settings saved at different steps
179+
├── run_manifest.csv # info about site, PFT, etc for each runid
180+
└── samples.Rdata # draws from parameter distributions
181+
176182
```
177183

178184
The root output directory is defined here as `demo_outdir/` by `settings$outdir`. This directory contains log and record files from the PEcAn workflow. They provide a detailed record of how data was generated and are key components of the analysis metadata and provenance. These can be useful for debugging as well as for downstream analysis.
179185

180186
Key subdirectories include `run/` and `out/` that contain files used to configure and run the model, files generated by the underlying ecosystem model, and PEcAn standard outputs used in downstream analyses. These are described in subsequent sections.
181187

182-
Additional outputs include logs, a `STATUS` file that records the steps of the workflow along with timestamps and whether each step was successful, and a copy of the `pecan.*.xml` file.
183-
184188
# Write Model Configuration Files
185189

186190
This step generates the model-specific configuration files and scripts that will be used to run the ecosystem model. The process involves generating PEPRMT configuration files using the `runModule.run.write.configs()` function.
@@ -193,27 +197,25 @@ settings <- PEcAn.workflow::runModule.run.write.configs(settings)
193197

194198
This section executes the actual model simulations and retrieves the results. The process is managed by PEcAn's workflow system, which handles the execution of your chosen ecosystem model.
195199

196-
- `runModule_start_model_runs(settings)`: This function initiates the model runs based on your configuration. It manages the execution of your chosen ecosystem model, using the configuration files generated in the previous step.
200+
- `runModule_start_model_runs(settings)`: This function initiates the model runs based on your configuration. It manages the execution of your chosen ecosystem model, using the configuration files generated in the previous step.
197201

198202
```{r run-model}
199203
PEcAn.workflow::runModule_start_model_runs(settings)
200204
```
201205

202-
203206
This step generates raw model outputs in model-specific format (in this case, `out.csv`) as well as log files.
204207

205208
# Extract Model Results and Prepare for Analysis
206209

207210
After the model simulation completes, we need to extract the results and prepare them for analysis. This involves:
208211

209-
1. Reading the run ID
210-
2. Setting up output paths
211-
3. Defining time period
212-
4. Loading model output
213-
5. Convert to a standard format
212+
1. Reading the run ID
213+
2. Setting up output paths
214+
3. Defining time period
215+
4. Loading model output
216+
5. Convert to a standard format
214217

215-
Here we read output one site at a time to account for differing simulation periods.
216-
For runs where all sites have the same dates, it should also work to pass the entire runid vector to a single `read.output` call.
218+
Here we read output one site at a time to account for differing simulation periods. For runs where all sites have the same dates, it should also work to pass the entire runid vector to a single `read.output` call.
217219

218220
```{r get-plot-vars}
219221
runid <- read.csv(file.path(settings$outdir, "runs_manifest.csv"))$run_id
@@ -236,26 +238,19 @@ model_output <- purrr::map2_dfr(
236238
available_vars <- names(model_output)[!names(model_output) %in% c("posix", "time_bounds")]
237239
```
238240

239-
Running this code will convert model specific output files into a standardized netCDF ([year].nc) that can be downloaded for visualization and analysis (R, Matlab, ncview, panoply, etc). This is a key step, because this standardization enables PEcAn to apply downstream analyses to outputs from different ecosystem models.
241+
Running this code will convert model specific output files into a standardized netCDF (\[year\].nc) that can be downloaded for visualization and analysis (R, Matlab, ncview, panoply, etc). This is a key step, because this standardization enables PEcAn to apply downstream analyses to outputs from different ecosystem models.
240242

241243
# Display Available Model Variables
242244

243-
This section shows all the variables that are available in the model output. These variables represent different ecosystem processes and states that the model has simulated.
245+
This section shows all the variables that are available in the model output. These variables represent different ecosystem processes and states that the model has simulated. Here we are referencing PEcAn standard variables for documentation.
244246

245247
```{r show-variables, echo=FALSE}
246248
vars_df <- PEcAn.utils::standard_vars |>
247249
dplyr::select(
248250
Variable = Variable.Name,
249251
Description = Long.name
250252
) |>
251-
dplyr::filter(Variable %in% available_vars) |>
252-
# TODO: add year to PEcAn.utils::standard vars
253-
dplyr::bind_rows(
254-
dplyr::tibble(
255-
Variable = "year",
256-
Description = "Year"
257-
)
258-
)
253+
dplyr::filter(Variable %in% available_vars)
259254
260255
vars_df$Description[is.na(vars_df$Description)] <- "(No description available)"
261256
knitr::kable(vars_df, caption = "Model Output Variables and Descriptions")
@@ -328,6 +323,7 @@ If you want to remove all files and directories created by this workflow and sta
328323
```
329324

330325
# Session Info
326+
331327
This section prints your R session information for reproducibility.
332328

333329
```{r session-info}

0 commit comments

Comments
 (0)