gridPrecip: Grids station precipitation

Description Usage Arguments Value Author(s) See Also Examples

View source: R/gridPrecip.R

Description

Grids station interval precipitation values, so that they can be used as MESH inputs. The station values are distributed over the domain of the basin. Values outside of the basin are set to the missing value. The gridding method is performed by the hydroTSM function hydrokrige, using the IDW (inverse distance weighting) algorithm for each time interval. If there are no values present in a given interval, then the entire domain will be set to the missing value. If all of the values are identical, or if there is a single value, then all of the domain will have that value. It is possible that the IDW algorithm will be unable to grid the specified values in a given interval. In this case, the error is trapped, and the mean of the station values is used for the entire domain.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
gridPrecip(
  precip = NULL,
  source_file_name = "unknown",
  shed_raster = NULL,
  IDW_file = NULL,
  missing_value = 0,
  zeromissing = FALSE,
  quiet = TRUE,
  progress_bar = TRUE
)

Arguments

precip

Required. A list containing 3 elements: 1. the header meta data, 2. the column meta data, and 3. the precipitation values (in mm). These values are returned automatically by the MESHr command read_tb0. Note that the precipitation values are in mm.

source_file_name

Required. The name of the original .tb0 source file. Default value is unknown. The name of the source file is written to the r2c file header.

shed_raster

Required. A RasterBrick object describing the MESH basin. This can be read from a MESH r2c shed file using the MESHr command read_r2c_shed with the parameter as_rasters = TRUE.

IDW_file

Required. Name of the output file which will hold the gridded precipitation for all time intervals.

missing_value

Required. Value to be used if all values in an interval are missing. Default is 0. Also used to code individual missing values.

zeromissing

Required. If there are enough precipitation values for gridding to take place, but there are still missing values, setting zeromissing = TRUE will set the missing values to zero, before the gridding takes place. The default value is FALSE.

quiet

Optional. If TRUE (the default), messages are suppressed. If FALSE, the time interval and messages from each gridding are listed.

progress_bar

Optional. This function can take a long time to execute, depending on the number of time intervals, and the number of stations. If progress_bar = TRUE (the default), a progress bar is displayed showing the completed fraction of the precip. If you are calling this function from a Notebook which is to be knitted to a file, then you will probably want to set progress_bar = FALSE, to avoid having multiple copies of the progress bar in the output file.

Value

If unsuccessful, returns FALSE. If successful, returns TRUE and the gridded precipitation values are written to the IDW_file. Note that each interval's precipitation is written as it is gridded. This saves on memory, and will save at least some of the values in case there is a crash, but is slow. The gridded precipitation is in mm/s.

Author(s)

Kevin Shook

See Also

gridTemp read_r2c_shed read_tb0

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: 
hourly_precip_file <- "Red_Deer_all_hourly_precip_new.tb0"
precip <- read_tb0(hourly_precip_file, values_only = FALSE, timezone = "Etc/GMT+7", NAvalue = -0.1)
shedfile <- "RedDeer_MESH_drainage_database.r2c"
shed_raster <- read_r2c_shed(shedfile, as_rasters = TRUE, values_only = TRUE)
IDW_file <- "RedDeerPrecip_idw.r2c"
source_file_name <- "Red_Deer_all_hourly_precip_new.tb0"
gridPrecip(precip, source_file_name, shed_raster, IDW_file, missing_value = -999)

## End(Not run)

CentreForHydrology/MESHr documentation built on Jan. 11, 2021, 8:34 p.m.