Skip to content

Commit 579b9d9

Browse files
authored
Merge pull request #3570 from AritraDey-Dev/quarto-ensemble-sensivity
Demo 2 Quarto notebook tutorial for PEcAn uncertainty analysis
2 parents 3724ee9 + 45553d2 commit 579b9d9

File tree

8 files changed

+683
-29
lines changed

8 files changed

+683
-29
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,6 @@ contrib/modellauncher/modellauncher
115115
# Ignore any folder named demo_outdir (Quarto notebook outputs)
116116
**/demo_outdir/
117117
dbfiles/
118+
**/temperate.coniferous/
119+
*.sensitivity.analysis.*.pdf
120+
*.variance.decomposition.*.pdf

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ For more information about this file see also [Keep a Changelog](http://keepacha
3333
- Directory structure for PEcAn Quarto notebooks under `pecan/documentation/tutorials/Demo_1_Basic_Run`
3434
- Support for inspecting and plotting NetCDF output variables within the notebook workflow.
3535
- added support for soil temperature, relative humidity, soil moisture, and PPFD downscaling to `met_temporal_downscale.Gaussian_ensemble`
36+
- The PEcAn uncertainty analysis tutorial ("Demo 2") has been updated and reimplemented as a Quarto notebook at `documentation/tutorials/Demo_02_Uncertainty_Analysis/uncertainty.qmd`. (#3570)
3637

3738
### Fixed
3839

CITATION.cff

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ authors:
125125
orcid: 'https://orcid.org/0009-0005-0253-8642'
126126
- given-names: Akash BV
127127
affiliation: CMR Institute of Technology, Bengaluru
128+
- given-names: Aritra Dey
129+
affiliation: National Institute of Technology, Tiruchirappalli
128130

129131
preferred-citation:
130132
type: article
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<pecan>
3+
<info>
4+
<notes/>
5+
<userid>-1</userid>
6+
<username/>
7+
<date>2025-06-19-15-34-01</date>
8+
</info>
9+
<outdir>demo_outdir</outdir>
10+
<pfts>
11+
<pft>
12+
<name>temperate.coniferous</name>
13+
<posterior.files>pft/temperate.coniferous/prior.distns.Rdata</posterior.files>
14+
<outdir>pft/temperate.coniferous</outdir>
15+
</pft>
16+
</pfts>
17+
<ensemble>
18+
<size>50</size>
19+
<variable>NPP</variable>
20+
<samplingspace>
21+
<parameters>
22+
<method>halton</method>
23+
</parameters>
24+
</samplingspace>
25+
<start.year>2004</start.year>
26+
<end.year>2004</end.year>
27+
</ensemble>
28+
<sensitivity.analysis>
29+
<quantiles>
30+
<sigma>-1</sigma>
31+
<sigma>1</sigma>
32+
</quantiles>
33+
<variable>NPP</variable>
34+
<start.year>2004</start.year>
35+
<end.year>2004</end.year>
36+
</sensitivity.analysis>
37+
<model>
38+
<type>SIPNET</type>
39+
<revision>1.3.0</revision>
40+
<delete.raw>FALSE</delete.raw>
41+
<binary>demo_outdir/sipnet</binary>
42+
</model>
43+
<run>
44+
<site>
45+
<met.start>2004/01/01</met.start>
46+
<met.end>2004/12/31</met.end>
47+
<name>Niwot Ridge Forest/LTER NWT1 (US-NR1)</name>
48+
<lat>40.0329</lat>
49+
<lon>-105.546</lon>
50+
</site>
51+
<inputs>
52+
<met>
53+
<source>AmerifluxLBL</source>
54+
<output>SIPNET</output>
55+
<username>Aritra_2004</username>
56+
<path>
57+
<path1>dbfiles/AMF_US-NR1_BASE_HH_23-5.2004-01-01.2004-12-31.clim</path1>
58+
</path>
59+
</met>
60+
</inputs>
61+
<start.date>2004/01/01</start.date>
62+
<end.date>2004/12/31</end.date>
63+
</run>
64+
<host>
65+
<name>localhost</name>
66+
</host>
67+
</pecan>
Binary file not shown.

documentation/tutorials/Demo_02_Uncertainty_Analysis/uncertainty.qmd

Lines changed: 555 additions & 0 deletions
Large diffs are not rendered by default.

documentation/tutorials/Demo_1_Basic_Run/download_sipnet.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if (os == "Linux") {
1515
PEcAn.logger::logger.error("Unsupported operating system: ", os)
1616
}
1717

18-
demo_outdir <- here::here("documentation/tutorials/Demo_1_Basic_Run/demo_outdir")
18+
demo_outdir <- file.path("demo_outdir")
1919
dest_path <- file.path(demo_outdir, "sipnet")
2020
if (!dir.exists(demo_outdir)) {
2121
# using if(!dir.exists) instead of `showWarnings = FALSE`

documentation/tutorials/Demo_1_Basic_Run/run_pecan.qmd

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
---
22
title: "Running Ecosystem Simulations Using PEcAn"
3-
author: "Aritra Dey"
3+
author:
4+
- "Aritra Dey"
5+
- "David LeBauer"
46
format:
57
pdf:
68
toc: true
7-
number-sections: false
9+
number-sections: true
810
fig-width: 10
911
fig-height: 6
1012
fig-dpi: 300
1113
---
1214

13-
# 1. Introduction {#introduction}
15+
# Introduction {#introduction}
1416

1517
Welcome to this PEcAn workflow notebook! This notebook will guide you through running an ecosystem model using PEcAn's programmatic interface.
1618

17-
## 1.1 What Is PEcAn?
19+
## What Is PEcAn?
1820

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

@@ -23,7 +25,7 @@ PEcAn (Predictive Ecosystem Analyzer) is a scientific workflow system designed t
2325
- Compare model predictions with observations
2426
- Share and reproduce scientific workflows
2527

26-
## 1.2 What This Notebook Does
28+
## What This Notebook Does
2729

2830
This notebook demonstrates how to:
2931

@@ -43,7 +45,7 @@ This run is based on a study by [Moore et. al. (2007)](https://doi.org/10.1016/j
4345

4446

4547

46-
## 1.3 Prerequisites
48+
## Prerequisites
4749

4850
Before running this notebook, make sure you have:
4951

@@ -62,7 +64,7 @@ install.packages('PEcAn.all')
6264

6365
- A valid `pecan.xml` configuration file or use the example provided: `pecan/documentation/tutorials/Demo_1_Basic_Run/pecan.xml`
6466

65-
## 1.4 How to Use This Notebook
67+
## How to Use This Notebook
6668

6769
1. Each section is clearly marked with a heading
6870
2. Code chunks are provided with explanations
@@ -73,15 +75,15 @@ install.packages('PEcAn.all')
7375

7476
This demo illustrates how to run a basic PEcAn workflow using an R-based Quarto notebook. It will cover loading settings, writing model configuration files, and running model simulations. This approach provides a programmatic alternative to the web-based PEcAn interface for executing ecosystem models.
7577

76-
# 2. Session Info
78+
# Session Info
7779

7880
This section prints your R session information for reproducibility. Having this information at the beginning helps with debugging even if the notebook encounters errors later.
7981

8082
```{r version-info}
8183
PEcAn.all::pecan_version()
8284
```
8385

84-
# 3. Install SIPNET v1.3.0
86+
# Install SIPNET v1.3.0
8587

8688
If you haven't already installed the SIPNET binary, you can do so by running the following code. This will download the SIPNET binary to `demo_outdir/sipnet` and make it executable.
8789

@@ -98,7 +100,7 @@ source(
98100

99101
> Note: You can find the most recent version of the SIPNET binary at: [SIPNET GitHub Releases](https://github.com/PecanProject/sipnet/releases), but this notebook is designed to work with SIPNET v1.3.0.
100102
101-
# 4. Load PEcAn Packages
103+
# Load PEcAn Packages
102104

103105
First, we need to load the PEcAn R packages. These packages provide all the functions we'll use to run the workflow.
104106

@@ -107,7 +109,7 @@ First, we need to load the PEcAn R packages. These packages provide all the func
107109
library("PEcAn.all")
108110
```
109111

110-
# 5. Load PEcAn Settings File
112+
# Load PEcAn Settings File
111113

112114
PEcAn uses an XML-based settings file (pecan.xml) to configure model runs. This file defines key information about the run including: PFT(s), site location, time period of the run, the location of input files and where outputs will be saved. Other settings outside the scope of this demo include the types of analyses that will be performed, how to connect to a database, and how to run it on a high performance computing cluster (we are using the default single model run on a single computer).
113115

@@ -122,7 +124,7 @@ This is how PEcAn loads the settings file:
122124
settings_path <- here::here("documentation/tutorials/Demo_1_Basic_Run/pecan.xml")
123125
```
124126

125-
# 6. Prepare and Validate Settings
127+
# Prepare and Validate Settings
126128

127129
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.
128130

@@ -137,7 +139,7 @@ settings <- PEcAn.settings::read.settings(settings_path)
137139
settings <- PEcAn.settings::prepare.settings(settings)
138140
```
139141

140-
# 7. Explore the Settings Object
142+
# Explore the Settings Object
141143

142144
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.
143145

@@ -165,7 +167,7 @@ settings$info <- list(
165167

166168
Editing the more interesting settings to change the PFT (`settings$pfts`) or extend the run (`settings$run$end.date`) is beyond the scope of this demo. You _could_ change the pft or the end date, but you would need a new file containing parameters for that PFT (`settings$pfts$pft$posterior.files`), or a climate file (`settings$run$met$path$path1`) that extends to the desired simulation period.
167169

168-
# 8. Create Output Directory
170+
# Create Output Directory
169171

170172
Before running the workflow, we need to ensure that the output directory specified in the settings exists. This directory will store all the model outputs, configuration files, and results from the simulation.
171173

@@ -175,9 +177,28 @@ Before running the workflow, we need to ensure that the output directory specifi
175177
dir.create(settings$outdir, recursive = TRUE, showWarnings = FALSE)
176178
```
177179

178-
# 9. Write Model Configuration Files
179180

180-
This step generates the model-specific configuration files that will be used to run the ecosystem model. The process involves:
181+
The directory structure created by PEcAn for this demo run will look like this:
182+
183+
```
184+
demo_outdir/ # Root output directory
185+
├── run/ # Configuration & execution metadata
186+
│ ├── runs.txt # List of run IDs (one per model realization)
187+
│ ├── <runid>/ # Model-specific config copies (sometimes)
188+
│ └── config.* # Generated model configs (e.g., SIPNET)
189+
├── out/ # Raw model outputs by run ID
190+
│ └── <runid>/ # E.g., daily or sub-daily SIPNET output files
191+
```
192+
193+
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.
194+
195+
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.
196+
197+
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.
198+
199+
# Write Model Configuration Files
200+
201+
This step generates the model-specific configuration files and scripts that will be used to run the ecosystem model. The process involves:
181202

182203
1. Disabling database write operations because we are not using a database
183204
2. Generating SIPNET configuration files using the `runModule.run.write.configs()` function.
@@ -187,7 +208,7 @@ settings$database <- NULL # Disable database operations for this demo
187208
settings <- PEcAn.workflow::runModule.run.write.configs(settings)
188209
```
189210

190-
# 10. Run Model Simulations and Fetch Results
211+
# Run Model Simulations and Fetch Results
191212

192213
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.
193214

@@ -197,14 +218,18 @@ This section executes the actual model simulations and retrieves the results. Th
197218
PEcAn.workflow::runModule_start_model_runs(settings)
198219
```
199220

200-
# 11. Extract Model Results and Prepare for Analysis
221+
222+
This step generates raw model outputs in model-specific format (in this case, `sipnet.out`) as well as log files.
223+
224+
# Extract Model Results and Prepare for Analysis
201225

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

204228
1. Reading the run ID
205229
2. Setting up output paths
206230
3. Defining time period
207231
4. Loading model output
232+
5. Convert to a standard format
208233

209234
```{r get-plot-vars}
210235
runid <- as.character(read.table(paste(settings$outdir, "/run/", "runs.txt", sep = ""))[1, 1]) # Note: if you are using an xml from a run with multiple ensembles this line will provide only the first run id
@@ -223,7 +248,9 @@ model_output <- PEcAn.utils::read.output(
223248
available_vars <- names(model_output)[!names(model_output) %in% c("posix", "time_bounds")]
224249
```
225250

226-
# 12. Display Available Model Variables
251+
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.
252+
253+
# Display Available Model Variables
227254

228255
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.
229256

@@ -246,11 +273,11 @@ vars_df$Description[is.na(vars_df$Description)] <- "(No description available)"
246273
knitr::kable(vars_df, caption = "Model Output Variables and Descriptions")
247274
```
248275

249-
# 13. Visualize Model Results
276+
# Visualize Model Results
250277

251278
This section provides examples of how to create time series plots of different model variables. The examples cover various ecosystem processes including carbon fluxes, carbon pools, water variables, and structural variables like Leaf Area Index (LAI).
252279

253-
## 13.1 Plot Carbon Fluxes
280+
## Plot Carbon Fluxes
254281

255282
```{r plot-carbon-fluxes}
256283
# Plot Gross Primary Productivity (GPP) and Net Primary Productivity (NPP)
@@ -265,7 +292,7 @@ lines(model_output$posix, model_output$NPP, col = "blue")
265292
legend("topright", legend = c("GPP", "NPP"), col = c("green", "blue"), lty = 1)
266293
```
267294

268-
## 13.2 Plot Carbon Pools
295+
## Plot Carbon Pools
269296

270297
```{r plot-carbon-pools}
271298
# Plot Total Live Biomass and Total Soil Carbon
@@ -280,7 +307,7 @@ lines(model_output$posix, model_output$TotSoilCarb, col = "brown")
280307
legend("topright", legend = c("Total Live Biomass", "Total Soil Carbon"), col = c("darkgreen", "brown"), lty = 1)
281308
```
282309

283-
## 13.3 Plot Water Variables
310+
## Plot Water Variables
284311

285312
```{r plot-water-variables}
286313
# Plot Soil Moisture and Snow Water Equivalent
@@ -295,7 +322,7 @@ lines(model_output$posix, model_output$SWE, col = "lightblue")
295322
legend("topright", legend = c("Soil Moisture", "Snow Water Equivalent"), col = c("blue", "lightblue"), lty = 1)
296323
```
297324

298-
## 13.4 Plot LAI and Biomass
325+
## Plot LAI and Biomass
299326

300327
```{r plot-lai-biomass}
301328
# Plot Leaf Area Index (LAI) and Above Ground Wood
@@ -310,13 +337,13 @@ lines(model_output$posix, model_output$AbvGrndWood, col = "brown")
310337
legend("topright", legend = c("LAI", "Above Ground Wood"), col = c("darkgreen", "brown"), lty = 1)
311338
```
312339

313-
# 14. Conclusion
340+
# Conclusion
314341

315342
This notebook demonstrated how to set up, run, and analyze a PEcAn ecosystem model workflow programmatically. You can now modify parameters, try different models, or extend the analysis as needed.
316343

317344
Try editing the `pecan.xml` file. Give it a new name and update the **settings_path** variable at the beginning of this Demo to point to the new file. See how the changes affect the model output!
318345

319-
# 15. Clean Up Workflow Output (Optional)
346+
# Clean Up Workflow Output (Optional)
320347

321348
If you want to remove all files and directories created by this workflow and start fresh, you can run the following code. This will delete the entire output directory specified in your settings. **Use with caution!**
322349

@@ -326,10 +353,9 @@ If you want to remove all files and directories created by this workflow and sta
326353
# fs::dir_delete(settings$outdir)
327354
```
328355

329-
# 16. Session Info
356+
# Session Info
330357
This section prints your R session information for reproducibility.
331358

332359
```{r session-info}
333360
sessionInfo()
334361
```
335-

0 commit comments

Comments
 (0)