Get trait data from the database for a single PFT
Source:R/get.trait.data.pft.R
get.trait.data.pft.RdQueries BETYdb for trait observations and prior distributions for a single
plant functional type (PFT). Results are saved to files in the PFT output
directory (pft$outdir), and also registered in the database as posterior
records when write = TRUE.
Usage
get.trait.data.pft(
pft,
modeltype,
dbfiles,
dbcon,
trait.names = NULL,
forceupdate = FALSE,
write = TRUE,
return_data = FALSE
)Arguments
- pft
list of settings for the pft whose traits to retrieve. See details.
- modeltype
type of model that is used, this is used to distinguish between different pfts with the same name.
- dbfiles
location where previous results are found
- dbcon
database connection
- trait.names
list of trait names to retrieve
- forceupdate
set this to true to force an update, auto will check to see if an update is needed.
- write
(Logical) If
TRUEupdated posteriors will be written to BETYdb. Defaults toFALSE.- return_data
(Logical) If
TRUE, the returnedpftlist also includestrait_dataandprior_distnsas in-memory objects. Defaults toFALSEto preserve legacy behavior — whenpftis embedded inside asettingsobject, attaching these data frames by default would inflate the settings and break serialization.
Value
The updated pft list with posteriorid set to the
ID of the (possibly new) posterior record in BETYdb. The posterior ID
can be used to locate the output files (trait.data.Rdata,
prior.distns.Rdata, etc.) via BETYdb's dbfiles table.
When return_data = TRUE, the returned list also includes
trait_data and prior_distns as in-memory objects, so
downstream callers can use them without reloading from pft$outdir.
Details
pft should be a list containing at least name and outdir, and
optionally posteriorid and constants.
File-based side effects
The following files are written to pft$outdir:
trait.data.RdataNamed list of trait data frames, one per trait that has observations. Read by
run.meta.analysis.pft().prior.distns.RdataData frame of prior distributions, rows named by trait. Read by
run.meta.analysis.pft().species.csvorcultivars.csvData frame of PFT member species or cultivar IDs, depending on PFT type.
trait.data.csvFlattened CSV of all trait observations, one row per observation, for human inspection.
In addition, each output file is registered in BETYdb via
dbfile.insert() and associated with the posterior record whose ID
is returned as pft$posteriorid.
Downstream contract
run.meta.analysis.pft() reads trait.data.Rdata and
prior.distns.Rdata from pft$outdir at the start of the
meta-analysis step. These two files are therefore a required output of
this wrapper.
Note: this file-based contract will be removed once
run.meta.analysis.pft() is refactored to accept in-memory inputs
(GSoC Week 2).