| 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, cre], David LeBauer [aut], Xiaohui Feng [ctb], Dan Wang [ctb], Carl Davidson [ctb], Rob Kooper [ctb], Alexey Shiklomanov [ctb], University of Illinois, NCSA [cph] |
| Maintainer: | Mike Dietze <[email protected]> |
| License: | BSD_3_clause + file LICENSE |
| Version: | 1.9.0.9000 |
| Built: | 2026-06-05 14:56:15 UTC |
| Source: | https://github.com/PecanProject/pecan |
Groups by location and applies calc_water_balance to each group. Unlike 'calc_water_balance', the units here *do* matter – they should be 'mm_day'.
apply_water_balance( df, idcol, whc_mm = 500, irrigation_max_mm = 150, flood_target = 125, flood_min = 62.5, flood_max = 175, seepage = 2.5 )apply_water_balance( df, idcol, whc_mm = 500, irrigation_max_mm = 150, flood_target = 125, flood_min = 62.5, flood_max = 175, seepage = 2.5 )
df |
Data frame with columns: 'date', 'location_id', 'etc_mm_day', 'precip_mm_day', 'crop_name', and 'whc_min_frac' (optional, defaults to 0.375). If a 'whc_mm' column is present, it is used as the water holding capacity. |
idcol |
Column name for grouping (typically, 'location_id', 'parcel_id' or similar). |
whc_mm |
Water holding capacity (mm); ignored if 'whc_mm' is a column in 'df'. |
irrigation_max_mm |
Maximum irrigation to be applied at a time. See 'irrigation_max' argument of [calc_water_balance()]. Ignored if 'irrigation_max_mm' is a column of 'df'. |
flood_target |
Numeric scalar. Target ponded water depth. Irrigation refills to this level. |
flood_min |
Numeric scalar. Minimum acceptable pond depth before irrigation is triggered. |
flood_max |
Numeric scalar. Maximum pond depth before bund overflow / runoff occurs. |
seepage |
Numeric scalar. Daily seepage + percolation loss Represents losses through the bund and downward percolation through the hardpan (if any). Typical range: 1-5 mm/day for well-puddled California soils. |
Data frame with added columns: 'W_t' / 'pond_depth', 'irr', 'runoff'
Contains data from 246 Fluxnet sites. Variables include aboveground and belowground biomass in various pools, plus soil texture/chemistry/horizonation/C&N stocks.
BADMBADM
## 'BADM' A data frame with 12,300 rows and 13 columns:
Fluxnet code for the site
site coordinates
Measurement date
TODO
category, eg abovground biomass or soil chemistry
key and value for each measured variable
numeric IDs and names for the Level 1 and level 2 ecoregions where this site is located
Originally from Fluxnet <https://fluxnet.org/badm-data-product/>, but the provenence and age of this specific file is not clear.
BADM_IC_process
BADM_IC_process(settings, dir, overwrite = TRUE)BADM_IC_process(settings, dir, overwrite = TRUE)
settings |
pecan xml settings |
dir |
output dir which you want to store the IC netcdf file |
overwrite |
Flag for overwriting the IC file. |
a list of paths to generated and stored IC files.
## Not run: settings <- PEcAn.settings::read.settings("pecan.xml") output_dir <- withr::local_tempdir() ic_files <- BADM_IC_process(settings, dir = output_dir) ## End(Not run)## Not run: settings <- PEcAn.settings::read.settings("pecan.xml") output_dir <- withr::local_tempdir() ic_files <- BADM_IC_process(settings, dir = output_dir) ## End(Not run)
Crop and growth stage specific coefficients (Kc) from the Basic Irrigation Scheduling
(BIS) Excel workbook (Snyder et. al., 2014).
The dataset is an export of the BISm.xlsx workbook's 'CropRef' worksheet, with columns renamed
and columns added that map to LandIQ CADWR land use dataset
(landiq_crop_mapping_codes; California Department of Water Resources, 2023).
This dataset provides the information needed to reconstruct a stage-based daily Kc curve when
combined with grass-reference evapotranspiration (ETo), such as that provided
by CIMIS (California Department of Water Resources, 2025).
bism_kc_by_cropbism_kc_by_crop
A data frame with one row per crop and the following columns:
Numeric crop identifier used internally by BIS.
Crop name as listed in the 'CropRef' worksheet.
Percent-of-season location of growth date B.
Percent-of-season location of growth date C.
Percent-of-season location of growth date D.
Crop coefficient at growth date B (approximately Kc1 for field crops).
Crop coefficient at growth date C (mid-season plateau, Kc2).
Crop coefficient at growth date D (typically equal to KcC for most crops).
Crop coefficient at growth date E (late-season value, Kc3).
Representative planting month used by BIS.
Representative planting day used by BIS.
Representative harvest month used by BIS.
Representative harvest day used by BIS.
LandIQ class code matched by BISm crop number.
LandIQ subclass code matched by BISm crop number.
LandIQ subclass name matched by BISm crop number.
BIS follows the crop-coefficient framework of Doorenbos and Pruitt (1977), in which maximum crop evapotranspiration is calculated as
Rather than specifying fixed durations for growth stages, BIS expresses the locations of key growth dates (B, C, and D) as percentages of the total season length between planting (A) and harvest or dormancy (E). Daily Kc values are obtained by linear interpolation between the stage-specific coefficients stored in this dataset.
Growth-stage interpretation depends on crop type:
Field and row crops (Type 1): A-B corresponds to initial growth from planting to roughly 10% ground cover; B-C represents rapid canopy development with Kc increasing toward its mid-season value; C-D is the mid-season period at near-maximum Kc (typically around 75% ground cover); and D-E represents late-season senescence, during which Kc may decline.
Deciduous tree and vine crops (Type 3): there is no explicit initial A-B period; the season begins at leaf-out (B). Kc increases during B-C as the canopy develops, reaches a maximum at approximately 61-63% ground cover during C-D, and declines during D-E toward leaf drop or the first hard freeze.
Snyder, R., Orang, M., Bali, K., Eching, S., Zaccaria, D. (2014). BISm Basic Irrigation Scheduling Excel program (metric units).
Doorenbos, J., Pruitt, W.O. (1977). Guidelines for predicting crop water requirements. FAO Irrigation and Drainage Paper 24.
Snyder, R.L., Shackel, K.A., Sanden, B., Fulton, A.E., Suvočarev, K. (2024). Irrigation scheduling. In Microirrigation for Crop Production. Elsevier.
California Department of Water Resources (2025). California Irrigation Management Information System (CIMIS).
data(bism_kc_by_crop) head(bism_kc_by_crop)data(bism_kc_by_crop) head(bism_kc_by_crop)
builds the JAGS data object for the tree ring / inventory fusion code also sets all the priors
buildJAGSdata_InventoryRings(combined, inc.unit.conv = 0.1)buildJAGSdata_InventoryRings(combined, inc.unit.conv = 0.1)
combined |
object returned from matchInventoryRings. Matrix with both increment and plot data |
inc.unit.conv |
conversion factor from loaded increments to cm (of radius) |
list
Michael Dietze
Properties of organic amendment materials used in California agriculture,
including C:N ratios, carbon and nitrogen content, plant-available nitrogen
(PAN), and application rates. Some materials appear in multiple rows when
values are reported by different sources (e.g. Corn stalks, Cow manure,
Vegetable waste). The source column disambiguates these.
ca_compost_amendmentca_compost_amendment
A tibble with 32 rows and the following columns:
character. Amendment material name.
numeric. Carbon-to-nitrogen ratio
range and average.
numeric. Assumed carbon content (percent).
numeric. Total nitrogen content (percent).
numeric. Plant-available nitrogen after 4 weeks
(percent). Negative values indicate N immobilization.
character. "LOWER" or "HIGHER" N content class.
numeric. Application rate range
(lbs/acre).
numeric.
Total carbon applied (lbs C/acre).
numeric.
Total nitrogen applied (lbs N/acre).
numeric.
Total carbon in SI units (g C/m).
numeric.
Total nitrogen in SI units (g N/m).
character. Short citation for the data source.
Eghball, B. Composting Manure and Other Organic Residues. University of Nebraska-Lincoln Extension, Publication G2222. https://extensionpubs.unl.edu/publication/g2222/na/html/view
Rynk, R. (ed.) Compost Production and Use in Sustainable Farming Systems. NC State Extension. https://content.ces.ncsu.edu/compost-production-and-use-in-sustainable-farming-systems
look_up_ca_compost_amendment for looking up
amendments by material name.
look_up_fertilizer_components for fertilizer nutrient
composition (N/C fractions) from the SWAT/DayCent database.
Crop-specific recommended nitrogen fertilizer application rates for California agriculture. Contains total-season rates (not per-stage breakdowns). When multiple sources report rates for the same crop, the rate represents the envelope (min of minimums, max of maximums) across sources.
ca_n_application_rateca_n_application_rate
A tibble with one row per crop and the following columns:
character. Plant functional type group
(e.g. "row", "woody", "rice").
character. Crop name as given in the source.
numeric. Minimum recommended N rate
(lbs N/acre).
numeric. Maximum recommended N rate
(lbs N/acre).
character. Short citation for the source(s).
Multiple sources are separated by "; ".
numeric. Minimum N rate in SI units
(g N/m). Conversion: 1 lb/acre = 0.112085 g/m.
numeric. Maximum N rate in SI units
(g N/m).
Rosenstock, T. S., Liptzin, D., Six, J., & Tomich, T. P. (2013). Nitrogen fertilizer use in California: Assessing the data, trends and a way forward. California Agriculture, 67(1). https://escholarship.org/uc/item/5mk2q1sm
Meyer, R. D., Marcum, D. B., Orloff, S. B., & Schmierer, J. L. (2007). Alfalfa fertilization strategies. UC ANR Publication 8296.
look_up_ca_n_rate for looking up rates by crop name.
look_up_fertilizer_components for fertilizer nutrient
composition (N/C fractions) from the SWAT/DayCent database.
This is the core water balance calculation that operates on primitive numeric vectors for easy testing and debugging. Each input is a time series of daily values for a single location (one date per row). The units for all quantities are arbitrary, but they should be consistent (distance / time; e.g., most commonly, mm/day).
calc_water_balance( et, precip, whc, whc_min_frac, W_initial = NULL, w_min = NULL, irrigation_max = NULL )calc_water_balance( et, precip, whc, whc_min_frac, W_initial = NULL, w_min = NULL, irrigation_max = NULL )
et |
Vector of evapotranspiration values (distance / time) |
precip |
Vector of precipitation values (distance / time) |
whc |
Water holding capacity (distance); the plant-available range from wilting point to field capacity (i.e., 'whc = field_capacity - wilting_point'). Can be a single value or a vector of the same length as 'et'. |
whc_min_frac |
Fraction of WHC for minimum water level (irrigation trigger); unused if 'w_min' is explicitly specified. Can be a single value or a vector of the same length as 'et'. |
W_initial |
Initial soil water content at start of time series (distance); defaults to 'whc[1]' (field capacity) if NULL |
w_min |
Minimum water level threshold (distance); irrigation is triggered when soil water falls below this level; defaults to 'whc_min_frac * whc' if NULL. Can be a single value or a vector of the same length as 'et'. |
irrigation_max |
If set, maximum amount of irrigation to apply at a time (distance). |
This function operates in *relative* WHC space, where: - 'w = 0' represents wilting point (no plant-available water) - 'w = whc' represents field capacity (maximum plant-available water) - 'whc = (field_capacity - wilting_point) * rooting_depth' (the plant-available range)
Although this function can be used as a crude approximation of rice irrigation (by setting 'whc_min_frac = 1.0'), we recommend using [calc_water_balance_rice()] instead, which explicitly tracks rice pond depth, implements seepage, etc.
List with vectors: W_t (soil water), irr (irrigation), runoff
# Calculate WHC from field capacity, wilting point, and rooting depth field_capacity <- 0.30 # volumetric (m3/m3) wilting_point <- 0.10 # volumetric (m3/m3) rooting_depth <- 1000 # mm whc <- (field_capacity - wilting_point) * rooting_depth # mm # Run water balance with 5 days of ET and precip data et <- c(4, 5, 6, 4, 3) # mm/day precip <- c(0, 0, 10, 0, 0) # mm/day result <- calc_water_balance(et, precip, whc = whc, whc_min_frac = 0.5) str(result)# Calculate WHC from field capacity, wilting point, and rooting depth field_capacity <- 0.30 # volumetric (m3/m3) wilting_point <- 0.10 # volumetric (m3/m3) rooting_depth <- 1000 # mm whc <- (field_capacity - wilting_point) * rooting_depth # mm # Run water balance with 5 days of ET and precip data et <- c(4, 5, 6, 4, 3) # mm/day precip <- c(0, 0, 10, 0, 0) # mm/day result <- calc_water_balance(et, precip, whc = whc, whc_min_frac = 0.5) str(result)
Models the water balance of a flooded rice system with a two-layer structure: a ponded water layer above a saturated soil profile. This is physically distinct from the upland soil water balance in [calc_water_balance()]. Water is managed to maintain a target flood depth, with support for mid-season drainage events.
calc_water_balance_rice( et, precip, flood_target, flood_min, flood_max, seepage, drain = NULL, pond_init = flood_target )calc_water_balance_rice( et, precip, flood_target, flood_min, flood_max, seepage, drain = NULL, pond_init = flood_target )
et |
Numeric vector. Daily reference ET. During flooded periods this is treated as open-water ET; no crop coefficient is applied here but you can pre-multiply if needed. |
precip |
Numeric vector. Daily precipitation. |
flood_target |
Numeric scalar. Target ponded water depth. Irrigation refills to this level. |
flood_min |
Numeric scalar. Minimum acceptable pond depth before irrigation is triggered. |
flood_max |
Numeric scalar. Maximum pond depth before bund overflow / runoff occurs. |
seepage |
Numeric scalar. Daily seepage + percolation loss Represents losses through the bund and downward percolation through the hardpan (if any). Typical range: 1-5 mm/day for well-puddled California soils. |
drain |
Logical vector (same length as et). TRUE on days when an intentional drainage event occurs (e.g., mid-season drain, pre-harvest drawdown). Pond is set to 0 on these days and irrigation is suppressed. |
pond_init |
Numeric scalar. Initial pond depth at t = 1. Defaults to flood_target. |
The soil profile is assumed to be continuously saturated during flooded periods, so plant-available soil water is not tracked separately. ET is applied directly to the pond layer (open-water ET during flooded periods).
Irrigation is triggered when pond_depth falls below flood_min. Farmers refill to flood_target. Runoff (bund overflow) occurs when pond_depth exceeds flood_max.
Mid-season drainage is specified as a logical vector ('drain[t] = TRUE' means the field is intentionally drained on day t). During drainage days, the pond is drawn down to pond_depth = 0 and irrigation is suppressed. This represents practices such as weed control or pre-harvest drainage.
A list with numeric vectors of length n:
pond_depth |
Ponded water depth at end of each day |
irr |
Irrigation applied |
runoff |
Bund overflow / surface runoff |
tree core QAQC
Clean_Tucson(file)Clean_Tucson(file)
file |
WinDendro output |
Clips a raster to a polygon bounding box, optionally masks to polygon, and saves the output in the same format as the input.
clip_and_save_raster_file( input_path, polygon, out_path, mask = TRUE, overwrite = TRUE )clip_and_save_raster_file( input_path, polygon, out_path, mask = TRUE, overwrite = TRUE )
input_path |
Character. Path to the input raster file. |
polygon |
An object or file coercible to a 'SpatVector' by 'terra::vect()' (e.g., an 'sf' object, a 'SpatVector', or a file path to a vector dataset). used for clipping and masking. Must have a valid CRS. |
out_path |
Character. Path to save the processed raster. |
mask |
Logical: Should pixels outside the polygon but inside its bounding box be masked out (TRUE) or included (FALSE)? |
overwrite |
Logical: Replace output file if it already exists? |
Invisibly, the clipped 'SpatRaster' object. The raster is also saved to 'out_path'.
David LeBauer
Converts .rds files into pool netcdf files.
cohort2pool(dat, allom_param = NULL, dbh_name = "DBH")cohort2pool(dat, allom_param = NULL, dbh_name = "DBH")
dat |
veg_info file |
allom_param |
parameters for allometric equation, a and b. Based on base-10 log-log linear model (power law) |
dbh_name |
Default is "DBH". This is the column name in the veg_file that represents DBH. May differ depending on data source. |
cohort2pool function Calculates total biomass using veg cohort file.
Saloni Shah
## Not run: veg_file <- "~/downloads/FFT_site_1-25665/FFT.2008.veg.rds" cohort2pool(dat = veg_file, allom_param = NULL) ## End(Not run)## Not run: veg_file <- "~/downloads/FFT_site_1-25665/FFT.2008.veg.rds" cohort2pool(dat = veg_file, allom_param = NULL) ## End(Not run)
Aggregates irrigation to weekly values and formats for SIPNET. Irrigation is summed by week and reported on the first day of each week. Units are converted from mm to cm.
create_event_file(df)create_event_file(df)
df |
Data frame with columns: date, year, week, day_of_year, irr |
Data frame with columns: loc, year, doy, event_type, irr_cm, type
Maximum effective rooting depth and minimum soil water content thresholds for various crops. The 'whc_min_frac' column represents the fraction of total available water (TAW) that should remain in the root zone to avoid moisture stress (equivalent to 1 - p, where p is the depletion fraction from FAO-56).
crop_whccrop_whc
A tibble with one row per crop and the following columns:
BIS crop number (character). Blank for crops not in BIS.
Crop name.
Crop category (e.g., Woody Perennial, Annual (Hardy)).
Maximum effective rooting depth in meters.
Minimum soil water as fraction of available water-holding capacity (0-1).
Rationale or source for the minimum WHC value.
Rationale or source for the rooting depth value.
Allen, R. G., Pereira, L. S., Raes, D., & Smith, M. FAO Irrigation and Drainage Paper No. 56: Crop evapotranspiration. Chapter 8. Table 22. https://www.fao.org/4/x0490e/x0490e0e.htm#chapter
data(crop_whc) head(crop_whc)data(crop_whc) head(crop_whc)
Adapts the dataone::getDataPackage workflow to allow users to download data from the DataONE federation by simply entering the doi or associated package id
dataone_download( id, filepath = "/fs/data1/pecan.data/dbfiles", CNode = "PROD", lazyLoad = FALSE, quiet = FALSE )dataone_download( id, filepath = "/fs/data1/pecan.data/dbfiles", CNode = "PROD", lazyLoad = FALSE, quiet = FALSE )
id |
"The identifier of a package, package metadata or other package member" – dataone r |
filepath |
path to where files will be stored |
CNode |
character, passed to 'dataone::CNode' |
lazyLoad |
"A logical value. If TRUE, then only package member system metadata is downloaded and not data. The default is FALSE." – dataone R |
quiet |
"A 'logical'. If TRUE (the default) then informational messages will not be printed." – dataone R |
Liam P Burke, [email protected]
## Not run: dataone_download( id = "doi:10.6073/pasta/63ad7159306bc031520f09b2faefcf87", filepath = "/fs/data1/pecan.data/dbfiles" ) ## End(Not run)## Not run: dataone_download( id = "doi:10.6073/pasta/63ad7159306bc031520f09b2faefcf87", filepath = "/fs/data1/pecan.data/dbfiles" ) ## End(Not run)
Download NEON Soil Water Content and Soil Salinity data by date and site name
download_NEON_soilmoist( site, avg = "all", var = "all", startdate = NA, enddate = NA, outdir )download_NEON_soilmoist( site, avg = "all", var = "all", startdate = NA, enddate = NA, outdir )
site |
four letter NEON site code name(s). If no site is specified, it will download all of them (chr) (e.g "BART" or c("SRER", "KONA", "BART")) |
avg |
averaging interval (minutes): 1, 30, or both ("all") . default returns both |
var |
variable of interest: "SWC" (soil water content) or "SIC" (soil ion content) or both ("all") default returns both. Both variables will be saved in outdir automatically (chr) |
startdate |
start date as YYYY-mm. If left empty, all data available will be downloaded (chr) |
enddate |
start date as YYYY-mm. If left empty, all data available will be downloaded (chr) |
outdir |
out directory to store the following data: .rds list files of SWC and SIC data for each site and sensor position, sensor positions .csv for each site, variable description .csv file, readme .csv file |
List of specified variable(s) AND prints the path to output folder
Juliette Bateman
## Not run: test <- download_NEON_soilmoisture( site = c("SRER", "BART", "KONA"), avg = 30, var = "SWC", startdate = "2019-01", enddate = "2020-01", outdir = getwd()) ## End(Not run)## Not run: test <- download_NEON_soilmoisture( site = c("SRER", "BART", "KONA"), avg = 30, var = "SWC", startdate = "2019-01", enddate = "2020-01", outdir = getwd()) ## End(Not run)
Uses resource_map and dataone::getPackage to download the data into a BagItFile. Then utils::unzip unzips the data and stores in the user's directory.
download_package_rm( resource_map, directory, CNode = "PROD", download_format = "application/bagit-097", overwrite_directory = TRUE )download_package_rm( resource_map, directory, CNode = "PROD", download_format = "application/bagit-097", overwrite_directory = TRUE )
resource_map |
the resource map that corresponds to the given data package |
directory |
location that download.packages places the data |
CNode |
defaults to "PROD" |
download_format |
typically "application/bagit-097". Other possible formats currently unknown. |
overwrite_directory |
boolean that indicates whether or not the function should overwrite the directory |
results of download
Download CDS soil moisture data for the SDA workflow.
download.SM_CDS( outfolder, time.points, overwrite = FALSE, auto.create.key = FALSE )download.SM_CDS( outfolder, time.points, overwrite = FALSE, auto.create.key = FALSE )
outfolder |
physical paths to where the unziped soil moisture files are downloaded. |
time.points |
A vector contains each time point within the start and end date. |
overwrite |
flag determine if we want to overwrite existing files when downloading. |
auto.create.key |
flag determine if we want to automatically create the credential file. |
Introduction on how to play with the CDS python API to correctly build the python environment with the cdsapi installed, you need to follow those steps. 1. Install miniconda. create a directory to install minicaonda 'mkdir -p ~/miniconda3' 2. Download latest miniconda version. 'wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh' 3. run the install script. 'bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3' 4. delete the intall script. 'rm -rf ~/miniconda3/miniconda.sh' 5. add a conda initialize to your bash '~/miniconda3/bin/conda init bash' 6. Verify the installaton, you need to restart your session first. 'conda list' 7. Create Python environment. 'conda update conda' 'conda create -n myenv python=3.9 –yes' 8. Activate your python env. 'conda activate myenv' 9. Install the cdsapi package. 'pip install cdsapi' in the meantime, you might encounter several issues saying XXXX dependency is not available. to solve this issue, you just need to install those dependencies before hand. 10. Create CDS account. go to 'https://cds.climate.copernicus.eu/how-to-api' website. create an account. 11. Create CDS personel token. run this function. go to 'https://cds.climate.copernicus.eu/how-to-api' website. copy and paste url and key to the prompt window.
A vector containing file paths to the downloaded files.
Dongchen Zhang
Sampling/ensemble module
ens_veg_module( getveg.id, dbparms, input_veg, outfolder, machine, start_date, end_date, n.ensemble, new_site, host )ens_veg_module( getveg.id, dbparms, input_veg, outfolder, machine, start_date, end_date, n.ensemble, new_site, host )
getveg.id |
list, input.id and dbfile.id of the IC file in intermediate pecan standard |
dbparms |
list, settings$database info reqired for opening a connection to DB |
input_veg |
list, this is a sublist of settings$run$inputs that has info about source, id, metadata of the requested IC file |
outfolder |
path to where the processed files will be written |
machine |
data frame, DB info regarding localhost machine id/hostname etc. |
start_date |
date in "YYYY-MM-DD" format, in case of source==FIA it's the settings$run$start.date, otherwise start_date of the IC file in DB |
end_date |
date in "YYYY-MM-DD" format, in case of source==FIA it's the settings$run$end.date, otherwise end_date of the IC file in DB |
n.ensemble |
integer, ensemble member number |
new_site |
data frame, id/lat/lon/name info about the site |
host |
list, host info as in settings$host, host$name forced to be "localhost" upstream |
Istem Fer
This function is designed to find the level1 and level2 code ecoregions for a given lat and long. You can learn more about ecoregions here: https://www.epa.gov/eco-research/ecoregions.
EPA_ecoregion_finder(Lat, Lon, folder.path = NULL)EPA_ecoregion_finder(Lat, Lon, folder.path = NULL)
Lat |
numeric latitude |
Lon |
numeric longitude |
folder.path |
path to the directory where you store the shape files of L1 and L2 ecoregion maps. |
a dataframe with codes corresponding to level1 and level2 codes as two columns
A function to estimate individual alphas for Dirichlet distribution to approximate the observed quantiles with means as known moments for SoilGrids soil texture data. Dirichlet distribution is assumed as soil texture data follow categorical distribution and the probability of each category is in the range 0 to 1, and all must sum to 1.
estimate_dirichlet_parameters(means, quantiles)estimate_dirichlet_parameters(means, quantiles)
means |
A vector of means of sand, clay, and silt proportion for one soil layer at one site from SoilGrids data |
quantiles |
A list of 5th, 50th, and 95th percentiles for sand, clay, and silt for one soil layer at one site from SoilGrids data |
The individual alphas that work best to fit the observed quantiles
Qianyu Li
## Not run: # Means and percentiles for each category: sand, clay, and silt at one site and one depth means <- c(0.566,0.193,0.241) quantiles <-list( q5 = c(0.127,0.034,0.052), # 5th percentile q50 = c(0.615,0.15,0.191), # 50th percentile (median) q95 = c(0.799,0.66,0.616)) # 95th percentile alpha_est <- estimate_dirichlet_parameters(means, quantiles) ## End(Not run)## Not run: # Means and percentiles for each category: sand, clay, and silt at one site and one depth means <- c(0.566,0.193,0.241) quantiles <-list( q5 = c(0.127,0.034,0.052), # 5th percentile q50 = c(0.615,0.15,0.191), # 50th percentile (median) q95 = c(0.799,0.66,0.616)) # 95th percentile alpha_est <- estimate_dirichlet_parameters(means, quantiles) ## End(Not run)
Multiply reference evapotranspiration (ETo) by a unitless crop coefficient (Kc) to produce crop evapotranspiration (ETc). Output has the same units as input ETo, with length/time scale, e.g., mm d-1.
eto_to_etc(eto, kc)eto_to_etc(eto, kc)
eto |
numeric vector of reference evapotranspiration |
kc |
numeric vector of crop coefficients |
numeric vector of crop evapotranspiration
Convert grass-reference evapotranspiration (ETo) to crop evapotranspiration
(ETc) using crop coefficient (Kc) schedules from the BIS/BISm framework
(Snyder et al.). Daily ETc is calculated as ETc = Kc * ETo.
Kc values are determined using one of two mutually exclusive timing modes, selected by input:
Date-based (percent-of-season) mode: If date is
provided, Kc is interpolated linearly between BIS/BISm growth-stage anchors
(B–C–D–E) using percent-of-season, with default planting and
harvest dates taken from bism_kc_by_crop.
Canopy-cover mode: If canopy_cover is provided, Kc is
estimated from observed ground cover. For field and row crops, canopy cover
is used to locate position within the B–C growth phase (linear increase from
Kc_B at ~10% cover to Kc_C at ~75% cover, capped thereafter).
For tree, vine, and subtropical crops, Kc is scaled from the mature mid-season
value using the immaturity relationships of Snyder et al. (Snyder, Fig. 15).
Exactly one of date or canopy_cover must be supplied.
eto_to_etc_bism(eto, crop_name, date = NULL, canopy_cover = NULL)eto_to_etc_bism(eto, crop_name, date = NULL, canopy_cover = NULL)
eto |
Numeric vector of reference evapotranspiration (ETo). |
crop_name |
Character scalar identifying a crop in
|
date |
Optional |
canopy_cover |
Optional numeric vector giving fractional ground cover
(0-1), length 1 or |
Numeric vector of crop evapotranspiration (ETc), with the same units as
eto (e.g., mm d-1).
Snyder, R., Orang, M., Bali, K., Eching, S., Zaccaria, D. (2014). BISm Basic Irrigation Scheduling Excel program (metric units). University of California Cooperative Extension.
Snyder, R.L., 2014. Irrigation scheduling and soil water budgeting (ISWBM). University of California, Davis. https://biomet.ucdavis.edu/basic-irrigation-scheduling-(BIS).html
Doorenbos, J., Pruitt, W.O. (1977). Guidelines for predicting crop water requirements. FAO Irrigation and Drainage Paper 24.
Writes ensembles of PEcan events stored in parquet format to valid PEcAn events.json files, based on a manifest table specification.
event_parquet_to_json( event_paths, events_ensemble_manifest, site_ids = NULL, start_date = NULL, end_date = NULL, parquet_dir = NULL, pecan_events_version = "0.1.2" )event_parquet_to_json( event_paths, events_ensemble_manifest, site_ids = NULL, start_date = NULL, end_date = NULL, parquet_dir = NULL, pecan_events_version = "0.1.2" )
event_paths |
(character) Named character vector of paths to PEcAn standard event parquet files. Names correspond to event types; e.g., 'c(leafon = "/path/to/leaf_on.parquet")'. If not names are provided, they are deduced from the file name (stripping the '.parquet' extension). Folders containing parquet files are also supported. |
events_ensemble_manifest |
'data.frame' that maps PEcAn ensemble IDs and events.json paths onto ensembles of each event type. (See Details). |
site_ids |
(character) Optional vector of 'site_id' values for filtering. |
start_date |
(Date or POSIXct) Optional start date for filtering events |
end_date |
(Date or POSIXct) Optional end date for filtering events. |
parquet_dir |
Alternative way to pass 'event_paths' by just specifying a directory of PEcAn standard event files. Each file or folder must be named '<event_type>.parquet' (e.g., 'irrigation.parquet/', 'leafon.parquet'). |
pecan_events_version |
(character) Version of the PEcAn events.json standard to write to 'events.json'. Default = 0.1.2. |
Similar to the overall PEcAn ensemble structure, the 'events_ensemble_manifest' is a data frame that maps PEcAn ensemble IDs onto ensembles of each individual event. The data frame must have the following columns:
- 'ensemble_id' (character) — PEcAn ensemble ID (used by PEcAn ensemble code) - 'json_path' (character) — Path to the events.json file that will be written for this ensemble. - One column per event type (e.g., 'irrigation', 'planting', 'harvest', etc.), with values (character) corresponding to values in the 'event_member_id' column in the corresponding files. The special value '"_NO_EVENT_ENSEMBLE"' means that the parquet data for that event does not have an 'event_member_id' column (i.e., there is no ensemble analysis for that event type).
Nested tibble containing event data. 'events.json' files are created for each ensemble member as a side effect.
Reads a (JSON) management events file and finds the planting events at which the site changes from from one crop to another, ignoring repeat plantings of the same crop. These are the dates when single-PFT models will need to restart to update their crop parameterization.
events_to_crop_cycle_starts(event_json)events_to_crop_cycle_starts(event_json)
event_json |
path to an 'events.json' file |
Requires each planting event to specify a 'crop_code' attribute, and reports a crop cycle change every time the crop code changes. Note that crop codes are not required to match your model's PFT names, so deciding how (or whether) to change parameterization on these dates is up to the model operator.
Also note that only _changes_ in crop code are detected: If the event file contains no planting events the result has zero rows, and any crop present before the first observed planting event (say from initial conditions) is not reported.
data frame with columns 'site_id', 'date', 'crop', with one row per detected crop cycle.
Chris Black
evts <- system.file( "events_fixtures/events_site1_site2.json", package = "PEcAn.data.land" ) events_to_crop_cycle_starts(evts)evts <- system.file( "events_fixtures/events_site1_site2.json", package = "PEcAn.data.land" ) events_to_crop_cycle_starts(evts)
extract_FIA
extract_FIA(lon, lat, start_date, end_date, gridres = 0.075, dbparms, ...)extract_FIA(lon, lat, start_date, end_date, gridres = 0.075, dbparms, ...)
lon |
site longitude |
lat |
site latitude |
start_date |
"YYYY-MM-DD" |
end_date |
"YYYY-MM-DD" |
gridres |
taken from input_veg, DEFAULT = 0.075 |
dbparms |
taken from settings object |
... |
Additional parameters |
Istem Fer
extract_NEON_veg
extract_NEON_veg( lon, lat, start_date, end_date, store_dir, neonsites = NULL, ... )extract_NEON_veg( lon, lat, start_date, end_date, store_dir, neonsites = NULL, ... )
lon |
site longitude, passed from ic_process |
lat |
site latitude, passed from ic_process |
start_date |
"YYYY-MM-DD", used to download NEON datasets for desired time period |
end_date |
"YYYY_MM_DD", used to download NEON datasets for desired time period |
store_dir |
location where you want to store downloaded NEON files |
neonsites |
prepared datasets table from NEON using neonstore::neon_sites(api = "https://data.neonscience.org/api/v0", .token = Sys.getenv("NEON_TOKEN")) |
... |
Additional parameters |
veg_info object to be passed to extract_veg within ic_process
Alexis Helgeson and Michael Dietze
start_date = as.Date("2020-01-01") end_date = as.Date("2021-09-01")start_date = as.Date("2020-01-01") end_date = as.Date("2021-09-01")
Note that this requires the environment variable 'OPENET_API_KEY' to be set. A convenient way to do this is via a '.Renviron', either globally ('~/.Renviron') or in the current working directory ('./.Renviron'), with contents like:
extract_openet_daily(design_points, start_date, end_date)extract_openet_daily(design_points, start_date, end_date)
design_points |
'data.frame' of design points with columns 'lat' and 'lon' |
start_date |
Start date for data extraction |
end_date |
End date for data extraction |
“' OPENET_API_KEY="abcdefg123456" “'
You can obtain an OpenET API key from the OpenET data portal.
'design_points' 'data.frame' with additional columns 'date', and 'et_mm_day' (ET, mm/day)
Extract CDS soil moisture data for the SDA workflow.
extract_SM_CDS( site_info, time.points, in.path, out.path = NULL, allow.download = TRUE, search_window = 10 )extract_SM_CDS( site_info, time.points, in.path, out.path = NULL, allow.download = TRUE, search_window = 10 )
site_info |
Bety list of site info including site_id, lon, and lat. |
time.points |
A vector contains each time point within the start and end date. |
in.path |
physical paths to where the unziped soil moisture files are downloaded. |
out.path |
Where the final CSV file will be stored. |
allow.download |
Flag determine if we want to automatic download files if they are not available. |
search_window |
time length (days) for locate available soil moisture values. |
A data frame containing soil moisture and sd for each site and each time step.
Dongchen Zhang
Extract soil data from gssurgo
extract_soil_gssurgo( outdir, lat, lon, size = 1, grid_size = 3, grid_spacing = 100, depths = c(0.15, 0.3, 0.6) )extract_soil_gssurgo( outdir, lat, lon, size = 1, grid_size = 3, grid_spacing = 100, depths = c(0.15, 0.3, 0.6) )
outdir |
Output directory for writing down the netcdf file |
lat |
Latitude of center point (single numeric value) |
lon |
Longitude of center point (single numeric value) |
size |
Ensemble size |
grid_size |
Size of the spatial sampling grid around the center point (default: 3) |
grid_spacing |
Spacing between grid cells in meters (default: 100) |
depths |
Standard set of soil depths in m to create the ensemble of soil profiles with. |
This function takes a single lat/lon point and creates a spatial grid around it for sampling soil variability. The grid_size parameter determines how many grid points (grid_size x grid_size) are created around the center point.
It returns the address for the generated soil netcdf file
- MUKEY frequency weighting treats occurrence counts as proportional to area coverage - This approximation may introduce geometric bias for irregular polygon data - Buffer radius is set to grid_spacing/2 to reduce overlapping queries, but may still miss coverage - True area-weighted aggregation using polygon geometries is planned (see issue #3609)
Hamze Dokoohaki, Akash
## Not run: outdir <- "~/paleon/envTest" lat <- 40 lon <- -80 PEcAn.data.land::extract_soil_gssurgo(outdir, lat, lon) ## End(Not run)## Not run: outdir <- "~/paleon/envTest" lat <- 40 lon <- -80 PEcAn.data.land::extract_soil_gssurgo(outdir, lat, lon) ## End(Not run)
Extract soil data from the gridpoint closest to a location
extract_soil_nc(in.file, outdir, lat, lon)extract_soil_nc(in.file, outdir, lat, lon)
in.file |
path to netcdf file containing soil data |
outdir |
directory in which to write netcdf file of extracted data. Output filename will be the same as input filename. |
lat, lon
|
location in decimal degrees. Data will be extracted from the point in 'in.file' that is nearest this |
path to netCDF file containing extracted data
## Not run: in.file <- "~/paleon/env_paleon/soil/paleon_soil.nc" outdir <- "~/paleon/envTest" lat <- 40 lon <- -80 PEcAn.data.land::extract_soil_nc(in.file,outdir,lat,lon) ## End(Not run)## Not run: in.file <- "~/paleon/env_paleon/soil/paleon_soil.nc" outdir <- "~/paleon/envTest" lat <- 40 lon <- -80 PEcAn.data.land::extract_soil_nc(in.file,outdir,lat,lon) ## End(Not run)
Function queries a DB to extract veg info downstream
extract_veg( new_site, start_date, end_date, source, gridres, format_name = NULL, machine_host, dbparms, outfolder, overwrite = FALSE, input_veg = input_veg, ... )extract_veg( new_site, start_date, end_date, source, gridres, format_name = NULL, machine_host, dbparms, outfolder, overwrite = FALSE, input_veg = input_veg, ... )
new_site |
new_site object passed from ic_process includes lat, lon, id, and name |
start_date |
"YYYY-MM-DD" |
end_date |
"YYYY-MM-DD" |
source |
taken from input$source, passed from ic_process |
gridres |
only used for source = "FIA" |
format_name |
DEFAULT=NULL |
machine_host |
passed from ic_process |
dbparms |
taken from settings object, passed from ic_process |
outfolder |
passed from ic_process, location where to store files |
overwrite |
DEFAULT = FALSE |
input_veg |
passed from input object in ic_process |
... |
Additional parameters |
results object to be passed back to get.veg.module
Istem Fer and Alexis Helgeson
extract.stringCode
extract.stringCode(x, extractor = from.TreeCode)extract.stringCode(x, extractor = from.TreeCode)
x |
string to decode |
extractor |
function to apply |
A dataset of fertilizer and organic matter addition types and their nitrogen and carbon composition, based on the SWAT model's 'fertilizer.frt' table and DayCent model defaults for organic matter C:N ratio parameters.
fertilizer_composition_datafertilizer_composition_data
A tibble with one row per fertilizer type and the following columns:
character. Short identifier from SWAT (e.g., "urea", "manure").
character. Longer description of the fertilizer or manure type.
numeric. Fraction of total nitrogen in mineral form.
numeric. Fraction of fertilizer by mass that is ammonium-n (NH-N).
numeric. Fraction of fertilizer by mass that is nitrate-N (NO-N).
Computed as fraction_mineral_n - fraction_nh3_n.
numeric. Fraction of organic matter that is nitrogen.
numeric. Fraction of mass that is carbon.
numeric. Carbon-to-nitrogen ratio for organic matter.
Assigned based on DayCent organic matter parameterterizations.
This table is based on SWAT model's fertilizer.frt file, and uses
C:N ratios (cn_ratio) from DayCent model default parameter files.
fraction_nh3_n and fraction_no3_n represent the fraction of
fertilizer by mass that is ammonium-N and nitrate-N, respectively. This is different from
the SWAT model's definition of fraction_nh3_n as a fraction of the total mineral N.
https://github.com/swat-model/swatplus
DayCent model default parameter file: 'omad.100' obtained from the Soil Carbon Solutions Center, https://www.soilcarbonsolutionscenter.com
Create pss/css files based on data in the fia database
fia.to.psscss( settings, lat = as.numeric(settings$run$site$lat), lon = as.numeric(settings$run$site$lon), year = lubridate::year(settings$run$start.date), gridres = 0.075, min.year = year - 5, max.year = year + 5, overwrite = FALSE )fia.to.psscss( settings, lat = as.numeric(settings$run$site$lat), lon = as.numeric(settings$run$site$lon), year = lubridate::year(settings$run$start.date), gridres = 0.075, min.year = year - 5, max.year = year + 5, overwrite = FALSE )
settings |
PEcAn settings object |
lat, lon
|
site location in decimal degrees. Defults to values passed in 'settings'. |
year |
defaults to year of start date passed in settings |
gridres |
grid resolution in degrees |
min.year, max.year
|
limits on years of FIA data to look for |
overwrite |
logical: regenerate files already in the database? |
modified settings, invisibly
Mike Dietze, Rob Kooper, Ryan Kelly
This function is for formatting purposes. It simply inserts the doi or id that the user wishes to query into Solr format so that it is compatible with the dataoneR query functionality in the PEcAn function
format_identifier(id)format_identifier(id)
id |
the doi or other identifier linked to the package in DataONE |
returns the id in the proper format for querying the DataONE Federation (using solrQuery syntax)
Liam P Burke, [email protected]
from.TreeCode
from.TreeCode(x)from.TreeCode(x)
x |
string to decode |
Generates ensemble members for soil carbon at specified depth layer. Uses site-specific uncertainty when available; otherwise integrates over coefficient of variation distributions fit to population data. Samples are drawn from gamma distributions to ensure positive, right-skewed values appropriate for soil carbon estimates.
generate_soilgrids_ensemble( processed_data, site_id, size, depth_layer, verbose = FALSE )generate_soilgrids_ensemble( processed_data, site_id, size, depth_layer, verbose = FALSE )
processed_data |
Output from preprocess_soilgrids_data() |
site_id |
Target site ID |
size |
Number of ensemble members to generate |
depth_layer |
Depth layer ("0-30cm" or "0-200cm") |
verbose |
Logical, print detailed progress information |
Numeric vector of soil carbon values including uncertainty, length equal to size.
Efficiently extract unique event IDs from parquet files
get_event_ensemble_ids(event_paths, parquet_dir = NULL)get_event_ensemble_ids(event_paths, parquet_dir = NULL)
event_paths |
(character) Named character vector of paths to PEcAn standard event parquet files. Names correspond to event types; e.g., 'c(leafon = "/path/to/leaf_on.parquet")'. If not names are provided, they are deduced from the file name (stripping the '.parquet' extension). Folders containing parquet files are also supported. |
parquet_dir |
Alternative way to pass 'event_paths' by just specifying a directory of PEcAn standard event files. Each file or folder must be named '<event_type>.parquet' (e.g., 'irrigation.parquet/', 'leafon.parquet'). |
Named list of unique ensemble IDs for each event type. Names correspond to event types.
Locates data in DataONE and returns the resource_map or a message indicating that there is no corresponding resource_map for the given id
get_resource_map(id, CNode = "PROD")get_resource_map(id, CNode = "PROD")
id |
the doi or other identifier linked to the package in DataONE |
CNode |
default is "PROD" |
return the resource_map or a message indicating that there is no corresponding resource_map for the given id
Load/extract + match species module
get_veg_module( input_veg, outfolder, start_date, end_date, dbparms, new_site, host, machine_host, overwrite )get_veg_module( input_veg, outfolder, start_date, end_date, dbparms, new_site, host, machine_host, overwrite )
input_veg |
list, this is a sublist of settings$run$inputs that has info about source, id, metadata of the requested IC file |
outfolder |
path to where the processed files will be written |
start_date |
date in "YYYY-MM-DD" format, in case of source==FIA it's the settings$run$start.date, otherwise start_date of the IC file in DB |
end_date |
date in "YYYY-MM-DD" format, in case of source==FIA it's the settings$run$end.date, otherwise end_date of the IC file in DB |
dbparms |
list, settings$database info reqired for opening a connection to DB |
new_site |
data frame, id/lat/lon/name info about the site |
host |
list, host info as in settings$host, host$name forced to be "localhost" upstream |
machine_host |
local machine hostname, e.g. "pecan2.bu.edu" |
overwrite |
logical flag for convert_input |
Istem Fer
Function to extract attribute information from vector or raster data layer.
get.attributes(file, coords)get.attributes(file, coords)
file |
vector or raster layer |
coords |
vector containin xmin,ymin,xmax,ymax defing the bounding box for subset |
Shawn P. Serbin
## Not run: file <- Sys.glob(file.path(R.home(), 'library', 'PEcAn.data.land','data','*.kml')) out <- get.attributes(file=file,coords=c(-95,42,-84,47)) print(out) ## End(Not run)## Not run: file <- Sys.glob(file.path(R.home(), 'library', 'PEcAn.data.land','data','*.kml')) out <- get.attributes(file=file,coords=c(-95,42,-84,47)) print(out) ## End(Not run)
Get Soil
get.soil(lat, lon, soil.nc = soil.nc)get.soil(lat, lon, soil.nc = soil.nc)
lat |
latitude |
lon |
longitude |
soil.nc |
netCDFe file with soil data |
usda soil class
David LeBauer
This function queries the gSSURGO database for a series of map unit keys
gSSURGO.Query( mukeys, fields = c("chorizon.sandtotal_r", "chorizon.silttotal_r", "chorizon.claytotal_r") )gSSURGO.Query( mukeys, fields = c("chorizon.sandtotal_r", "chorizon.silttotal_r", "chorizon.claytotal_r") )
mukeys |
map unit key from gssurgo |
fields |
a character vector of the fields to be extracted. See details and the default argument to find out how to define fields. |
This function queries the NRCS gSSURGO database using map unit keys (mukeys).
Available tables: mapunit, component, muaggatt, chorizon, and chfrags.
Field definitions: Fields must be specified with their associated table name.
For example, total sand content is stored in the chorizon table and must be
requested as chorizon.sandtotal_(r|l|h), where:
r = representative value
l = low value
h = high value
Commonly queried fields and units (see NRCS gSSURGO "Tables and Columns Report" for full list):
| Field | Description | Units |
chorizon.cec7_r |
Cation exchange capacity at pH 7 | cmol(+)/kg |
chorizon.sandtotal_r |
Total sand (<2 mm fraction) | % |
chorizon.silttotal_r |
Total silt (<2 mm fraction) | % |
chorizon.claytotal_r |
Total clay (<0.002 mm fraction) | % |
chorizon.om_r |
Organic matter (<2 mm soil) | % |
chorizon.hzdept_r |
Horizon top depth | cm |
chfrags.fragvol_r |
Rock fragments | % (by volume) |
chorizon.dbthirdbar_r |
Bulk density at field capacity | g/cm3 |
chorizon.ph1to1h2o_r |
Soil pH (1:1 H2O) | pH (unitless) |
chorizon.cokey |
Component key (identifier) | - |
chorizon.chkey |
Horizon key (identifier) | - |
API stability: The NRCS occasionally modifies the API schema. If queries fail, adjustments may be required here to align with the updated structure.
Full documentation of available tables and their relationships is provided in the gSSURGO documentation.
a dataframe with soil properties.
Hamze Dokohaki, Akash
## Not run: PEcAn.data.land::gSSURGO.Query( mukeys = 2747727, fields = c( "chorizon.cec7_r", "chorizon.sandtotal_r", "chorizon.silttotal_r","chorizon.claytotal_r", "chorizon.om_r","chorizon.hzdept_r","chorizon.frag3to10_r", "chorizon.dbovendry_r","chorizon.ph1to1h2o_r", "chorizon.cokey","chorizon.chkey")) ## End(Not run)## Not run: PEcAn.data.land::gSSURGO.Query( mukeys = 2747727, fields = c( "chorizon.cec7_r", "chorizon.sandtotal_r", "chorizon.silttotal_r","chorizon.claytotal_r", "chorizon.om_r","chorizon.hzdept_r","chorizon.frag3to10_r", "chorizon.dbovendry_r","chorizon.ph1to1h2o_r", "chorizon.cokey","chorizon.chkey")) ## End(Not run)
Extract ISCN SOC initial conditions from existing ISCN database.
IC_ISCN_SOC(site_info, ens = 100, ecoregion.path = NULL)IC_ISCN_SOC(site_info, ens = 100, ecoregion.path = NULL)
site_info |
Bety list of site info including site_id, lon, and lat. |
ens |
ensemble number. |
ecoregion.path |
path to the directory where you store the shape files of L1 and L2 ecoregion maps. |
A data frame containing sampled SOC, each row represent each site.
Dongchen Zhang
ic_process
ic_process(settings, input, dir, overwrite = FALSE)ic_process(settings, input, dir, overwrite = FALSE)
settings |
pecan settings list |
input |
Taken from settings$run$inputs. This should include id, path, and source |
dir |
settings$database$dbfiles |
overwrite |
Default = FALSE. whether to force ic_process to proceed |
Istem Fer, Hamze Dokoohaki
Uses dataone::query from dataoneR to query DataONE. Prints result if data exists
id_resolveable(id, return_result = TRUE, CNode = "PROD")id_resolveable(id, return_result = TRUE, CNode = "PROD")
id |
the doi or other identifier linked to the package in DataONE |
return_result |
boolean that returns or suppresses result of query. defaults to TRUE. |
CNode |
CNode="PROD" |
returns message indicating wether or not the id resolves to data in the DataONE federation and information about said data.
this code fuses forest inventory data with tree growth data (tree ring or dendrometer band) for the same plots. Code is a rewrite of Clark et al 2007 Ecol Appl into JAGS
InventoryGrowthFusion( data, cov.data = NULL, time_data = NULL, n.iter = 5000, n.chunk = n.iter, n.burn = min(n.chunk, 2000), random = NULL, fixed = NULL, time_varying = NULL, burnin_plot = FALSE, save.jags = "IGF.txt", z0 = NULL, save.state = TRUE, restart = NULL )InventoryGrowthFusion( data, cov.data = NULL, time_data = NULL, n.iter = 5000, n.chunk = n.iter, n.burn = min(n.chunk, 2000), random = NULL, fixed = NULL, time_varying = NULL, burnin_plot = FALSE, save.jags = "IGF.txt", z0 = NULL, save.state = TRUE, restart = NULL )
data |
list of data inputs |
cov.data |
covariate data |
time_data |
required if time_varying is provided |
n.iter |
total number of iterations across all chunks |
n.chunk |
number of MCMC steps to evaluate at a time. Will only return LAST. If restarting, second number in vector is chunk to start from |
n.burn |
number of steps to automatically discard as burn-in |
random |
whether or not to include random effects |
fixed |
formula for fixed effects |
time_varying |
formula for time-varying effects |
burnin_plot |
logical: display a plot of the burnin steps? |
save.jags |
logical: Save the generated JAGS script? |
z0 |
initial conditions for state variable |
save.state |
whether or not to include inferred DBH in output (can be large). Enter numeric value to save.state periodically (in terms of n.chunk) |
restart |
final mcmc.list from previous execution. NULL for new run. TRUE to save final state for new run. |
an mcmc.list object
Requires JAGS
InventoryGrowthFusionDiagnostics
InventoryGrowthFusionDiagnostics(jags.out, combined = NULL)InventoryGrowthFusionDiagnostics(jags.out, combined = NULL)
jags.out |
output mcmc.list from InventoryGrowthFusion |
combined |
data output from matchInventoryRings |
Michael Dietze
Contains 200 ensemble SOC data from 43 level 2 eco-regions across North America. Variable include SOC densities in g/cm2.
iscn_sociscn_soc
## 'iscn_soc' A data frame with 200 rows and 43 columns:
1 to 200 ensemble members
43 level 2 ecoregion codes across North America
https://iscn.fluxdata.org/wp-content/uploads/sites/23/2019/05/ISCN_ALL_DATA_DATASET_1-1.xlsx
LandIQ land-use class and subclass labels used for crop mapping.
landiq_crop_mapping_codeslandiq_crop_mapping_codes
## 'landiq_crop_mapping_codes' A data frame with 203 rows and 4 columns:
LandIQ class code.
LandIQ class name.
LandIQ subclass code.
LandIQ subclass name.
California Department of Water Resources. (2023). Statewide Crop Mapping—California Natural Resources Agency Open Data. Metadata retrieved from https://data.cnra.ca.gov/dataset/statewide-crop-mapping and manually extracted into 'data-raw/landiq_crop_mapping_codes.tsv'.
uses 'PEcAn.benchmark::load_data()' to get veg data
load_veg( new_site, start_date, end_date, source_id, source, icmeta = NULL, format_name = NULL, machine_host, dbparms, outfolder, overwrite = FALSE, ... )load_veg( new_site, start_date, end_date, source_id, source, icmeta = NULL, format_name = NULL, machine_host, dbparms, outfolder, overwrite = FALSE, ... )
new_site |
list passed to 'load_data' |
start_date, end_date
|
date range to look up |
source_id |
input id to look up in DB |
source |
name of data source (used in file naming) |
icmeta |
metadata for initial conditions |
format_name |
file format to look for |
machine_host |
hostname of machine where the data lives |
dbparms |
parameters to use when opening connection to database |
outfolder |
path to write results |
overwrite |
Logical: replace existing files? NOTE: Currently ignored! |
... |
Additional arguments, currently ignored |
Istem Fer
Returns properties of organic amendment materials including carbon and nitrogen content, C:N ratio, and plant-available nitrogen (PAN).
look_up_ca_compost_amendment( material, n_class = NULL, aggregate = c("none", "mean") )look_up_ca_compost_amendment( material, n_class = NULL, aggregate = c("none", "mean") )
material |
Character string. Amendment material to look up. |
n_class |
Optional, one of "LOWER" or "HIGHER". Filter by N class. |
aggregate |
Character, one of "none" (default) or "mean". If "mean", rows for the same material are averaged into a single row. |
Matching is case-insensitive. Exact matches are returned directly. If no exact match is found, partial matching suggests possible materials.
Some materials have multiple rows from different sources (e.g. Cow manure, Vegetable waste). Set 'aggregate = "mean"' to collapse these into a single row per material using the mean of numeric columns.
A tibble with columns: 'material', 'cn_min', 'cn_max', 'cn_avg', 'c_pct', 'n_pct', 'pan_pct', 'n_class', 'total_c_min_g_m2', 'total_c_max_g_m2', 'total_n_min_g_m2', 'total_n_max_g_m2', 'source'. Returns an empty tibble (with a warning) if no match is found.
Eghball, B. Composting Manure and Other Organic Residues. University of Nebraska-Lincoln Extension, Publication G2222. https://extensionpubs.unl.edu/publication/g2222/na/html/view
Rynk, R. (ed.) Compost Production and Use in Sustainable Farming Systems. NC State Extension. https://content.ces.ncsu.edu/compost-production-and-use-in-sustainable-farming-systems
[look_up_fertilizer_components()] for fertilizer nutrient composition (N/C fractions) from the SWAT/DayCent database. [ca_compost_amendment] for the underlying dataset.
look_up_ca_compost_amendment("Cow manure") look_up_ca_compost_amendment("Cow manure", aggregate = "mean") look_up_ca_compost_amendment("Poultry litter", n_class = "LOWER")look_up_ca_compost_amendment("Cow manure") look_up_ca_compost_amendment("Cow manure", aggregate = "mean") look_up_ca_compost_amendment("Poultry litter", n_class = "LOWER")
Returns recommended nitrogen application rate ranges for California crops. Rates are provided in both imperial (lbs N/acre) and SI (g N/m2) units.
look_up_ca_n_rate(crop, pft_group = NULL, unit = c("g_m2", "lbs_acre"))look_up_ca_n_rate(crop, pft_group = NULL, unit = c("g_m2", "lbs_acre"))
crop |
Character string. Crop name to look up. |
pft_group |
Optional character string. Filter results to a specific plant functional type group (e.g. "row", "woody", "rice"). |
unit |
Character, one of "g_m2" (default) or "lbs_acre". Controls which columns appear as 'min_n' and 'max_n' in the output. |
Matching is case-insensitive. Exact matches are returned directly. If no exact match is found, partial matching is used to suggest possible crops and an empty data frame is returned.
A tibble with columns: 'pft_group', 'crop', 'min_n', 'max_n', 'source'. The 'min_n' and 'max_n' columns are in the requested unit. Returns an empty tibble (with warning) if no match is found.
Rosenstock, T. S., Liptzin, D., Six, J., & Tomich, T. P. (2013). Nitrogen fertilizer use in California: Assessing the data, trends and a way forward. California Agriculture, 67(1). https://escholarship.org/uc/item/5mk2q1sm
Meyer, R. D., Marcum, D. B., Orloff, S. B., & Schmierer, J. L. (2007). Alfalfa fertilization strategies. UC ANR Publication 8296.
[look_up_fertilizer_components()] for fertilizer nutrient composition (N/C fractions) from the SWAT/DayCent database. [ca_n_application_rate] for the underlying dataset.
look_up_ca_n_rate("Tomatoes, Processing") look_up_ca_n_rate("corn") look_up_ca_n_rate("wheat", unit = "lbs_acre") look_up_ca_n_rate("pistachios", pft_group = "woody")look_up_ca_n_rate("Tomatoes, Processing") look_up_ca_n_rate("corn") look_up_ca_n_rate("wheat", unit = "lbs_acre") look_up_ca_n_rate("pistachios", pft_group = "woody")
This function calculates the different forms of nitrogen (NO3-N, NH4-N, organic N) and organic carbon (C_org) in a fertilizer application.
It can determine fertilizer nitrogen and carbon content using either a lookup table based on
the SWAT model's fertilizer.frt
file, determine the fertilizer's nutrient content based on NN-PP-KK format, or use user-specified
fractions of organic nitrogen and carbon.
look_up_fertilizer_components( type, amount, fraction_organic_n = NULL, fraction_organic_c = NULL )look_up_fertilizer_components( type, amount, fraction_organic_n = NULL, fraction_organic_c = NULL )
type |
Character string specifying the type of fertilizer. Valid values include NN-PP-KK format (e.g., "45-5-10") as well as enumerated types including: "urea", "ammonium_nitrate", "compost", "manure", "dairy_fr", "beef_fr". See notes for full list of valid types. |
amount |
Numeric value specifying the amount of fertilizer applied in kg/ha. |
fraction_organic_n |
Optional numeric value specifying the fraction of the organic matter that is nitrogen. Used to define organic matter additions if not provided in the dataset. |
fraction_organic_c |
Optional numeric value specifying the fraction of the organic matter that is carbon. Used to define organic matter additions if not provided in the dataset. |
Consistent with assumptions in DayCent, DSSAT, and other models, urea is treated as NH3 because the transformation typically occurs within a day.
A list containing:
type: The type of fertilizer used.
NO3_N: The amount of nitrate nitrogen (NO3-N) in kg/ha.
NH4_N: The amount of ammonium nitrogen (NH4-N) in kg/ha.
N_org: The amount of organic nitrogen in kg/ha.
C_org: The amount of organic carbon in kg/ha.
The following is a list of valid fertilizer names:
Mineral fertilizers: ammonium_nitrate, anhydrous_ammonia, urea
Fresh manures: manure, beef_fr, broil_fr, dairy_fr, duck_fr, goat_fr, horse_fr, layer_fr, sheep_fr, swine_fr, trkey_fr, veal_fr
Compost: org_compost
# View all available fertilizer types unique(PEcAn.data.land::fertilizer_composition_data$name) # Calculate components for different fertilizer types look_up_fertilizer_components("urea", 200) look_up_fertilizer_components("45-00-00", 200) look_up_fertilizer_components("org_compost", 1000) look_up_fertilizer_components("dairy_fr", 500) look_up_fertilizer_components("manure", 1000, fraction_organic_n = 0.02, fraction_organic_c = 0.08)# View all available fertilizer types unique(PEcAn.data.land::fertilizer_composition_data$name) # Calculate components for different fertilizer types look_up_fertilizer_components("urea", 200) look_up_fertilizer_components("45-00-00", 200) look_up_fertilizer_components("org_compost", 1000) look_up_fertilizer_components("dairy_fr", 500) look_up_fertilizer_components("manure", 1000, fraction_organic_n = 0.02, fraction_organic_c = 0.08)
Matches BETYdb species IDs to model-specific PFTs
match_pft( bety_species_id, pfts, query = NULL, con = NULL, allow_missing = FALSE, model = NULL )match_pft( bety_species_id, pfts, query = NULL, con = NULL, allow_missing = FALSE, model = NULL )
bety_species_id |
vector of BETYdb species IDs |
pfts |
settings$pfts. List of pfts with database matching based on name |
query |
Default is NULL. query to BETY db. |
con |
database connection, if NULL use traits package |
allow_missing |
flag to indicate that settings file does not need to match exactly |
model |
Default is NULL. This is the BETY model ID for matching pfts to the correct model. |
table of BETYdb PFT IDs matched to species IDs
Mike Dietze, Istem Fer
Parses species codes in input data and matches them with the BETY species ID.
match_species_id( input_codes, format_name = "custom", bety = NULL, translation_table = NULL, ... )match_species_id( input_codes, format_name = "custom", bety = NULL, translation_table = NULL, ... )
input_codes |
Character vector of species codes |
format_name |
Species code format name (see details) |
bety |
BETY connection object |
translation_table |
Data frame with custom translation table (see details). |
... |
additional arguments, currently ignored |
format_name can be one of the following:
usdaUSDA Plants database symbol (e.g. QURU, TSCA)
fiaFIA species code
latin_nameScientific name, as "Genus species"; must match exactly and unambiguously to scientificname field in BETY
customA data frame matching BETY IDs (column name bety_species_id) to input codes (column name input_code). This data frame must be passed via the translation_table argument.
data.frame containing the following columns:
input_codeCharacter provided as input
bety_species_idBig integer species ID, unique and specific to BETY
genusGenus part of Latin name, from BETY
speciesSpecies part of Latin name, from BETY
Alexey Shiklomanov <[email protected]>, Istem Fer
## Not run: con <- PEcAn.DB::db.open(list( driver = "Postgres", dbname = 'bety', user = 'bety', password = 'bety', host = 'localhost') ) input_codes <- c('ACRU', 'PIMA', 'TSCA') format_name <- 'usda' match_species_id(input_codes = input_codes, format_name = format_name, bety = con) ## End(Not run)## Not run: con <- PEcAn.DB::db.open(list( driver = "Postgres", dbname = 'bety', user = 'bety', password = 'bety', host = 'localhost') ) input_codes <- c('ACRU', 'PIMA', 'TSCA') format_name <- 'usda' match_species_id(input_codes = input_codes, format_name = format_name, bety = con) ## End(Not run)
matchInventoryRings
matchInventoryRings( trees, rings, extractor = "TreeCode", nyears = 30, coredOnly = TRUE )matchInventoryRings( trees, rings, extractor = "TreeCode", nyears = 30, coredOnly = TRUE )
trees, rings
|
codes from which to extract IDs |
extractor |
function to call, specified without its initial 'to.' e.g. "TreeCode" calls 'to.TreeCode' |
nyears |
number of years to extract |
coredOnly |
logical: Only include trees with data from 2000? |
Convert a matric potential to a soil moisture
mpot2smoist( mpot, soil_water_potential_at_saturation, soil_hydraulic_b, volume_fraction_of_water_in_soil_at_saturation )mpot2smoist( mpot, soil_water_potential_at_saturation, soil_hydraulic_b, volume_fraction_of_water_in_soil_at_saturation )
mpot |
water potential (cm H2O) |
soil_water_potential_at_saturation |
water potential when soil is saturated (cm H2O) |
soil_hydraulic_b |
pore-size distribution parameter for Campbell (1974) water content model |
volume_fraction_of_water_in_soil_at_saturation |
VSWC when soil is saturated (numeric in range 0-1) |
volumetric soil water content
Convert MSLSP phenology data to tidy canopy cover
mslsp_to_canopycover(mslsp_path, parcel_ids = NULL, years = NULL)mslsp_to_canopycover(mslsp_path, parcel_ids = NULL, years = NULL)
mslsp_path |
Path to directory containing MSLSP outputs (in parquet format) |
parcel_ids |
Vector of parcel IDs for filtering. If 'NULL', use all parcels. |
years |
Vector of years for filtering. If 'NULL', use all years. |
'data.frame' of 'parcel_id', 'year', 'season', 'date', and 'canopy_cover' (fraction). 'date' is a sequence from the MSLSP greenness onset (growing season start) to the greenness minimum (growing season end). 'canopy_cover' is the fractional canpoy cover (0 to 1), suitable for ingest into [eto_to_etc_bism()] in "canopy cover mode".
Maps the fractional NDTI drop produced by the CCMMF NDTI pipeline
to tillage_eff_0to1 for use in the PEcAn events JSON schema
and written to SIPNET events.in by
write.events.SIPNET.
ndti_to_sipnet_tillage(delta_ndti, no_till_threshold = 0.3, slope = 2.5)ndti_to_sipnet_tillage(delta_ndti, no_till_threshold = 0.3, slope = 2.5)
delta_ndti |
numeric vector. Fractional NDTI drop in \[0, 1\],
computed as |
no_till_threshold |
numeric scalar. |
slope |
numeric scalar. Slope of the linear response above
|
NDTI drops after tillage as residue is incorporated into soil. The fractional drop over the fallow season is a proxy for tillage intensity. Default thresholds are from Dietze & Kanee (pers. comm.). The slope parameter can be calibrated once field data (SOC or soil respiration) are available.
numeric vector of tillage_eff_0to1 values, same
length as delta_ndti, clamped to \[0, 1\].
NA inputs propagate to NA outputs.
Daughtry, C.S.T., Hunt, E.R., Doraiswamy, P.C., McMurtrey, J.E. (2005). Remote sensing the spatial distribution of crop residues. Agronomy Journal, 97(3), 864–871. doi:10.2134/agronj2004.0291
ndti_to_sipnet_tillage(c(0.25, 0.50, 0.80)) # Custom slope for sensitivity analysis ndti_to_sipnet_tillage(c(0.25, 0.50, 0.80), slope = 2.0)ndti_to_sipnet_tillage(c(0.25, 0.50, 0.80)) # Custom slope for sensitivity analysis ndti_to_sipnet_tillage(c(0.25, 0.50, 0.80), slope = 2.0)
netcdf.writer.BADAM
netcdf.writer.BADM(lat, long, siteid, outdir, ens)netcdf.writer.BADM(lat, long, siteid, outdir, ens)
lat |
numeric latitude |
long |
numeric longitude |
siteid |
site id as a string |
outdir |
output dir which you want to store the IC netcdf file |
ens |
ensemble members, passed on to 'pool_ic_list2netcdf' |
a dataframe with file, host, mimetype, formatname, startdate, enddate and dbfile.name columns
Converts organic matter content to soil organic carbon using the Van Bemmelen factor (1.724).
om2soc(om_percent)om2soc(om_percent)
om_percent |
organic matter percentage (0-100) |
soil organic carbon percentage (0-100)
Akash
Parse responses from the mukey WFS service
parse_mukey_response(resp)parse_mukey_response(resp)
resp |
'httr2' response object from SSURGO mukey WFS API |
character vector of mukeys
parse.MatrixNames
parse.MatrixNames(w, pre = "x", numeric = FALSE)parse.MatrixNames(w, pre = "x", numeric = FALSE)
w |
mcmc object containing matrix outputs |
pre |
prefix (variable name) for the matrix variable to be extracted |
numeric |
boolean, whether to coerce class to numeric |
matrix
Michael Dietze
Given a vector of root size thresholds (lower bound of each) and a vector of corresponding root carbon values, partition_roots checks if the input can be partitioned along the .002 m threshold between fine and coarse roots and returns a list containing the summed values for fine and coarse. If there are fewer than two thresholds or none within .0005 m of .002 m, returns NULL. Meant to be used in conjunction with standard variable root_carbon_content with rtsize dimension, extracted from netcdf.
partition_roots(roots, rtsize)partition_roots(roots, rtsize)
roots |
vector of root carbon values in kg C m-2 |
rtsize |
vector of lower bounds of root size class thresholds in m, length greater than one and equal to roots. Must contain threshold within .0005 m of .002 m |
list containing summed fine root and coarse root carbon (2 values)
Anne Thomas
convert composite ring & census data into AGB
plot2AGB(combined, out, outfolder, allom.stats, unit.conv = 0.02)plot2AGB(combined, out, outfolder, allom.stats, unit.conv = 0.02)
combined |
data frame merging plot inventory and tree ring data |
out |
MCMC samples for diameter (sample x tree) |
outfolder |
output folder for graphs & data |
allom.stats |
Allometry statistics computed by 'AllomAve' |
unit.conv |
area conversion from sum(kg/tree) to kg/area |
Mike Dietze [email protected]
Converts input list containing standard dimensions and variables (named values) for initial conditions to a netcdf file, input to pool-based models.
pool_ic_list2netcdf(input, outdir, siteid, ens = NA)pool_ic_list2netcdf(input, outdir, siteid, ens = NA)
input |
list with two elements: list of netcdf dimensions (dims, with named values) and list of variables (vals, with named values) |
outdir |
directory to write netcdf file |
siteid |
site id |
ens |
Default is NA. Ensemble members. |
Anne Thomas
Converts netcdf containing standard dimensions and variables for pool-based initial conditions, created by pool_ic_list2netcdf, back into list format
pool_ic_netcdf2list(nc.path)pool_ic_netcdf2list(nc.path)
nc.path |
path to netcdf file containing standard dimensions and variables |
list with two elements: list of netcdf dimensions (dims, with named values) and list of variables (vals, with named values)
Anne Thomas
Calculates pools from given initial condition values, deriving complements where necessary/possible if given TotLivBiomass
prepare_pools(nc.path, constants = NULL)prepare_pools(nc.path, constants = NULL)
nc.path |
path to netcdf file containing standard dimensions and variables; currently supports these variables: TotLivBiom, leaf_carbon_content, LAI, AbvGrndWood, root_carbon_content, fine_root_carbon_content, coarse_root_carbon_content, litter_carbon_content, soil_organic_carbon_content, soil_carbon_content, wood_debris_carbon_content |
constants |
list of constants; must include SLA in m2 / kg C if providing LAI for leaf carbon |
list of pool values in kg C / m2 with generic names
Anne Thomas
Preprocess SoilGrids data for ensemble generation
preprocess_soilgrids_data(soil_data, depth_layers, verbose = FALSE)preprocess_soilgrids_data(soil_data, depth_layers, verbose = FALSE)
soil_data |
Dataframe with SoilGrids soil carbon data |
depth_layers |
Character vector of depth layers to process (e.g., c("0-30cm", "0-200cm")) |
verbose |
Logical, print detailed progress information |
List containing processed data and CV distributions for requested depths
Match species to PFTs + veg2model module
put_veg_module( getveg.id, dbparms, input_veg, pfts, outfolder, n.ensemble, dir, model, start_date, end_date, new_site, host, overwrite )put_veg_module( getveg.id, dbparms, input_veg, pfts, outfolder, n.ensemble, dir, model, start_date, end_date, new_site, host, overwrite )
getveg.id |
list, input.id and dbfile.id of the IC file in intermediate pecan standard |
dbparms |
list, settings$database info reqired for opening a connection to DB |
input_veg |
list, this is a sublist of settings$run$inputs that has info about source, id, metadata of the requested IC file |
pfts |
list, same as settings$pfts |
outfolder |
path to where the processed files will be written |
n.ensemble |
integer, ensemble member number |
dir |
dir path to dbfiles on local machine |
model |
model name, e.g. "ED2" |
start_date |
date in "YYYY-MM-DD" format, in case of source==FIA it's the settings$run$start.date, otherwise start_date of the IC file in DB |
end_date |
date in "YYYY-MM-DD" format, in case of source==FIA it's the settings$run$end.date, otherwise end_date of the IC file in DB |
new_site |
data frame, id/lat/lon/name info about the site |
host |
list, host info as in settings$host, host$name forced to be "localhost" upstream |
overwrite |
logical flag for convert_input |
Istem Fer
wrapper around read.tucson that loads a whole directory of tree ring files and calls a 'clean' function that removes redundant records (WinDendro can sometimes create duplicate records when editing)
Read_Tucson(folder)Read_Tucson(folder)
folder |
path to read files from. Will read all files at this path matching "TXT", "rwl", or "rw" |
This function returns a dataframe of plant biomass, root and soil carbon for a set of lat and long coordinates. This function first finds the level1 and level2 ecoregions for the given coordinates, and then tries to filter BADM database for those eco-regions. If no data found in the BADM database for the given lat/longs eco-regions, then all the data in the database will be used to return the initial condition. All the variables are also converted to kg/m^2.
Read.IC.info.BADM(lat, long)Read.IC.info.BADM(lat, long)
lat |
numeric latitude |
long |
numeric longitude |
a dataframe with 7 columns of Site, Variable, Date, Organ, AGB, soil_organic_carbon_content, litter_carbon_content. Variable in the return object refers to what this value was called inside BADM database.
badm_test <- Read.IC.info.BADM(45.805925,-90.07961)badm_test <- Read.IC.info.BADM(45.805925,-90.07961)
sample_ic
sample_ic( in.path, in.name, start_date, end_date, outfolder, n.ensemble, machine_host, source, bin_var = "DBH", bin_size = 10, bin_herb_soil = TRUE, ... )sample_ic( in.path, in.name, start_date, end_date, outfolder, n.ensemble, machine_host, source, bin_var = "DBH", bin_size = 10, bin_herb_soil = TRUE, ... )
in.path |
path to folder of the file to be sampled |
in.name |
file name of the file to be sampled |
start_date |
date in "YYYY-MM-DD" format |
end_date |
date in "YYYY-MM-DD" format |
outfolder |
dir path, whete to write the file |
n.ensemble |
integer, ensemble member number |
machine_host |
localhost name, e.g. "pecan2.bu.edu" |
source |
string to appear in file names, e.g. "PalEON" |
bin_var |
variable you would like to sample by, DEFAULT is DBH |
bin_size |
bin size for sampling, DEFAULT is 10 |
bin_herb_soil |
if we want to use bin size for both herb and soil sampling |
... |
Other inputs |
Istem Fer
This function determines the soil class number based on the fraction of sand, clay, and silt
sclass(sandfrac, clayfrac)sclass(sandfrac, clayfrac)
sandfrac, clayfrac
|
numeric vectors with values in range 0 to 1. Silt fraction is assumed to be the difference between (sand+clay) and 1 |
vector of integers identifying textural class of each input layer. Possible values are 1 through 17; NB these are NOT the same class boundaries as the 12 USDA soil texture classes.
sclass(0.3,0.3)sclass(0.3,0.3)
Convert ESRI shapefile (*.shp) to keyhole markup language (KML) file format
shp2kml( dir, ext, kmz = FALSE, proj4 = NULL, color = NULL, NameField = NULL, out.dir = NULL )shp2kml( dir, ext, kmz = FALSE, proj4 = NULL, color = NULL, NameField = NULL, out.dir = NULL )
dir |
Directory of GIS shapefiles to convert to kml/kmz |
ext |
File extension for files to convert to kml/kmz. Defaults to ESRI shapefile, '.shp'. [Place holder for other potential vector files to conver to kml] |
kmz |
TRUE/FALSE. Option to write out file as a compressed kml. Requires zip utility |
proj4 |
OPTIONAL. Define output proj4 projection string. If set, input vector will be reprojected to desired projection. Not yet implemented. |
color |
OPTIONAL. Fill color for output kml/kmz file |
NameField |
OPTIONAL. Define names for individual features in KML/KMZ file |
out.dir |
OPTIONAL. Output directory for converted files |
Shawn P. Serbin
## Not run: dir <- Sys.glob(file.path(R.home(), 'library', 'PEcAn.data.land','data')) out.dir <- path.expand('~/temp') shp2kml(dir,'.shp',kmz=FALSE,NameField='STATE',out.dir=out.dir) system(paste('rm -r ',out.dir)) ## End(Not run)## Not run: dir <- Sys.glob(file.path(R.home(), 'library', 'PEcAn.data.land','data')) out.dir <- path.expand('~/temp') shp2kml(dir,'.shp',kmz=FALSE,NameField='STATE',out.dir=out.dir) system(paste('rm -r ',out.dir)) ## End(Not run)
Convert soil organic carbon concentration to organic carbon stock
soc2ocs(soc_percent, bulk_density, thickness, coarse_fraction = 0)soc2ocs(soc_percent, bulk_density, thickness, coarse_fraction = 0)
soc_percent |
soil organic carbon concentration (percent, 0-100) |
bulk_density |
bulk density (g/cm3) |
thickness |
layer thickness (cm) |
coarse_fraction |
coarse fragment volume fraction (0-1, default = 0) |
organic carbon stock (kg/m2)
Akash
soc2ocs(2.5, 1.3, 30, 0.15) # Multiple soil layers soc_pct <- c(3.2, 2.1, 1.8) bd_g_cm3 <- c(1.2, 1.4, 1.5) thickness_cm <- c(15, 15, 30) coarse_fraction <- c(0.10, 0.20, 0.25) soc2ocs(soc_pct, bd_g_cm3, thickness_cm, coarse_fraction)soc2ocs(2.5, 1.3, 30, 0.15) # Multiple soil layers soc_pct <- c(3.2, 2.1, 1.8) bd_g_cm3 <- c(1.2, 1.4, 1.5) thickness_cm <- c(15, 15, 30) coarse_fraction <- c(0.10, 0.20, 0.25) soc2ocs(soc_pct, bd_g_cm3, thickness_cm, coarse_fraction)
Default parameters for calculating soil properties from sand & clay content
soil_classsoil_class
## 'soil_class' A list with 26 entries:
thermal conductivity, W m^-1 K^-1
heat capacity, J m^-3 K^-1
relative conductivity factor
hydraulic conductance at field capacity, mm day^-1
gravity acceleration, m s^-2
Abbreviations for each of 18 soil texture classes, e.g. "SiL", "LSa"
Names for 18 soil texture classes, e.g. "Sand", "Silty clay"
soil water potential when air-dry, MPa
soil water potential at critical water content, MPa
soil water potential at wilting point, MPa
list of 18 lists, each giving minimum and maximum sand/silt/clay contents for a soil texture class
list of 18 lists, each giving corner points in the soil texture triangle for a soil texture class
data frame with 13 rows and 21 columns, giving default parameter values for 13 named soil textures
critical water content (fractional soil moisture at which plants start dropping leaves), m^3 m^-3
default volume fraction of sand in each of 18 soil texture classes
default volume fraction of clay in each of 18 soil texture classes
The hydraulic parameters are derived from Cosby et al 1984, "A Statistical Exploration of the Relationships of Soil Moisture Characteristics to the Physical Properties of Soils", Water Resources Research 20(6): 682-690. This implementation comes from one provided by the ED2 model, plus 'texture.csv' from a source not recorded. Package 'PEcAn.linkages' contains an identical texture.csv, also with no obvious source label. See also comments in soil_utils.R
Estimate soil parameters from texture class or sand/silt/clay
soil_params( soil_type = NULL, sand = NULL, silt = NULL, clay = NULL, bulk = NULL )soil_params( soil_type = NULL, sand = NULL, silt = NULL, clay = NULL, bulk = NULL )
soil_type |
USDA Soil Class. See Details |
sand |
percent sand |
silt |
percent silt |
clay |
percent clay |
bulk |
soil bulk density (optional, kg m-3) |
* Specify _either_ soil_type or sand/silt/clay. soil_type will be ignored if sand/silt/clay is provided * If only 2 out of sand/silt/clay are provided, it will be assumed they sum to 100 * Valid soil class options: "Sand","Loamy sand","Sandy loam","Silt loam","Loam", "Sandy clay loam","Silty clay loam","Clayey loam", "Sandy clay","Silty clay","Clay","Peat","Bedrock", "Silt","Heavy clay","Clayey sand","Clayey silt" * Based on ED2/R-utils/soilutils.r * Hydraulics based on Cosby et al 1984, using table 4 and equation 1 (which is incorrect it should be saturated moisture potential over moisture potential)
list of soil hydraulic and thermal parameters
sand <- c(0.3, 0.4, 0.5) clay <- c(0.3, 0.3, 0.3) soil_params(sand=sand,clay=clay)sand <- c(0.3, 0.4, 0.5) clay <- c(0.3, 0.3, 0.3) soil_params(sand=sand,clay=clay)
A function to estimate the soil parameters based on SoilGrids soil texture data and write the parameter paths into settings
soil_params_ensemble_soilgrids( settings, sand, clay, silt, outdir, write_into_settings = TRUE )soil_params_ensemble_soilgrids( settings, sand, clay, silt, outdir, write_into_settings = TRUE )
settings |
A multi-site settings |
sand, clay, silt
|
Data frames containing fraction in percentage from SoilGrids250m v2.0, each with columns "Depth", "Quantile", "Siteid", and "Value" |
outdir |
Provide the path to store the parameter files |
write_into_settings |
Whether to write the path of parameter file into the setting. The default is TRUE |
Ensemble soil parameter files defined in outdir and file paths in xml file
Qianyu Li
## Not run: outdir <- "/projectnb/dietzelab/Cherry/SoilGrids_texture/39NEON" # each file contains percent salt, silt, or clay sand <- readRDS("/path/to/SoilGrids_texture/sand_percent.rds") clay <- readRDS("/path/to/SoilGrids_texture/clay_percent.rds") silt <- readRDS("/path/to/SoilGrids_texture/silt_percent.rds") settings <-read.settings("/path/to/pecan_monthly_SDA_soilwater.xml") soil_params_ensemble_soilgrids(settings,sand,clay,silt,outdir) ## End(Not run)## Not run: outdir <- "/projectnb/dietzelab/Cherry/SoilGrids_texture/39NEON" # each file contains percent salt, silt, or clay sand <- readRDS("/path/to/SoilGrids_texture/sand_percent.rds") clay <- readRDS("/path/to/SoilGrids_texture/clay_percent.rds") silt <- readRDS("/path/to/SoilGrids_texture/silt_percent.rds") settings <-read.settings("/path/to/pecan_monthly_SDA_soilwater.xml") soil_params_ensemble_soilgrids(settings,sand,clay,silt,outdir) ## End(Not run)
Module for managing soil texture extraction
soil_process(settings, input, dbfiles, overwrite = FALSE, run.local = TRUE)soil_process(settings, input, dbfiles, overwrite = FALSE, run.local = TRUE)
settings |
PEcAn settings list |
input |
PEcAn input list |
dbfiles |
directory to write database files |
overwrite |
overwrite previous results (boolean) |
run.local |
logical: Run only on the current machine? If FALSE, runs on 'settings$host' (which might turn out to be the current machine) |
path to soil file
Given SSURGO names for soil properties, looks up their standard units. Note that names must match exactly.
soil.units(varname = NA)soil.units(varname = NA)
varname |
character vector. See details |
Supported variables are:
soil_depth
soil_cec
fraction_of_clay_in_soil
fraction_of_sand_in_soil
fraction_of_silt_in_soil
fraction_of_gravel_in_soil
volume_fraction_of_water_in_soil_at_saturation
volume_fraction_of_water_in_soil_at_field_capacity
volume_fraction_of_condensed_water_in_dry_soil
volume_fraction_of_condensed_water_in_soil_at_wilting_point
soilC
soil_ph
soil_bulk_density
soil_type
soil_hydraulic_b
soil_water_potential_at_saturation
soil_hydraulic_conductivity_at_saturation
thcond0
thcond1
thcond2
thcond3
soil_thermal_conductivity
soil_thermal_conductivity_at_saturation
soil_thermal_capacity
soil_albedo
slpotwp
slpotcp
slcpd
slden
soil_organic_carbon_stock
character matrix with columns var and unit
soil.units("soil_albedo")soil.units("soil_albedo")
A table of standard names and units can be displayed by running soil.units() without any arguements
soil2netcdf(soil.data, new.file)soil2netcdf(soil.data, new.file)
soil.data |
List of soil variables in standard names & units. Minimum is soil_depth and two of [sand, silt, clay]. Bulk density encouraged. |
new.file |
filename (including path) for output |
soil_params is called internally to estimate additional soil physical parameters from sand/silt/clay & bulk density. Will not overwrite any provided values
Need to expand to alternatively take soil_type (texture class) as an input
On output, soil_type named class is converted to a number because netCDF is a pain for storing strings. Conversion back can be done by load(system.file ("data/soil_class.RData",package = "PEcAn.data.land")) and then soil.name[soil_n]
none
## Not run: soil.data <- list( fraction_of_sand_in_soil = c(0.3,0.4,0.5), fraction_of_clay_in_soil = c(0.3,0.3,0.3), soil_depth = c(0.2,0.5,1.0) ) soil2netcdf(soil.data,"soil.nc") ## End(Not run)## Not run: soil.data <- list( fraction_of_sand_in_soil = c(0.3,0.4,0.5), fraction_of_clay_in_soil = c(0.3,0.3,0.3), soil_depth = c(0.2,0.5,1.0) ) soil2netcdf(soil.data,"soil.nc") ## End(Not run)
Functions for generating soil carbon IC files from SoilGrids250m data
soilgrids_ic_process( settings, dir, depth = c(0.3, 2), overwrite = FALSE, verbose = FALSE )soilgrids_ic_process( settings, dir, depth = c(0.3, 2), overwrite = FALSE, verbose = FALSE )
settings |
PEcAn settings list containing site information |
dir |
Output directory for IC files |
depth |
Numeric vector of depth values in meters. Can be single value or multiple values c(0.3, 2.0). Default: c(0.3, 2.0) |
overwrite |
Overwrite existing files? (Default: FALSE) |
verbose |
Print detailed progress information? (Default: FALSE) |
This module provides functions for extracting, processing, and generating ensemble members for soil carbon initial conditions using SoilGrids data. All soil carbon values are in kg/m2.
Process SoilGrids data for initial conditions
List of paths to generated IC files, organized by site ID
Akash
## Not run: # Process both depths (default) settings <- PEcAn.settings::read.settings("pecan.xml") output_dir <- withr::local_tempdir() ic_files <- soilgrids_ic_process(settings, dir = output_dir) # Process only 30cm depth ic_files <- soilgrids_ic_process(settings, dir = output_dir, depth = 0.3) ## End(Not run)## Not run: # Process both depths (default) settings <- PEcAn.settings::read.settings("pecan.xml") output_dir <- withr::local_tempdir() ic_files <- soilgrids_ic_process(settings, dir = output_dir) # Process only 30cm depth ic_files <- soilgrids_ic_process(settings, dir = output_dir, depth = 0.3) ## End(Not run)
soilgrids_soilC_extract function A function to extract total soil organic carbon for a single or group of lat/long locationsbased on user-defined site location from SoilGrids250m version 2.0 : https://soilgrids.org
soilgrids_soilC_extract(site_info, outdir = NULL, verbose = TRUE)soilgrids_soilC_extract(site_info, outdir = NULL, verbose = TRUE)
site_info |
A dataframe of site info containing the BETYdb site ID, site name, latitude, and longitude, e.g. (site_id, site_name, lat, lon) |
outdir |
Optional. Provide the results as a CSV file (soilgrids_soilC_data.csv) |
verbose |
Provide progress feedback to the terminal? TRUE/FALSE |
a dataframe containing the total soil carbon values and the corresponding standard deviation values (uncertainties) for each location Output column names are c("Site_ID","Site_Name","Latitude","Longitude", "Total_soilC","Std_soilC")
Qianyu Li, Shawn P. Serbin
## Not run: # Example 1 - using the modex.bnl.gov BETYdb and site IDs to extract data db <- 'betydb' host_db <- 'modex.bnl.gov' db_port <- '5432' db_user <- 'bety' db_password <- 'bety' bety <- list(user='bety', password='bety', host=host_db, dbname='betydb', driver=RPostgres::Postgres(),write=FALSE) con <- DBI::dbConnect(drv=bety$driver, dbname=bety$dbname, host=bety$host, password=bety$password, user=bety$user) suppressWarnings(site_qry <- glue::glue_sql("SELECT *, ST_X(ST_CENTROID(geometry)) AS lon, ST_Y(ST_CENTROID(geometry)) AS lat FROM sites WHERE id IN ({ids*})", ids = c("676","622","678","766","764"), .con = con)) suppressWarnings(qry_results.1 <- DBI::dbSendQuery(con,site_qry)) suppressWarnings(qry_results.2 <- DBI::dbFetch(qry_results.1)) DBI::dbClearResult(qry_results.1) DBI::dbDisconnect(con) site_info <- qry_results.2 verbose <- TRUE system.time(result_soc <- PEcAn.data.land::soilgrids_soilC_extract(site_info=site_info, verbose=verbose)) result_soc ## End(Not run)## Not run: # Example 1 - using the modex.bnl.gov BETYdb and site IDs to extract data db <- 'betydb' host_db <- 'modex.bnl.gov' db_port <- '5432' db_user <- 'bety' db_password <- 'bety' bety <- list(user='bety', password='bety', host=host_db, dbname='betydb', driver=RPostgres::Postgres(),write=FALSE) con <- DBI::dbConnect(drv=bety$driver, dbname=bety$dbname, host=bety$host, password=bety$password, user=bety$user) suppressWarnings(site_qry <- glue::glue_sql("SELECT *, ST_X(ST_CENTROID(geometry)) AS lon, ST_Y(ST_CENTROID(geometry)) AS lat FROM sites WHERE id IN ({ids*})", ids = c("676","622","678","766","764"), .con = con)) suppressWarnings(qry_results.1 <- DBI::dbSendQuery(con,site_qry)) suppressWarnings(qry_results.2 <- DBI::dbFetch(qry_results.1)) DBI::dbClearResult(qry_results.1) DBI::dbDisconnect(con) site_info <- qry_results.2 verbose <- TRUE system.time(result_soc <- PEcAn.data.land::soilgrids_soilC_extract(site_info=site_info, verbose=verbose)) result_soc ## End(Not run)
Prepare Soilgrids SoilC data for the SDA workflow.
Soilgrids_SoilC_prep( site_info, start_date, end_date, time_points, outdir = NULL, export_csv = FALSE )Soilgrids_SoilC_prep( site_info, start_date, end_date, time_points, outdir = NULL, export_csv = FALSE )
site_info |
Bety list of site info including site_id, lon, and lat. |
start_date |
Start date of SDA workflow. |
end_date |
End date of SDA workflow. |
time_points |
A vector contains each time point within the start and end date. |
outdir |
Where the final CSV file will be stored. |
export_csv |
Decide if we want to export the CSV file. |
A data frame containing AGB median and sd for each site and each time step.
Dongchen Zhang
soilgrids_texture_extraction function A function to extract and save three types of soil texture data in parallel for a single or group of lat/long locations based on user-defined site location from SoilGrids250m version 2.0 : https://soilgrids.org
soilgrids_texture_extraction( data_paths, site_info, outdir = NULL, verbose = TRUE )soilgrids_texture_extraction( data_paths, site_info, outdir = NULL, verbose = TRUE )
data_paths |
A list containing the data (either virtual raster files or local file folders) and output path for all types of SoilGrids texture data e.g. data_paths <- list( list( url = "/vsicurl?max_retry=30&retry_delay=60&list_dir=no&url=https://files.isric.org/soilgrids/latest/data/sand/sand_", local = NULL, save_path = paste0(outdir, "sand_percent.rds")), list( url = "/vsicurl?max_retry=30&retry_delay=60&list_dir=no&url=https://files.isric.org/soilgrids/latest/data/clay/clay_", local = NULL, save_path = paste0(outdir, "clay_percent.rds")), list( url = "/vsicurl?max_retry=30&retry_delay=60&list_dir=no&url=https://files.isric.org/soilgrids/latest/data/silt/silt_", local = NULL, save_path = paste0(outdir, "silt_percent.rds"))) |
site_info |
A data frame of site info containing the BETYdb site ID, site name, latitude, and longitude, e.g. (site_id, lat, lon) |
outdir |
Provide the path to store the texture data file |
verbose |
Provide progress feedback to the terminal? TRUE/FALSE |
a data frame containing the soil texture data with columns "Depth", "Quantile", "Siteid", and "Value"
Qianyu Li
Maximum area for SSURGO API requests
SSURGO_API_MAX_AREA_M2SSURGO_API_MAX_AREA_M2
An object of class numeric of length 1.
These functions query the NRCS gSSURGO Web Feature Service to retrieve map unit keys based on different spatial filters.
ssurgo_mukeys_bbox(bbox) ssurgo_mukeys_point(point, distance) ssurgo_mukeys_bigbbox(bbox)ssurgo_mukeys_bbox(bbox) ssurgo_mukeys_point(point, distance) ssurgo_mukeys_bigbbox(bbox)
bbox |
Numeric vector of length 4: c(xmin, ymin, xmax, ymax) in WGS84 (EPSG:4326). Features that intersect the bounding box are returned. |
point |
Numeric vector of length 2: c(lon, lat) in WGS84 (EPSG:4326). |
distance |
Numeric. Distance in meters from the point. Use 0 for exact point intersection. |
These functions use the NRCS SDM Data Access Web Feature Service: https://sdmdataaccess.nrcs.usda.gov/SpatialFilterHelp.htm
The total extent cannot exceed 10,100,000,000 square meters (~3,900 square miles). Use 'ssurgo_mukeys_bigbbox()' for large bounding boxes.
Character vector of unique map unit keys (mukeys).
## Not run: # Bounding box query mukeys <- ssurgo_mukeys_bbox(bbox = c(-114.006, 32.1823, -113.806, 32.2823)) # Point with distance (600m radius) mukeys <- ssurgo_mukeys_point(point = c(-91.22, 38.46), distance = 600) # Large bounding box mukeys <- ssurgo_mukeys_bigbbox(bbox = c(-120, 35, -110, 45)) ## End(Not run)## Not run: # Bounding box query mukeys <- ssurgo_mukeys_bbox(bbox = c(-114.006, 32.1823, -113.806, 32.2823)) # Point with distance (600m radius) mukeys <- ssurgo_mukeys_point(point = c(-91.22, 38.46), distance = 600) # Large bounding box mukeys <- ssurgo_mukeys_bigbbox(bbox = c(-120, 35, -110, 45)) ## End(Not run)
Function to subset and clip a GIS vector or raster layer by a bounding box or clip/subset layer (e.g. shapefile/KML)
subset_layer( file, coords = NULL, sub.layer = NULL, clip = FALSE, out.dir = NULL, out.name = NULL )subset_layer( file, coords = NULL, sub.layer = NULL, clip = FALSE, out.dir = NULL, out.name = NULL )
file |
input file to be subset |
coords |
vector with xmin,ymin,xmax,ymax defing the bounding box for subset |
sub.layer |
Vector layer defining the subset region |
clip |
clip geometries to bounding box/subset layer? TRUE/FALSE |
out.dir |
output directory for subset layer. Defaults to location of input file. Can also set to 'pwd' |
out.name |
filename for subset layer. Defaults to original filename with the suffix *.sub |
Shawn P. Serbin
## Not run: # Test dataset file <- Sys.glob(file.path(R.home(), 'library', 'PEcAn.data.land','data','*.shp')) out.dir <- path.expand('~/temp') # with clipping enabled subset_layer(file=file,coords=c(-95,42,-84,47),clip=TRUE,out.dir=out.dir) # without clipping enables subset_layer(file=file,coords=c(-95,42,-84,47),out.dir=out.dir) system(paste('rm -r',out.dir,sep='')) ## End(Not run)## Not run: # Test dataset file <- Sys.glob(file.path(R.home(), 'library', 'PEcAn.data.land','data','*.shp')) out.dir <- path.expand('~/temp') # with clipping enabled subset_layer(file=file,coords=c(-95,42,-84,47),clip=TRUE,out.dir=out.dir) # without clipping enables subset_layer(file=file,coords=c(-95,42,-84,47),out.dir=out.dir) system(paste('rm -r',out.dir,sep='')) ## End(Not run)
Converts soil organic carbon (SOC) stock change and CH4/N2O fluxes to CO2-equivalent emissions using 100-year GWP values.
to_co2e(delta_soc = 0, ch4 = 0, n2o = 0, gwp = c("AR6", "AR5", "AR4"))to_co2e(delta_soc = 0, ch4 = 0, n2o = 0, gwp = c("AR6", "AR5", "AR4"))
delta_soc |
Numeric. Change in soil organic carbon as mass of elemental carbon (C). Positive values indicate soil carbon gain; negative values indicate loss. |
ch4 |
Numeric. Methane emissions as mass of CH4. |
n2o |
Numeric. Nitrous oxide emissions as mass of N2O. |
gwp |
Character. IPCC report containing GWP100 values used: "AR6", "AR5", or "AR4". |
Inputs may use any mass units, but must be converted to consistent units and expressed on the same spatial and temporal basis before summing. Equations:
CO2e_SOC = -ΔSOC * (44 / 12)
CO2e_i = m_i * GWP100_i
GWP values:
- Default GWP100 values are from AR6 (IPCC, 2021). - For CARB inventories, use "AR4" for comparability with current CARB inventories (CARB, 2025).
Numeric. Total CO2-equivalent emissions as mass of CO2e, expressed on the same spatial and temporal basis as the inputs.
IPCC (2021). Climate Change 2021: The Physical Science Basis (WG1 AR6). Cambridge University Press. https://doi.org/10.1017/9781009157896
IPCC (2006). 2006 Guidelines for National Greenhouse Gas Inventories. IGES, Japan.
IPCC (2019). 2019 Refinement to the 2006 IPCC Guidelines. IPCC, Switzerland.
Greenhouse Gas Protocol (2024). Global Warming Potential Values. WRI/WBCSD. https://ghgprotocol.org/global-warming-potential-values
California Air Resources Board (CARB), 2025. Greenhouse Gas Global Warming Potentials. https://ww2.arb.ca.gov/ghg-gwps
to_co2e(delta_soc = 1) to_co2e(ch4 = 1) to_co2e(n2o = 1) # return total over all sources to_co2e(delta_soc = 1, ch4 = 0.1, n2o = 0.01)to_co2e(delta_soc = 1) to_co2e(ch4 = 1) to_co2e(n2o = 1) # return total over all sources to_co2e(delta_soc = 1, ch4 = 0.1, n2o = 0.01)
to.Tag
to.Tag(SITE, PLOT, SUBPLOT, TAG = NULL)to.Tag(SITE, PLOT, SUBPLOT, TAG = NULL)
SITE, PLOT, SUBPLOT
|
ignored |
TAG |
string (or coercible to) |
to.TreeCode
to.TreeCode(SITE, PLOT, SUBPLOT, TAG = NULL)to.TreeCode(SITE, PLOT, SUBPLOT, TAG = NULL)
SITE, PLOT, SUBPLOT, TAG
|
strings (or coercible to) |
Validates a PEcAn events JSON file (single-site object or an array of site objects) against the bundled JSON Schema using the AJV engine.
validate_events_json( events_json, schema_version = "0.1.2", verbose = TRUE, max_errs = 50 )validate_events_json( events_json, schema_version = "0.1.2", verbose = TRUE, max_errs = 50 )
events_json |
character. Path to the JSON file to validate. |
schema_version |
character. Version of the PEcAn events schema to validate against. |
verbose |
logical. When 'TRUE', include detailed AJV messages on error. |
max_errs |
integer. Print only this many validation errors. To see the rest, use the 'errors' attribute of the return value. |
- Logs an error and returns FALSE if the JSON file does not exist or does not conform to the schema. - Logs a warning and returns TRUE if the optional package 'jsonvalidate' is not installed, so calling code can proceed without a hard dependency.
Logical TRUE if valid. If invalid, FALSE with an attribute "errors" containing a dataframe of reported problems. NA if validator unavailable.
David LeBauer
# validate_events_json(system.file("events_fixtures/events_site1.json", # package = "PEcAn.data.land"))# validate_events_json(system.file("events_fixtures/events_site1.json", # package = "PEcAn.data.land"))
write_ic
write_ic( in.path, in.name, start_date, end_date, outfolder, model, new_site, pfts, source = input_veg$source, overwrite = FALSE, n.ensemble, host.inputargs, ... )write_ic( in.path, in.name, start_date, end_date, outfolder, model, new_site, pfts, source = input_veg$source, overwrite = FALSE, n.ensemble, host.inputargs, ... )
in.path |
file path to rds file with IC data |
in.name |
file name of IC data |
start_date |
YYYY-MM-DD |
end_date |
YYYY-MM-DD |
outfolder |
Location to store function outputs |
model |
BETY model ID |
new_site |
Site info including lat, lon, and BETT site ID |
pfts |
list settings$pfts. |
source |
Data source as saved in the BETY db |
overwrite |
DEfault is FALSE. Option to overwrite existing files. |
n.ensemble |
number of ensemble members |
host.inputargs |
host info taken from settings object |
... |
Additional parameters |
Istem Fer
Function to save intermediate rds file
write_veg(outfolder, start_date, veg_info, source)write_veg(outfolder, start_date, veg_info, source)
outfolder |
output folder |
start_date |
start date |
veg_info |
vegetation data to be saved |
source |
name of data source (used in file naming) |