aboutsummaryrefslogtreecommitdiff
path: root/xar.py
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2023-08-25 12:23:02 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2023-08-25 12:23:02 +0200
commit7a4b8a91ce5b9bbd2ce806d2463e95634ad8b1a1 (patch)
tree74d99cb96a93c974a84308516d8362f5f0c338d2 /xar.py
parent42210578d4b6fece59a57c1a5eedec85e89b8a05 (diff)
downloadmeteo_toolbox-7a4b8a91ce5b9bbd2ce806d2463e95634ad8b1a1.tar.gz
skewt with CAPE/CIN and info
Diffstat (limited to 'xar.py')
-rwxr-xr-xxar.py31
1 files changed, 28 insertions, 3 deletions
diff --git a/xar.py b/xar.py
index fca3887..13d5f62 100755
--- a/xar.py
+++ b/xar.py
@@ -4,8 +4,19 @@ import xarray as xr
from metpy.units import units
import metpy.calc as mpcalc
+import numpy as np
+
+import datetime
+
import skewt
+def np_time_convert(dt64):
+ unix_epoch = np.datetime64(0, 's')
+ one_second = np.timedelta64(1, 's')
+ seconds_since_epoch = (dt64 - unix_epoch) / one_second
+
+ return datetime.datetime.utcfromtimestamp(seconds_since_epoch)
+
#grib = pygrib.open('dwd_icon-d2/combined.grib2')
data = xr.load_dataset('dwd_icon-d2/combined.grib2', engine='cfgrib')
@@ -26,9 +37,23 @@ for step in for_temp.coords['step']:
u = this_step.u.values * (units.m / units.s)
v = this_step.v.values * (units.m / units.s)
+ valid = np_time_convert(step.valid_time.values)
+ init = np_time_convert(step.time.values)
+
+ valid_str = valid.strftime('%d %b %Y - %HUTC')
+ init_str = init.strftime('%d %b %Y - %HUTC')
+ hours_since_init_str = str(int(this_step.step.values / np.timedelta64(1,'h'))).zfill(2)
+
skt = skewt.Skewt(p=p, T=T, Td=Td)
skt.addWindUV(u, v)
- skt.addInfo("TEST")
- skt.plot(filename=f'skewt.png')
+ skt.addInfo(f"VALID: {valid_str}")
+ skt.addInfo(f"INIT : {init_str}")
+ skt.addInfo(f"LAT {lat} LON {lon}")
+ skt.addInfo('INIT+' + hours_since_init_str)
+ skt.addInfo(f'')
+ skt.addAnalysis(shade=True, analysis='lcl')
+ skt.addInfo("DWD ICON-D2")
+
+ init_for_filename = init.strftime('%Y-%m-%d-%H')
- break
+ skt.plot(filename=f'skewt_{init_for_filename}+{hours_since_init_str}.png')