KWB-R / kwb.dwd

R Package to Access Information Provided by Deutscher Wetterdienst (DWD)
https://kwb-r.github.io/kwb.dwd
MIT License
0 stars 0 forks source link

Add `hyras_de` data (`daily` / `monthly` / `multi_annual`) #45

Open mrustl opened 2 years ago

mrustl commented 2 years ago

Actually hyras_de offers these now: https://opendata.dwd.de/climate_environment/CDC/grids_germany/daily/hyras_de/air_temperature_min/ https://opendata.dwd.de/climate_environment/CDC/grids_germany/daily/hyras_de/air_temperature_mean/ https://opendata.dwd.de/climate_environment/CDC/grids_germany/daily/hyras_de/air_temperature_max/ https://opendata.dwd.de/climate_environment/CDC/grids_germany/daily/hyras_de/humidity/ https://opendata.dwd.de/climate_environment/CDC/grids_germany/daily/hyras_de/precipitation/ https://opendata.dwd.de/climate_environment/CDC/grids_germany/daily/hyras_de/radiation_global/ https://opendata.dwd.de/climate_environment/CDC/grids_germany/monthly/hyras_de/precipitation/ https://opendata.dwd.de/climate_environment/CDC/grids_germany/multi_annual/hyras_de/precipitation/

These were for example used here:

grafik

https://github.com/AndreasWunsch/Long-Term-GWL-Simulations

I extended read_daily_data_over_shape() to support all possible variables. The function list_daily_grids_germany_tgz() tells you which variables are available:

> kwb.dwd:::list_daily_grids_germany_tgz("x")
 Error in match.arg(variable, c("evapo_p", "evapo_r", "frost_depth", "soil_moist", : 
'arg' should be one of “evapo_p”, “evapo_r”, “frost_depth”, “soil_moist”, “soil_temperature_5cm”

Unfortunately, precipitation data are not available on a daily basis.

I added a function read_monthly_data_over_shape() that can provide precipitation data as well as further variables. The function list_monthly_grids_germany_asc_gz() informs about possible variables:

> kwb.dwd:::list_monthly_grids_germany_asc_gz(variable = "x")
 Error in match.arg(variable, c("air_temperature_max", "air_temperature_mean", : 
'arg' should be one of “air_temperature_max”, “air_temperature_mean”, “air_temperature_min”, “drought_index”, “evapo_p”, “evapo_r”, “frost_depth”, “precipitation”, “soil_moist”, “soil_temperature_5cm”, “sunshine_duration”

Finally, our package fhpredict has a function to read (and cut) current precipitation data (RADOLAN), see: https://kwb-r.github.io/fhpredict/articles/tutorial.html#spacially-select-and-aggregate-rain-data

Altogether: Too many different functions that do too many different things...

Originally posted by @hsonne in https://github.com/KWB-R/kwb.dwd/issues/37#issuecomment-1251872323

mrustl commented 2 years ago

Example for download. File format is netCDF:

url <- "https://opendata.dwd.de/climate_environment/CDC/grids_germany/monthly/hyras_de/precipitation/pr_hyras_1_1931_v3-0_de_monsum.nc"

tfile <- basename(url)
download.file(url, tfile, mode = "wb")

hyras_sf <- sf::read_sf(tfile)
#> Warning in CPL_read_ogr(dsn, layer, query, as.character(options), quiet, :
#> GDAL Message 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid
#> argument".
hyras_sf
#> # A tibble: 12 × 2
#>     time number_of_station
#>    <dbl>             <dbl>
#>  1   378              881.
#>  2  1086              879.
#>  3  1794              876.
#>  4  2526              879.
#>  5  3258              883.
#>  6  3990              884.
#>  7  4722              883.
#>  8  5466              886.
#>  9  6198              886.
#> 10  6930              885.
#> 11  7662              888.
#> 12  8394              883.
hyras_raster <- raster::raster(tfile)
#> Lade nötigen Namensraum: ncdf4
hyras_raster
#> class      : RasterLayer 
#> band       : 1  (of  12  bands)
#> dimensions : 1100, 1200, 1320000  (nrow, ncol, ncell)
#> resolution : 1000, 1000  (x, y)
#> extent     : 3500000, 4700000, 2100000, 3200000  (xmin, xmax, ymin, ymax)
#> crs        : +proj=lcc +lat_0=52 +lon_0=10 +lat_1=35 +lat_2=65 +x_0=4000000 +y_0=2800000 +ellps=GRS80 +units=m +no_defs 
#> source     : pr_hyras_1_1931_v3-0_de_monsum.nc 
#> names      : Precipitation 
#> z-value    : 1931-01-16 18:00:00 
#> zvar       : pr

Created on 2022-09-22 by the reprex package (v2.0.1)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.2.1 (2022-06-23 ucrt) #> os Windows 10 x64 (build 19044) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate German_Germany.utf8 #> ctype German_Germany.utf8 #> tz Europe/Berlin #> date 2022-09-22 #> pandoc 2.18 @ C:/Program Files/RStudio/bin/quarto/bin/tools/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.2.0) #> class 7.3-20 2022-01-16 [2] CRAN (R 4.2.1) #> classInt 0.4-7 2022-06-10 [1] CRAN (R 4.2.0) #> cli 3.3.0 2022-04-25 [1] CRAN (R 4.2.0) #> codetools 0.2-18 2020-11-04 [2] CRAN (R 4.2.1) #> DBI 1.1.3 2022-06-18 [1] CRAN (R 4.2.0) #> digest 0.6.29 2021-12-01 [1] CRAN (R 4.2.0) #> dplyr 1.0.9 2022-04-28 [1] CRAN (R 4.2.0) #> e1071 1.7-11 2022-06-07 [1] CRAN (R 4.2.0) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.2.0) #> evaluate 0.15 2022-02-18 [1] CRAN (R 4.2.0) #> fansi 1.0.3 2022-03-24 [1] CRAN (R 4.2.0) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.0) #> fs 1.5.2 2021-12-08 [1] CRAN (R 4.2.0) #> generics 0.1.3 2022-07-05 [1] CRAN (R 4.2.0) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0) #> highr 0.9 2021-04-16 [1] CRAN (R 4.2.0) #> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.2.0) #> KernSmooth 2.23-20 2021-05-03 [2] CRAN (R 4.2.1) #> knitr 1.39 2022-04-26 [1] CRAN (R 4.2.0) #> lattice 0.20-45 2021-09-22 [2] CRAN (R 4.2.1) #> lifecycle 1.0.2 2022-09-09 [1] CRAN (R 4.2.1) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0) #> ncdf4 1.19 2021-12-15 [1] CRAN (R 4.2.0) #> pillar 1.8.1 2022-08-19 [1] CRAN (R 4.2.1) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0) #> proxy 0.4-27 2022-06-09 [1] CRAN (R 4.2.0) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.2.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0) #> raster 3.5-15 2022-01-22 [1] CRAN (R 4.2.0) #> Rcpp 1.0.9 2022-07-08 [1] CRAN (R 4.2.1) #> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.2.1) #> rgdal 1.5-32 2022-05-09 [1] CRAN (R 4.2.0) #> rlang 1.0.5 2022-08-31 [1] CRAN (R 4.2.1) #> rmarkdown 2.14 2022-04-25 [1] CRAN (R 4.2.0) #> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.2.0) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.1) #> sf 1.0-7 2022-03-07 [1] CRAN (R 4.2.0) #> sp 1.5-0 2022-06-05 [1] CRAN (R 4.2.0) #> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.2.0) #> stringr 1.4.1 2022-08-20 [1] CRAN (R 4.2.1) #> terra 1.5-34 2022-06-09 [1] CRAN (R 4.2.0) #> tibble 3.1.7 2022-05-03 [1] CRAN (R 4.2.0) #> tidyselect 1.1.2 2022-02-21 [1] CRAN (R 4.2.0) #> units 0.8-0 2022-02-05 [1] CRAN (R 4.2.0) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.2.0) #> vctrs 0.4.1 2022-04-13 [1] CRAN (R 4.2.0) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0) #> xfun 0.31 2022-05-10 [1] CRAN (R 4.2.0) #> yaml 2.3.5 2022-02-21 [1] CRAN (R 4.2.0) #> #> [1] C:/Users/mrustl/AppData/Local/R/win-library/4.2 #> [2] C:/Program Files/R/R-4.2.1/library #> #> ────────────────────────────────────────────────────────────────────────────── ```