fnc_read_climdb_poly: Reading from Climate Database when input is a Polygon Layer

View source: R/fnc_read_climdb_poly.R

fnc_read_climdb_polyR Documentation

Reading from Climate Database when input is a Polygon Layer

Description

This function reads in the Project Climate Data files in "R:/klima/whh/brook90_input/rds/" plus the respective tranche, and processes the data correctly, so that it can be used via the function parameters climate and climate_args in run_multisite_LWFB90. Function arguments must be passed to run_multisite_LWFB90 as a list of lists, which is created in fnc_get_climate_args_poly See example on how to do this.

Usage

fnc_read_climdb_poly(IDs, clim_dir, weights, mindate = NA, maxdate = NA)

Arguments

clim_dir

path to project climate data files

weights

vector of weights, which are being calculated from the percentage of climate-cell area covered by the respective polygon

mindate

R-date-object, optional. Set if only a selection of the data (1961-2020) in the climate-database shall be retrieved.

maxdate

R-date-object, optional, same as mindate. Must be provided with mindate if sub-selection on date is desired.

ID_custom

ID-name of point in project climate data base

Value

returns climate data in correct format

Examples

# set options
options.b90 <- set_optionsLWFB90(startdate = as.Date("2009-01-01"),
                                 enddate = as.Date("2010-12-31"),
                                 root_method = "soilvar")


# climate arguments for on-the-fly-processing
clim_args <- fnc_get_climate_args_poly(df.ids = shp.ids,
                                       mindate = options.b90$startdate,
                                       maxdate = options.b90$enddate)

# create soil
soil.test <- fnc_get_soil(df.ids = shp.ids,
                          soil_option = "STOK",
                          PTF_to_use = "WESSOLEK",
                          parallel_processing = F)


# create parameters
parms.test <- fnc_get_params(df.ids = shp.ids,
                             tree_species = "spruce")

# remove poins without soil information
with_soil_data <- which(shp.ids$ID_custom %in% names(soil.test))
parms.test <- parms.test[with_soil_data]
clim_args <- clim_args[with_soil_data]

res <- run_multisite_LWFB90(options_b90 = options.b90,
                            param_b90 = parms.test,
                            soil = soil.test,

                            climate = fnc_read_climdb_poly,
                            climate_args = clim_args,

                            rtrn_input = F,

                            cores = parallel::detectCores())

# single df
clim_args[[1]]
test <- fnc_read_climdb_poly(IDs = clim_args[[1]]$IDs,
                             clim_dir = clim_args[[1]]$clim_dir,
                             weights = clim_args[[1]]$weights,
                             mindate = clim_args[[1]]$mindate,
                             maxdate = clim_args[[1]]$maxdate)


rhabel/modLWFB90 documentation built on Nov. 21, 2024, 3:28 a.m.