#!/usr/bin/env python # coding: utf-8 # # # Unzip bz2 files # In[3]: import bz2 import glob # In[6]: # extract data that was downloaded from https://opendata.dwd.de/weather/nwp/icon-eu/ path = "/shared/eduard" for filename in glob.glob("{}/*.bz2".format(path)): print (filename) with bz2.open(filename, "rb") as f: # Decompress data from file outfilename = filename.split(".bz2")[0] with open(outfilename, 'wb') as out: out.write(f.read()) print ("-> {}".format(outfilename)) # In[101]: import xarray as xr import numpy as np import pandas as pd import matplotlib.pyplot as plt # read dwd grib data from local directory x = None path = "/shared/eduard" for filename in glob.glob("{}/icon-eu_*.grib2".format(path)): print (filename) tmp = xr.open_dataset(filename, engine='cfgrib') tmp = tmp - 273.15 # Convert to celsius if x is None: x = tmp else: x = xr.concat([x, tmp], "valid_time") # In[102]: # display contents x # In[100]: # Plotting xarray https://xarray.pydata.org/en/v0.7.1/plotting.html # plot 3 dimensional, optionally: wrap after 2 plots x.t2m.plot(x="longitude", y="latitude", col="valid_time") #, col_wrap=2)