Title: | PEcAn Package for Integration of the LPJ-GUESS Model |
---|---|
Description: | This module provides functions to link LPJ-GUESS to PEcAn. |
Authors: | Istem Fer [aut, cre], Tony Gardella [aut], University of Illinois, NCSA [cph] |
Maintainer: | Istem Fer <[email protected]> |
License: | BSD_3_clause + file LICENSE |
Version: | 1.7.3.9000 |
Built: | 2025-03-07 03:15:32 UTC |
Source: | https://github.com/PecanProject/pecan |
Calculates a per-PFT, gridcell-summed quantity from the LPJ-GUESS state, correctly averaging over patches. This should be put into the SDA procedure.
calculateGridcellVariablePerPFT( model.state, variable, pft.params, min.diam = 5 )
calculateGridcellVariablePerPFT( model.state, variable, pft.params, min.diam = 5 )
model.state |
A large multiply-nested list containing the entire LPJ-GUESS state as read by
function |
variable |
A character string specifying what variable to extract. This can be chosen based on the LPJ-GUESS variable name as recorded in the big list of list (that represents describes the model state in R). Once special case is "biomass" which returns the sum of "cmass_leaf", "cmass_root", "cmass_sap" and "cmass_heart" |
pft.params |
A data frame containing PFT parameters such as allometric coefficients. |
min.diam |
Minimum tree diameter (in cm) required for inclusion in calculations. |
A numeric vector, with one entry per PFT
Matthew Forrest
Identifies the line number of the matching closing bracket for a given opening bracket.
find_closing(find = "}", line_no, file_in, if_else_check = FALSE)
find_closing(find = "}", line_no, file_in, if_else_check = FALSE)
find |
A character string of the opening bracket. |
line_no |
A numeric value indicating the line number to start the search. |
file_in |
A character vector of the file content. |
if_else_check |
Optional. A logical value indicating whether to check for if/else blocks (default is FALSE). |
A numeric value indicating the line number of the matching closing bracket.
Determines the size (number of variables) in a stream based on the file content.
find_stream_size( current_stream_type, guessh_in, LPJ_GUESS_TYPES, LPJ_GUESS_CONST_INTS )
find_stream_size( current_stream_type, guessh_in, LPJ_GUESS_TYPES, LPJ_GUESS_CONST_INTS )
current_stream_type |
A list containing details of the current stream. |
guessh_in |
A character vector of LPJ-GUESS header file content. |
LPJ_GUESS_TYPES |
A character vector of recognized LPJ-GUESS types. |
LPJ_GUESS_CONST_INTS |
A dataframe mapping LPJ-GUESS constants to their values. |
A numeric value representing the size (number of streamed variables).
Determines the type of a given stream variable in an LPJ-GUESS file.
find_stream_type( class = NULL, current_stream_var, LPJ_GUESS_CLASSES, LPJ_GUESS_TYPES, guessh_in )
find_stream_type( class = NULL, current_stream_var, LPJ_GUESS_CLASSES, LPJ_GUESS_TYPES, guessh_in )
class |
A character string representing the class of the stream variable (default is NULL). |
current_stream_var |
A character string representing the current stream variable. |
LPJ_GUESS_CLASSES |
A character vector of LPJ-GUESS class names. |
LPJ_GUESS_TYPES |
A character vector of recognized LPJ-GUESS types. |
guessh_in |
A character vector of LPJ-GUESS header file content. |
A character string indicating the stream type.
A helper function that lists streamed variables. It returns the names of streamed variables.
find_stream_var(file_in, line_nos)
find_stream_var(file_in, line_nos)
file_in |
A character vector representing the file content to search through. |
line_nos |
A numeric vector of length 2, specifying the start and end lines to search for streamed variables. |
A character vector of streamed variable names.
met2model wrapper for LPJ-GUESS
met2model.LPJGUESS( in.path, in.prefix, outfolder, start_date, end_date, overwrite = FALSE, verbose = FALSE, ... )
met2model.LPJGUESS( in.path, in.prefix, outfolder, start_date, end_date, overwrite = FALSE, verbose = FALSE, ... )
in.path |
location on disk where inputs are stored |
in.prefix |
prefix of input and output files |
outfolder |
location on disk where outputs will be stored |
start_date |
the start date of the data to be downloaded (will only use the year part of the date) |
end_date |
the end date of the data to be downloaded (will only use the year part of the date) |
overwrite |
should existing files be overwritten |
verbose |
should the function be very verbose |
... |
additional arguments, currently ignored |
Istem Fer
Convert LPJ-GUESS output to netCDF
model2netcdf.LPJGUESS(outdir, sitelat, sitelon, start_date, end_date)
model2netcdf.LPJGUESS(outdir, sitelat, sitelon, start_date, end_date)
outdir |
Location of LPJ-GUESS model output |
sitelat |
Latitude of the site |
sitelon |
Longitude of the site |
start_date |
Start time of the simulation |
end_date |
End time of the simulation |
Istem Fer
Function to translate pecan param names and units to lpjguess names and units
pecan2lpjguess(trait.values)
pecan2lpjguess(trait.values)
trait.values |
trait.values, list |
translated list
Istem Fer
Reads a binary file formatted for LPJ-GUESS and extracts relevant data.
read_binary_LPJGUESS(outdir, version = "PalEON")
read_binary_LPJGUESS(outdir, version = "PalEON")
outdir |
A character string specifying the output directory containing the binary state files. |
version |
A character string specifying the LPJ-GUESS version (default is "PalEON"). |
A matrix or list containing the extracted data.
Reads a state file and processes its contents for further use.
read_state(file_path)
read_state(file_path)
file_path |
A character string specifying the path to the state file. |
A list containing the processed state information.
read binary state file of LPJ-GUESS
readStateBinary(out.path, npft)
readStateBinary(out.path, npft)
out.path |
location on disk where model run outputs are stored |
npft |
number of pfts specified in instruction file |
Patchpft_list state variables common to all individuals of a particular PFT
Istem Fer
Finds the start and end lines for serialization.
serialize_starts_ends(file_in, pattern = "void Gridcell::serialize")
serialize_starts_ends(file_in, pattern = "void Gridcell::serialize")
file_in |
A character vector of file lines to search through. |
pattern |
A character string pattern to look for in the file. |
A numeric vector of length 2, giving the start and end line numbers.
Splits climate met for LPJGUESS
split_inputs.LPJGUESS( settings, start.time, stop.time, inputs, overwrite = FALSE, outpath = NULL )
split_inputs.LPJGUESS( settings, start.time, stop.time, inputs, overwrite = FALSE, outpath = NULL )
settings |
PEcAn settings object |
start.time |
start date and time for each SDA ensemble |
stop.time |
stop date and time for each SDA ensemble |
inputs |
list of model inputs to use in write.configs.LPJGUESS |
overwrite |
Default FALSE |
outpath |
if specified, write output to a new directory. Default NULL writes back to the directory being read |
name of the split met file
Istem Fer
Adjust LPJ-GUESS state variables based on input parameters.
update_state_LPJGUESS( model.state, pft.params, dens.initial, dens.target, AbvGrndWood.initial, AbvGrndWood.target, AbvGrndWood.epsilon, trace, min.diam, HEIGHT_MAX = 150 )
update_state_LPJGUESS( model.state, pft.params, dens.initial, dens.target, AbvGrndWood.initial, AbvGrndWood.target, AbvGrndWood.epsilon, trace, min.diam, HEIGHT_MAX = 150 )
model.state |
A large multiply-nested list containing the entire LPJ-GUESS state as read by
function |
pft.params |
A data.frame containing the parameters for each PFT. Each row represents one PFT (ordering must be consistent with the vectors below. The names of the columns describe the per-PFT parameter and must include: wooddens, crownarea_max, lifeform (1 = tree, 2 = grass), k_latosa, k_rp, k_allom1, k_allom2, k_allom3, crownarea_max and sla. wooddens, crownarea_max, lifeform (1 = tree, 2 = grass), k_latosa, k_rp, k_allom1, k_allom2, k_allom3, crownarea_max and sla. |
dens.initial |
A numeric vector of the initial stand-level stem densities (indiv/m^2) as named numeric vector with one entry per PFT/species, with the names being the PFT/species codes. These values should be produced using state data assimilation from function XXXXXX. |
dens.target |
A numeric vector of the target stand-level stem densities (indiv/m^2) as named numeric vector with one entry per PFT/species, with the names being the PFT/species codes. These values should be produced using state data assimilation from function XXXXXX |
AbvGrndWood.initial |
A numeric vector of the target stand-level above ground wood (kgC/m^2) as named numeric vector with one entry per PFT/species, with the names being the PFT/species codes. These values should be produced using state data assimilation from function XXXXXX |
AbvGrndWood.target |
A numeric vector of the target stand-level above ground wood (kgC/m^2) as named numeric vector with one entry per PFT/species, with the names being the PFT/species codes. These values should be produced using state data assimilation from function XXXXXX |
AbvGrndWood.epsilon |
A single numeric specifying how close the final above ground wood needs to be to the target above ground stem biomass for each individual. eg. 0.05 requires that the final above ground wood is within 5 of the target above ground wood |
trace |
Logical; if TRUE, prints detailed adjustment process information. |
min.diam |
Minimum tree diameter (in cm) for inclusion in adjustments. |
HEIGHT_MAX |
Maximum allowed height of an individual. This is the maximum height that a tree can have. This is hard-coded in LPJ-GUESS to 150 m, but for SDA that might be unrealistically big, so this argument allows adjustment. |
Adjust LPJ-GUESS state
And updated model state (as a big old list o' lists)
Matthew Forrest
Writes a LPJ-GUESS config file.
write.config.LPJGUESS(defaults, trait.values, settings, run.id, restart = NULL)
write.config.LPJGUESS(defaults, trait.values, settings, run.id, restart = NULL)
defaults |
list of defaults to process |
trait.values |
vector of samples for a given trait |
settings |
list of settings from pecan settings file |
run.id |
id of run |
restart |
Logical, whether to restart the simulation. |
Requires a pft xml object, a list of trait values for a single model run, and the name of the file to create
configuration file for LPJ-GUESS for given run
Istem Fer, Tony Gardella
Write LPJ-GUESS instruction script
write.insfile.LPJGUESS( settings, trait.values, rundir, outdir, run.id, restart = NULL )
write.insfile.LPJGUESS( settings, trait.values, rundir, outdir, run.id, restart = NULL )
settings |
PEcAn settings list |
trait.values |
trait.values |
rundir |
rundir |
outdir |
outdir |
run.id |
PEcAn run ID |
restart |
Logical, whether to restart the simulation. |
settings Updated list
Istem Fer