Adjust radar with rain gauge

Hello Guys!
When i tried gauge adjust method “wrl.adjust.AdjustAdd” i got the following error stating “TypeError: ‘<’ not supported between instances of ‘SingleBlockManager’ and ‘float’”.
I would like your help to try to resolve this problem.
Here is the code i followed .
addadjuster_ok_exp = wrl.adjust.AdjustAdd(obs_coords,
grid_coords.values,
cov = ‘1.0 Exp(10000.)’,
ipclass=wrl.ipol.OrdinaryKriging)
addadjusted_ok_exp_values = addadjuster_ok_exp(rf, radar_h_stack.values)

Hello @skr5332 and welcome to openradar discourse,

To examine this issue properly you would need to add an MCVE (Craft Minimal Bug Reports — Matthew Rocklin) so that we can reproduce the error in our systems. Also it would help to provide the complete traceback of the error as text snippet.

Cheers,
Kai

Hello Kai,
Thank you for message and prompt response. Really wradlib makes our job easy in radar data analysis.
I have posted detailed info as below. Please excuse me if the message format doesn’t meet standards. i am new to in this platform.

import os
import math
import copy
import warnings
import numpy as np
import numpy.ma as ma
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import xarray as xr
import wradlib as wrl
try:
    get_ipython().run_line_magic("matplotlib inline")
except:
    plt.ion()
warnings.filterwarnings('ignore')
# radar input file
filename = '/home/sunil/Downloads/data/radar/test6.nc'
# select base 2d grid
grid = grid.isel(time=0, z=0)
# ARG input file
xls = pd.ExcelFile("/home/sunil//Downloads/data/MESONET/2024-10-09rainfall.xlsx")
sheetX = xls.parse(0)
rf = sheetX['Rainfall']
# rf[rf==-99.99]=0
lat1=sheetX['Latitude']
lon1=sheetX['Longitude']
obs_coords=np.column_stack((lon1, lat1))
obs_coords.shape
# arranging data
nanmask_h = xr.where(np.isnan(grid.RR), True, False)
radar_h = grid.RR.fillna(0)
radar_h_stack = radar_h.stack(radar_obs=("x", "y"))
display(radar_h)
grid_coords = xr.concat([radar_h_stack.x, radar_h_stack.y], "xy").transpose(..., "xy")
display(grid_coords)
# Gauge adjustment
addadjuster_ok_exp = wrl.adjust.AdjustAdd(obs_coords, 
                                      grid_coords.values,
                                      cov = '1.0 Exp(10000.)',
                                      ipclass=wrl.ipol.OrdinaryKriging)
addadjusted_ok_exp_values = addadjuster_ok_exp(rf, radar_h_stack.values)
# Gauge adjustment
addadjuster_ok_exp = wrl.adjust.AdjustAdd(obs_coords, 
                                      grid_coords.values,
                                      cov = '1.0 Exp(10000.)',
                                      ipclass=wrl.ipol.OrdinaryKriging)
addadjusted_ok_exp_values = addadjuster_ok_exp(rf, radar_h_stack.values)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[301], line 5
      1 addadjuster_ok_exp = wrl.adjust.AdjustAdd(obs_coords, 
      2                                       grid_coords.values,
      3                                       cov = '1.0 Exp(10000.)',
      4                                       ipclass=wrl.ipol.OrdinaryKriging)
----> 5 addadjusted_ok_exp_values = addadjuster_ok_exp(rf, radar_h_stack.values)

File ~/anaconda3/envs/wrad/lib/python3.12/site-packages/wradlib/adjust.py:431, in AdjustAdd.__call__(self, obs, raw, targets, rawatobs, ix)
    427 # ----------------GENERIC PART FOR MOST __call__ methods---------------
    428 if (ix is None) or (rawatobs is None):
    429     # Check for valid observation-radar pairs in case this method has
    430     # not been called from self.xvalidate
--> 431     rawatobs, ix = self._get_valid_pairs(obs, raw)
    432 if len(ix) < self.mingages:
    433     # Not enough valid gages for adjustment? - return unadjusted data
    434     return raw

File ~/anaconda3/envs/wrad/lib/python3.12/site-packages/wradlib/adjust.py:327, in AdjustBase._get_valid_pairs(self, obs, raw)
    324 rawatobs = self.get_raw_at_obs(raw, obs)
    325 # check where both gage and radar observations are valid
    326 ix = np.intersect1d(
--> 327     util._idvalid(obs, minval=self.minval),
    328     util._idvalid(rawatobs, minval=self.minval),
    329 )
    330 return rawatobs, ix

File ~/anaconda3/envs/wrad/lib/python3.12/site-packages/wradlib/util.py:199, in _idvalid(data, isinvalid, minval, maxval)
    197     ix = np.logical_or(ix, np.ma.masked_where(data == el, data).mask)
    198 if minval is not None:
--> 199     ix = np.logical_or(ix, np.ma.masked_less(data, minval).mask)
    200 if maxval is not None:
    201     ix = np.logical_or(ix, np.ma.masked_greater(data, maxval).mask)

File ~/anaconda3/envs/wrad/lib/python3.12/site-packages/numpy/ma/core.py:2025, in masked_less(x, value, copy)
   2002 def masked_less(x, value, copy=True):
   2003     """
   2004     Mask an array where less than a given value.
   2005 
   (...)
   2023 
   2024     """
-> 2025     return masked_where(less(x, value), x, copy=copy)

File ~/anaconda3/envs/wrad/lib/python3.12/site-packages/numpy/ma/core.py:1020, in _MaskedBinaryOperation.__call__(self, a, b, *args, **kwargs)
   1018 with np.errstate():
   1019     np.seterr(divide='ignore', invalid='ignore')
-> 1020     result = self.f(da, db, *args, **kwargs)
   1021 # Get the mask for the result
   1022 (ma, mb) = (getmask(a), getmask(b))

TypeError: '<' not supported between instances of 'SingleBlockManager' and 'float'

ARG and Radar data

Hello @skr5332,

thanks for the addtional information. I think the issue is with the pandas.Series rf. You’d need to transform it to xarray like:

addadjusted_ok_exp_values = addadjuster_ok_exp(rf.to_xarray(), radar_h_stack.values)

HTH,
Kai

Hello Kai,
It perfectly works. Thank you very much.
Do you have any idea about implementation of krigging with external drift correction (wrl.ipol.ExternalDriftKriging)) to ARG data containing NaN values.

Hello @skr5332,

glad it works on your side now. Unfortunately I’m not much using gauge adjustment. So I’d rely on experts on that topic, too.

There has been some discussion of ExternalDriftKriging in Interpolation of radar and rain gauge data with wradlib. Example notebook:

Maybe @eltonrobaina can chime in here and share his experience with ExternalDriftKriging.

HTH
Kai

Hello Kai,
Thank you for help.

Hello @kmuehlbauer and it’s a pleasure to meet you @skr5332
So, what can I do to help you?
Could you describe your problem better please?
Thanks

Hello @ eltonrobaina! NIce to meet you.
Thank you for your message.
I am new to python world and i try to adjust radar rainfall using surface rainfall observations. I am using all the available methods in wradlib such as addadjuster_additve, multiplicative, mixed, and MFB using various interpolation methods. TO begin with, i will start with wrl.adjust.AdjustAdd using krigging external drift interpolation method. I think that the radar rainfall is over corrected as compared to ARG observations. I seek your kind interaction in this regard.
Please find output from results

Thank You
SKR

Hi @skr5332
This is probably caused by outliers. I have been facing similar problems here in Brazil.
My suggestion is:

  1. Create a workflow from the raw radar data for example using Z-KDP to convert it to rain

  2. Spatialize the rain gauges using some wralib interpolator, for example: wradlib.ipol.OrdinaryKriging

  3. Check if the data is consistent, radar data and rain gauges (interpolated). You can do this using: wradlib.verify.ErrorMetrics

Remember that you must choose the correct scale: either work with mm (depth) or mm/h. Both must be on the same scale

thanks

Hello eltonrobaina,
I am sorry for delayed replay since i was in long leave. I shall follow your suggestion and get back to you soon.
Thank you.

1 Like