aboutsummaryrefslogtreecommitdiff
path: root/test/grib.py
blob: 767f3d7795066484c56a67cb7617348b71cfedea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
import pygrib

# http://opendata.dwd.de/weather/nwp/icon-d2/grib/00/t/icon-d2_germany_regular-lat-lon_pressure-level_2023080200_000_1000_t.grib2.bz2

# <BASE>/<RUN>/<PARAMETER>/icon-d2_regular-lat-lon_pressure-level_<INIT>_<OFFSET>_<LEVEL>_<PARAMETER>

GRIBDIR='dwd_icon-d2'

# Flugplatz Saal a. d. Saale
target_lat='50.3108796'
target_lon='10.0646952'

# Find nearest coords in model
# TODO

grib = pygrib.open('dwd_icon-d2/combined.grib2')

# GRIB-Objekt wichtige attribute:
# analDate
# validDate
# units
# level
# typeOfLevel
# name
# shortName

for grb in grib:
    #print(grb)
    vals = grb.values

    lats, lons = grb.latlons()

    for k in grb.keys():
        print(k)

    print(grb.analDate)
    print(grb.validDate)
    print(grb.units)
    print(grb.typeOfLevel)
    break

    # TODO Data in xarray?

    print(grb.name)
    print(grb.level)

    #print('lats min/max: ', lats.shape, lats.max(), lats.min())
    #print('lons min/max: ', lons.shape, lons.max(), lons.min())

    #print(vals.shape)

    #print(vals[100][::100])

    #print(grb.latlons())