Retrieve trait data and priors for one PFT from BETYdb
Source:R/get_trait_data_pft.R
get_trait_data_pft.RdCore computation extracted from get.trait.data.pft.
Queries the database for trait observations and prior distributions,
returning them as R objects with no file I/O of any kind.
Usage
get_trait_data_pft(pft_name, modeltype, dbcon, trait_names, constants = list())Arguments
- pft_name
character. PFT name as stored in BETYdb.
- modeltype
character or NULL. Disambiguates PFTs that share a name across model types (e.g.
"SIPNET","ED2").- dbcon
database connection from
db.open.- trait_names
character vector of trait names to retrieve.
- constants
named list from
pft$constantsin the settings. Traits named here are excluded from the returned priors because their values are fixed rather than sampled by the meta-analysis.
Value
Named list with three elements:
trait_dataNamed list of data frames, one per trait that has observations. Column structure matches what
meta_analysis_standaloneexpects. Traits with no observations are omitted from the list.prior_distnsData frame with columns
distn,parama,paramb,n; rows named by trait. Traits listed inconstantsare excluded.pft_infoList with
name,pft_id,pft_type,pft_members,pft_member_filename, andposteriorid.pft_membersis the data frame of species or cultivar IDs used during the query.pft_member_filenameis"species.csv"or"cultivars.csv"depending on PFT type.posterioridis alwaysNULL— the wrapper sets it after registering outputs in BETYdb.
Details
The wrapper get.trait.data.pft handles directory creation,
caching, CSV output, and BETYdb registration via dbfile.insert.
This function handles only the query. Choosing between them is the
provenance opt-in: calling the wrapper saves artifacts to disk; calling
this function never does.
This follows the pattern established by meta_analysis_standalone
for the meta-analysis step and get_parameter_samples for parameter
sampling — each is a computation core that can be tested in isolation
without a filesystem or a settings object.
See also
get.trait.data.pft for the backward-compatible
wrapper that handles provenance and caching.
meta_analysis_standalone (in PEcAn.MA) for the analogous
function in the meta-analysis step.
get_parameter_samples for the analogous function in the
parameter sampling step.
Examples
if (FALSE) { # \dontrun{
dbcon <- PEcAn.DB::db.open(list(
host = "localhost", user = "bety",
password = "bety", dbname = "bety"
))
result <- get_trait_data_pft(
pft_name = "temperate.deciduous",
modeltype = "SIPNET",
dbcon = dbcon,
trait_names = c("SLA", "Vcmax", "leaf_respiration_rate_m2")
)
str(result$trait_data)
str(result$prior_distns)
PEcAn.DB::db.close(dbcon)
} # }