brry / rdwd

download climate data from DWD (German Weather Service)
https://bookdown.org/brry/rdwd
72 stars 13 forks source link

grib2 reading fails #28

Closed brry closed 2 years ago

brry commented 3 years ago
nwp_t2m_base <- "ftp://opendata.dwd.de/weather/nwp/icon-d2/grib/03/p"
nwp_urls <- indexFTP("", base=nwp_t2m_base, dir=tempdir())
nwp_file <- dataDWD(nwp_urls[6], base=nwp_t2m_base, dir=tempdir(), joinbf=TRUE, dbin=TRUE, read=FALSE)
nwp_data <- readDWD(nwp_file, quiet=TRUE)

Fails with messsage from rgdal::readGDAL: **.grib2 is a grib file, but no raster dataset was successfully identified.

brry commented 3 years ago

I think it worked in January even though GDAL and icon seem to be incompatible since 2018: https://github.com/OSGeo/gdal/issues/1018: back then I used a file in ftp-cdc.dwd.de/weather/nwp/cosmo-d2/grib/00/t_2m On the new opendata.dwd.de/weather/nwp, the cosmo-d2 folder no longer exists, see tree

brry commented 3 years ago

See also https://www.dwd.de/DE/leistungen/opendata/neuigkeiten/opendata_aug2020_01.html which says

The grid definition file for ICON-D2/ICON-D2-EPS (Germany) is available at: https://opendata.dwd.de/weather/lib/cdo/icon_grid_0047_R19B07_L.nc.bz2 and Guide for converting the original ICON triangular grid into a regular lat/lon grid: https://www.dwd.de/DE/leistungen/opendata/help/modelle/Opendata_cdo_EN.pdf

dimfalk commented 2 years ago

Hey Berry,

having retirement of rgdal, rgeos and maptools by the end of 2023 in mind, have you considered migrating to {stars}?

stars::read_stars("*.grib2") seems to do the job.

PS:

On the new opendata.dwd.de/weather/nwp, the cosmo-d2 folder no longer exists, see tree

COSMO-D2 has been decommissioned in favor of ICON-D2, somewhere in 02/2021, as far as I remember.

brry commented 2 years ago

Hey thanks so much for the pointers! I was not aware of that. It's not perfect as the rdwd maintainer to not follow r-spatial, but time limitations and other real life annoyances get in the way...

I plan to implement stars for grib2 in the next days (before the next CRAN release).

dimfalk commented 2 years ago

You're very welcome! No worries, maintainance can be quite time-consuming.. 😏

dimfalk commented 2 years ago

Small remark since I have to mess around with raster packages at the moment:

stars::read_stars() seems to fail for the icon-d2_germany_icosahedral_model-level_*.grib2.bz2 files:

trying to read file: C:\Temp\icon-d2_germany_icosahedral_model-level_2022051903_000_14_p.grib2
Error in CPL_read_gdal(as.character(x), as.character(options), as.character(driver),  : 
  file not found
In addition: Warning message:
In CPL_read_gdal(as.character(x), as.character(options), as.character(driver),  :
  GDAL Error 4: C:\Temp\icon-d2_germany_icosahedral_model-level_2022051903_000_14_p.grib2 is a grib file, but no raster dataset was successfully identified.

icon-d2_germany_regular-lat-lon_model-level_*.grib2.bz2 files work fine with stars::read_stars().

However, there is also terra being able to read grib2 via terra::rast("*.grib2"). No idea yet which one to prefer in which use case tbh.

brry commented 2 years ago

I added terra and stars support to readDWD.grib2() and noted in the examples which files work and which don't.
terra has a plot function that works out of the box (see the new examples), so I set that as the default pack.

I will close this issue now, but anybody may feel free to reopen it if changes are needed.

brry commented 1 year ago

rgdal will be retired 2023, so the rgdal option will be removed. Any contrary wishes can be posted here, of course :)