aboutsummaryrefslogtreecommitdiff
path: root/xar.py
blob: fca3887c23c60eb58fc5c81e89be3879d7c6b187 (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
#!/usr/bin/env python3

import xarray as xr
from metpy.units import units
import metpy.calc as mpcalc

import skewt

#grib = pygrib.open('dwd_icon-d2/combined.grib2')
data = xr.load_dataset('dwd_icon-d2/combined.grib2', engine='cfgrib')

lat = 47.9626
lon = 11.9964

for_temp = data.sel(latitude=lat, longitude = lon, method='nearest')

for_temp = for_temp[['r', 't', 'u', 'v']]

for step in for_temp.coords['step']:
    this_step = for_temp.sel(step=step)

    p = this_step.coords['isobaricInhPa'].values * units.hPa
    T = this_step.t.values * units.K
    relHum = this_step.r.values * units.percent
    Td = mpcalc.dewpoint_from_relative_humidity(T, relHum)
    u = this_step.u.values * (units.m / units.s)
    v = this_step.v.values * (units.m / units.s)

    skt = skewt.Skewt(p=p, T=T, Td=Td)
    skt.addWindUV(u, v)
    skt.addInfo("TEST")
    skt.plot(filename=f'skewt.png')

    break