There is an index error occuring when iam trying to estimate rain rate using python wradlib

grid2 = pyart.io.read_grid(“D:/radar data/radinout/griddedradout20/griddedradout20grid_ZDR_JPR220620165253-IMD-B.nc”)

xg2 = grid2.to_xarray()
Z1 = wrl.trafo.idecibel(xg1.REF[0,0])
rain1 = wrl.zr.z_to_r(Z1,a = 200,b=1.6)#marshal palmer

There is an index error occuring when iam trying to estimate rain rate using python :


IndexError Traceback (most recent call last)
Cell In[95], line 1
----> 1 rain1 = wrl.zr.z_to_r(Z1,a = 200,b=1.6)#marshal palmer

File ~\PYTHON\envs\pcf\lib\functools.py:888, in singledispatch..wrapper(*args, **kw)
884 if not args:
885 raise TypeError(f’{funcname} requires at least ’
886 ‘1 positional argument’)
→ 888 return dispatch(args[0].class)(*args, **kw)

File ~\PYTHON\envs\pcf\lib\site-packages\wradlib\zr.py:96, in _z_to_r_xarray(obj, **kwargs)
65 @z_to_r.register(xr.DataArray)
66 def _z_to_r_xarray(obj, **kwargs):
67 “”“Conversion from reflectivities to rain rates.
68
69 Calculates rain rates from radar reflectivities using
(…)
94 rainfall intensity in mm/h
95 “””
—> 96 dim0 = obj.wrl.util.dim0()
97 out = xr.apply_ufunc(
98 z_to_r,
99 obj,
(…)
104 dask_gufunc_kwargs=dict(allow_rechunk=True),
105 )
106 out.attrs = sweep_vars_mapping[“RATE”]

File ~\PYTHON\envs\pcf\lib\site-packages\wradlib\util.py:1504, in UtilMethods.dim0(self, *args, **kwargs)
1502 return dim0(self, *args, **kwargs)
1503 else:
→ 1504 return dim0(self._obj, *args, **kwargs)

File ~\PYTHON\envs\pcf\lib\site-packages\wradlib\util.py:1410, in dim0(obj)
1408 def dim0(obj):
1409 “”“Return major dimension (azimuth/elevation) of xarray object.”“”
→ 1410 return list(set(obj.dims) & {“azimuth”, “elevation”})[-1]

IndexError: list index out of range

Hi @ankithva ,

Please show the content of Z1. It looks like the dimensions do not have the correct name

Best,
Kai

Just realising you are extracting one value from the DataArray. Then just use Z1.values in the call to wrl.zr.z_to_r.

HTH,
Kai