From 4895e8336006d5c226dd00c4f8d52a02a70123f2 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Sat, 2 Sep 2023 00:19:49 +0200 Subject: horizontal frist draft --- horizontal.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 horizontal.py (limited to 'horizontal.py') diff --git a/horizontal.py b/horizontal.py new file mode 100755 index 0000000..d421cd1 --- /dev/null +++ b/horizontal.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +import xarray as xr + +from metpy.plots import MapPanel, PanelContainer, RasterPlot, ContourPlot + +config = { + 'source': 'dwd_icon-d2/combined.grib2', + 'plots': [ + { + 'name':'', + 'area': None, + 'layers': [ + { + 'layertype': 'raster', + 'field': 'r', + 'level': 750, + }, + { + 'layertype': 'contour', + 'field': 't', + 'level': 750, + 'contours': 5, + 'clabels': True + }, + ] + }, + ] +} + +def run(config): + data = xr.load_dataset(config['source'], engine='cfgrib') + + for plot in config['plots']: + _plot(data, **plot) + +def _plot(data, name, area, layers): + + for step in data.coords['step']: + this_step = data.sel(step=step) + + map_layers = [] + + for layer in layers: + map_layers.append(_layer(this_step, **layer)) + + panel = MapPanel() + #panel.area = 'de' + panel.projection = 'mer' + panel.layers = ['coastline', 'borders'] + panel.plots = map_layers + + pc = PanelContainer() + pc.size = (8, 8) + pc.panels = [panel] + pc.draw() + pc.show() + +def _layer(data, layertype, **kwargs): + layertypes={ + 'raster': { + 'obj': RasterPlot, + 'defaults': { + 'colorbar': 'vertical', + } + }, + 'contour': { + 'obj': ContourPlot, + 'defaults': {} + } + } + + args = layertypes[layertype]['defaults'] | kwargs + + ret = layertypes[layertype]['obj'](**args) + ret.data = data + + return ret + +if __name__ == '__main__': + run(config) -- cgit v1.2.3