You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,7 @@ For more information about this file see also [Keep a Changelog](http://keepacha
33
33
- Directory structure for PEcAn Quarto notebooks under `pecan/documentation/tutorials/Demo_1_Basic_Run`
34
34
- Support for inspecting and plotting NetCDF output variables within the notebook workflow.
35
35
- 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)
Copy file name to clipboardExpand all lines: documentation/tutorials/Demo_1_Basic_Run/run_pecan.qmd
+54-28Lines changed: 54 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,22 @@
1
1
---
2
2
title: "Running Ecosystem Simulations Using PEcAn"
3
-
author: "Aritra Dey"
3
+
author:
4
+
- "Aritra Dey"
5
+
- "David LeBauer"
4
6
format:
5
7
pdf:
6
8
toc: true
7
-
number-sections: false
9
+
number-sections: true
8
10
fig-width: 10
9
11
fig-height: 6
10
12
fig-dpi: 300
11
13
---
12
14
13
-
# 1. Introduction {#introduction}
15
+
# Introduction {#introduction}
14
16
15
17
Welcome to this PEcAn workflow notebook! This notebook will guide you through running an ecosystem model using PEcAn's programmatic interface.
16
18
17
-
## 1.1 What Is PEcAn?
19
+
## What Is PEcAn?
18
20
19
21
PEcAn (Predictive Ecosystem Analyzer) is a scientific workflow system designed to make ecosystem modeling more transparent, repeatable, and accessible. It helps researchers:
20
22
@@ -23,7 +25,7 @@ PEcAn (Predictive Ecosystem Analyzer) is a scientific workflow system designed t
23
25
- Compare model predictions with observations
24
26
- Share and reproduce scientific workflows
25
27
26
-
## 1.2 What This Notebook Does
28
+
## What This Notebook Does
27
29
28
30
This notebook demonstrates how to:
29
31
@@ -43,7 +45,7 @@ This run is based on a study by [Moore et. al. (2007)](https://doi.org/10.1016/j
43
45
44
46
45
47
46
-
## 1.3 Prerequisites
48
+
## Prerequisites
47
49
48
50
Before running this notebook, make sure you have:
49
51
@@ -62,7 +64,7 @@ install.packages('PEcAn.all')
62
64
63
65
- A valid `pecan.xml` configuration file or use the example provided: `pecan/documentation/tutorials/Demo_1_Basic_Run/pecan.xml`
64
66
65
-
## 1.4 How to Use This Notebook
67
+
## How to Use This Notebook
66
68
67
69
1. Each section is clearly marked with a heading
68
70
2. Code chunks are provided with explanations
@@ -73,15 +75,15 @@ install.packages('PEcAn.all')
73
75
74
76
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.
75
77
76
-
# 2. Session Info
78
+
# Session Info
77
79
78
80
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.
79
81
80
82
```{r version-info}
81
83
PEcAn.all::pecan_version()
82
84
```
83
85
84
-
# 3. Install SIPNET v1.3.0
86
+
# Install SIPNET v1.3.0
85
87
86
88
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.
87
89
@@ -98,7 +100,7 @@ source(
98
100
99
101
> 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.
100
102
101
-
# 4. Load PEcAn Packages
103
+
# Load PEcAn Packages
102
104
103
105
First, we need to load the PEcAn R packages. These packages provide all the functions we'll use to run the workflow.
104
106
@@ -107,7 +109,7 @@ First, we need to load the PEcAn R packages. These packages provide all the func
107
109
library("PEcAn.all")
108
110
```
109
111
110
-
# 5. Load PEcAn Settings File
112
+
# Load PEcAn Settings File
111
113
112
114
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).
113
115
@@ -122,7 +124,7 @@ This is how PEcAn loads the settings file:
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.
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.
143
145
@@ -165,7 +167,7 @@ settings$info <- list(
165
167
166
168
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.
167
169
168
-
# 8. Create Output Directory
170
+
# Create Output Directory
169
171
170
172
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.
171
173
@@ -175,9 +177,28 @@ Before running the workflow, we need to ensure that the output directory specifi
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:
181
202
182
203
1. Disabling database write operations because we are not using a database
183
204
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
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.
193
214
@@ -197,14 +218,18 @@ This section executes the actual model simulations and retrieves the results. Th
# 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
201
225
202
226
After the model simulation completes, we need to extract the results and prepare them for analysis. This involves:
203
227
204
228
1. Reading the run ID
205
229
2. Setting up output paths
206
230
3. Defining time period
207
231
4. Loading model output
232
+
5. Convert to a standard format
208
233
209
234
```{r get-plot-vars}
210
235
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
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
227
254
228
255
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.
knitr::kable(vars_df, caption = "Model Output Variables and Descriptions")
247
274
```
248
275
249
-
# 13. Visualize Model Results
276
+
# Visualize Model Results
250
277
251
278
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).
252
279
253
-
## 13.1 Plot Carbon Fluxes
280
+
## Plot Carbon Fluxes
254
281
255
282
```{r plot-carbon-fluxes}
256
283
# Plot Gross Primary Productivity (GPP) and Net Primary Productivity (NPP)
@@ -265,7 +292,7 @@ lines(model_output$posix, model_output$NPP, col = "blue")
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.
316
343
317
344
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!
318
345
319
-
# 15. Clean Up Workflow Output (Optional)
346
+
# Clean Up Workflow Output (Optional)
320
347
321
348
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!**
322
349
@@ -326,10 +353,9 @@ If you want to remove all files and directories created by this workflow and sta
326
353
# fs::dir_delete(settings$outdir)
327
354
```
328
355
329
-
# 16. Session Info
356
+
# Session Info
330
357
This section prints your R session information for reproducibility.
0 commit comments