Title: | PEcAn Functions Used for Ecological Forecasts and Reanalysis |
---|---|
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. |
Authors: | Mike Dietze [aut], Rob Kooper [aut, cre], David LeBauer [aut], Xiaohui Feng [aut], Dan Wang [aut], Carl Davidson [aut], Shawn Serbin [aut], Shashank Singh [aut], Chris Black [aut], Tanishq Jain [aut], University of Illinois, NCSA [cph] |
Maintainer: | Rob Kooper <[email protected]> |
License: | BSD_3_clause + file LICENSE |
Version: | 1.8.0.9000 |
Built: | 2024-11-20 21:26:11 UTC |
Source: | https://github.com/PecanProject/pecan |
Scale temperature dependent trait from measurement temperature to reference temperature
arrhenius.scaling(observed.value, old.temp, new.temp = 25)
arrhenius.scaling(observed.value, old.temp, new.temp = 25)
observed.value |
observed value of temperature dependent trait, e.g. Vcmax, root respiration rate |
old.temp |
temperature at which measurement was taken or previously scaled to |
new.temp |
temperature to be scaled to, default = 25 C |
numeric value at reference temperature
unknown
Turns any categorical variable into a sequential integer. This transformation is required for using data in BUGS/JAGS
as.sequence(x, na.rm = TRUE)
as.sequence(x, na.rm = TRUE)
x |
categorical variable as vector |
na.rm |
logical: return NA's or replace with max(x) + 1 |
sequence from 1:length(unique(x))
David LeBauer
Converts author year title to bibtex author1999abc
format
bibtexify(author, year, title)
bibtexify(author, year, title)
author |
name of first author |
year |
year of publication |
title |
manuscript title |
bibtex citation
unknown
Takes a distribution with R parameterization, converts it to a BUGS parameterization, and then samples from the distribution using JAGS
bugs.rdist( prior = data.frame(distn = "norm", parama = 0, paramb = 1), n.iter = 1e+05, n = NULL )
bugs.rdist( prior = data.frame(distn = "norm", parama = 0, paramb = 1), n.iter = 1e+05, n = NULL )
prior |
dataframe with distribution name and parameters |
n.iter |
number of MCMC samples. Output will have n.iter/4 samples |
n |
number of randomly chosen samples to return. |
vector of samples
David LeBauer
Capitalize a string
capitalize(x)
capitalize(x)
x |
string |
x, capitalized
David LeBauer
Convert CF-style date-time to POSIXct date-time
cf2datetime(value, unit, tz = "UTC")
cf2datetime(value, unit, tz = "UTC")
value |
Numeric value of CF date-time |
unit |
CF style unit (e.g. "days since 2010-01-01") |
tz |
Time zone of result (default = "UTC") |
POSIXct datetime
Alexey Shiklomanov
cf2datetime(5, "days since 1981-01-01") cf2datetime(27, "minutes since 1963-01-03 12:00:00 -05:00") # no leap year cf2datetime(365, "days since 1999-01-01") # leap year cf2datetime(365, "days since 2000-01-01 12:00:00 -05:00")
cf2datetime(5, "days since 1981-01-01") cf2datetime(27, "minutes since 1963-01-03 12:00:00 -05:00") # no leap year cf2datetime(365, "days since 1999-01-01") # leap year cf2datetime(365, "days since 2000-01-01 12:00:00 -05:00")
Removes previous model run output from worker node local scratch directories on EBI-CLUSTER
clear.scratch(settings)
clear.scratch(settings)
settings |
list of PEcAn settings. Only |
nothing
Shawn Serbin
## Not run: clear.scratch(settings) ## End(Not run)
## Not run: clear.scratch(settings) ## End(Not run)
Convert expression to variable names
convert.expr(expression)
convert.expr(expression)
expression |
expression string |
list
Istem Fer
Convert POSIXct date-time to CF-style date-time
datetime2cf(datetime, unit, ...)
datetime2cf(datetime, unit, ...)
datetime |
POSIXct datetime, or object that can be to POSIXct
via |
unit |
Target CF-style unit (e.g. "days since 2010-01-01") |
... |
Additional arguments to |
Numeric value of date-time in target CF unit
datetime2cf("1990-10-05", "days since 1990-01-01", tz = "UTC")
datetime2cf("1990-10-05", "days since 1990-01-01", tz = "UTC")
This gets around the fact that most functions for calculating Julian Day do not support non-integer days.
datetime2doy(datetime, tz = "UTC") cf2doy(value, unit, tz = "UTC")
datetime2doy(datetime, tz = "UTC") cf2doy(value, unit, tz = "UTC")
datetime |
POSIXct datetime, or object that can be to POSIXct
via |
tz |
Time zone of result (default = "UTC") |
value |
Numeric value of CF date-time |
unit |
CF style unit (e.g. "days since 2010-01-01") |
Numeric Julian date
Alexey Shiklomanov
datetime2doy("2010-01-01") # 1 datetime2doy("2010-01-01 12:00:00") # 1.5 cf2doy(0, "days since 2007-01-01") cf2doy(5, "days since 2010-01-01") # 6 cf2doy(5, "days since 2010-01-01") # 6
datetime2doy("2010-01-01") # 1 datetime2doy("2010-01-01 12:00:00") # 1.5 cf2doy(0, "days since 2007-01-01") cf2doy(5, "days since 2010-01-01") # 6 cf2doy(5, "days since 2010-01-01") # 6
Calculate number of days in a year based on whether it is a leap year or not.
days_in_year(year, leap_year = TRUE)
days_in_year(year, leap_year = TRUE)
year |
Numeric year (can be a vector) |
leap_year |
Default = TRUE. If set to FALSE will always return 365 |
integer vector, all either 365 or 366
Alexey Shiklomanov
days_in_year(2010) # Not a leap year -- returns 365 days_in_year(2012) # Leap year -- returns 366 days_in_year(2000:2008) # Function is vectorized over years
days_in_year(2010) # Not a leap year -- returns 365 days_in_year(2012) # Leap year -- returns 366 days_in_year(2000:2008) # Function is vectorized over years
Implementation of standard equations used to calculate mean and sd for a variety of named distributions different
distn.stats(distn, a, b)
distn.stats(distn, a, b)
distn |
named distribution, one of 'beta', 'exp', 'f', 'gamma', 'lnorm', 'norm', 't', |
a |
numeric; first parameter of |
b |
numeric; second parameter of |
vector with mean and standard deviation
David LeBauer
distn.stats('norm', 0, 1)
distn.stats('norm', 0, 1)
return mean and standard deviation of a distribution for each distribution in a table with colnames = c('distn', 'a', 'b')
,
e.g. in a table of priors
distn.table.stats(distns)
distn.table.stats(distns)
distns |
table of distributions; see examples |
named vector of mean and SD
David LeBauer
Requires ncftpget and a properly formatted config file in the users home directory
download_file(url, filename, method)
download_file(url, filename, method)
url |
complete URL for file download |
filename |
destination file name |
method |
Method of file retrieval. Can set this using the |
Shawn Serbin, Rob Kooper
## Not run: download_file("http://lib.stat.cmu.edu/datasets/csb/ch11b.txt","~/test.download.txt") download_file(" ftp://ftp.cdc.noaa.gov/Datasets/NARR/monolevel/pres.sfc.2000.nc", "~/pres.sfc.2000.nc") ## End(Not run)
## Not run: download_file("http://lib.stat.cmu.edu/datasets/csb/ch11b.txt","~/test.download.txt") download_file(" ftp://ftp.cdc.noaa.gov/Datasets/NARR/monolevel/pres.sfc.2000.nc", "~/pres.sfc.2000.nc") ## End(Not run)
This will download a file, if retry is set and 404 is returned it will wait until the file is available. If the file is still not available after timeout tries, it will return NA. If the file is downloaded it will return the name of the file
download.url(url, file, timeout = 600, .opts = list(), retry = TRUE)
download.url(url, file, timeout = 600, .opts = list(), retry = TRUE)
url |
the url of the file to download |
file |
the filename |
timeout |
number of seconds to wait for file (default 600) |
.opts |
list of options for curl, for example to download from a protected site use list(userpwd=userpass, httpauth = 1L) |
retry |
retry if url not found yet, this is used by Brown Dog |
returns name of file if successful or NA if not.
## Not run: download.url('http://localhost/', index.html) ## End(Not run)
## Not run: download.url('http://localhost/', index.html) ## End(Not run)
This will take a folder and make it into an absolute folder name. It will normalize the path and prepend it with the current working folder if needed to get an absolute path name.
full.path(folder)
full.path(folder)
folder |
folder for file paths. |
absolute path
Rob Kooper
full.path('pecan')
full.path('pecan')
Splits climate met for SIPNET
get.ensemble.inputs(settings, ens = 1)
get.ensemble.inputs(settings, ens = 1)
settings |
PEcAn settings list |
ens |
ensemble number. default = 1 |
find correct ensemble inputs
Mike Dietze and Ann Raiho
Gets statistics for LaTeX - formatted table
get.parameter.stat(mcmc.summary, parameter)
get.parameter.stat(mcmc.summary, parameter)
mcmc.summary |
probably produced by |
parameter |
name of parameter to extract, as character |
table with parameter statistics
David LeBauer
## Not run: get.parameter.stat(mcmc.summaries[[1]], 'beta.o')
## Not run: get.parameter.stat(mcmc.summaries[[1]], 'beta.o')
Returns a vector of quantiles specified by a given <quantiles>
xml tag
get.quantiles(quantiles.tag)
get.quantiles(quantiles.tag)
quantiles.tag |
specifies tag used to specify quantiles |
vector of quantiles
David LeBauer
Provides a consistent method of naming runs; for use in model input files and indices
get.run.id(run.type, index, trait = NULL, pft.name = NULL, site.id = NULL)
get.run.id(run.type, index, trait = NULL, pft.name = NULL, site.id = NULL)
run.type |
character, can be any character; currently 'SA' is used for sensitivity analysis, 'ENS' for ensemble run. |
index |
unique index for different runs, e.g. integer counting members of an ensemble or a quantile used to which a trait has been perturbed for sensitivity analysis |
trait |
name of trait being sampled (for sensitivity analysis) |
pft.name |
name of PFT (value from pfts.names field in database) |
site.id |
optional site id .This is could be necessary for multisite write=false ensembles. |
id representing a model run
Carl Davidson, David LeBauer
get.run.id('ENS', left.pad.zeros(1, 5)) get.run.id('SA', round(qnorm(-3),3), trait = 'Vcmax')
get.run.id('ENS', left.pad.zeros(1, 5)) get.run.id('SA', round(qnorm(-3),3), trait = 'Vcmax')
get sensitivity samples as a list
get.sa.sample.list(pft, env, quantiles)
get.sa.sample.list(pft, env, quantiles)
pft |
list of samples from Plant Functional Types |
env |
list of samples from environment parameters |
quantiles |
quantiles at which to obtain samples from parameter for sensitivity analysis |
sa.sample.list
Samples parameters for a model run at specified quantiles.
get.sa.samples(samples, quantiles)
get.sa.samples(samples, quantiles)
samples |
random samples from trait distribution |
quantiles |
list of quantiles to at which to sample, set in settings file |
Samples from long (>2000) vectors that represent random samples from a trait distribution. Samples are either the MCMC chains output from the Bayesian meta-analysis or are randomly sampled from the closed-form distribution of the parameter probability distribution function. The list is indexed first by trait, then by quantile.
a list of lists representing quantile values of trait distributions
David LeBauer
Further summarizes output from summary.mcmc
get.stats.mcmc(mcmc.summary, sample.size)
get.stats.mcmc(mcmc.summary, sample.size)
mcmc.summary |
probably produced by |
sample.size |
passed as 'n' in returned list |
list with summary statistics for parameters in an MCMC chain
David LeBauer
left padded by zeros up to a given number of digits.
left.pad.zeros(num, digits = 5)
left.pad.zeros(num, digits = 5)
num |
number to be padded (integer) |
digits |
number of digits to add |
returns a string representing a given number
num with zeros to the left
Carl Davidson
format a list of arguments as one comma-separated string
listToArgString(l)
listToArgString(l)
l |
a named list of function arguments |
A string containing named argument/value pairs separated by commas
Ryan Kelly
RData
file into a listInstead of polluting the current environment, this allows you to
read an RData
file into a list object of whatever name you choose.
load_local(file)
load_local(file)
file |
a (readable binary-mode) connection or a character string giving the name of the file to load (when tilde expansion is done). |
List, with names corresponding to object names in file
Alexey Shiklomanov
x <- 1:10 y <- 11:15 tmp <- tempfile() save(x, y, file = tmp) my_list <- load_local(tmp) rm(tmp)
x <- 1:10 y <- 11:15 tmp <- tempfile() save(x, y, file = tmp) my_list <- load_local(tmp) rm(tmp)
Load model package
load.modelpkg(model)
load.modelpkg(model)
model |
name of model |
FALSE if function returns error; else TRUE
David LeBauer
## Not run: require.modelpkg(BioCro)
## Not run: require.modelpkg(BioCro)
Return a list of files given a full prefix and optional suffix. Optionally, confirm that the right number of files are returned. If the wrong number of files is returned, throw an error.
match_file(path_prefix, suffix = NULL, expect = NULL)
match_file(path_prefix, suffix = NULL, expect = NULL)
path_prefix |
Full path and file prefix |
suffix |
File suffix, as character (default = |
expect |
Number of files expected to be returned (default = |
If path_prefix
points to a directory, then all files inside that directory
that match the suffix (if provided) are returned.
Character vector of matched file names, as full paths.
Used for restarting MCMC code based on last parameters sampled (e.g. in JAGS)
mcmc.list2init(dat)
mcmc.list2init(dat)
dat |
mcmc.list object |
list
Mike Dietze
Checks if met2model.<model>
exists for a particular model
met2model.exists(model)
met2model.exists(model)
model |
model package name |
logical
function to check whether units are convertible by misc.convert function
misc.are.convertible(u1, u2)
misc.are.convertible(u1, u2)
u1 |
unit to be converted from, character |
u2 |
unit to be converted to, character |
logical
Istem Fer, Shawn Serbin
conversion function for the unit conversions that udunits cannot handle but often needed in PEcAn calculations
misc.convert(x, u1, u2)
misc.convert(x, u1, u2)
x |
convertible values |
u1 |
unit to be converted from, character |
u2 |
unit to be converted to, character |
val converted values
Istem Fer, Shawn Serbin
returns a MstMIP variable as a ncvar based on name and other parameters passed in.
mstmipvar( name, lat = NULL, lon = NULL, time = NULL, nsoil = NULL, silent = FALSE )
mstmipvar( name, lat = NULL, lon = NULL, time = NULL, nsoil = NULL, silent = FALSE )
name |
of variable |
lat |
latitude if dimension requests it |
lon |
longitude if dimension requests it |
time |
time if dimension requests it |
nsoil |
nsoil if dimension requests it |
silent |
logical: suppress log messages about missing variables? |
ncvar based on MstMIP definition
Rob Kooper
number of leap days between two dates
n_leap_day(start_date, end_date)
n_leap_day(start_date, end_date)
start_date , end_date
|
dates in any format recognized by |
Mike Dietze
Check if required packages are installed, and throw an informative error if not.
need_packages(...)
need_packages(...)
... |
Package names, as characters. Can be passed as individual arguments, character vectors, or any combination thereof. |
pkgs
, invisibly
Alexey Shiklomanov
# Only need ::: because package isn't exported. # Inside a package, just call `need_packages` PEcAn.utils:::need_packages("stats", "methods") # Always works try(PEcAn.utils:::need_packages("notapackage"))
# Only need ::: because package isn't exported. # Inside a package, just call `need_packages` PEcAn.utils:::need_packages("stats", "methods") # Always works try(PEcAn.utils:::need_packages("notapackage"))
utility to properly escape the '%' sign for latex
newxtable( x, environment = "table", table.placement = "ht", label = NULL, caption = NULL, caption.placement = NULL, align = NULL )
newxtable( x, environment = "table", table.placement = "ht", label = NULL, caption = NULL, caption.placement = NULL, align = NULL )
x |
data.frame to be converted to latex table |
environment |
can be 'table'; 'sidewaystable' if using latex rotating package |
table.placement , label , caption , caption.placement , align
|
passed to |
Latex version of table, with percentages properly formatted
David LeBauer
A helper function for building a LaTex table.
paste.stats(median, lcl, ucl, n = 2)
paste.stats(median, lcl, ucl, n = 2)
median |
50-percent quantile |
lcl |
lower confidence limit |
ucl |
upper confidence limit |
n |
significant digits for printing. Passed to |
Used by get.parameter.stat
.
David LeBauer
paste.stats(3.333333, 5.00001, 6.22222, n = 3) # [1] "$3.33(5,6.22)$"
paste.stats(3.333333, 5.00001, 6.22222, n = 3) # [1] "$3.33(5,6.22)$"
Calculate mean, variance statistics, and CI from a known distribution
pdf.stats(distn, A, B)
pdf.stats(distn, A, B)
distn |
name of distribution used by R (beta, f, gamma, lnorm, norm, weibull) |
A |
first parameter |
B |
second parameter |
list with mean, variance, and 95 CI
David LeBauer
Instructions for the use of this package are provided in the project documentation https://pecanproject.github.io/documentation.html.
Project homepage: pecanproject.org
Description of PEcAn
The Predictive Ecosystem 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. PEcAn is an open source utility that encapsulates:
acquisition of meteorological inputs
synthesis of physiological trait data as the posterior distribution of a Bayesian meta-analysis
sampling trait meta-analysis posterior distributions to parameterize ensembles of ED2 and other ecophysiological models
probabilistic forecasts
postprocessing to constrain forecasts and model parameters with field, meterological, eddy flux, and spectral data, and
provenance tracking
PECAn integrates available data into ecological forecasts by running ensembles of a terrestrial ecosystem model that is parameterized by the posterior distribution from a meta-analysis of available plant trait data. These trait data are assembled from field research and primary literature, and are stored in a PostgreSQL database. Current development focused on biofuel crops uses BETYdb. In addition to generating forecasts that reflect available data, PEcAn quantifies the contribution of each parameter to model uncertainty. This information informs targeted data collection and synthesis efforts that most efficiently reduce forecast uncertainty.
Current development is focused on developing PEcAn into a real-time data assimilation and forecasting system. This system will provide a detailed analysis of the past and present ecosystem functioning that seamlessly transitions into forecasts.
Maintainer: Rob Kooper [email protected]
Authors:
Mike Dietze [email protected]
David LeBauer [email protected]
Xiaohui Feng [email protected]
Dan Wang
Carl Davidson [email protected]
Shawn Serbin [email protected]
Shashank Singh [email protected]
Chris Black [email protected]
Tanishq Jain [email protected]
Other contributors:
University of Illinois, NCSA [copyright holder]
R and BUGS have different parameterizations for some distributions. This function transforms the distributions from R defaults to BUGS defaults. BUGS is an implementation of the BUGS language, and these transformations are expected to work for bugs.
r2bugs.distributions(priors, direction = "r2bugs")
r2bugs.distributions(priors, direction = "r2bugs")
priors |
data.frame with columns distn = distribution name, parama, paramb using R default parameterizations. |
direction |
One of "r2bugs" or "bugs2r" |
priors dataframe using JAGS default parameterizations
David LeBauer, Ben Bolker
priors <- data.frame(distn = c('weibull', 'lnorm', 'norm', 'gamma'), parama = c(1, 1, 1, 1), paramb = c(2, 2, 2, 2)) r2bugs.distributions(priors)
priors <- data.frame(distn = c('weibull', 'lnorm', 'norm', 'gamma'), parama = c(1, 1, 1, 1), paramb = c(2, 2, 2, 2)) r2bugs.distributions(priors)
config.php
file into an R listRead config.php
file into an R list
read_web_config( php.config = "../../web/config.php", parse = TRUE, expand = TRUE )
read_web_config( php.config = "../../web/config.php", parse = TRUE, expand = TRUE )
php.config |
Path to |
parse |
Logical. If |
expand |
Logical. If |
Named list of variable-value pairs set in config.php
Alexey Shiklomanov, Michael Dietze, Rob Kooper
## Not run: # Read Docker configuration and extract the `dbfiles` and output folders. docker_config <- read_web_config(file.path("..", "..", "docker", "web", "config.docker.php")) docker_config[["dbfiles_folder"]] docker_config[["output_folder"]] ## End(Not run)
## Not run: # Read Docker configuration and extract the `dbfiles` and output folders. docker_config <- read_web_config(file.path("..", "..", "docker", "web", "config.docker.php")) docker_config[["dbfiles_folder"]] docker_config[["output_folder"]] ## End(Not run)
Reads the output of a single model run
read.output( runid, outdir, start.year = NA, end.year = NA, variables = "GPP", dataframe = FALSE, pft.name = NULL, ncfiles = NULL, verbose = FALSE, print_summary = TRUE )
read.output( runid, outdir, start.year = NA, end.year = NA, variables = "GPP", dataframe = FALSE, pft.name = NULL, ncfiles = NULL, verbose = FALSE, print_summary = TRUE )
runid |
the ID distinguishing the model run. Can be omitted
if |
outdir |
the directory that the model's output was sent to.
Can be omitted if |
start.year , end.year
|
first and last year of output to read.
Specify as a date-time (only the year portion is used) or as a
four-digit number or string. If |
variables |
Character vector of variables to be read from
model output. Default = |
dataframe |
Logical: if TRUE, will return output in a
|
pft.name |
character string, name of the plant functional
type (PFT) to read PFT-specific output. If |
ncfiles |
Custom character vector of full paths to NetCDF
files. If |
verbose |
Logical. If |
print_summary |
Logical. If |
Generic function to convert model output from model-specific format to a common PEcAn format. This function uses MsTMIP variables except that units of (kg m-2 d-1) are converted to kg ha-1 y-1. Currently this function converts Carbon fluxes: GPP, NPP, NEE, TotalResp, AutoResp, HeteroResp, DOC_flux, Fire_flux, and Stem (Stem is specific to the BioCro model) and Water fluxes: Evaporation (Evap), Transpiration (TVeg), surface runoff (Qs), subsurface runoff (Qsb), and rainfall (Rainf).
For more details, see the MsTMIP variables documentation.
If dataframe = FALSE
, a vector of output variables. If
dataframe = TRUE
, a data.frame
of output variables with
POSIXct timestamps added (posix
column). The posix
column
is in seconds after January 1 of start.year
, or 1970 if
start.year
is not provided.
Michael Dietze, David LeBauer, Alexey Shiklomanov
Retry function X times before stopping in error
retry.func( expr, isError = function(x) inherits(x, "try-error"), maxErrors = 5, sleep = 0 )
retry.func( expr, isError = function(x) inherits(x, "try-error"), maxErrors = 5, sleep = 0 )
expr |
The function to try running |
isError |
function to use for checking whether to try again.
Must take one argument that contains the result of evaluating |
maxErrors |
The number of times to retry the function |
sleep |
How long to wait before retrying the function call |
retval returns the results of the function call
Shawn Serbin <adapted from https://stackoverflow.com/questions/20770497/how-to-retry-a-statement-on-error>
## Not run: file_url <- paste0("https://thredds.daac.ornl.gov/", "thredds/dodsC/ornldaac/1220", "/mstmip_driver_global_hd_climate_lwdown_1999_v1.nc4") dap <- retry.func( ncdf4::nc_open(file_url), maxErrors=10, sleep=2) ## End(Not run)
## Not run: file_url <- paste0("https://thredds.daac.ornl.gov/", "thredds/dodsC/ornldaac/1220", "/mstmip_driver_global_hd_climate_lwdown_1999_v1.nc4") dap <- retry.func( ncdf4::nc_open(file_url), maxErrors=10, sleep=2) ## End(Not run)
n
times before giving upAdverb to try calling a function n
times before giving up
robustly(.f, n = 10, timeout = 0.2, silent = TRUE)
robustly(.f, n = 10, timeout = 0.2, silent = TRUE)
.f |
Function to call. |
n |
Number of attempts to try |
timeout |
Timeout between attempts, in seconds |
silent |
Silence error messages? |
Modified version of input function
rlog <- robustly(log, timeout = 0.3) try(rlog("fail")) ## Not run: nc_openr <- robustly(ncdf4::nc_open, n = 10, timeout = 0.5) nc <- nc_openr(url) # ...or just call the function directly nc <- robustly(ncdf4::nc_open, n = 20)(url) # Useful in `purrr` maps many_vars <- purrr::map(varnames, robustly(ncdf4::ncvar_get), nc = nc) ## End(Not run)
rlog <- robustly(log, timeout = 0.3) try(rlog("fail")) ## Not run: nc_openr <- robustly(ncdf4::nc_open, n = 10, timeout = 0.5) nc <- nc_openr(url) # ...or just call the function directly nc <- robustly(ncdf4::nc_open, n = 20)(url) # Useful in `purrr` maps many_vars <- purrr::map(varnames, robustly(ncdf4::ncvar_get), nc = nc) ## End(Not run)
rsync is a file copying tool in bash
rsync(args, from, to, pattern = "")
rsync(args, from, to, pattern = "")
args |
rsync arguments (see man rsync) |
from |
source |
to |
destination |
pattern |
file pattern to be matched |
nothing, transfers files as a side effect
David LeBauer
Shawn Serbin
Number of seconds in a given year
seconds_in_year(year, leap_year = TRUE, ...)
seconds_in_year(year, leap_year = TRUE, ...)
year |
Numeric year (can be a vector) |
leap_year |
Default = TRUE. If set to FALSE will always return 31536000. |
... |
additional arguments, all currently ignored |
Alexey Shiklomanov
seconds_in_year(2000) # Leap year -- 366 x 24 x 60 x 60 = 31622400 seconds_in_year(2001) # Regular year -- 365 x 24 x 60 x 60 = 31536000 seconds_in_year(2000:2005) # Vectorized over year
seconds_in_year(2000) # Leap year -- 366 x 24 x 60 x 60 = 31622400 seconds_in_year(2001) # Regular year -- 365 x 24 x 60 x 60 = 31536000 seconds_in_year(2000:2005) # Vectorized over year
Sends email. This assumes the program sendmail is installed.
sendmail(from, to, subject, body)
sendmail(from, to, subject, body)
from |
the sender of the mail message |
to |
the receipient of the mail message |
subject |
the subject of the mail message |
body |
the body of the mail message |
nothing
Rob Kooper
## Not run: sendmail('[email protected]', '[email protected]', 'Hi', 'This is R.') ## End(Not run)
## Not run: sendmail('[email protected]', '[email protected]', 'Hi', 'This is R.') ## End(Not run)
R implementation of SSH
ssh(host, ..., args = "")
ssh(host, ..., args = "")
host |
(character) machine to connect to |
... |
Commands to execute. Will be passed as a single quoted string |
args |
futher arguments |
A lookup table giving standard names, units and descriptions for variables in PEcAn input/output files.
Originally based on the MsTMIP standards,
with additions to accomodate a wider range of model inputs and outputs.
The standard_vars table replaces both mstmip_vars
and mstmip_local
,
both of which are now deprecated.
standard_vars
standard_vars
data frame, all columns character
Short name suitable for programming with
Name used in the NetCDF CF metadata conventions
Standard units for this variable. Do not call variables by these names if they are in different units.
See ud_convert
for conversions to and from non-standard units
Human-readable variable name, suitable for e.g. axis labels
What kind of variable is it? (Carbon pool, N flux, dimension, input driver, etc)
Storage type (character, integer, etc)
Dimensions across which is this variable allowed to vary. Dimension names are themselves standard vars and must be present in the table with category "Dimension"
Further details. For composite measures, list the variables it is calculated from
Records the progress of a PEcAn workflow by writing statuses and timestamps to a STATUS file. Use these each time a module starts, finishes, or is skipped.
status.start(name, file = NULL) status.end(status = "DONE", file = NULL) status.skip(name, file = NULL) status.check(name, file = NULL)
status.start(name, file = NULL) status.end(status = "DONE", file = NULL) status.skip(name, file = NULL) status.check(name, file = NULL)
name |
one-word description of the module being checked or recorded, e.g. "TRAIT", "MODEL", "ENSEMBLE" |
file |
path to status file.
If NULL, taken from |
status |
one-word summary of the module result, e.g. "DONE", "ERROR" |
All of these functions write to or read from a STATUS file in your run's
output directory. If the file is not specified in the call, they will look
for a settings
object in the global environment and use
<settings$outdir>/STATUS
if possible.
Since the status functions may be called inside error-handling routines,
it's important that they not produce new errors of their own. Therefore
if the output file doesn't exist or is not writable, rather than complain
the writer functions (status.start
, status.end
, status.skip
) will
print to the console and status.check
will simply return 0.
For status.start
, status.end
, and status.skip
: NULL, invisibly
For status.check
, an integer:
0 if module not run, 1 if done, -1 if error
status.start()
: Record module start time
status.end()
: Record module completion time and status
status.skip()
: Record that module was skipped
status.check()
: Look up module status from file
Rob Kooper
Summarize results of replicate observations in trait data query
summarize.result(result)
summarize.result(result)
result |
dataframe with results of trait data query |
result with replicate observations summarized
David LeBauer, Alexey Shiklomanov
Convert number to n significant digits
tabnum(x, n = 3)
tabnum(x, n = 3)
x |
numeric value or vector |
n |
number of significant figures |
x rounded to n significant figures
David LeBauer
tabnum(1.2345) tabnum(1.2345, n = 4)
tabnum(1.2345) tabnum(1.2345, n = 4)
Uses tempfile
function to provide a valid temporary file (OS independent)
Useful for testing functions that depend on settings file
Reference: http://stackoverflow.com/a/12940705/199217
temp.settings(settings.txt)
temp.settings(settings.txt)
settings.txt |
character vector to be written |
character vector written to and read from a temporary file
David LeBauer
Returns the number of hours offset to UTC for a timezone.
timezone_hour(timezone)
timezone_hour(timezone)
timezone |
to be converted |
hours offset of the timezone
Rob Kooper
## Not run: timezone_hour('America/New_York') ## End(Not run)
## Not run: timezone_hour('America/New_York') ## End(Not run)
Units and longnames are looked up from the standard_vars
table
to_ncdim(dimname, vals)
to_ncdim(dimname, vals)
dimname |
character vector, standard dimension name (must be in PEcAn.utils::standard_vars) |
vals |
values of dimension; can be single value or vector |
ncdim defined according to standard_vars
Anne Thomas
Define an NCDF variable
to_ncvar(varname, dims)
to_ncvar(varname, dims)
varname |
character vector, standard variable name (must be in PEcAn.utils::standard_vars) |
dims |
list of previously defined ncdims (function will match subset of dims for this variable in standard_vars; can include other dims–enables lapply.) |
ncvar defined according to standard_vars
Anne Thomas
Dictionary of terms used to identify traits in ed, filenames, and figures
trait.lookup(traits = NULL)
trait.lookup(traits = NULL)
traits |
a vector of trait names, if traits = NULL, all of the traits will be returned. |
a dataframe with id, the name used by ED and PEcAn database for a parameter; fileid, an abbreviated name used for files; figid, the parameter name written out as best known in english for figures and tables.
# convert parameter name to a string appropriate for end-use plotting ## Not run: trait.lookup('growth_resp_factor') trait.lookup('growth_resp_factor')$figid # get a list of all traits and units in dictionary trait.lookup()[,c('figid', 'units')] ## End(Not run)
# convert parameter name to a string appropriate for end-use plotting ## Not run: trait.lookup('growth_resp_factor') trait.lookup('growth_resp_factor')$figid # get a list of all traits and units in dictionary trait.lookup()[,c('figid', 'units')] ## End(Not run)
Automates transformations of SD, MSE, LSD, 95%CI, HSD, and MSD to conservative estimates of SE. Method details and assumptions described in LeBauer 2020 Transforming ANOVA and Regression statistics for Meta-analysis. Authorea. DOI: https://doi.org/10.22541/au.158359749.96662550
transformstats(data)
transformstats(data)
data |
data frame with columns for mean, statistic, n, and statistic name |
data frame with statistics transformed to SE
David LeBauer
statdf <- data.frame(Y=rep(1,5), stat=rep(1,5), n=rep(4,5), statname=c('SD', 'MSE', 'LSD', 'HSD', 'MSD')) transformstats(statdf)
statdf <- data.frame(Y=rep(1,5), stat=rep(1,5), n=rep(4,5), statname=c('SD', 'MSE', 'LSD', 'HSD', 'MSD')) transformstats(statdf)
adaptation of try that returns a logical value (FALSE if error)
tryl(FUN)
tryl(FUN)
FUN |
function to be evaluated for error |
FALSE if function returns error; else TRUE
David LeBauer
tryl(1+1) # TRUE tryl(sum('a')) # FALSE
tryl(1+1) # TRUE tryl(sum('a')) # FALSE
Unit conversion to replace the now-unmaintained udunits2::ud.convert
ud_convert(x, u1, u2)
ud_convert(x, u1, u2)
x |
vector of class "numeric" or "difftime" |
u1 |
string parseable as the units in which |
u2 |
string parseable as the units to convert to |
numeric vector with values converted to units in u2
Chris Black
Function will replace the now-unmaintained udunits2::ud.is.parseable
unit_is_parseable(unit)
unit_is_parseable(unit)
unit |
A character string representing a type of units |
TRUE if the units is parseable, FALSE otherwise.
Tanishq Jain
unit_is_parseable("g/sec^2") unit_is_parseable("kiglometters")
unit_is_parseable("g/sec^2") unit_is_parseable("kiglometters")
This is to allow multiple forms of the same unit to work, such as
m/s
vs. m s-1
or K
and Kelvin
.
units_are_equivalent(x, y)
units_are_equivalent(x, y)
x |
A unit string, as character |
y |
Another unit string for comparison, as character |
TRUE
if equivalent, FALSE
otherwise
Alexey Shiklomanov
vecpaste, turns vector into comma delimited string fit for SQL statements.
vecpaste(x)
vecpaste(x)
x |
vector |
comma delimited string
Provides a zero bounded density estimate of a parameter.
Kernel Density Estimation used by the density
function will cause problems
at the left hand end because it will put some weight on negative values.
One useful approach is to transform to logs, estimate the density using KDE, and then transform back.
zero.bounded.density(x, bw = "SJ", n = 1001)
zero.bounded.density(x, bw = "SJ", n = 1001)
x |
data, as a numeric vector |
bw |
The smoothing bandwidth to be used. See 'bw.nrd' |
n |
number of points to use in kernel density estimate. See |
data frame with back-transformed log density estimate
M. P. Wand, J. S. Marron and D. Ruppert, 1991. Transformations in Density Estimation. Journal of the American Statistical Association. 86(414):343-353 http://www.jstor.org/stable/2290569
Truncates vector at 0
zero.truncate(y)
zero.truncate(y)
y |
numeric vector |
numeric vector with all values less than 0 set to 0
unknown