radarx.retrieve.kdp.estimate_kdp#

radarx.retrieve.kdp.estimate_kdp(obj, phidp=None, rhohv=None, dbz=None, *, method='hubbert', min_rhohv=0.85, texture_window=2.0, texture_max=None, texture_method='circular', band=None, band_factors=None, n_offset=10, offset='sweep', filter_window=None, noise_fraction=0.04, n_iter=None, delta_threshold=None, kdp_window=(2.0, 6.0), z_threshold=40.0, kdp_bounds=None, min_valid_fraction=0.5, phidp_sign='auto', n_threads=None, engine='auto', model=None)[source]#

Process the differential phase and estimate KDP for a sweep or a volume.

Parameters:
  • obj (xarray.Dataset or xarray.DataTree) – A sweep on (azimuth, range) (or (elevation, range)), a single sweep node (dtree["sweep_0"]), or a volume with sweep_* groups, e.g. from xradar. Range gates must be uniformly spaced; range is in metres.

  • phidp, rhohv, dbz (str, optional) – Names of the measured (raw) differential phase (degrees), the copolar correlation coefficient and the reflectivity (dBZ). By default the first name found is used: UPHIDP, PHIDP, uncorrected_differential_phase, differential_phase, PHI; RHOHV, cross_correlation_ratio, copol_correlation_coeff; DBZH, DBZ, reflectivity, corrected_reflectivity. Files often hold several phase fields (raw, unfolded, corrected); pass the raw one explicitly when in doubt. The fields used are listed in the source_fields attribute of the output PHIDP_processed. Without \(\rho_{hv}\) only the texture test masks gates; without reflectivity the long KDP window is used everywhere.

  • method ({"hubbert", "vulpiani", "monotone", "ml"}, optional) – Range filtering method, see radarx.retrieve.kdp. Default "hubbert". "ml" runs a neural network and needs pip install radarx[ml] and a registered model (see model).

  • min_rhohv (float, optional) – Minimum \(\rho_{hv}\) of meteorological gates. Default 0.85, the level below which Park et al. (2009) [3] consider the data contaminated by non-meteorological scatterers (p. 736).

  • texture_window (float, optional) – Length (km) of the window for the phase texture. Default 2 (radarx choice).

  • texture_max (float, optional) – Maximum texture (degrees) within the texture window. Default 20 at S band (radarx choice); see band.

  • texture_method ({"circular", "detrended"}, optional) – "circular" (default) is the circular standard deviation of the phase, which includes the rain ramp: in uniform rain it is about 0.58 degrees per degree/km of KDP for the 2 km window, so with the default limit rain with KDP above about 17 degrees/km is masked as non-meteorological, and all of it from about 20 degrees/km (X band, heavy rain at C band). "detrended" estimates the noise standard deviation from the second differences of the wrapped phase (their rms divided by the square root of 6, which is exact for white noise around a ramp), so a ramp of any slope, folded or not, has no texture; texture_max then limits that standard deviation. No published detrending rule was found, so both rules and the limit are radarx choices.

  • band (str or None, optional) – Radar band, a key of band_factors ("S", "C" or "X"). The defaults of texture_max, delta_threshold and the upper kdp_bounds are S-band values (20 degrees, 4 degrees and 20 degrees/km); they are multiplied by the factor of the band. Values you pass are used as given. The windows and the 40 dBZ switch are not changed. Default None: S band values, the same as "S".

  • band_factors (dict, optional) – Factors by band that update the table BAND_FACTORS of this module ({"S": 1, "C": 2, "X": 3}), for example {"X": 2.0} or a new band {"Ku": 4.0}. The factors 1, 2 and 3 are radarx choices, about the ratio of the frequencies (KDP grows with frequency); they are not taken from a paper, and the backscatter phase and the KDP values at C and X band have not been checked against a reference. Set them for your radar.

  • n_offset (int, optional) – Number of first valid gates used for the system offset. Default 10 (radarx choice).

  • offset ({"sweep", "ray"} or float, optional) – "sweep" (default) pools the first gates of all rays, "ray" estimates one offset per ray, a number is used as the offset in degrees.

  • filter_window (float or None, optional) – Length (km) of each of the three moving-average passes of the low-pass filter ("hubbert" and "monotone"; the filter is a substitute for the FIR filter of Hubbert and Bringi 1995 [1]); the combined kernel has a standard deviation of about half this length. Default None: "hubbert" adapts the window to the phase noise, the gate spacing and the largest KDP of each sweep, at most 2 km (see radarx.retrieve.kdp), and "monotone" uses 2 km. A number is used as given (2.0 is the fixed window of earlier versions).

  • noise_fraction (float, optional) – Adaptive window only: the share of the largest KDP of the sweep that the noise of KDP may reach. Default 0.04 (radarx choice).

  • n_iter (int, optional) – Iterations: default 10 for "hubbert" and 4 for "vulpiani" (radarx choices, not checked against the papers [1], [4]).

  • delta_threshold (float, optional) – "hubbert": gates departing from the filtered profile by more than this (degrees) are replaced by the filtered value. Default 4 at S band (radarx choice, not checked against Hubbert and Bringi 1995 [1]); see band.

  • kdp_window ((float, float), optional) – Length (km) of the least-squares KDP window where the reflectivity is at least / below z_threshold. Default (2, 6): the 9 and 25 gates (at 0.25 km spacing) of Park et al. (2009) [3], p. 732.

  • z_threshold (float, optional) – Reflectivity (dBZ) above which the short window is used. Default 40, as in Park et al. (2009) [3], p. 732 (they use Z > 40, radarx Z >= 40).

  • kdp_bounds ((float, float), optional) – "vulpiani": KDP values (degree km-1) outside these bounds are set to zero in each iteration. Default (-2, 20) at S band (radarx choice); see band.

  • min_valid_fraction (float, optional) – KDP is only given at gates where at least this share of the gates in the KDP window is valid, which removes unreliable values at echo edges and next to masked gates. Default 0.5 (radarx choice).

  • phidp_sign ({"auto", 1, -1}, optional) – Sign convention of the input phase. Some systems record a phase that decreases with range in rain. "auto" (default) multiplies the phase by -1 when it decreases with range in rain (Z >= 30 dBZ, rhohv >= 0.95): the sum of the phase differences of adjacent rain gates (wrapped into [-180, 180), so folding does not matter), pooled over all rays of all sweeps, must be negative by more than three times its noise. The value used is stored in the phidp_sign attribute of the output PHIDP_processed.

  • n_threads (int, optional) – Threads for the compiled kernel. Default: all cores.

  • engine ({"auto", "compiled", "numpy"}, optional) – Implementation to use. "auto" (default) prefers the compiled kernel and falls back to NumPy. Not used by "ml".

  • model (str or radarx.ml.Model, optional) – method="ml" only: the name of a model registered with radarx.ml (default "radarx-kdp-v1") or a loaded model. Its ONNX graph takes features (float32, ray x feature x range) and returns kdp, delta and kdp_std (ray x range).

Returns:

xarray.Dataset or xarray.DataTree – For a sweep, a Dataset with the processed differential phase PHIDP_processed (degrees, increasing with range in rain; masked gates are bridged and gates beyond the first and last valid gate hold the end values), KDP (degree km-1; NaN at non-meteorological gates), the system offset PHIDP_OFFSET per ray (in the convention of the input phase) and the standard deviation KDP_UNCERTAINTY of KDP, on the input coordinates. method="hubbert" adds the backscatter phase PHIDP_BACKSCATTER, and the attributes phase_noise (degrees), filter_window (km) and kdp_reference (the largest KDP of the sweep; NaN if the window was given) of PHIDP_processed hold the values used (all methods but "ml"). method="ml" returns PHIDP_BACKSCATTER and KDP_UNCERTAINTY from the network and the attributes ml_model, ml_model_version and ml_model_licence. For a volume, a DataTree with one such node per sweep that has the differential phase, and the root of the input. Merge the products into the input with ds.radarx.assign(products) or dtree.radarx.assign(products).

Raises:
  • KeyError – If a requested field is missing.

  • ValueError – For unknown options or non-uniform range gates, or for method="ml" with a model name that is not registered.

  • ImportError – If engine="compiled" and the compiled kernel is not available, or for method="ml" without radarx.ml and ONNX Runtime.

Notes

Which parts follow the references: the iterative filtering idea [1], [5], the iterative KDP idea [4] and the monotone assumption [6] are the published concepts; their implementation details and all default values marked “radarx choice” above are not taken from the papers. The windows and the 40 dBZ switch are those of Park et al. (2009) [3]. Wang and Chandrasekar (2009) [2] is cited for the resolution/noise trade-off of the KDP window; its algorithm is not implemented, because neither the paper nor an open description of it could be read.

Dask and extra dimensions. The fields may have extra leading dimensions (for example time or volume): each sweep is processed on its own and the result has the same extra dimensions. Dask arrays stay lazy: the result is a dask array and nothing is computed until it is (the sweep dimensions are rechunked into one chunk). For dask or stacked input phidp_sign='auto' is decided for each sweep, and the attributes of the filter (phase_noise, filter_window, kdp_reference) are not written.

References

Examples

>>> out = radarx.retrieve.estimate_kdp(dtree["sweep_0"].ds)
>>> out = dtree.radarx.kdp(method="vulpiani")
>>> out = estimate_kdp(sweep, method="ml", model="my-kdp")