Any time series in the transfR package is supposed to be georeferenced. In order to use your discharge observations in transfR, two inputs are thus required: the discharge time series and a georeferenced vector layer describing the location of this gauged catchments. These two attributes will be merged into one R object of class stars. This vignette provides some guidance to create this object from common input formats.
For the sake of the example, we will create a shapefile and a text file from the ‘Oudon’ example dataset provided with the transfR package:
library(transfR) data(Oudon) <- tempdir(check = TRUE) wd st_write(st_sf(ID = paste0("ID", 1:6), geom = st_geometry(Oudon$obs)), dsn = file.path(wd, "catchments.shp"), delete_layer = TRUE) write.table(data.frame(DateTime = format(st_get_dimension_values(Oudon$obs,1), "%Y-%m-%d %H:%M:%S"), ID1 = Oudon$obs$Qobs[,1], ID2 = Oudon$obs$Qobs[,2], ID3 = Oudon$obs$Qobs[,3], ID4 = Oudon$obs$Qobs[,4], ID5 = Oudon$obs$Qobs[,5], ID6 = Oudon$obs$Qobs[,6]), file = file.path(wd, "discharge.txt"), col.names = TRUE, row.names = FALSE, sep = ";", quote = FALSE)
The spacial vector layer describes the location of the catchments. It could be the catchments delineation, outlet or centroid. However, catchment delineation allows a better assessment of the distances between them (de Lavenne et al. 2016). It is advised to use the sf package to load this layer.
library(sf) <- st_read(file.path(wd, "catchments.shp"), "catchments", stringsAsFactors = FALSE) catchments <- catchments[1:5,] # Gauged catchments obs_sf <- catchments[6,] # Ungauged catchmentssim_sf
It is advised to provide the units of your discharge time series using the units package.
library(units) <- read.table(file.path(wd, "discharge.txt"), header = TRUE, sep = ";", Q colClasses = c("character", rep("numeric", 6))) <- as.matrix(Q[,-1]) Qmatrix <- set_units(Qmatrix, "m^3/s")Qmatrix
These time series and the spacial vector layer are merged into one stars object. Make sure that both are organised in the same order. The stars object will have two dimensions (time and space) and one attribute (discharge observation) for gauged catchments. The ungauged catchments will have the same dimensions but no attribute for the moment.
library(stars) <- Qmatrix[,obs_sf$ID] #to have the same order as in the spacial data layer Qmatrix <- st_as_stars(list(Qobs = Qmatrix), obs_st dimensions = st_dimensions(time = as.POSIXct(Q$DateTime, tz="UTC"), space = obs_sf$geometry)) <- st_as_stars(dimensions = st_dimensions(time = as.POSIXct(Q$DateTime, tz="UTC"), sim_st space = sim_sf$geometry))
These stars objects can finally be used to create objects of class
transfR by using the function
st) and perform simulations.
<- as_transfr(st = obs_st, hl = Oudon$hl[1:5]) obs <- as_transfr(st = sim_st, hl = Oudon$hl)sim
A transfer of hydrograph from the gauged catchments to the ungauged
catchments can then quickly be implemented using the
<- quick_transfr(obs, sim, parallel = TRUE, cores = 2)sim
The simulated time series will be available in its stars object as new attributes.
$st sim#> stars object with 2 dimensions and 2 attributes #> attribute(s): #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> RnSim [mm/h] 0.0281581 0.05252997 0.07866417 0.1007725 0.1221599 0.3407832 #> Qsim [m^3/s] 1.1534612 1.93758212 2.92629686 3.7211211 4.5186670 11.9147539 #> NA's #> RnSim [mm/h] 444 #> Qsim [m^3/s] 466 #> dimension(s): #> from to offset delta refsys point #> time 1 2185 2019-12-01 UTC 1 hours POSIXct FALSE #> space 1 1 NA NA RGF93 v1 / Lambert-93 FALSE #> values #> time NULL #> space POLYGON ((404349 6766262, 4...