aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2023-09-02 00:19:49 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2023-09-02 00:19:49 +0200
commit4895e8336006d5c226dd00c4f8d52a02a70123f2 (patch)
treed8ca5b60ec0cbeaa2e78f1a6f0a1d6f873e1636c
parent7142ee404df02eb8bb3f4a919091277d7a3104e1 (diff)
downloadmeteo_toolbox-4895e8336006d5c226dd00c4f8d52a02a70123f2.tar.gz
horizontal frist draft
-rwxr-xr-xhorizontal.py80
1 files changed, 80 insertions, 0 deletions
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)