diff options
-rwxr-xr-x | horizontal.py | 35 | ||||
-rwxr-xr-x | run.py | 19 | ||||
-rwxr-xr-x | vertical_from_grib.py | 10 |
3 files changed, 49 insertions, 15 deletions
diff --git a/horizontal.py b/horizontal.py index d421cd1..280599f 100755 --- a/horizontal.py +++ b/horizontal.py @@ -1,13 +1,16 @@ #!/usr/bin/env python3 import xarray as xr +import numpy as np from metpy.plots import MapPanel, PanelContainer, RasterPlot, ContourPlot +import misc + config = { - 'source': 'dwd_icon-d2/combined.grib2', + 'source': 'dwd_icon-eu/combined.grib2', 'plots': [ { - 'name':'', + 'name':'r_t-750', 'area': None, 'layers': [ { @@ -27,13 +30,13 @@ config = { ] } -def run(config): - data = xr.load_dataset(config['source'], engine='cfgrib') +def run(source, plots): + data = xr.load_dataset(source, engine='cfgrib') - for plot in config['plots']: + for plot in plots: _plot(data, **plot) -def _plot(data, name, area, layers): +def _plot(data, name, layers, area = None): for step in data.coords['step']: this_step = data.sel(step=step) @@ -43,17 +46,29 @@ def _plot(data, name, area, layers): for layer in layers: map_layers.append(_layer(this_step, **layer)) + valid = misc.np_time_convert(step.valid_time.values) + init = misc.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) + init_for_filename = init.strftime('%Y-%m-%d-%HUTC') + panel = MapPanel() - #panel.area = 'de' + if area is not None: + panel.area = area panel.projection = 'mer' panel.layers = ['coastline', 'borders'] panel.plots = map_layers + panel.left_title = f'{name} VALID: {valid_str} (INIT +{hours_since_init_str}) INIT: {init_str}' + panel.right_title = 'FORECAST DWD ICON-EU' pc = PanelContainer() - pc.size = (8, 8) + pc.size = (12.8, 9.6) pc.panels = [panel] pc.draw() - pc.show() + #pc.show() + pc.save(f'{name}_{init_for_filename}+{hours_since_init_str}.png') def _layer(data, layertype, **kwargs): layertypes={ @@ -77,4 +92,4 @@ def _layer(data, layertype, **kwargs): return ret if __name__ == '__main__': - run(config) + run(**config) @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +import sys +import yaml + +FILE = 'config.yaml' +if len(sys.argv) > 1: + FILE = sys.argv[1] + +conf = None +with open(FILE, 'r') as f: + conf = yaml.safe_load(f) + +for plotter in conf['plotter']: + modname = plotter['module'] + del plotter['module'] + + mod = __import__(modname) + mod.run(**plotter) diff --git a/vertical_from_grib.py b/vertical_from_grib.py index e5d6593..9251410 100755 --- a/vertical_from_grib.py +++ b/vertical_from_grib.py @@ -12,7 +12,7 @@ import skewt import misc config = { - 'source':'dwd_icon-d2/combined.grib2', + 'source':'dwd_icon-eu/combined.grib2', 'plots':[ { 'lat':47.9626, @@ -23,10 +23,10 @@ config = { ] } -def run(config): - data = xr.load_dataset(config['source'], engine='cfgrib') +def run(source, plots): + data = xr.load_dataset(source, engine='cfgrib') - for plot in config['plots']: + for plot in plots: _plot(data, **plot) def _plot(data, lat, lon, name, analysis=None): @@ -68,4 +68,4 @@ def _plot(data, lat, lon, name, analysis=None): skt.plot(filename=f'skewt_{name}_{init_for_filename}+{hours_since_init_str}.png') if __name__ == '__main__': - run(config) + run(**config) |