############
## Loading the monthly time series of precipitation within the Ebro River basin.
data(EbroPPtsMonthly)
## Loading the gis data
data(EbroPPgis)
## Loading the shapefile with the subcatchments
data(EbroCatchmentsCHE)
## Projection for the Subcatchments file
# European Datum 50, Zone 30N
require(sp)
p4s <- CRS("+proj=utm +zone=30 +ellps=intl +units=m +no_defs")
## Selecting the first day of 'EbroPPtsMonthly' for all the stations.
# The first column of 'EbroPPtsMonthly' has the dates
x.ts <- as.numeric(EbroPPtsMonthly[1, 2:ncol(EbroPPtsMonthly)])
## Setting the name of the gauging stations
names(x.ts) <- colnames(EbroPPtsMonthly[1,2:ncol(EbroPPtsMonthly)])
##################################################
## 1) IDW interpolation and plot
## Probably you will need to resize your window
x.idw <- hydrokrige(x.ts= x.ts, x.gis=EbroPPgis,
X="EAST_ED50", Y="NORTH_ED50", sname="ID", bname="CHE_BASIN_NAME",
type= "both",
subcatchments= EbroCatchmentsCHE,
cell.size= 3000,
ColorRamp= "Precipitation",
main= "IDW Precipitation on the Ebro")
##################################################
## 2) Ordinary Kriging interpolation and plot, in catchments defined by a shapefile
## Probably you will need to resize your window
# Computing OK, over of 3000x3000m, sampled withinthe subcatchments defined by 'subcatchments'
x.ok <- hydrokrige(x.ts= x.ts, x.gis=EbroPPgis,
X="EAST_ED50", Y="NORTH_ED50", sname="ID", bname="CHE_BASIN_NAME",
type= "both", formula=value~1,
subcatchments= EbroCatchmentsCHE,
p4s= p4s,
cell.size= 3000,
ColorRamp= "Precipitation",
main= "OK Precipitation on the Ebro", arrow.plot= TRUE,
arrow.offset= c(900000,4750000), arrow.scale= 20000,
scalebar.plot= TRUE,
sb.offset= c(400000,4480000), sb.scale= 100000)
##################################################
## 3) Ordinary Kriging interpolation and plot, in an area defined by a raster map.
## The raster map may be any \link[sp]{SpatialGridDataFrame-class} object, read with
## the \code{\link[rgdal]{readGDAL}} function of the \pkg{rgdal} package or similar.
## Probably you will need to resize your window
#Loading the DEM
data(EbroDEM1000m)
#Giving a meaningful name to the predictor
EbroDEM1000m$ELEVATION <- EbroDEM1000m$band1
# Saving memory
EbroDEM1000m$band1 <- NULL
# Computing OK, over the spatial grid defined by the DEM
x.ok <- hydrokrige(x.ts= x.ts, x.gis=EbroPPgis,
X="EAST_ED50", Y="NORTH_ED50", sname="ID",
formula=value~1,
p4s= p4s,
predictors=EbroDEM1000m,
ColorRamp= "Precipitation",
main= "OK Precipitation on the Ebro",
arrow.plot= TRUE,
arrow.offset= c(900000,4750000), arrow.scale= 20000,
scalebar.plot= TRUE,
sb.offset= c(400000,4480000), sb.scale= 100000)
##################################################
## 4) Kriging with External Drift interpolation and plot
## Probably you will need to resize your window
#Loading the DEM
data(EbroDEM1000m)
#Giving a meaningful name to the predictor
EbroDEM1000m$ELEVATION <- EbroDEM1000m$band1
# Saving memory
EbroDEM1000m$band1 <- NULL
# Computing KED
x.ked <- hydrokrige(x.ts= x.ts, x.gis=EbroPPgis,
X="EAST_ED50", Y="NORTH_ED50", sname="ID",
bname="CHE_BASIN_NAME", elevation="ELEVATION",
type= "cells",
formula=value~ELEVATION,
subcatchments= EbroCatchmentsCHE,
predictors=EbroDEM1000m,
cell.size= 3000,
ColorRamp= "Precipitation",
main= "KED Precipitation on the Ebro",
arrow.plot= TRUE,
arrow.offset= c(900000,4750000), arrow.scale= 20000,
scalebar.plot= TRUE,
sb.offset= c(400000,4480000), sb.scale= 100000)
##################################################
## 5) Block IDW interpolation and plot of 'EbroPPtsMonthly' for 3 months
x.idw <- hydrokrige(x.ts= EbroPPtsMonthly, x.gis=EbroPPgis,
X="EAST_ED50", Y="NORTH_ED50", sname="ID",
bname="CHE_BASIN_NAME",
type= "cells", #'both'
subcatchments= EbroCatchmentsCHE,
cell.size= 3000,
ColorRamp= "Precipitation",
arrow.plot= TRUE,
arrow.offset= c(900000,4750000), arrow.scale= 20000,
scalebar.plot= TRUE,
sb.offset= c(400000,4480000), sb.scale= 100000,
dates=1,
from="1942-01-01", to="1942-03-01")
Run the code above in your browser using DataLab