15 - 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)
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"
## [9] "annual/air_temperature_max/grids_germany_annual_air_temp_max_202117.asc.gz"
## [10] "annual/air_temperature_max/grids_germany_annual_air_temp_max_202217.asc.gz"
## [11] "annual/air_temperature_max/grids_germany_annual_air_temp_max_202317.asc.gz"
# download & read data:
tempmax <- dataDWD(index, base=gridbase, joinbf=TRUE)
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")
# terra raster:
tempmax_stack <- terra::rast(tempmax)
tempmax_stack <- projectRasterDWD(tempmax_stack, proj="seasonal",extent="seasonal")
tempmax_stack
## class : SpatRaster
## dimensions : 712, 917, 11 (nrow, ncol, nlyr)
## resolution : 0.01113365, 0.01113365 (x, y)
## extent : 5.565801, 15.77536, 47.13312, 55.06029 (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=longlat +datum=WGS84 +no_defs
## source(s) : memory
## names : 2013, 2014, 2015, 2016, 2017, 2018, ...
## min values : 0.1265155, 1.514933, 2.026515, 0.5265155, 0.4445348, 1.226516, ...
## max values : 15.5918045, 17.526398, 17.495947, 16.2808685, 16.9263973, 18.000000, ...
# Time series at given location:
loc <- data.frame(x=12.65295, y=53.06547) # Aussichtspunkt Kyritz-Ruppiner Heide
round(unlist(terra::extract(tempmax_stack, loc)[-1]),1)
## 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023
## 12.9 14.6 14.2 14.0 13.5 15.1 15.2 15.1 13.6 15.1 14.8