Package 'PEcAn.LPJGUESS'

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

Help Index


calculateGridcellVariablePerPFT

Description

Calculates a per-PFT, gridcell-summed quantity from the LPJ-GUESS state, correctly averaging over patches. This should be put into the SDA procedure.

Usage

calculateGridcellVariablePerPFT(
  model.state,
  variable,
  pft.params,
  min.diam = 5
)

Arguments

model.state

A large multiply-nested list containing the entire LPJ-GUESS state as read by function readStateBinary.LPJGUESS

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.

Value

A numeric vector, with one entry per PFT

Author(s)

Matthew Forrest


Find Closing Bracket

Description

Identifies the line number of the matching closing bracket for a given opening bracket.

Usage

find_closing(find = "}", line_no, file_in, if_else_check = FALSE)

Arguments

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

Value

A numeric value indicating the line number of the matching closing bracket.


Find Stream Size

Description

Determines the size (number of variables) in a stream based on the file content.

Usage

find_stream_size(
  current_stream_type,
  guessh_in,
  LPJ_GUESS_TYPES,
  LPJ_GUESS_CONST_INTS
)

Arguments

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.

Value

A numeric value representing the size (number of streamed variables).


Find Stream Type

Description

Determines the type of a given stream variable in an LPJ-GUESS file.

Usage

find_stream_type(
  class = NULL,
  current_stream_var,
  LPJ_GUESS_CLASSES,
  LPJ_GUESS_TYPES,
  guessh_in
)

Arguments

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.

Value

A character string indicating the stream type.


Find Stream Variable

Description

A helper function that lists streamed variables. It returns the names of streamed variables.

Usage

find_stream_var(file_in, line_nos)

Arguments

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.

Value

A character vector of streamed variable names.


met2model.LPJGUESS

Description

met2model wrapper for LPJ-GUESS

Usage

met2model.LPJGUESS(
  in.path,
  in.prefix,
  outfolder,
  start_date,
  end_date,
  overwrite = FALSE,
  verbose = FALSE,
  ...
)

Arguments

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

Author(s)

Istem Fer


Function to convert LPJ-GUESS model output to standard netCDF format

Description

Convert LPJ-GUESS output to netCDF

Usage

model2netcdf.LPJGUESS(outdir, sitelat, sitelon, start_date, end_date)

Arguments

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

Author(s)

Istem Fer


Function to translate pecan param names and units to lpjguess names and units

Description

Function to translate pecan param names and units to lpjguess names and units

Usage

pecan2lpjguess(trait.values)

Arguments

trait.values

trait.values, list

Value

translated list

Author(s)

Istem Fer


Read Binary File for LPJ-GUESS

Description

Reads a binary file formatted for LPJ-GUESS and extracts relevant data.

Usage

read_binary_LPJGUESS(outdir, version = "PalEON")

Arguments

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

Value

A matrix or list containing the extracted data.


Read State File

Description

Reads a state file and processes its contents for further use.

Usage

read_state(file_path)

Arguments

file_path

A character string specifying the path to the state file.

Value

A list containing the processed state information.


readStateBinary.LPJGUESS

Description

read binary state file of LPJ-GUESS

Usage

readStateBinary(out.path, npft)

Arguments

out.path

location on disk where model run outputs are stored

npft

number of pfts specified in instruction file

Value

Patchpft_list state variables common to all individuals of a particular PFT

Author(s)

Istem Fer


Serialize Starts and Ends

Description

Finds the start and end lines for serialization.

Usage

serialize_starts_ends(file_in, pattern = "void Gridcell::serialize")

Arguments

file_in

A character vector of file lines to search through.

pattern

A character string pattern to look for in the file.

Value

A numeric vector of length 2, giving the start and end line numbers.


Split inputs for LPJ-GUESS model

Description

Splits climate met for LPJGUESS

Usage

split_inputs.LPJGUESS(
  settings,
  start.time,
  stop.time,
  inputs,
  overwrite = FALSE,
  outpath = NULL
)

Arguments

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

Value

name of the split met file

Author(s)

Istem Fer


updateState.LPJGUESS

Description

Adjust LPJ-GUESS state variables based on input parameters.

Usage

update_state_LPJGUESS(
  model.state,
  pft.params,
  dens.initial,
  dens.target,
  AbvGrndWood.initial,
  AbvGrndWood.target,
  AbvGrndWood.epsilon,
  trace,
  min.diam,
  HEIGHT_MAX = 150
)

Arguments

model.state

A large multiply-nested list containing the entire LPJ-GUESS state as read by function readStateBinary.LPJGUESS

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.

Details

Adjust LPJ-GUESS state

Value

And updated model state (as a big old list o' lists)

Author(s)

Matthew Forrest


Write LPJ-GUESS configuration files

Description

Writes a LPJ-GUESS config file.

Usage

write.config.LPJGUESS(defaults, trait.values, settings, run.id, restart = NULL)

Arguments

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.

Details

Requires a pft xml object, a list of trait values for a single model run, and the name of the file to create

Value

configuration file for LPJ-GUESS for given run

Author(s)

Istem Fer, Tony Gardella


Write LPJ-GUESS instruction script

Description

Write LPJ-GUESS instruction script

Usage

write.insfile.LPJGUESS(
  settings,
  trait.values,
  rundir,
  outdir,
  run.id,
  restart = NULL
)

Arguments

settings

PEcAn settings list

trait.values

trait.values

rundir

rundir

outdir

outdir

run.id

PEcAn run ID

restart

Logical, whether to restart the simulation.

Value

settings Updated list

Author(s)

Istem Fer