Reading Radolan RW files

Hi Guys,

     Wradlib Version: 1.16.2
     Python  Version: 3.10.5

I am able to read and plot the graph with raa01-rw_10000-2208301350-dwd—bin.gz
file with xy co-ordinates.

The below code works fine. But I want your help to plot the graph with longitude and latitude. Could you please send me some working code/links for the same product type.

Moreover I need to know if there is any function which can tell me what is the rainfall rate value [data] for a particular longitude and latitude.
Or how should I have to find it only with data without ploting it?

if __name__ == '__main__':
   data, attrs = read_radolan("raa01-rw_10000-2208301350-dwd---bin.gz")
   data = np.ma.masked_equal(data, -9999)
   radolan_grid_xy = wrl.georef.get_radolan_grid(900, 900)
   plot_radolan(data, attrs, radolan_grid_xy, clabel="mm * h-1")
   pl.show()


def read_radolan(rad_file):
     rad_data_file = wrl.util.get_wradlib_data_file(rad_file)
     print_header(rad_data_file)
     return wrl.io.read_radolan_composite(rad_data_file)


def plot_radolan(data, attrs, grid, clabel=None):
   fig = pl.figure(figsize=(10, 8))
   ax = fig.add_subplot(111, aspect="equal")
   x = grid[:, :, 0]
   y = grid[:, :, 1]
   pm = ax.pcolormesh(x, y, data, cmap="viridis")
   cb = fig.colorbar(pm, shrink=0.75)
   cb.set_label(clabel)
   pl.xlabel("x [km]")
   pl.ylabel("y [km]")
   pl.title(
    "{0} Product\n{1}".format(attrs["producttype"], attrs["datetime"].isoformat())
    )
    pl.xlim((x[0, 0], x[-1, -1]))
    pl.ylim((y[0, 0], y[-1, -1]))
    pl.grid(color="r")
1 Like

Hi Muru,

welcome to our openradar discourse and thanks for the question. I’ll move the discussion to Openradar until we have decided on the final structure.

I’ve created a jupyter notebook gist with a code example for your use case here → radolan-rw.ipynb. One more word of clarification. In the notebook I’ve used wradlib’s RADOLAN xarray backend to conveniently have data and coordinates merged in one Dataset/DataArray. Further reading in the wradlib backend docs.

But you would need to be careful when using the DWD grids, they have changed their grid projection base ellipsoid from sphere to wgs84-ellipsoid for their latest products. But as you are using up-to-date wradlib you should have all the bits and pieces available to be prepared.

A write-up on DWD grids is available in this gist → analyze_dwd_grids.ipynb. Please also refer to the wradlib docs on RADOLAN, they are a bit aged and need refreshing, though.

Hi Kai,
Thank you for your support. It works very well. It prints like below,

Figure_lat_long_grid

<xarray.DataArray 'RW' ()>
array(0., dtype=float32)
Coordinates:
    y        float64 -3.759e+06
    x        float64 37.83
    lon      float64 9.993
    lat      float64 54.9
Attributes:
    valid_min:      0
    valid_max:      4095
    standard_name:  rainfall_rate
    long_name:      RW
    unit:           mm h-1

I would like to understand about the rain-fall rate values. It shows as

valid_min 0
valid_max 4095
Color values shows as 0 to 60.

Could you please help me on
How can we decide whether rainfall happened or not in that location?

Hi Muru,

the RADOLAN RW data is taken verbatim from the datafile as uint16. The xarray reader is applying CF convention based scale_factor and add_offset (see at ds.RW.encoding) and let xarray do the CF decoding. Please follow-up with the netcdf-c attribute conventions for valid_min and valid_max.

So valid_min and valid_max are the packed values (uint16) of the data, which in this case evaluate to 0 and 409.5. If you have a value of 0 than no rain was measured at that location.

Hi Kai,
Thank you, understood. So rainfall has occurred at this location.

    lon      float64        9.993
    lat      float64        54.9

Attributes:
    valid_min:      0
    valid_max:      4095
    standard_name:  rainfall_rate
    long_name:      RW
    unit:           mm h-1

But if you look at the plotted map, it does not look like showing rain color there.
is it possible to take the color value as well for that location?

Hi Muru,

maybe I was too sparse with my explanations. The valid_min/valid_max are two dataset-wide values and not point-specific.

The correct value in the above example is 0:

<xarray.DataArray 'RW' ()>
array(0., dtype=float32)

Hi Kai, Ohh Ok.

def print_nearest_ds(lat, lon):
    # find nearest xy-grid point to a specific latlon-coordinate
    abslat = np.abs(dsg.lat - lat)
    abslon = np.abs(dsg.lon - lon)
    c = np.maximum(abslon, abslat)
    ([xloc], [yloc]) = np.where(c == np.min(c))

    # Select index location at the x/y dimension
    point_ds = dsg.sel(x=xloc, y=yloc, method="nearest")
    print(point_ds.RW)


print(print_nearest_ds(lat = 47.190504802, lon = 6.510980544))

As per the plot, I could see some rain color available in that area. [lat = 47.190504802, lon = 6.510980544]. But still it prints its value as 0 only. Is that function “print_nearest_ds” correct? No idea why it is returning nearest as [lon 9.993, lat 54.9].

<xarray.DataArray 'RW' ()>
array(0., dtype=float32)
Coordinates:
    y        float64 -3.759e+06
    x        float64 37.83
    lon      float64 9.993
    lat      float64 54.9
Attributes:
    valid_min:      0
    valid_max:      4095
    standard_name:  rainfall_rate
    long_name:      RW
    unit:           mm h-1

Hi Muru,

sorry that was my bad, I’ve made a mistake when adapting the solution from SO. I’ve fixed the notebook gist (see link above).

For corrected code to determine the wanted pixel see below. There are two changes. First, y/lat is the first dim of our 2d array. Second, we need to use .isel to select from the given index. The SO solution worked since in that example x and y didn’t have coordinates and a zero-based index is used with .sel.

lat = 50.0
lon = 10.0

# find nearest xy-grid point to a specific latlon-coordinate   
abslat = np.abs(dsg.lat-lat)
abslon = np.abs(dsg.lon-lon)
c = np.maximum(abslon, abslat)

# Attention: y/lat is first dim, get
([yidx], [xidx]) = np.where(c == np.min(c))
    
# Select index location at the x/y dimension
# use isel as we select with index 
point_ds = dsg.isel(x=xidx, y=yidx)

display(point_ds.RW)
<xarray.DataArray 'RW' ()>
array(1.1, dtype=float32)
Coordinates:
    y        float64 -4.326e+06
    x        float64 37.83
    lon      float64 9.994
    lat      float64 50.0
Attributes:
    valid_min:      0
    valid_max:      4095
    standard_name:  rainfall_rate
    long_name:      RW
    unit:           mm h-1    

As you can see, the lon/lat coordinates are now giving back our selected values (“nearest”).

Hi Kai,
Thank you so much. It works like gem. I could now see the proper rainfall value [14.7].

<xarray.DataArray 'RW' ()>
array(14.7, dtype=float32)
Coordinates:
    y        float64 -4.65e+06
    x        float64 -2.83e+05
    lon      float64 6.512
    lat      float64 47.19
Attributes:
    valid_min:      0
    valid_max:      4095
    standard_name:  rainfall_rate
    long_name:      RW
    unit:           mm h-1
1 Like

A post was split to a new topic: How to plot the graph to a specific location within a certain radius