12 - use case: values at locations in grid

Obtain time series of values at a selected location in gridded data.

library(rdwd)
# select data
index <- indexFTP(folder="annual/air_temperature_max", base=gridbase, dir=localtestdir())
index <- index[-(1:2)] # exclude description files
index <- index[as.numeric(substr(index,62,65))>=2013] # after year 2013
index
## [1] "annual/air_temperature_max/grids_germany_annual_air_temp_max_201317.asc.gz"
## [2] "annual/air_temperature_max/grids_germany_annual_air_temp_max_201417.asc.gz"
## [3] "annual/air_temperature_max/grids_germany_annual_air_temp_max_201517.asc.gz"
## [4] "annual/air_temperature_max/grids_germany_annual_air_temp_max_201617.asc.gz"
## [5] "annual/air_temperature_max/grids_germany_annual_air_temp_max_201717.asc.gz"
## [6] "annual/air_temperature_max/grids_germany_annual_air_temp_max_201817.asc.gz"
## [7] "annual/air_temperature_max/grids_germany_annual_air_temp_max_201917.asc.gz"
## [8] "annual/air_temperature_max/grids_germany_annual_air_temp_max_202017.asc.gz"
# download & read data:
tempmax <- dataDWD(index, base=gridbase, joinbf=TRUE, dir=localtestdir())
names(tempmax) <- substr(names(tempmax), 62, 65)
# visual data & projection check:
plotRadar(tempmax[[1]], proj="seasonal",extent="seasonal", 
          main="Annual grid of monthly averaged daily maximum air temperature (2m) - 2013")

# raster stack:
tempmax_stack <- raster::stack(tempmax)
tempmax_stack <- projectRasterDWD(tempmax_stack, proj="seasonal",extent="seasonal")
tempmax_stack
## class      : RasterBrick 
## dimensions : 898, 724, 650152, 8  (nrow, ncol, ncell, nlayers)
## resolution : 0.0143, 0.00899  (x, y)
## extent     : 5.49436, 15.84756, 47.05917, 55.13219  (xmin, xmax, ymin, ymax)
## crs        : +proj=longlat +datum=WGS84 +no_defs 
## source     : memory
## names      :     X2013,     X2014,     X2015,     X2016,     X2017,     X2018,     X2019,     X2020 
## min values : 0.5851453, 1.9204592, 2.4851453, 0.9851453, 0.8851453, 1.6851453, 1.4851453, 2.0851453 
## max values :  15.56372,  17.52138,  17.48903,  16.29086,  16.92138,  18.00000,  17.42138,  18.20000
raster::plot(tempmax_stack, zlim=range(raster::cellStats(tempmax_stack, range)) )

# Time series at given location:
loc <- data.frame(x=12.65295, y=53.06547) # Aussichtspunkt Kyritz-Ruppiner Heide
raster::extract(tempmax_stack, loc)
##      X2013 X2014 X2015 X2016 X2017    X2018 X2019    X2020
## [1,]  12.9  14.6  14.3    14  13.5 15.19027  15.2 15.09027