Skip to main content

dwdGribExtractor: A tiny Python interface to request and extract NWP grib file data from opendata.dwd.de

https://img.shields.io/pypi/v/dwdGribExtractor.svg

dwdGribExtractor is a smart package to easely extract data from numerical weather prediction grib files provided by DWD. The difference to other packages is the location flexibility. So every point on the 2.2km x 2.2km grid (ICON-D2) can be retrieved for the next X forecast hours.

At the moment only ICON_D2 is supported.

Supported weather variables

For currently available weather variabels see: ICON User Manual Chapter 6.1.4 table 6.4

Installation

Install with pip:

$ pip install dwdGrilbExtractor

Dependencies

To read the grib2 files xarray with cfgrib engine is used. The easiest way to install cfgrib and all its binary dependencies is via Conda:

$ conda install -c conda-forge cfgrib

alternatively, if you install the binary dependencies yourself, you can install the Python package from PyPI with:

$ pip install cfgrib

Binary dependencies

cfgrib depends on the eccodes python package to access the ECMWF ecCodes binary library, when not using conda please follow the System dependencies section there.

Windows

It is strongly recommended to use Unix enironment running dwdGrib2location. For windows several issues may appear. At the moment dwdGrib2location is tested with Windows10 and works if following requirements are satiesfied. To build eccodes on windows by your own should be avoided. The easiest way to use eccodes on windows is to install it in an MSYS environment.

  1. Install MSYS

  2. Install eccodes. Depending on your system run in the MSYS cli:

    $ pacman -S mingw-w64-ucrt-x86_64-eccodes
  3. Set environment variables:

    ECCODES_DIR = <path_to_ecccodes_install_dir> e.g (C:\msys64\ucrt64)
    ECCODES_DEFINITION_PATH = <path_to_eccodes_definitions> (e.g C:\msys64\ucrt64\share\eccodes\definitions)
  4. Add eccodes to path. This is the folder inside the MSYS environment where the .exe files are located:

    e.g. C:\msys64\ucrt64\bin
  5. Install ecCodes:

    $ pip install eccodes
  6. Install cfgrib:

    $ pip install cfgrib
  7. Check if cfgrib is working:

    $ python -m cfgrib selfcheck
    Found: ecCodes v2.20.0.
    Your system is ready.

Linux

1. Install eccodes with apt or build it by your own TODO

Example

locationList = {
    "Vienna": {
        "lat": 48.20,
        "lon": 16.37
    },
    "Graz": {
        "lat": 47.07,
        "lon": 15.43
    }
}

variables = ["aswdir_s", "aswdifd_s", "t_2m"]

forecast = ICON_D2(locations = locationList, forecastHours = 3)
data = forecast.collectData(varList = variables, cores = None) # Disable multiprocessing
#data = forecast.collectData(varList = variables, cores = 4)


#### Indexing one location
loc = "Graz"
result = data.loc[loc]
result = data.loc[loc, "2021-09-06 06:15:00"]

#### Indexing multiple locations
loc = ["Graz", "Vienna"]
result = data.loc[loc]

#### Indexing one location with datetime condition
loc = "Graz"
mask = data.loc[loc].index.get_level_values(0) > np.datetime64('2021-09-06T06:15:00')
mask = data.loc[loc].index.get_level_values(0).hour == 8
result = data.loc[loc][mask]

#### Indexing multiple locations with datetime condition
loc = ["Graz", "Vienna"]
mask = data.loc[loc].index.get_level_values(1) > np.datetime64('2021-09-06 06:15:00')
mask = data.loc[loc].index.get_level_values(1).hour == 8
result = data.loc[loc][mask]

Knwon Issues

Windows

  • Multiprocessing on some windows machines may not work. Disable it by setting forecast.collectData(varList = variables, cores = None)

  • Spyder IDE does not produce print outputs if multiprocessing is enabled.

  • Dont run the code in Spyder with F5 or debug mode. This calls runfile() and sometimes crashes memory.

Author

Manuel Strohmaier

License

Code license

Licensed under the MIT license. See LICENSE for details.

Data license

The DWD has information about their terms of use policy in German and English.

Metadata

Release files for dwdGribExtractor 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dwdGribExtractor 0.0.7
File Size Uploaded
dwdGribExtractor-0.0.7.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dwdGribExtractor 0.0.7
File Interpreter ABI Platform
dwdGribExtractor-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 16.0 kB

Release files / dwdGribExtractor-0.0.7.tar.gz

Download URL dwdGribExtractor-0.0.7.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6e0bc94f259fe3db956841f1bc48456e75e2c5eb84882233bf42fddb56f8c174
BLAKE2b-256 checksum
How to use checksums
8ff4aa55f4baad457990b07be88baf875b968acc9c14d82f28034040650adc81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.5

Release files / dwdGribExtractor-0.0.7-py3-none-any.whl

Download URL dwdGribExtractor-0.0.7-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f13ac7f2cd8fb6e4eb898e0287258e3480095f82fe414702cc6978c76be8546
BLAKE2b-256 checksum
How to use checksums
60175a8572a6d1fb3bfe4c6403d9fa334a159da72a2b1f4f1fbdedee5d6a1253
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page