Skip to contents

This function creates a table with environmental variables from an specific subset of subcatchments.

Usage

get_predict_table(
  variable,
  statistics = "ALL",
  tile_id,
  input_var_path,
  subcatch_id,
  out_file_path,
  n_cores = NULL,
  read = TRUE,
  quiet = TRUE,
  tempdir = NULL,
  overwrite = FALSE
)

Arguments

variable

character vector of variable names. Possible values are: all variables in the Env90m dataset, which can bew viewed by calling 'download__tables()'. For more details, see '?download_env90m_tables'.

statistics

character vector of statistics names. Possible values are "sd", "mean", "range" or "ALL". Default "ALL".

tile_id

character. The IDs of the tiles of interest.

input_var_path

path to directory that contains table with environmental variables for entire tiles. Tables may be in subdirectories of the provided directory.

subcatch_id

path to a text file with subcatchment ids, or numeric vector containing subcatchment ids.

out_file_path

character. The path to the output file to be created.

n_cores

numeric. Number of cores used for parallelization.

read

logical. If TRUE, the table with environmental variables gets read into R. If FALSE, the table is only stored on disk. Default is TRUE.

quiet

logical. If FALSE, the standard output will be printed. Default is TRUE.

tempdir

String. Path to the directory where to store/look for the file size table. If not passed, defaults to the output of base::tempdir().

overwrite

logical. If TRUE, the output file will be overwritten if it. already exists. Useful for repeated testing. Default is FALSE.

Value

The function returns a table with

  • sub-catchment ID (subcID)

  • a column for each descriptive statistic of each variable (eg. bio1_mean: mean of the variable bio1)

Author

Jaime García Márquez, Yusdiel Torres-Cambas

Examples

# Download test data into the temporary R folder
# or define a different directory
my_directory <- tempdir()
download_test_data(my_directory) # TODO make test data available for download!

# Define variable and tile:
var <- c("bio1")
tile_id <- c("h18v02")

# Point to input data
in_path <- paste0(my_directory, '/hydrography90m_test_data')
subc_ids <- paste0(my_directory, '/hydrography90m_test_data/subc_IDs.txt')
output <- paste0(my_directory, '/hydrography90m_test_data/predictTB.csv')

# Run the function with 2 cores and calculate all statistics:
get_predict_table(variable = var,
                  statistics = c("ALL"),
                  tile_id = tile_id,
                  input_var_path = in_path,
                  subcatch_id = subc_ids,
                  out_file_path = output,
                  read = FALSE, quiet = FALSE,
                  n_cores = 2)

# Now you can see the result in /tmp/.../hydrography90m_test_data/predictTB.csv