Package 'PEcAn.data.land'

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

Help Index


Apply water balance calculations to a data frame with multiple sites

Description

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'.

Usage

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
)

Arguments

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.

Value

Data frame with added columns: 'W_t' / 'pond_depth', 'irr', 'runoff'


Biomass and soil data from FluxNet sites

Description

Contains data from 246 Fluxnet sites. Variables include aboveground and belowground biomass in various pools, plus soil texture/chemistry/horizonation/C&N stocks.

Usage

BADM

Format

## 'BADM' A data frame with 12,300 rows and 13 columns:

SITE_ID

Fluxnet code for the site

LOCATION_ELEV, LOCATION_LAT, LOCATION_LON

site coordinates

Date

Measurement date

GROUP_ID

TODO

VARIABLE_GROUP

category, eg abovground biomass or soil chemistry

VARIABLE, DATAVALUE

key and value for each measured variable

NA_L1CODE, NA_L1NAME, NA_L2CODE, NA_L2NAME

numeric IDs and names for the Level 1 and level 2 ecoregions where this site is located

Source

Originally from Fluxnet <https://fluxnet.org/badm-data-product/>, but the provenence and age of this specific file is not clear.


BADM_IC_process

Description

BADM_IC_process

Usage

BADM_IC_process(settings, dir, overwrite = TRUE)

Arguments

settings

pecan xml settings

dir

output dir which you want to store the IC netcdf file

overwrite

Flag for overwriting the IC file.

Value

a list of paths to generated and stored IC files.

Examples

## 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)

BIS crop coefficients by crop

Description

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).

Usage

bism_kc_by_crop

Format

A data frame with one row per crop and the following columns:

crop_number

Numeric crop identifier used internally by BIS.

crop_name

Crop name as listed in the 'CropRef' worksheet.

percent_season_B

Percent-of-season location of growth date B.

percent_season_C

Percent-of-season location of growth date C.

percent_season_D

Percent-of-season location of growth date D.

KcB

Crop coefficient at growth date B (approximately Kc1 for field crops).

KcC

Crop coefficient at growth date C (mid-season plateau, Kc2).

KcD

Crop coefficient at growth date D (typically equal to KcC for most crops).

KcE

Crop coefficient at growth date E (late-season value, Kc3).

planting_month

Representative planting month used by BIS.

planting_day

Representative planting day used by BIS.

harvest_month

Representative harvest month used by BIS.

harvest_day

Representative harvest day used by BIS.

landiq_class

LandIQ class code matched by BISm crop number.

landiq_subclass

LandIQ subclass code matched by BISm crop number.

landiq_subclass_name

LandIQ subclass name matched by BISm crop number.

Details

BIS follows the crop-coefficient framework of Doorenbos and Pruitt (1977), in which maximum crop evapotranspiration is calculated as

ETc=Kc×ETo.ETc = Kc \times ETo.

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.

Source

Snyder, R., Orang, M., Bali, K., Eching, S., Zaccaria, D. (2014). BISm Basic Irrigation Scheduling Excel program (metric units).

References

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).

Examples

data(bism_kc_by_crop)
head(bism_kc_by_crop)

Format ring & plot data for JAGA

Description

builds the JAGS data object for the tree ring / inventory fusion code also sets all the priors

Usage

buildJAGSdata_InventoryRings(combined, inc.unit.conv = 0.1)

Arguments

combined

object returned from matchInventoryRings. Matrix with both increment and plot data

inc.unit.conv

conversion factor from loaded increments to cm (of radius)

Value

list

Author(s)

Michael Dietze


California organic amendment (compost) properties

Description

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.

Usage

ca_compost_amendment

Format

A tibble with 32 rows and the following columns:

material

character. Amendment material name.

cn_min, cn_max, cn_avg

numeric. Carbon-to-nitrogen ratio range and average.

c_pct

numeric. Assumed carbon content (percent).

n_pct

numeric. Total nitrogen content (percent).

pan_pct

numeric. Plant-available nitrogen after 4 weeks (percent). Negative values indicate N immobilization.

n_class

character. "LOWER" or "HIGHER" N content class.

app_rate_min, app_rate_max

numeric. Application rate range (lbs/acre).

total_c_min_lbs_acre, total_c_max_lbs_acre

numeric. Total carbon applied (lbs C/acre).

total_n_min_lbs_acre, total_n_max_lbs_acre

numeric. Total nitrogen applied (lbs N/acre).

total_c_min_g_m2, total_c_max_g_m2

numeric. Total carbon in SI units (g C/m2^2).

total_n_min_g_m2, total_n_max_g_m2

numeric. Total nitrogen in SI units (g N/m2^2).

source

character. Short citation for the data source.

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

See Also

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.


California recommended N application rates by crop

Description

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.

Usage

ca_n_application_rate

Format

A tibble with one row per crop and the following columns:

pft_group

character. Plant functional type group (e.g. "row", "woody", "rice").

crop

character. Crop name as given in the source.

min_n_lbs_acre

numeric. Minimum recommended N rate (lbs N/acre).

max_n_lbs_acre

numeric. Maximum recommended N rate (lbs N/acre).

source

character. Short citation for the source(s). Multiple sources are separated by "; ".

min_n_g_m2

numeric. Minimum N rate in SI units (g N/m2^2). Conversion: 1 lb/acre = 0.112085 g/m2^2.

max_n_g_m2

numeric. Maximum N rate in SI units (g N/m2^2).

Source

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.

See Also

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.


Calculate water balance for a time series at a single site

Description

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).

Usage

calc_water_balance(
  et,
  precip,
  whc,
  whc_min_frac,
  W_initial = NULL,
  w_min = NULL,
  irrigation_max = NULL
)

Arguments

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).

Details

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.

Value

List with vectors: W_t (soil water), irr (irrigation), runoff

Examples

# 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 water balance for a flooded rice paddy

Description

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.

Usage

calc_water_balance_rice(
  et,
  precip,
  flood_target,
  flood_min,
  flood_max,
  seepage,
  drain = NULL,
  pond_init = flood_target
)

Arguments

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.

Details

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.

Value

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


Clean_Tucson

Description

tree core QAQC

Usage

Clean_Tucson(file)

Arguments

file

WinDendro output


Clip and Save a Raster File

Description

Clips a raster to a polygon bounding box, optionally masks to polygon, and saves the output in the same format as the input.

Usage

clip_and_save_raster_file(
  input_path,
  polygon,
  out_path,
  mask = TRUE,
  overwrite = TRUE
)

Arguments

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?

Value

Invisibly, the clipped 'SpatRaster' object. The raster is also saved to 'out_path'.

Author(s)

David LeBauer


cohort2pool

Description

Converts .rds files into pool netcdf files.

Usage

cohort2pool(dat, allom_param = NULL, dbh_name = "DBH")

Arguments

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.

Details

cohort2pool function Calculates total biomass using veg cohort file.

Author(s)

Saloni Shah

Examples

## Not run: 
veg_file <- "~/downloads/FFT_site_1-25665/FFT.2008.veg.rds"
cohort2pool(dat = veg_file, allom_param = NULL)

## End(Not run)

Create SIPNET event files from water balance data

Description

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.

Usage

create_event_file(df)

Arguments

df

Data frame with columns: date, year, week, day_of_year, irr

Value

Data frame with columns: loc, year, doy, event_type, irr_cm, type


Crop-specific rooting depths and water-depletion thresholds

Description

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).

Usage

crop_whc

Format

A tibble with one row per crop and the following columns:

crop_number

BIS crop number (character). Blank for crops not in BIS.

crop_name

Crop name.

Category

Crop category (e.g., Woody Perennial, Annual (Hardy)).

rooting_depth_m

Maximum effective rooting depth in meters.

whc_min_frac

Minimum soil water as fraction of available water-holding capacity (0-1).

whc_notes

Rationale or source for the minimum WHC value.

rooting_depth_notes

Rationale or source for the rooting depth value.

Source

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

Examples

data(crop_whc)
head(crop_whc)

DataONE download

Description

Adapts the dataone::getDataPackage workflow to allow users to download data from the DataONE federation by simply entering the doi or associated package id

Usage

dataone_download(
  id,
  filepath = "/fs/data1/pecan.data/dbfiles",
  CNode = "PROD",
  lazyLoad = FALSE,
  quiet = FALSE
)

Arguments

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

Author(s)

Liam P Burke, [email protected]

Examples

## 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

Description

Download NEON Soil Water Content and Soil Salinity data by date and site name

Usage

download_NEON_soilmoist(
  site,
  avg = "all",
  var = "all",
  startdate = NA,
  enddate = NA,
  outdir
)

Arguments

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

Value

List of specified variable(s) AND prints the path to output folder

Author(s)

Juliette Bateman

Examples

## 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)

download_packages

Description

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.

Usage

download_package_rm(
  resource_map,
  directory,
  CNode = "PROD",
  download_format = "application/bagit-097",
  overwrite_directory = TRUE
)

Arguments

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

Value

results of download


Download CDS soil moisture data for the SDA workflow.

Description

Download CDS soil moisture data for the SDA workflow.

Usage

download.SM_CDS(
  outfolder,
  time.points,
  overwrite = FALSE,
  auto.create.key = FALSE
)

Arguments

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.

Details

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.

Value

A vector containing file paths to the downloaded files.

Author(s)

Dongchen Zhang


Sampling/ensemble module

Description

Sampling/ensemble module

Usage

ens_veg_module(
  getveg.id,
  dbparms,
  input_veg,
  outfolder,
  machine,
  start_date,
  end_date,
  n.ensemble,
  new_site,
  host
)

Arguments

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

Author(s)

Istem Fer


EPA_ecoregion_finder

Description

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.

Usage

EPA_ecoregion_finder(Lat, Lon, folder.path = NULL)

Arguments

Lat

numeric latitude

Lon

numeric longitude

folder.path

path to the directory where you store the shape files of L1 and L2 ecoregion maps.

Value

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.

Description

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.

Usage

estimate_dirichlet_parameters(means, quantiles)

Arguments

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

Value

The individual alphas that work best to fit the observed quantiles

Author(s)

Qianyu Li

Examples

## 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)

Convert reference evapotranspiration to crop evapotranspiration

Description

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.

Usage

eto_to_etc(eto, kc)

Arguments

eto

numeric vector of reference evapotranspiration

kc

numeric vector of crop coefficients

Value

numeric vector of crop evapotranspiration


Convert ETo to ETc using BIS/BISm crop coefficients

Description

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:

  1. 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.

  2. 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.

Usage

eto_to_etc_bism(eto, crop_name, date = NULL, canopy_cover = NULL)

Arguments

eto

Numeric vector of reference evapotranspiration (ETo).

crop_name

Character scalar identifying a crop in bism_kc_by_crop.

date

Optional Date vector (same length as eto); triggers percent-of-season interpolation using BIS/BISm defaults.

canopy_cover

Optional numeric vector giving fractional ground cover (0-1), length 1 or length(eto); triggers canopy-cover-based Kc estimation.

Value

Numeric vector of crop evapotranspiration (ETc), with the same units as eto (e.g., mm d-1).

References

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.


Convert PEcAn standard event parquet files to events.json

Description

Writes ensembles of PEcan events stored in parquet format to valid PEcAn events.json files, based on a manifest table specification.

Usage

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"
)

Arguments

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.

Details

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).

Value

Nested tibble containing event data. 'events.json' files are created for each ensemble member as a side effect.


Extract the first planting date of each crop cycle

Description

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.

Usage

events_to_crop_cycle_starts(event_json)

Arguments

event_json

path to an 'events.json' file

Details

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.

Value

data frame with columns 'site_id', 'date', 'crop', with one row per detected crop cycle.

Author(s)

Chris Black

Examples

evts <- system.file(
  "events_fixtures/events_site1_site2.json",
  package = "PEcAn.data.land"
)
events_to_crop_cycle_starts(evts)

extract_FIA

Description

extract_FIA

Usage

extract_FIA(lon, lat, start_date, end_date, gridres = 0.075, dbparms, ...)

Arguments

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

Author(s)

Istem Fer


extract_NEON_veg

Description

extract_NEON_veg

Usage

extract_NEON_veg(
  lon,
  lat,
  start_date,
  end_date,
  store_dir,
  neonsites = NULL,
  ...
)

Arguments

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

Value

veg_info object to be passed to extract_veg within ic_process

Author(s)

Alexis Helgeson and Michael Dietze

Examples

start_date = as.Date("2020-01-01") 
end_date = as.Date("2021-09-01")

Extract daily ET data from OpenET

Description

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:

Usage

extract_openet_daily(design_points, start_date, end_date)

Arguments

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

Details

“' OPENET_API_KEY="abcdefg123456" “'

You can obtain an OpenET API key from the OpenET data portal.

Value

'design_points' 'data.frame' with additional columns 'date', and 'et_mm_day' (ET, mm/day)


Extract CDS soil moisture data for the SDA workflow.

Description

Extract CDS soil moisture data for the SDA workflow.

Usage

extract_SM_CDS(
  site_info,
  time.points,
  in.path,
  out.path = NULL,
  allow.download = TRUE,
  search_window = 10
)

Arguments

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.

Value

A data frame containing soil moisture and sd for each site and each time step.

Author(s)

Dongchen Zhang


Extract soil data from gssurgo

Description

Extract soil data from gssurgo

Usage

extract_soil_gssurgo(
  outdir,
  lat,
  lon,
  size = 1,
  grid_size = 3,
  grid_spacing = 100,
  depths = c(0.15, 0.3, 0.6)
)

Arguments

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.

Details

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.

Value

It returns the address for the generated soil netcdf file

Current Limitations

- 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)

Author(s)

Hamze Dokoohaki, Akash

Examples

## 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

Description

Extract soil data from the gridpoint closest to a location

Usage

extract_soil_nc(in.file, outdir, lat, lon)

Arguments

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

Value

path to netCDF file containing extracted data

Examples

## 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)

extract_veg

Description

Function queries a DB to extract veg info downstream

Usage

extract_veg(
  new_site,
  start_date,
  end_date,
  source,
  gridres,
  format_name = NULL,
  machine_host,
  dbparms,
  outfolder,
  overwrite = FALSE,
  input_veg = input_veg,
  ...
)

Arguments

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

Value

results object to be passed back to get.veg.module

Author(s)

Istem Fer and Alexis Helgeson


extract.stringCode

Description

extract.stringCode

Usage

extract.stringCode(x, extractor = from.TreeCode)

Arguments

x

string to decode

extractor

function to apply


Fertilizer Nutrient Composition Table

Description

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.

Usage

fertilizer_composition_data

Format

A tibble with one row per fertilizer type and the following columns:

name

character. Short identifier from SWAT (e.g., "urea", "manure").

description

character. Longer description of the fertilizer or manure type.

fraction_mineral_n

numeric. Fraction of total nitrogen in mineral form.

fraction_nh3_n

numeric. Fraction of fertilizer by mass that is ammonium-n (NH3_3-N).

fraction_no3_n

numeric. Fraction of fertilizer by mass that is nitrate-N (NO3_3-N). Computed as fraction_mineral_n - fraction_nh3_n.

fraction_organic_n

numeric. Fraction of organic matter that is nitrogen.

fraction_c

numeric. Fraction of mass that is carbon.

cn_ratio

numeric. Carbon-to-nitrogen ratio for organic matter. Assigned based on DayCent organic matter parameterterizations.

Details

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.

Source

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

Description

Create pss/css files based on data in the fia database

Usage

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
)

Arguments

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?

Value

modified settings, invisibly

Author(s)

Mike Dietze, Rob Kooper, Ryan Kelly


format_identifier

Description

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

Usage

format_identifier(id)

Arguments

id

the doi or other identifier linked to the package in DataONE

Value

returns the id in the proper format for querying the DataONE Federation (using solrQuery syntax)

Author(s)

Liam P Burke, [email protected]


from.Tag

Description

from.Tag

Usage

from.Tag(x)

Arguments

x

string to decode


from.TreeCode

Description

from.TreeCode

Usage

from.TreeCode(x)

Arguments

x

string to decode


Generate soil carbon ensemble members for specific depth

Description

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.

Usage

generate_soilgrids_ensemble(
  processed_data,
  site_id,
  size,
  depth_layer,
  verbose = FALSE
)

Arguments

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

Value

Numeric vector of soil carbon values including uncertainty, length equal to size.


Efficiently extract unique event IDs from parquet files

Description

Efficiently extract unique event IDs from parquet files

Usage

get_event_ensemble_ids(event_paths, parquet_dir = NULL)

Arguments

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').

Value

Named list of unique ensemble IDs for each event type. Names correspond to event types.


get_resource_map

Description

Locates data in DataONE and returns the resource_map or a message indicating that there is no corresponding resource_map for the given id

Usage

get_resource_map(id, CNode = "PROD")

Arguments

id

the doi or other identifier linked to the package in DataONE

CNode

default is "PROD"

Value

return the resource_map or a message indicating that there is no corresponding resource_map for the given id


Load/extract + match species module

Description

Load/extract + match species module

Usage

get_veg_module(
  input_veg,
  outfolder,
  start_date,
  end_date,
  dbparms,
  new_site,
  host,
  machine_host,
  overwrite
)

Arguments

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

Author(s)

Istem Fer


Retrieve attribute information from a vector or raster layer

Description

Function to extract attribute information from vector or raster data layer.

Usage

get.attributes(file, coords)

Arguments

file

vector or raster layer

coords

vector containin xmin,ymin,xmax,ymax defing the bounding box for subset

Author(s)

Shawn P. Serbin

Examples

## 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

Description

Get Soil

Usage

get.soil(lat, lon, soil.nc = soil.nc)

Arguments

lat

latitude

lon

longitude

soil.nc

netCDFe file with soil data

Value

usda soil class

Author(s)

David LeBauer


This function queries the gSSURGO database for a series of map unit keys

Description

This function queries the gSSURGO database for a series of map unit keys

Usage

gSSURGO.Query(
  mukeys,
  fields = c("chorizon.sandtotal_r", "chorizon.silttotal_r", "chorizon.claytotal_r")
)

Arguments

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.

Details

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.

Value

a dataframe with soil properties.

Author(s)

Hamze Dokohaki, Akash

Examples

## 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.

Description

Extract ISCN SOC initial conditions from existing ISCN database.

Usage

IC_ISCN_SOC(site_info, ens = 100, ecoregion.path = NULL)

Arguments

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.

Value

A data frame containing sampled SOC, each row represent each site.

Author(s)

Dongchen Zhang


ic_process

Description

ic_process

Usage

ic_process(settings, input, dir, overwrite = FALSE)

Arguments

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

Author(s)

Istem Fer, Hamze Dokoohaki


id_resolveable

Description

Uses dataone::query from dataoneR to query DataONE. Prints result if data exists

Usage

id_resolveable(id, return_result = TRUE, CNode = "PROD")

Arguments

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"

Value

returns message indicating wether or not the id resolves to data in the DataONE federation and information about said data.


InventoryGrowthFusion

Description

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

Usage

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
)

Arguments

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.

Value

an mcmc.list object

Note

Requires JAGS


InventoryGrowthFusionDiagnostics

Description

InventoryGrowthFusionDiagnostics

Usage

InventoryGrowthFusionDiagnostics(jags.out, combined = NULL)

Arguments

jags.out

output mcmc.list from InventoryGrowthFusion

combined

data output from matchInventoryRings

Author(s)

Michael Dietze


Soil organic carbon (SOC) density based on eco-region level 2 code from the ISCN database.

Description

Contains 200 ensemble SOC data from 43 level 2 eco-regions across North America. Variable include SOC densities in g/cm2.

Usage

iscn_soc

Format

## 'iscn_soc' A data frame with 200 rows and 43 columns:

rows

1 to 200 ensemble members

columns

43 level 2 ecoregion codes across North America

Source

https://iscn.fluxdata.org/wp-content/uploads/sites/23/2019/05/ISCN_ALL_DATA_DATASET_1-1.xlsx


LandIQ crop mapping codes

Description

LandIQ land-use class and subclass labels used for crop mapping.

Usage

landiq_crop_mapping_codes

Format

## 'landiq_crop_mapping_codes' A data frame with 203 rows and 4 columns:

CLASS

LandIQ class code.

class_name

LandIQ class name.

SUBCLASS

LandIQ subclass code.

subclass_name

LandIQ subclass name.

Source

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'.


load_veg

Description

uses 'PEcAn.benchmark::load_data()' to get veg data

Usage

load_veg(
  new_site,
  start_date,
  end_date,
  source_id,
  source,
  icmeta = NULL,
  format_name = NULL,
  machine_host,
  dbparms,
  outfolder,
  overwrite = FALSE,
  ...
)

Arguments

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

Author(s)

Istem Fer


Look up California compost amendment properties

Description

Returns properties of organic amendment materials including carbon and nitrogen content, C:N ratio, and plant-available nitrogen (PAN).

Usage

look_up_ca_compost_amendment(
  material,
  n_class = NULL,
  aggregate = c("none", "mean")
)

Arguments

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.

Details

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.

Value

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.

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

See Also

[look_up_fertilizer_components()] for fertilizer nutrient composition (N/C fractions) from the SWAT/DayCent database. [ca_compost_amendment] for the underlying dataset.

Examples

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 California N application rates by crop

Description

Returns recommended nitrogen application rate ranges for California crops. Rates are provided in both imperial (lbs N/acre) and SI (g N/m2) units.

Usage

look_up_ca_n_rate(crop, pft_group = NULL, unit = c("g_m2", "lbs_acre"))

Arguments

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.

Details

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.

Value

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.

Source

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.

See Also

[look_up_fertilizer_components()] for fertilizer nutrient composition (N/C fractions) from the SWAT/DayCent database. [ca_n_application_rate] for the underlying dataset.

Examples

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")

Calculate the Nitrogen and Carbon Content of a Fertilizer Application

Description

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.

Usage

look_up_fertilizer_components(
  type,
  amount,
  fraction_organic_n = NULL,
  fraction_organic_c = NULL
)

Arguments

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.

Details

Consistent with assumptions in DayCent, DSSAT, and other models, urea is treated as NH3 because the transformation typically occurs within a day.

Value

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.

Note

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

Examples

# 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)

match_pft

Description

Matches BETYdb species IDs to model-specific PFTs

Usage

match_pft(
  bety_species_id,
  pfts,
  query = NULL,
  con = NULL,
  allow_missing = FALSE,
  model = NULL
)

Arguments

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.

Value

table of BETYdb PFT IDs matched to species IDs

Author(s)

Mike Dietze, Istem Fer


Match BETY species ID.

Description

Parses species codes in input data and matches them with the BETY species ID.

Usage

match_species_id(
  input_codes,
  format_name = "custom",
  bety = NULL,
  translation_table = NULL,
  ...
)

Arguments

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

Details

format_name can be one of the following:

usda

USDA Plants database symbol (e.g. QURU, TSCA)

fia

FIA species code

latin_name

Scientific name, as "Genus species"; must match exactly and unambiguously to scientificname field in BETY

custom

A 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.

Value

data.frame containing the following columns:

input_code

Character provided as input

bety_species_id

Big integer species ID, unique and specific to BETY

genus

Genus part of Latin name, from BETY

species

Species part of Latin name, from BETY

Author(s)

Alexey Shiklomanov <[email protected]>, Istem Fer

Examples

## 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

Description

matchInventoryRings

Usage

matchInventoryRings(
  trees,
  rings,
  extractor = "TreeCode",
  nyears = 30,
  coredOnly = TRUE
)

Arguments

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

Description

Convert a matric potential to a soil moisture

Usage

mpot2smoist(
  mpot,
  soil_water_potential_at_saturation,
  soil_hydraulic_b,
  volume_fraction_of_water_in_soil_at_saturation
)

Arguments

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)

Value

volumetric soil water content


Convert MSLSP phenology data to tidy canopy cover

Description

Convert MSLSP phenology data to tidy canopy cover

Usage

mslsp_to_canopycover(mslsp_path, parcel_ids = NULL, years = NULL)

Arguments

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.

Value

'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".


Convert fractional NDTI drop to SIPNET tillage effectiveness

Description

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.

Usage

ndti_to_sipnet_tillage(delta_ndti, no_till_threshold = 0.3, slope = 2.5)

Arguments

delta_ndti

numeric vector. Fractional NDTI drop in \[0, 1\], computed as (max_before_min - min_val) / max_before_min from a smoothed NDTI time series over the fallow season.

no_till_threshold

numeric scalar. delta_ndti values at or below this threshold are mapped to zero effectiveness (no-till). Default 0.30, based on Dietze & Kanee (pers. comm.).

slope

numeric scalar. Slope of the linear response above no_till_threshold. Default 2.5, which produces a ramp from 0 at delta_ndti = 0.30 to 1 at delta_ndti = 0.70 (i.e. 1 / (0.70 - 0.30)). Output is clamped to \[0, 1\].

Details

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.

Value

numeric vector of tillage_eff_0to1 values, same length as delta_ndti, clamped to \[0, 1\]. NA inputs propagate to NA outputs.

References

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

Examples

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

Description

netcdf.writer.BADAM

Usage

netcdf.writer.BADM(lat, long, siteid, outdir, ens)

Arguments

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'

Value

a dataframe with file, host, mimetype, formatname, startdate, enddate and dbfile.name columns


Convert organic matter to soil organic carbon

Description

Converts organic matter content to soil organic carbon using the Van Bemmelen factor (1.724).

Usage

om2soc(om_percent)

Arguments

om_percent

organic matter percentage (0-100)

Value

soil organic carbon percentage (0-100)

Author(s)

Akash


Parse responses from the mukey WFS service

Description

Parse responses from the mukey WFS service

Usage

parse_mukey_response(resp)

Arguments

resp

'httr2' response object from SSURGO mukey WFS API

Value

character vector of mukeys


parse.MatrixNames

Description

parse.MatrixNames

Usage

parse.MatrixNames(w, pre = "x", numeric = FALSE)

Arguments

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

Value

matrix

Author(s)

Michael Dietze


partition_roots

Description

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.

Usage

partition_roots(roots, rtsize)

Arguments

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

Value

list containing summed fine root and coarse root carbon (2 values)

Author(s)

Anne Thomas


plot2AGB

Description

convert composite ring & census data into AGB

Usage

plot2AGB(combined, out, outfolder, allom.stats, unit.conv = 0.02)

Arguments

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

Author(s)

Mike Dietze [email protected]


pool_ic_list2netcdf

Description

Converts input list containing standard dimensions and variables (named values) for initial conditions to a netcdf file, input to pool-based models.

Usage

pool_ic_list2netcdf(input, outdir, siteid, ens = NA)

Arguments

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.

Author(s)

Anne Thomas


pool_ic_netcdf2list

Description

Converts netcdf containing standard dimensions and variables for pool-based initial conditions, created by pool_ic_list2netcdf, back into list format

Usage

pool_ic_netcdf2list(nc.path)

Arguments

nc.path

path to netcdf file containing standard dimensions and variables

Value

list with two elements: list of netcdf dimensions (dims, with named values) and list of variables (vals, with named values)

Author(s)

Anne Thomas


prepare_pools

Description

Calculates pools from given initial condition values, deriving complements where necessary/possible if given TotLivBiomass

Usage

prepare_pools(nc.path, constants = NULL)

Arguments

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

Value

list of pool values in kg C / m2 with generic names

Author(s)

Anne Thomas


Preprocess SoilGrids data for ensemble generation

Description

Preprocess SoilGrids data for ensemble generation

Usage

preprocess_soilgrids_data(soil_data, depth_layers, verbose = FALSE)

Arguments

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

Value

List containing processed data and CV distributions for requested depths


Match species to PFTs + veg2model module

Description

Match species to PFTs + veg2model module

Usage

put_veg_module(
  getveg.id,
  dbparms,
  input_veg,
  pfts,
  outfolder,
  n.ensemble,
  dir,
  model,
  start_date,
  end_date,
  new_site,
  host,
  overwrite
)

Arguments

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

Author(s)

Istem Fer


Read_Tucson

Description

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)

Usage

Read_Tucson(folder)

Arguments

folder

path to read files from. Will read all files at this path matching "TXT", "rwl", or "rw"


Read.IC.info.BADM

Description

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.

Usage

Read.IC.info.BADM(lat, long)

Arguments

lat

numeric latitude

long

numeric longitude

Value

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.

Examples

badm_test <- Read.IC.info.BADM(45.805925,-90.07961)

sample_ic

Description

sample_ic

Usage

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,
  ...
)

Arguments

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

Author(s)

Istem Fer


This function determines the soil class number based on the fraction of sand, clay, and silt

Description

This function determines the soil class number based on the fraction of sand, clay, and silt

Usage

sclass(sandfrac, clayfrac)

Arguments

sandfrac, clayfrac

numeric vectors with values in range 0 to 1. Silt fraction is assumed to be the difference between (sand+clay) and 1

Value

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.

Examples

sclass(0.3,0.3)

Convert shapefile to KML

Description

Convert ESRI shapefile (*.shp) to keyhole markup language (KML) file format

Usage

shp2kml(
  dir,
  ext,
  kmz = FALSE,
  proj4 = NULL,
  color = NULL,
  NameField = NULL,
  out.dir = NULL
)

Arguments

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

Author(s)

Shawn P. Serbin

Examples

## 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

Description

Convert soil organic carbon concentration to organic carbon stock

Usage

soc2ocs(soc_percent, bulk_density, thickness, coarse_fraction = 0)

Arguments

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)

Value

organic carbon stock (kg/m2)

Author(s)

Akash

Examples

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

Description

Default parameters for calculating soil properties from sand & clay content

Usage

soil_class

Format

## 'soil_class' A list with 26 entries:

air.cond, h2o.cond, sand.cond, silt.cond, clay.cond

thermal conductivity, W m^-1 K^-1

air.hcap, sand.hcap, silt.hcap, clay.hcap

heat capacity, J m^-3 K^-1

kair, ksand, ksilt, kclay

relative conductivity factor

fieldcp.K

hydraulic conductance at field capacity, mm day^-1

grav

gravity acceleration, m s^-2

soil.key

Abbreviations for each of 18 soil texture classes, e.g. "SiL", "LSa"

soil.name

Names for 18 soil texture classes, e.g. "Sand", "Silty clay"

soilcp.MPa

soil water potential when air-dry, MPa

soilld.MPa

soil water potential at critical water content, MPa

soilwp.MPa

soil water potential at wilting point, MPa

stext.lines

list of 18 lists, each giving minimum and maximum sand/silt/clay contents for a soil texture class

stext.polygon

list of 18 lists, each giving corner points in the soil texture triangle for a soil texture class

texture

data frame with 13 rows and 21 columns, giving default parameter values for 13 named soil textures

theta.crit

critical water content (fractional soil moisture at which plants start dropping leaves), m^3 m^-3

xclay.def

default volume fraction of sand in each of 18 soil texture classes

xsand.def

default volume fraction of clay in each of 18 soil texture classes

Source

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

Description

Estimate soil parameters from texture class or sand/silt/clay

Usage

soil_params(
  soil_type = NULL,
  sand = NULL,
  silt = NULL,
  clay = NULL,
  bulk = NULL
)

Arguments

soil_type

USDA Soil Class. See Details

sand

percent sand

silt

percent silt

clay

percent clay

bulk

soil bulk density (optional, kg m-3)

Details

* 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)

Value

list of soil hydraulic and thermal parameters

Examples

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

Description

A function to estimate the soil parameters based on SoilGrids soil texture data and write the parameter paths into settings

Usage

soil_params_ensemble_soilgrids(
  settings,
  sand,
  clay,
  silt,
  outdir,
  write_into_settings = TRUE
)

Arguments

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

Value

Ensemble soil parameter files defined in outdir and file paths in xml file

Author(s)

Qianyu Li

Examples

## 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

Description

Module for managing soil texture extraction

Usage

soil_process(settings, input, dbfiles, overwrite = FALSE, run.local = TRUE)

Arguments

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)

Value

path to soil file


Get standard units for a soil variable

Description

Given SSURGO names for soil properties, looks up their standard units. Note that names must match exactly.

Usage

soil.units(varname = NA)

Arguments

varname

character vector. See details

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

Value

character matrix with columns var and unit

Examples

soil.units("soil_albedo")

Save soil texture & parameters in PEcAn standard netCDF CF

Description

A table of standard names and units can be displayed by running soil.units() without any arguements

Usage

soil2netcdf(soil.data, new.file)

Arguments

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

Details

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]

Value

none

Examples

## 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)

SoilGrids Initial Conditions (IC) Utilities

Description

Functions for generating soil carbon IC files from SoilGrids250m data

Usage

soilgrids_ic_process(
  settings,
  dir,
  depth = c(0.3, 2),
  overwrite = FALSE,
  verbose = FALSE
)

Arguments

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)

Details

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

Value

List of paths to generated IC files, organized by site ID

Author(s)

Akash

Examples

## 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

Description

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

Usage

soilgrids_soilC_extract(site_info, outdir = NULL, verbose = TRUE)

Arguments

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

Value

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")

Author(s)

Qianyu Li, Shawn P. Serbin

Examples

## 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.

Description

Prepare Soilgrids SoilC data for the SDA workflow.

Usage

Soilgrids_SoilC_prep(
  site_info,
  start_date,
  end_date,
  time_points,
  outdir = NULL,
  export_csv = FALSE
)

Arguments

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.

Value

A data frame containing AGB median and sd for each site and each time step.

Author(s)

Dongchen Zhang


soilgrids_texture_extraction

Description

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

Usage

soilgrids_texture_extraction(
  data_paths,
  site_info,
  outdir = NULL,
  verbose = TRUE
)

Arguments

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

Value

a data frame containing the soil texture data with columns "Depth", "Quantile", "Siteid", and "Value"

Author(s)

Qianyu Li


Maximum area for SSURGO API requests

Description

Maximum area for SSURGO API requests

Usage

SSURGO_API_MAX_AREA_M2

Format

An object of class numeric of length 1.


Get map unit keys (mukeys) from gSSURGO

Description

These functions query the NRCS gSSURGO Web Feature Service to retrieve map unit keys based on different spatial filters.

Usage

ssurgo_mukeys_bbox(bbox)

ssurgo_mukeys_point(point, distance)

ssurgo_mukeys_bigbbox(bbox)

Arguments

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.

Details

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.

Value

Character vector of unique map unit keys (mukeys).

Examples

## 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)

Description

Function to subset and clip a GIS vector or raster layer by a bounding box or clip/subset layer (e.g. shapefile/KML)

Usage

subset_layer(
  file,
  coords = NULL,
  sub.layer = NULL,
  clip = FALSE,
  out.dir = NULL,
  out.name = NULL
)

Arguments

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

Author(s)

Shawn P. Serbin

Examples

## 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)

Convert SOC change and greenhouse gas fluxes to CO2 equivalents

Description

Converts soil organic carbon (SOC) stock change and CH4/N2O fluxes to CO2-equivalent emissions using 100-year GWP values.

Usage

to_co2e(delta_soc = 0, ch4 = 0, n2o = 0, gwp = c("AR6", "AR5", "AR4"))

Arguments

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".

Details

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).

Value

Numeric. Total CO2-equivalent emissions as mass of CO2e, expressed on the same spatial and temporal basis as the inputs.

References

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

Examples

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

Description

to.Tag

Usage

to.Tag(SITE, PLOT, SUBPLOT, TAG = NULL)

Arguments

SITE, PLOT, SUBPLOT

ignored

TAG

string (or coercible to)


to.TreeCode

Description

to.TreeCode

Usage

to.TreeCode(SITE, PLOT, SUBPLOT, TAG = NULL)

Arguments

SITE, PLOT, SUBPLOT, TAG

strings (or coercible to)


Validate PEcAn events JSON against schema v0.1.0

Description

Validates a PEcAn events JSON file (single-site object or an array of site objects) against the bundled JSON Schema using the AJV engine.

Usage

validate_events_json(
  events_json,
  schema_version = "0.1.2",
  verbose = TRUE,
  max_errs = 50
)

Arguments

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.

Details

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

Value

Logical TRUE if valid. If invalid, FALSE with an attribute "errors" containing a dataframe of reported problems. NA if validator unavailable.

Author(s)

David LeBauer

Examples

# validate_events_json(system.file("events_fixtures/events_site1.json",
#                                package = "PEcAn.data.land"))

write_ic

Description

write_ic

Usage

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,
  ...
)

Arguments

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

Author(s)

Istem Fer


write_veg

Description

Function to save intermediate rds file

Usage

write_veg(outfolder, start_date, veg_info, source)

Arguments

outfolder

output folder

start_date

start date

veg_info

vegetation data to be saved

source

name of data source (used in file naming)