Use wradlib functions with DWD BUFR data

Hello everyone,

I’m sorry to say, but it’s about BUFR - the format we all admire so much.

So I’m trying to handle a dataset from DWD (it’s a ras08 - precipitation scan - DWD BUFR ras08 - Google Drive ; here is an example file).
I’m actually - what a surprise - able to read this data with this: Bram94/numpy_bufr: A numpy-based and very efficient BUFR decoder, for at least data from weather radars provided by the DWD. (github.com).

From this file I can read:

  • 2134: Antenna beam azimuth in deg
  • 2135: Antenna elevation in deg
  • 4026: time period or displacement in s
  • 21001: horizontal reflectivity in dB
  • the metadata about radar location etc.

So now my question is (sorry to ask this before trying myself):
Is it theoretically possible to use the wradlib functions on this data, given that I put the above mentioned variables in an xarray-Dataset with the correct name convention or am I too naive? Or if not, what is missing (maybe range?)?

Thanks and best regards,
Boran

So I’ve tried it and I guess I succeeded.
Could someone verify if this is correct/ makes sense though?
Hope this can be a workaround for everyone who is trying to work with wradlib and BUFR files.

# transform BUFR radar data to netcdf with xarray, so it can be used in wradlib
# BUFR package from https://github.com/Bram94/numpy_bufr

filename = 'ras08-tscpcp02_AttCorrZhCorr_z0-201605022300-ess-10410--buf'
  
from numpy_bufr import decode_bufr
import os
  
path = '/BUFR/numpy_bufr-master/Tables/'
table_type = 'libdwd' #Can also be 'eccodes'
table_path = os.path.join(path,table_type)
bufr_decoder = decode_bufr.DecodeBUFR(table_path, table_type)
  
#It is possible to overwrite here the table_path and table_type that have been specified above during the initialization of DecodeBUFR.
metadata, full_description, data, data_loops = bufr_decoder(filename)
  
print(metadata,'\n\n',full_description,'\n\n',data,'\n\n',data_loops)
  
# Create a dictionary
full_description_dict = {}
  
# Populate the dictionary using the 6 numbers at the beginning as keys
for entry in full_description:
    key = int(entry[:6])  # Extract the first 6 characters and convert to integer
    value = entry[8:]     # Exclude the first 8 characters (including ': ')
    full_description_dict[key] = value
  
  
## have a first look on the data
radar = data_loops[1]['021001']
import matplotlib.pyplot as plt
plt.imshow(radar)
plt.colorbar()
  
  
  
###############################
#https://tutorial.xarray.dev/fundamentals/01.1_io.html
import numpy as np
import xarray as xr
  
# range is not read from the BUFR data, but is copied from other DWD radar data
range_ = np.arange(125, 150000, 250, dtype=float)
  
  
ds1 = xr.Dataset(
    data_vars={
        "DBZH": (("azimuth", "range"), data_loops[1]['021001']),
        "sweep_mode": "azimuth_surveillance",
        "sweep_number": 0,
        "sweep_fixed_angle": 0.8
  
    },
    coords={
        "azimuth": data_loops[1]['002134'],
        "elevation": ("azimuth", data_loops[1]['002135']),
        "time": str((int(data['004001'][0]),int(data['004002'][0]),int(data['004003'][0]))),
        "longitude": np.array(data['006001'][0]),
        "latitude": np.array(data['005001'][0]),
        "altitude": np.array(data['007001'][0]),
        "range": range_
    },
)
  
# export to netcdf
ds1.to_netcdf("ds1.nc")
  
  
##################
# test the newly created dataset
  
swp_t = xr.open_dataset("ds1.nc")
plt.imshow(swp_t.DBZH.values)
  
# from here the .nc file can be used with wradlib ...

@atmoboran

Thanks for the nice write-up. Would be great to have this as example in the xradar package. BTW, is this open data?

Best,
Kai

Hi Kai,

so it makes sense to do it like this?

If you tell me some conventions etc. I could write this example! Happy to help the community.
No this specific file is not open data - it is a historic DWD radar file (precipitation scan), which is nowadays produced in hdf5. But there is definitely still some DWD radar data which is distributed in BUFR. So it would probably be better to write an example with these files?

Best regards,

Boran