Title: | PEcAn Package for Integration of ED2 Model |
---|---|
Description: | The Predictive Ecosystem Carbon Analyzer (PEcAn) is a scientific workflow management tool that is designed to simplify the management of model parameterization, execution, and analysis. The goal of PECAn is to streamline the interaction between data and models, and to improve the efficacy of scientific investigation. This package provides functions to link the Ecosystem Demography Model, version 2, to PEcAn. |
Authors: | David LeBauer, Mike Dietze, Xiaohui Feng, Dan Wang, Carl Davidson, Rob Kooper, Shawn Serbin, Alexey Shiklomanov, Eric R. Scott |
Maintainer: | Mike Dietze <[email protected]> |
License: | BSD_3_clause + file LICENSE |
Version: | 1.8.0.9000 |
Built: | 2024-11-20 21:32:57 UTC |
Source: | https://github.com/PecanProject/pecan |
Check if value is between (inclusive) a range
between(x, lower, upper)
between(x, lower, upper)
x |
Value to check |
lower |
Lower limit |
upper |
Upper limit |
Check internal file formatting, and optionally check for compatibility against related files.
check_css(css, pss = NULL) check_pss(pss, site = NULL) check_site(site)
check_css(css, pss = NULL) check_pss(pss, site = NULL) check_site(site)
css |
css data object (see read_css) |
pss |
pss data object (see read_pss) |
site |
site data object (see read_site) |
NULL
(invisibly)
Check individual ED metfile
check_ed_metfile(metfile, variables)
check_ed_metfile(metfile, variables)
metfile |
Path to meteorology file |
variables |
Variables table from ed_metheader object |
NULL
, invisibly, if successful or throw an error
Check that the object has all components, and throw an error if anything is wrong. Optionally, do some basic checks of actualy meteorology files as well.
check_ed_metheader(ed_metheader, check_files = TRUE) check_ed_metheader_format(ed_metheader_format, check_files = TRUE)
check_ed_metheader(ed_metheader, check_files = TRUE) check_ed_metheader_format(ed_metheader_format, check_files = TRUE)
ed_metheader |
ED meteorology header object (see read_ed_metheader) |
check_files |
Logical. If |
ed_metheader_format |
A single format inside the met header object |
check_ed_metheader_format
checks an individual format (one item in the
ed_metheader
list). check_ed_metheader
applies these checks to each item
in the format list.
Check the basic structure of ed2in
object, as well as consistency among
arguments (e.g. run dates and coordinates are within the range of vegetation
and meteorology data).
check_ed2in(ed2in)
check_ed2in(ed2in)
ed2in |
Named list of ED2IN tag-value pairs. See read_ed2in. |
Performs model specific unit conversions on a a list of trait values, such as those provided to write.config
convert.samples.ED(trait.samples)
convert.samples.ED(trait.samples)
trait.samples |
a matrix or dataframe of samples from the trait distribution |
matrix or dataframe with values transformed
Shawn Serbin, David LeBauer, Carl Davidson, Ryan Kelly
Create css, pss, and site files from examples
create_css(input, check = TRUE) create_pss(input, check = TRUE) create_site(input, check = TRUE)
create_css(input, check = TRUE) create_pss(input, check = TRUE) create_site(input, check = TRUE)
input |
Named |
check |
Logical. If |
css, pss, or site object (data.frame
, possibly with attributes)
Create full ED vegetation input object
create_ed_veg(css, pss, site, latitude, longitude, check = TRUE, ...)
create_ed_veg(css, pss, site, latitude, longitude, check = TRUE, ...)
css |
css object ( |
pss |
pss object ( |
site |
site object ( |
latitude |
Latitude coordinate |
longitude |
Longitude coordinate |
check |
Logical. If |
... |
Additional objects to store in list |
For a given date, figure out its month and return all of the dates for that month.
dates_in_month(date)
dates_in_month(date)
date |
Date as string or date object |
Sequence of dates from the first to the last day of the month.
Download and unzip common ED inputs from a public Open Science Framework
(OSF) repository (https://osf.io/b6umf). Inputs include the Olson Global
Ecosystems (OGE) database (oge2OLD
) and the chd
and dgd
databases.
download_edi(directory)
download_edi(directory)
directory |
Target directory for unzipping files. Will be created if it doesn't exist. |
The total download size around 28 MB.
TRUE
, invisibly
Lookup function for translating commonly used ED variables returns out list, readvar variables to read from file, expr if any derivation is needed
ed.var(varname)
ed.var(varname)
varname |
character; variable name to read from file |
ITIMEA/Z
string to hour and minuteConvert ED2IN ITIMEA/Z
string to hour and minute
ed2in2time(itimea)
ed2in2time(itimea)
itimea |
ED2IN time string, e.g. "1200" |
List containing numeric values of hour and minute
Example css, pss, and site objects
example_css example_pss example_site
example_css example_pss example_site
An object of class tbl_df
(inherits from tbl
, data.frame
) with 1 rows and 10 columns.
An object of class tbl_df
(inherits from tbl
, data.frame
) with 1 rows and 14 columns.
An object of class tbl_df
(inherits from tbl
, data.frame
) with 1 rows and 7 columns.
A helper function to extract a named vector of pft numbers from
settings$pfts
. Will use pft numbers in settings
if they exist, otherwise
it'll match using the pftmapping
dataset
extract_pfts(pfts)
extract_pfts(pfts)
pfts |
settings$pfts |
named numeric vector
Get ED2 config.xml file
get_configxml.ED2(rundir, runid)
get_configxml.ED2(rundir, runid)
rundir |
Model run directory. Usually |
runid |
PEcAn run ID |
Alexey Shiklomanov
Extract sequence of dates from ED2IN file
get_ed2in_dates(ed2in)
get_ed2in_dates(ed2in)
ed2in |
Named list of ED2IN tag-value pairs. See read_ed2in. |
Vector of dates from start date to end date by 1 day
Automatically determine latitude or longitude from an ED input filepath. If the latitude/longitude regular expression isn't matched, this will throw an error.
get_latlon(filepath, latlon)
get_latlon(filepath, latlon)
filepath |
Path to a css, pss, or site file |
latlon |
Which value to retrieve, either "lat" for latitude or "lon" for longitude |
Numeric value of latitude or longitude
Figure out the dates for which a given meteorology is available by parsing the matching file names.
get_met_dates(ed_metheader)
get_met_dates(ed_metheader)
ed_metheader |
ED meteorlogy header object (see read_ed_metheader) |
Vector of dates for a run
Get ED history restart file path
get_restartfile.ED2(mod_outdir, runid, file.time)
get_restartfile.ED2(mod_outdir, runid, file.time)
mod_outdir |
Directory where PEcAn stores ensemble outputs. Usually
|
runid |
PEcAn run ID |
file.time |
Start or end time from SDA analysis |
Alexey Shiklomanov
ed2in
Simple test if object inheirts from class "ed2in"
.
is.ed2in(x)
is.ed2in(x)
x |
Object to be tested |
Mostly useful when recursive
and full.names
are both FALSE:
The current implementation sets full.names
internally, and for recursive
listings list.files(..., include.dirs = FALSE)
is equivalent and faster.
list.files.nodir(path, ...)
list.files.nodir(path, ...)
path |
directory to list |
... |
arguments passed on to base::list.files |
Alexey Shiklomanov
Descriptions of ED met header variable flags.
met_flag_description
met_flag_description
An object of class tbl_df
(inherits from tbl
, data.frame
) with 5 rows and 2 columns.
data.frame
with the following columns:
flag
– Numeric flag (in header file)
flag_description
– Description of flag
Helpful information about ED_MET_DRIVER files.
met_variable_description
met_variable_description
An object of class tbl_df
(inherits from tbl
, data.frame
) with 15 rows and 3 columns.
data.frame
with the following columns:
variable
– Variable name
description
– Variable description
unit
– Variable unit (character, parse-able by udunints2
)
If files already exist in 'Outfolder', the default function is NOT to overwrite them and only gives user the notice that file already exists. If user wants to overwrite the existing files, just change overwrite statement below to TRUE.
met2model.ED2( in.path, in.prefix, outfolder, start_date, end_date, lst = 0, lat = NA, lon = NA, overwrite = FALSE, verbose = FALSE, leap_year = TRUE, ... )
met2model.ED2( in.path, in.prefix, outfolder, start_date, end_date, lst = 0, lat = NA, lon = NA, overwrite = FALSE, verbose = FALSE, leap_year = TRUE, ... )
in.path |
location on disk where inputs are stored |
in.prefix |
prefix of input and output files |
outfolder |
location on disk where outputs will be stored |
start_date |
the start date of the data to be downloaded (will only use the year part of the date) |
end_date |
the end date of the data to be downloaded (will only use the year part of the date) |
lst |
timezone offset to GMT in hours |
lat |
latitude; if not provide the function will attempt to discover it in input files |
lon |
longitude; if not provide the function will attempt to discover it in input files |
overwrite |
should existing files be overwritten |
verbose |
should the function be very verbose |
leap_year |
Enforce Leap-years? If set to TRUE, will require leap years to have 366 days. If set to false, will require all years to have 365 days. Default = TRUE. |
... |
currently unused |
Modified from code to convert ED2's HDF5 output into the NACP Intercomparison format (ALMA using netCDF)
model2netcdf.ED2( outdir, sitelat, sitelon, start_date, end_date, pfts, settings = NULL, process_partial = FALSE )
model2netcdf.ED2( outdir, sitelat, sitelon, start_date, end_date, pfts, settings = NULL, process_partial = FALSE )
outdir |
Location of ED model output (e.g. a path to a single ensemble output) |
sitelat |
Latitude of the site |
sitelon |
Longitude of the site |
start_date |
Start time of the simulation |
end_date |
End time of the simulation |
pfts |
a named vector of PFT numbers where the names are PFT names |
settings |
pecan settings object |
process_partial |
should failed runs be processed? Defaults to |
if settings
is provided, then values for missing arguments
sitelat
, sitelon
, start_date
, end_date
, and pfts
will be taken
from it
Michael Dietze, Shawn Serbin, Rob Kooper, Toni Viskari, Istem Fer
data.frame
Wrapper around modifyList
to allow expanding a data.frame
by modifying
only a single column.
modify_df(input, base)
modify_df(input, base)
input |
Named |
base |
Reference object to modify |
Modified data.frame
This is a convenience function for modifying an ed2in
list object.
Arguments passed in all caps are assumed to be ED2IN namelist parameters and
are inserted directly into the ed2in
list objects. Lowercase arguments are
defined explicitly (see "Parameters"), and those that do not match explicit
arguments will be ignored with a warning. Because the lowercase arguments
come with additional validity checks, they are recommended over modifying
the ED2IN file directly via uppercase arguments. For all lowercase
arguments, the default (NULL
) means to use whatever is currently
in the input ed2in
.
modify_ed2in( ed2in, ..., veg_prefix = NULL, latitude = NULL, longitude = NULL, met_driver = NULL, start_date = NULL, end_date = NULL, EDI_path = NULL, output_types = NULL, output_dir = NULL, run_dir = NULL, runtype = NULL, run_name = NULL, include_these_pft = NULL, pecan_defaults = FALSE, add_if_missing = FALSE, check_paths = TRUE, .dots = list() )
modify_ed2in( ed2in, ..., veg_prefix = NULL, latitude = NULL, longitude = NULL, met_driver = NULL, start_date = NULL, end_date = NULL, EDI_path = NULL, output_types = NULL, output_dir = NULL, run_dir = NULL, runtype = NULL, run_name = NULL, include_these_pft = NULL, pecan_defaults = FALSE, add_if_missing = FALSE, check_paths = TRUE, .dots = list() )
ed2in |
list to modify |
... |
Namelist arguments (see Description and Details) |
veg_prefix |
Vegetation file prefix ( |
latitude |
Run latitude coordinate. If |
longitude |
Run longitude coordinate. If |
met_driver |
Path and filename of met driver header
( |
start_date |
Run start date ( |
end_date |
Run end date ( |
EDI_path |
Path to |
output_types |
Character vector of output types (see Details) |
output_dir |
Output directory, for |
run_dir |
Directory in which to store run-related config files (e.g. |
runtype |
ED initialization mode; either "INITIAL" or "HISTORY" |
run_name |
Give the run an informative name/description. Sets
the ED2IN |
include_these_pft |
Numeric vector describing the PFTs to
include in ED. Note that this is in addition to any PFTs
specified by the |
pecan_defaults |
Logical. If |
add_if_missing |
Logical. If |
check_paths |
Logical. If |
.dots |
A list of |
Namelist arguments are applied last, and will silently overwrite any arguments set by special case arguments.
Namelist arguments can be stored in a list and passed in via the .dots
argument (e.g. .dots = list(SFILIN = "/path/prefix_", ...)
), or using the
rlang::!!!
splicing operator. If both are provided, they will be spliced
together, with the ...
taking precedence.
For output_types
, select one or more of the following:
"fast" – Fast analysis; mostly polygon-level averages (IFOUTPUT
)
"daily – Daily means (one file per day) (IDOUTPUT
)
"monthly" – Monthly means (one file per month) (IMOUTPUT
)
"monthly_diurnal" – Monthly means of the diurnal cycle (one file per
month) (IQOUTPUT
)
"annual" – Annual (one file per year) (IYOUTPUT
)
"instant" – Instantaneous fluxes, mostly polygon-level variables, one
file per year (ITOUTPUT
)
"restart" – Restart file for HISTORY runs. (ISOUTPUT
)
"all" – All output types
Modified ed2in
list object. See read_ed2in.
This will generate the CSV file needed by write configs to write the config.xml. This is a hack right now, all this information should be in the PEcAn DB.
parse.history(historyfile, outfile = "")
parse.history(historyfile, outfile = "")
historyfile |
filename of history file generated by ED. |
outfile |
location where to write output, if no specified it will write to the console. |
Rob Kooper
Generate a vector of integer indices for mapping ED state
cohort vectors onto patches, for instance for use with tapply
.
patch_cohort_index(nc)
patch_cohort_index(nc)
nc |
|
Alexey Shiklomanov
A dataset matching PEcAn PFT names to ED PFT numbers.
pftmapping
pftmapping
A data frame with 73 rows and 2 variables:
PEcAn PFT names
ED2 PFT numbers
...
https://github.com/EDmodel/ED2/wiki/Plant-functional-types
Adds the latitude and longitude, or checks if they are formatted correctly. Then, splits the prefix into the directory and base name, appends the suffix to the base name (adding a starting dot, if necessary), and returns the filename as a character.
prepare_ed_veg_filename(path_prefix, suffix, latitude = NULL, longitude = NULL)
prepare_ed_veg_filename(path_prefix, suffix, latitude = NULL, longitude = NULL)
path_prefix |
Desired path and prefix (without latitude and longitude) |
suffix |
Character string of filename suffix. |
latitude |
Site latitude coordinate (default = |
longitude |
Site longitude coordinate (default = |
Character string of full formatted file path
ed2in
Sets attributes to NULL
before printing, so the output isn't as messy.
## S3 method for class 'ed2in' print(x, ...)
## S3 method for class 'ed2in' print(x, ...)
x |
an object used to select a method. |
... |
further arguments passed to or from other methods. |
Puts a select number of variables from the monthly -E- files into a nc_var
list to be written to a .nc file.
put_E_values( yr, nc_var, var_list, lat, lon, start_date, end_date, begins, ends, out )
put_E_values( yr, nc_var, var_list, lat, lon, start_date, end_date, begins, ends, out )
yr |
the year being processed |
nc_var |
a list (potentially empty) for |
var_list |
list returned by |
lat |
|
lon |
|
start_date |
start time of simulation |
end_date |
end time of simulation |
begins |
deprecated; use |
ends |
deprecated; use |
out |
deprecated; use |
a list of ncdim4
objects
Function for put -T- values to nc_var list
put_T_values( yr, nc_var, var_list, lat, lon, start_date, end_date, begins, ends, out )
put_T_values( yr, nc_var, var_list, lat, lon, start_date, end_date, begins, ends, out )
yr |
the year being processed |
nc_var |
a list (potentially empty) for |
var_list |
list returned by |
lat |
|
lon |
|
start_date |
start time of simulation |
end_date |
end time of simulation |
begins |
deprecated; use |
ends |
deprecated; use |
out |
deprecated; use |
Read files into objects usable by other PEcAn.ED2 utilities, and optionally check for errors.
read_css(filepath, check = TRUE, ...) read_pss(filepath, check = TRUE) read_site(filepath, check = TRUE, ...)
read_css(filepath, check = TRUE, ...) read_pss(filepath, check = TRUE) read_site(filepath, check = TRUE, ...)
filepath |
Full path to css, pss, or site file |
check |
Logical. If |
... |
Additional arguments to check functions. |
data.frame
containing
This function reads in monthly output (-E- .h5 files) from ED2, does unit
conversions, and returns a list to be passed to put_E_values()
. Cohort
level variables (i.e. those ending in "_CO") are often (always?) in
per-plant units rather than per area. This function converts them to per
area using the plant density and patch area before converting units to PEcAn
standards.
read_E_files( yr, yfiles, h5_files, outdir, start_date, end_date, pfts, settings = NULL )
read_E_files( yr, yfiles, h5_files, outdir, start_date, end_date, pfts, settings = NULL )
yr |
unused. For consistency with |
yfiles |
unused. For consistency with |
h5_files |
character vector of names of E h5 files (e.g. "analysis-E-1999-06-00-000000-g01.h5") |
outdir |
directory where ED2 output files are found |
start_date |
Start time of the simulation |
end_date |
End time of the simulation |
pfts |
a named vector of PFT numbers where the names are PFT names |
settings |
pecan settings object |
if settings
is provided, then values for missing arguments
for start_date
, end_date
, and pfts
will be taken from it
a list
Read a ED_MET_DRIVER_HEADER file into a list-like object that can be manipulated within R. Returns a list of file formats.
read_ed_metheader(filename, check = TRUE, check_files = TRUE)
read_ed_metheader(filename, check = TRUE, check_files = TRUE)
filename |
File name (including path) of met driver header file, as character |
check |
Logical, whether or not to check file for correctness (default
= |
check_files |
Logical. If |
The output is an unnamed list with each element corresponding to a single file format. Each file format contains the following elements:
path_prefix
– Path and prefix of files
nlon
– Number of longitude grid cells
nlat
– Number of latitude grid cells
dx
– Size of longitude grid cell
dy
– Size of latitude grid cell
xmin
– Minimum longitude
ymin
– Minimum latitude
variables
– Data frame of variables, with the columns described below.
Starred columns are required for writing. This table is left joined with
met_variable_description and met_flag_description.
variable
– Variable name
description
– Variable description
unit
– Variable unit
update_frequency
– Update frequency (seconds) or scalar values if
flag=4
flag
– Variable flags.
flag_description
– Description of variable flag
The formatting of a meteorology header file is as follows (from the ED GitHub Wiki):
<number of file formats> # Repeat lines below this number of times <path and prefix of files> <nlon>, <nlat>, <dx>, <dy>, <xmin>, <ymin> <number of variables> <list of variable names> <list of update frequencies (seconds) or scalar values if flag=4> <list of variable flags>
The variables in the third row are defined as follows:
List of ED met input parameters. See Details.
Read ED2 css, pss, and site files into a single ED input object.
read_ed_veg(path_prefix, latitude = NULL, longitude = NULL, check = TRUE)
read_ed_veg(path_prefix, latitude = NULL, longitude = NULL, check = TRUE)
path_prefix |
Full path and prefix to initial condition files. |
latitude |
Run latitude (default = |
longitude |
Run longitude (default = |
check |
Whether or not to check css, pss, and site files for validity.
Default = |
List containing css
, pss
, and site
objects, latitude
and
longitude
, and orig_paths
, a list of paths to the original css
, pss
,
and site
files.
Parse an ED2IN file to a named list.
read_ed2in(filename)
read_ed2in(filename)
filename |
Full path to ED2IN file |
Named list of tag = value
State data assimilation read-restart for ED2
read_restart.ED2(outdir, runid, stop.time, settings, var.names, params)
read_restart.ED2(outdir, runid, stop.time, settings, var.names, params)
outdir |
Output directory |
runid |
Run ID |
stop.time |
Year that is being read |
settings |
PEcAn settings object |
var.names |
Variable names to be extracted |
params |
Any parameters required for state calculations |
Alexey Shiklomanov, Istem Fer
## Not run: outdir <- "~/sda-hackathon/outputs" runid <- "99000000020" settings_file <- "outputs/pecan.CONFIGS.xml" settings <- PEcAn.settings::read.settings(settings_file) forecast <- read_restart.ED2(...) ## End(Not run)
## Not run: outdir <- "~/sda-hackathon/outputs" runid <- "99000000020" settings_file <- "outputs/pecan.CONFIGS.xml" settings <- PEcAn.settings::read.settings(settings_file) forecast <- read_restart.ED2(...) ## End(Not run)
S-file contents are not written to standard netcdfs but are used by read_restart from SDA's perspective it doesn't make sense to write and read to ncdfs because ED restarts from history files
read_S_files(sfile, outdir, pfts, pecan_names = NULL, settings = NULL, ...)
read_S_files(sfile, outdir, pfts, pecan_names = NULL, settings = NULL, ...)
sfile |
history file name e.g. "history-S-1961-01-01-000000-g01.h5" |
outdir |
path to run outdir, where the -S- file is |
pfts |
a named vector of PFT numbers where the names are PFT names |
pecan_names |
string vector, pecan names of requested variables, e.g. c("AGB", "AbvGrndWood") |
settings |
pecan settings object |
... |
currently unused |
Function for reading -T- files
read_T_files( yr, yfiles, h5_files, outdir, start_date, end_date, pfts = NULL, settings = NULL )
read_T_files( yr, yfiles, h5_files, outdir, start_date, end_date, pfts = NULL, settings = NULL )
yr |
the year being processed |
yfiles |
the years on the filenames, will be used to matched h5_files for that year |
h5_files |
names of T files to be read |
outdir |
directory where ED2 output files are found |
start_date |
start date in YYYY-MM-DD format |
end_date |
end date in YYYY-MM-DD format |
pfts |
for consistency with |
settings |
A PEcAn settings object. Values for |
e.g. yr = 1999 yfiles = 1999 2000 h5_files = "analysis-T-1999-00-00-000000-g01.h5" "analysis-T-2000-00-00-000000-g01.h5"
Clear out old config and ED model run files.
remove.config.ED2(main.outdir = settings$outdir, settings)
remove.config.ED2(main.outdir = settings$outdir, settings)
main.outdir |
ignored |
settings |
PEcAn settings object |
nothing, removes config files as side effect
Shawn Serbin, David LeBauer, Alexey Shikomanov
Uses base::system2 to run ED or EDR via a Singularity container.
run_ed_singularity( img_path, ed2in_path, app = "ED", singularity_args = NULL, ... )
run_ed_singularity( img_path, ed2in_path, app = "ED", singularity_args = NULL, ... )
img_path |
Path to Singularity container (usually a |
ed2in_path |
Path to ED2IN file. |
app |
Singularity "app" to run. Either "ED" or "EDR". |
singularity_args |
Additional arguments to be passed to |
... |
Additional arguments to base::system2 |
On some systems, to run Singularity properly, you will need to bind
additional paths. To do this, pass the arguments as a character vector to
singularity_args
. For instance:
bindpaths <- c("/scratch", "/data") run_ed_singularity(..., singularity_args = paste("--bind", bindpaths))
By default, base::system2 prints the output to the console. To store
standard ED output in a variable as a character vector, set stdout = TRUE
.
To redirect all output to the variable, including GCC exceptions, use
stderr = TRUE
(this will automatically set stdout = TRUE
as well).
Output can also be redirected to a file via stderr = "/path/to/file.log"
.
This functions approximates landscape equilibrium steady state for vegetation and soil pools using the successional trajectory of a single patch modeled with disturbance off and the prescribed disturbance rates for runs (Xia et al. 2012 GMD 5:1259-1271).
SAS.ED2( dir.analy, dir.histo, outdir, lat, lon, blckyr, prefix, treefall, param.args = SAS.ED2.param.Args(), sufx = "g01.h5" )
SAS.ED2( dir.analy, dir.histo, outdir, lat, lon, blckyr, prefix, treefall, param.args = SAS.ED2.param.Args(), sufx = "g01.h5" )
dir.analy |
Location of ED2 analysis files; expects monthly and yearly output |
dir.histo |
Location of ED2 history files (for vars not in analy); expects monthly |
outdir |
Location to write SAS .css & .pss files |
lat |
site latitude; used for file naming |
lon |
site longitude; used for file naming |
blckyr |
Number of years between patch ages (aka blocks) |
prefix |
ED2 -E- output file prefix |
treefall |
Value to be used for TREEFALL_DISTURBANCE_RATE in ED2IN for full runs (disturbance on) |
param.args |
ED2 parameter arguments (mostly soil biogeochem) |
sufx |
ED2 out file suffix; used in constructing file names(default "g01.h5) |
Christine Rollinson, modified from original by Jaclyn Hatala-Matthes (2/18/14) 2014 Feb: Original ED SAS solution Script at PalEON modeling HIPS sites (Matthes) 2015 Aug: Modifications for greater site flexibility & updated ED 2016 Jan: Adaptation for regional-scale runs (single-cells run independently, but executed in batches) 2018 Jul: Conversion to function, Christine Rollinson July 2018
sets parameters and defaults for the ED2 semi-analytical spin-up
SAS.ED2.param.Args( decomp_scheme = 2, kh_active_depth = -0.2, decay_rate_fsc = 11, decay_rate_stsc = 4.5, decay_rate_ssc = 0.2, Lc = 0.049787, c2n_slow = 10, c2n_structural = 150, r_stsc = 0.3, rh_decay_low = 0.24, rh_decay_high = 0.6, rh_low_temp = 18 + 273.15, rh_high_temp = 45 + 273.15, rh_decay_dry = 12, rh_decay_wet = 36, rh_dry_smoist = 0.48, rh_wet_smoist = 0.98, resp_opt_water = 0.8938, resp_water_below_opt = 5.0786, resp_water_above_opt = 4.5139, resp_temperature_increase = 0.0757, rh_lloyd_1 = 308.56, rh_lloyd_2 = 1/56.02, rh_lloyd_3 = 227.15, yrs.met = 30, sm_fire = 0, fire_intensity = 0, slxsand = 0.33, slxclay = 0.33 )
SAS.ED2.param.Args( decomp_scheme = 2, kh_active_depth = -0.2, decay_rate_fsc = 11, decay_rate_stsc = 4.5, decay_rate_ssc = 0.2, Lc = 0.049787, c2n_slow = 10, c2n_structural = 150, r_stsc = 0.3, rh_decay_low = 0.24, rh_decay_high = 0.6, rh_low_temp = 18 + 273.15, rh_high_temp = 45 + 273.15, rh_decay_dry = 12, rh_decay_wet = 36, rh_dry_smoist = 0.48, rh_wet_smoist = 0.98, resp_opt_water = 0.8938, resp_water_below_opt = 5.0786, resp_water_above_opt = 4.5139, resp_temperature_increase = 0.0757, rh_lloyd_1 = 308.56, rh_lloyd_2 = 1/56.02, rh_lloyd_3 = 227.15, yrs.met = 30, sm_fire = 0, fire_intensity = 0, slxsand = 0.33, slxclay = 0.33 )
decomp_scheme |
Decomposition scheme specified in ED2IN |
kh_active_depth |
Depth threshold for averaging soil moisture and temperature |
decay_rate_fsc |
Fast soil carbon decay rate |
decay_rate_stsc |
Structural soil carbon decay rate |
decay_rate_ssc |
Slow soil carbon decay rate |
Lc |
Used to compute nitrogen immpobilzation factor; ED default is 0.049787 (soil_respiration.f90) |
c2n_slow |
Carbon to Nitrogen ratio, slow pool; ED Default 10.0 |
c2n_structural |
Carbon to Nitrogen ratio, structural pool. ED default 150.0 |
r_stsc |
Decomp param |
rh_decay_low |
Param used for ED-1/CENTURY decomp schemes; ED default = 0.24 |
rh_decay_high |
Param used for ED-1/CENTURY decomp schemes; ED default = 0.60 |
rh_low_temp |
Param used for ED-1/CENTURY decomp schemes; ED default = 291 |
rh_high_temp |
Param used for ED-1/CENTURY decomp schemes; ED default = 318.15 |
rh_decay_dry |
Param used for ED-1/CENTURY decomp schemes; ED default = 12.0 |
rh_decay_wet |
Param used for ED-1/CENTURY decomp schemes; ED default = 36.0 |
rh_dry_smoist |
Param used for ED-1/CENTURY decomp schemes; ED default = 0.48 |
rh_wet_smoist |
Param used for ED-1/CENTURY decomp schemes; ED default = 0.98 |
resp_opt_water |
Param used for decomp schemes 0 & 3, ED default = 0.8938 |
resp_water_below_opt |
Param used for decomp schemes 0 & 3, ED default = 5.0786 |
resp_water_above_opt |
Param used for decomp schemes 0 & 3, ED default = 4.5139 |
resp_temperature_increase |
Param used for decomp schemes 0 & 3, ED default = 0.0757 |
rh_lloyd_1 |
Param used for decomp schemes 1 & 4 (Lloyd & Taylor 1994); ED default = 308.56 |
rh_lloyd_2 |
Param used for decomp schemes 1 & 4 (Lloyd & Taylor 1994); ED default = 1/56.02 |
rh_lloyd_3 |
Param used for decomp schemes 1 & 4 (Lloyd & Taylor 1994); ED default = 227.15 |
yrs.met |
Number of years cycled in model spinup part 1 |
sm_fire |
Value to be used for SM_FIRE if INCLUDE_FIRE=2; defaults to 0 (fire off) |
fire_intensity |
Value to be used for FIRE_PARAMTER; defaults to 0 (fire off) |
slxsand |
Soil percent sand; used to calculate expected fire return interval |
slxclay |
Soil percent clay; used to calculate expected fire return interval |
Converts an ed2in
-like list to an ED2IN-formatted character vector.
tags2char(ed2in)
tags2char(ed2in)
ed2in |
Named list of ED2IN tag-value pairs. See read_ed2in. |
Function translating pecan vars to ED vars
translate_vars_ed(varnames)
translate_vars_ed(varnames)
varnames |
character; variable names to translate |
var.names <- c("DBH", "AGB", "AbvGrndWood") translate_vars_ed(var.names)
var.names <- c("DBH", "AGB", "AbvGrndWood") translate_vars_ed(var.names)
Writes ED specific IC files
veg2model.ED2(outfolder, veg_info, start_date, new_site, source, ens)
veg2model.ED2(outfolder, veg_info, start_date, new_site, source, ens)
outfolder |
where to write files |
veg_info |
object passed from write_ic includes pft matches |
start_date |
"YYYY-MM-DD" passed from write_ic |
new_site |
object passed from write_ic includes site id, lat, lon, and sitename |
source |
object passed from write_ic |
ens |
number of ensemble members |
filenames
Istem Fer
Functions for writing css, pss, and site files from their respective objects.
write_css(css, path_prefix, latitude = NULL, longitude = NULL) write_pss(pss, path_prefix, latitude = NULL, longitude = NULL) write_site(site, path_prefix, latitude = NULL, longitude = NULL)
write_css(css, path_prefix, latitude = NULL, longitude = NULL) write_pss(pss, path_prefix, latitude = NULL, longitude = NULL) write_site(site, path_prefix, latitude = NULL, longitude = NULL)
css |
css object (see read_css) |
path_prefix |
Desired path and prefix (without latitude and longitude) |
latitude |
Site latitude coordinate (default = |
longitude |
Site longitude coordinate (default = |
pss |
pss object (see read_pss) |
site |
site object (see read_site) |
Latitude and longitude coordinates will be converted directly to character,
without any changes to their precision. If they are NULL
(default), the
function assumes that lat
and lon
are already in the path_prefix
, and
if they are absent, the function will throw an error.
Full file path as character, invisibly
Write ED met driver header from R met driver list object
write_ed_metheader(ed_metheader, filename, header_line = shQuote("header"))
write_ed_metheader(ed_metheader, filename, header_line = shQuote("header"))
ed_metheader |
ED meteorlogy header object (see read_ed_metheader) |
filename |
Full file name (including path) of ED met header |
header_line |
Character string for top line of output file. Default is
|
Write a complete ED inputs object to disk. css
, pss
, and
site
files are automatically named and correctly formatted.
write_ed_veg(ed_veg, path_prefix)
write_ed_veg(ed_veg, path_prefix)
ed_veg |
ED vegetation inputs object (see read_ed_veg). |
path_prefix |
Desired path and prefix (without latitude and longitude) |
Named list (css
, pss
, site
) of full file paths, invisibly
This writes a ED2IN file from an ed2in
list. Default method writes a
barebones file without comments. S3 method for ed2in
objects extracts
comments and their locations from the object attributes (if barebones
is
FALSE
).
write_ed2in(ed2in, filename, custom_header = character(), barebones = FALSE) ## S3 method for class 'ed2in' write_ed2in(ed2in, filename, custom_header = character(), barebones = FALSE) ## Default S3 method: write_ed2in(ed2in, filename, custom_header = character(), barebones = FALSE)
write_ed2in(ed2in, filename, custom_header = character(), barebones = FALSE) ## S3 method for class 'ed2in' write_ed2in(ed2in, filename, custom_header = character(), barebones = FALSE) ## Default S3 method: write_ed2in(ed2in, filename, custom_header = character(), barebones = FALSE)
ed2in |
Named list of ED2IN tag-value pairs. See read_ed2in. |
filename |
Target file name |
custom_header |
Character vector for additional header comments. Each item gets its own line. |
barebones |
Logical. If |
Write ED2 restart file from SDA results
write_restart.ED2( outdir, runid, start.time, stop.time, settings, new.state, RENAME = TRUE, new.params, inputs )
write_restart.ED2( outdir, runid, start.time, stop.time, settings, new.state, RENAME = TRUE, new.params, inputs )
outdir |
output directory |
runid |
run id |
start.time |
Time of current assimilation step |
stop.time |
Time of next assimilation step |
settings |
pecan settings list |
new.state |
Analysis state matrix returned by |
RENAME |
flag to either rename output file or not |
new.params |
optional, additional params to pass |
inputs |
new input paths updated by the SDA workflow, will be passed to
|
TRUE if successful
Alexey Shiklomanov, Istem Fer
Writes an xml and ED2IN config files for use with the Ecological Demography model. Requires a pft xml object, a list of trait values for a single model run, and the name of the file to create
write.config.ED2( trait.values, settings, run.id, defaults = settings$constants, check = FALSE, ... )
write.config.ED2( trait.values, settings, run.id, defaults = settings$constants, check = FALSE, ... )
trait.values |
Named list of trait values, with names corresponding to PFT |
settings |
list of settings from pecan settings file |
run.id |
id of run |
defaults |
list of defaults to process. Default=settings$constants |
check |
Logical. If |
... |
unused |
configuration file and ED2IN namelist for given run
David LeBauer, Shawn Serbin, Carl Davidson, Alexey Shiklomanov, Istem Fer
Function for writing job.sh file for ED2 runs
write.config.jobsh.ED2(settings, run.id)
write.config.jobsh.ED2(settings, run.id)
settings |
PEcAn settings list. For this function, need the following: run$host$rundir, run$host$outdir, run$host$scratchdir, run$host$clearscratch, model$jobtemplate, model$job.sh, run$host$job.sh, run$site$lat, run$site$lon, run$inputs$met$path, run$start.date, run$end.date, model$binary, model$binary_args |
run.id |
PEcAn run ID |
Refactored by Alexey Shiklomanov to allow use in PEcAn RTM module.
Character vector containing job.sh file
David LeBauer, Shawn Serbin, Carl Davidson, Alexey Shiklomanov
Write ED2 config.xml file
write.config.xml.ED2(settings, trait.values, defaults = settings$constants)
write.config.xml.ED2(settings, trait.values, defaults = settings$constants)
settings |
PEcAn settings file. Settings required for this script are: model$revision, model$config.header, constants |
trait.values |
List of trait values with which to replace defaults |
defaults |
List of defaults to process. Default = settings$constants |
Refactored by Alexey Shiklomanov to allow use in PEcAn RTM module.
R XML object containing full ED2 XML file
David LeBauer, Shawn Serbin, Carl Davidson, Alexey Shiklomanov