Hello everyone,
I have problems with georeferencing with the HX composite of the German Weather Service. When I convert the data to WGS84, the individual pixels are slightly distorted (see images). Sorry - as a new user I can’t upload more than 1x picture…
Is there a way to avoid or correct these ‘distortions’? Or are they negligible for analyses?
I actually want to plot an exactly symmetrical radar pixel that lies exactly at the correct lat/long coordinate. I tried this once, but then the lat coordinates in particular don’t fit at all (image3 / image4) -
I hope you can help me and thank you in advance. The forum is really great and the websites with all the ideas are really useful.
Hier ist der Code zu Bild 3:
import matplotlib
matplotlib.use("TkAgg")
import h5py
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import Normalize
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from pyproj import Transformer
import wradlib as wrl
# -----------------------------------------------------
# 1. RADOLAN HX-Datei laden
# -----------------------------------------------------
file = "/Pfad/zur/Datei/composite_hx_20250331_1225-hd5"
with h5py.File(file, 'r') as f:
dbz_raw = f["dataset1/data1/data"][:]
gain = f["dataset1/data1/what"].attrs["gain"]
offset = f["dataset1/data1/what"].attrs["offset"]
dbz = dbz_raw * gain + offset
dbz = np.ma.masked_outside(dbz, 10, 70)
# -----------------------------------------------------
# 2. Farbskala: Gradient mit viridis (oder turbo)
# -----------------------------------------------------
cmap = plt.get_cmap("viridis") # alternativ: "turbo"
norm = Normalize(vmin=10, vmax=70)
# -----------------------------------------------------
# 3. Original-Koordinaten (DE4800, stereographisch)
# -----------------------------------------------------
nrows, ncols = dbz.shape
radolan_xy = wrl.georef.get_radolan_grid(nrows, ncols, center=True, proj="dwd-radolan")
x = radolan_xy[..., 0]
y = radolan_xy[..., 1]
# -----------------------------------------------------
# 4. Reprojektion nach EPSG:25832 (UTM Zone 32N)
# -----------------------------------------------------
proj_radolan = "+proj=stere +lat_0=90 +lat_ts=60 +lon_0=10 +a=6370040 +b=6370040 +no_defs"
transformer = Transformer.from_crs(proj_radolan, "epsg:25832", always_xy=True)
x_utm, y_utm = transformer.transform(x, y)
# Flip Radarbild passend zur Koordinatenachse (Nord oben)
dbz = np.flipud(dbz)
# -----------------------------------------------------
# 5. Plot mit schlanker Gradient-Legende
# -----------------------------------------------------
fig = plt.figure(figsize=(10, 10))
ax = plt.axes(projection=ccrs.UTM(zone=32))
ax.set_title("RADOLAN HX (EPSG:25832) mit Gradient-Legende")
ax.set_extent([x_utm.min(), x_utm.max(), y_utm.min(), y_utm.max()], crs=ccrs.UTM(32))
# Basisfeatures (optional)
ax.add_feature(cfeature.BORDERS, linewidth=0.5)
ax.add_feature(cfeature.STATES, linewidth=0.4, edgecolor='gray')
# Gitterlinien in Lat/Lon
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
linewidth=0.5, color='gray', alpha=0.5)
gl.top_labels = False
gl.right_labels = False
# Radarbild zeichnen
pm = ax.pcolormesh(x_utm, y_utm, dbz, transform=ccrs.UTM(32),
cmap=cmap, norm=norm, shading="auto")
# -----------------------------------------
# Gradient-Farbleiste (wie im Screenshot)
# -----------------------------------------
cb = plt.colorbar(pm, ax=ax, orientation="vertical", pad=0.01, shrink=0.75)
cb.set_label("Radarreflektivität (dBZ)", labelpad=15)
cb.set_ticks(np.arange(10, 75, 5)) # Ticks alle 5 dBZ
plt.tight_layout()
plt.show()