radarx.retrieve.qc.echo_mask#
- radarx.retrieve.qc.echo_mask(obj, dbz=None, zdr=None, rhohv=None, phidp=None, snr=None, *, method='radarx', field=None, zh_3km=None, zsigma=None, window=None, threshold=None, limits=None, weights=None, spin_threshold=2.0, min_size=None, min_snr=3.0, phidp_texture='circular', memberships=None, rules=None, range_correction=None, despeckle=None, nodata='auto', split_cuts=True, n_threads=None, engine='auto')[source]#
Classify every gate as meteorological or non-meteorological echo.
- Parameters:
obj (
xarray.Datasetorxarray.DataTree) – A sweep on(azimuth, range)(or(elevation, range)), a single sweep node (dtree["sweep_0"]), or a volume withsweep_*groups, e.g. from xradar. Range gates must be uniformly spaced;rangeis in metres.dbz, zdr, rhohv, phidp, snr (
str, optional) – Field names of the reflectivity (dBZ, required), differential reflectivity (dB), copolar correlation coefficient, differential phase (degrees) and signal-to-noise ratio (dB). By default the first name found is used:DBZH,DBZ,reflectivity,corrected_reflectivity;ZDR,differential_reflectivity,corrected_differential_reflectivity;RHOHV,cross_correlation_ratio,copol_correlation_coeff;UPHIDP,PHIDP,uncorrected_differential_phase,differential_phase,PHI;SNRH,SNR,signal_to_noise_ratio. Missing optional fields are left out of the classification.method (
{"radarx", "krause2016", "gourley2007"}, optional) –"radarx"(default) is the scheme described above, in the manner of Gourley et al. (2007) [1] and Krause (2016) [2] with memberships and weights of radarx."krause2016"is the MetSignal algorithm of Krause (2016) [2] with the memberships of its Fig. 2, the weights of its Table 1, nine-gate standard deviations and its post-processing rules (see Notes). With"krause2016",limits,weightsandwindoware not accepted,spin_thresholdandphidp_textureare not used, and the scoreMETEO_SCOREis the aggregation value A of the paper, not averaged over 3 x 3 gates."gourley2007"is the classifier of Gourley et al. (2007) [1] (see Notes). It acceptsweights(keys"rhohv","zdr_texture","phidp_texture"),memberships,rules,range_correction,despeckle,fieldandzsigma;limits,window,threshold,min_size,spin_thresholdandphidp_textureare not accepted. The scoreMETEO_SCOREis the share of the precipitation class in the sum of the aggregation values of the three classes; a gate is meteorological where that class has the largest value, not at a fixed threshold.field (
str, optional) – Radial velocity field (m/s) ofmethod="krause2016"andmethod="gourley2007"(where it only enters the suppression of the ground-clutter class,rules["vrad_max"]). By default the first ofVRADH,VRAD,VRADV,VEL,VELOCITY,velocity,radial_velocitythat a sweep holds. Where it is missing, as in the surveillance cut of a NEXRAD split cut, the velocity term is left out of the weighted mean. Not valid formethod="radarx", which does not use velocity.zsigma (
str, optional) – Field with the pulse-to-pulse variability of the reflectivity (dB), the “sigma” of Gourley et al. (2007) [1] (the mean absolute difference of the reflectivity of adjacent pulses), formethod="gourley2007"only. Where it exceedsrules["zsigma_max"]the ground-clutter class is suppressed. No such field is stored in NEXRAD Level II data; without it the rule is not applied.zh_3km (
str, optional) – Name of a field of the sweeps with the reflectivity (dBZ) at 3 km height of the previous volume scan on the same gates, for the override rule ofmethod="krause2016"(gates with at least 11 dBZ are meteorological). Krause (2016) builds it as a constant-altitude PPI from the previous volume (p. 1882); radarx does not compute it. Not valid formethod="radarx".window (
float, optional) – Length (km) of the window along the ray for the features. Default 1.5 (radarx choice; Krause 2016 [2] uses nine range bins, p. 1876). Only formethod="radarx";method="krause2016"always uses nine range bins.threshold (
float, optional) – Gates whose score are at least this are meteorological. Default formethod="radarx": 0.6 (the weighted mean membership averaged over 3 x 3 gates), radarx’s own choice, lower than the 0.8 (warm season) and 0.7 (cold season) of Krause (2016) [2] (p. 1876), whose memberships and weights differ (see Notes). Default formethod="krause2016": 0.8, the warm-season value; pass 0.7 for the cold season.limits (
dict, optional) – Trapezoid(a, b, c, d)of any of the features"rhohv","zdr"(dB),"zdr_texture"(dB),"phidp_texture"(degrees),"dbz_texture"(dB²),"spin"(%): membership 0 belowaand aboved, 1 betweenbandc. Defaults inradarx.retrieve.qc.DEFAULT_LIMITS(radarx’s own, see Notes).weights (
dict, optional) – Weights of the features (0 drops one). Defaults inradarx.retrieve.qc.DEFAULT_WEIGHTS(radarx’s own, see Notes).spin_threshold (
float, optional) – Smallest reflectivity jump (dB) counted in the spin feature. Default 2 (radarx choice; not checked against Steiner and Smith 2002 [4]).min_size (
int, optional) – Connected meteorological regions with fewer gates are speckle. Default 10 formethod="radarx"(radarx choice, not from the cited papers) and 1 formethod="krause2016", which has no speckle filter; 1 or less disables the filter.phidp_texture (
{"circular", "detrended"}, optional) –"circular"(default) is the circular standard deviation of the phase along the ray, which includes the rain ramp (about 0.58 degrees per degree/km of KDP over a 2 km window)."detrended"uses the noise standard deviation from the second differences of the wrapped phase (their rms divided by the square root of 6), which is zero for a ramp of any slope; seetexture_methodofradarx.retrieve.estimate_kdp(). On synthetic rain with KDP 5 to 30 degrees/km both classify all gates as meteorological. Both rules are radarx choices.memberships (
dict, optional) –method="gourley2007"only. Membership tables of"rhohv","zdr_texture"(dB) and"phidp_texture"(degrees) as(x, precipitation, ground_clutter, clear_air): the gridx(increasing) and the three density curves on it, interpolated linearly and held constant beyond the ends. Defaults inradarx.retrieve.qc.GOURLEY_MEMBERSHIPS, read from Fig. 3 of [1] (see Notes); refit them for other radars and wavelengths, as the paper advises.rules (
dict, optional) –method="gourley2007"only. Thresholds of Table 1 of [1], given keys replace the defaults ofradarx.retrieve.qc.GOURLEY_RULESand None switches one off. Precipitation is suppressed atrhohv_min(0.7),phidp_min(-40 degrees),dbz_min(5 dBZ) andphidp_texture_max(100 degrees); ground clutter atzsigma_max(5 dB) andvrad_max(5 m/s, absolute radial velocity); clear air atdbz_max(30 dBZ). The paper tuned them to the C-band radar of Trappes.range_correction (
dict, optional) –method="gourley2007"only. Linear increase with range (per km) beyond"start_km"(default 45, as in [1]) that is subtracted from the textures: keys"zdr"(dB/km),"phidp"(degrees/km),"start_km". Default: no correction. The paper fits the slopes to 12 scans of its radar (Fig. 2, from which about 0.008 dB/km and 0.05 degrees/km can be read, 1.5 degree elevation, 0.5 degree beams, 240 m gates); they depend on the gate and beam size and the elevation, so radarx does not apply them unasked.despeckle (
bool, optional) –method="gourley2007"only. Apply the despeckling of [1] (default True): an isolated precipitation gate (fewer than three of its eight neighbours precipitation) becomes non-meteorological (class 3), a clear-air gate with more than six precipitation neighbours becomes precipitation. The paper does it on a 1 km Cartesian grid; radarx applies it to the neighbouring rays and gates of the polar sweep.min_snr (
float, optional) – Gates with an SNR below this (dB) have no echo, if an SNR field is used. Default 3 (radarx choice).nodata (
{"auto", "nexrad"},dictorNone, optional) – No-data floors: values at or below them are flags, not data."auto"(default) uses the NEXRAD Level II codes as decoded by xradar (radarx.retrieve.qc.NEXRAD_NODATA) for NEXRAD data and none otherwise; a dict sets floors for"dbzh","zdr","rhohv"and"phidp". NaN is always missing.split_cuts (
bool, optional) – In a volume, sweeps without polarimetric fields (the Doppler cuts of NEXRAD split cuts) take the class of the nearest gate of the polarimetric sweep at the same elevation where both have echo. Default True.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.
- Returns:
xarray.Datasetorxarray.DataTree– For a sweep, a Dataset on the input coordinates withECHO_CLASS(int8: 0 no echo, 1 meteorological, 2 non-meteorological, 3 speckle),METEO_SCORE(float32, NaN without echo) andMETEO_MASK(True for meteorological echo). For a volume, a DataTree with one such node per sweep that has reflectivity, and the root of the input.- Raises:
KeyError – If a requested field is missing, or no sweep has reflectivity.
ValueError – For invalid options or non-uniform range gates.
ImportError – If
engine="compiled"and the compiled kernel is not available.
Notes
The scheme is not an implementation of Gourley et al. (2007) [1] or Krause (2016) [2]. Only the form of the weighted-mean aggregation (Krause 2016 [2], p. 1876) and the use of the variability of \(Z_{DR}\) and \(\Phi_{DP}\) as indicators of non-meteorological echo come from them. Which numbers are theirs and which are not (the paper values are read from the figures and tables on the pages given;
-means not used):feature
radarx
DEFAULT_LIMITS(a, b, c, d)radarx weight
Krause (2016) [2], Fig. 2 (p. 1877), weights in Table 1 (p. 1876)
Gourley et al. (2007) [1]
rhohv0.80, 0.95, inf, inf
1.0
0 at 0.75, 1 at 0.90; weight 1.0
Gaussian-kernel density estimate (Fig. 3, Eq. 2), no trapezoid
zdr-4, -2, 3, 6 dB
1.0
not used (mean \(Z_{DR}\) excluded, p. 1880)
not used
zdr_texture1 up to 1.0 dB, 0 at 2.5 dB
1.0
SD(ZDR): 1 up to 1 dB, 0 at 2 dB; weight 2.0
texture of ZDR (Eq. 1), density estimate
phidp_texture1 up to 12 deg, 0 at 30 deg
1.0
SD(PhiDP): 1 up to 10 deg, 0 at 20 deg; weight 2.0
texture of PhiDP (Eq. 1), density estimate
dbz_texture1 up to 30 dB2, 0 at 70 dB2
0.25
not used
not used
spin1 up to 30 %, 0 at 60 %
0.25
not used
not used
not computed by radarx
Z_h: 0 at 10, 1 at 30 dBZ (weight 1.0); V: 1 for abs(V) >= 1.5 m/s, 0 for abs(V) <= 1.0 m/s (weight 1.0); SD(rhohv): 1 up to 0.03, 0 at 0.04 (weight 1.0)
pulse-to-pulse variability of Z and radial velocity only as suppression thresholds (Table 1, p. 1446)
threshold
0.6 (on the 3 x 3 averaged score)
0.8 (warm season), 0.7 (cold season), p. 1876
none: the class with the largest aggregation value wins (p. 1445)
The only corner shared with a paper is the full membership of SD(ZDR) up to 1 dB (Krause 2016 [2]). All other corners, all weights, the threshold, the 1.5 km window (Krause: nine range bins), the 3 x 3 averaging of the score, the
min_sizespeckle filter,min_snr(3 dB),spin_threshold(2 dB), the NEXRAD no-data floors and the reflection of rhohv above 1 are radarx’s own choices and are not taken from these papers. They have not been tuned against the published algorithms or a labelled data set.Behavioural differences of
method="radarx"from the two papers. They are documented and not changed, so that existing results keep their numbers;method="krause2016"has none of the differences with Krause (2016) listed below except the choices named under “Methodkrause2016”:Weights. All polarimetric features have weight 1.0, the same as rhohv. Krause (2016) gives SD(PhiDP) and SD(ZDR) twice the weight of rhohv because they discriminate best (Table 1, p. 1876), and Gourley et al. (2007) derive weights from the overlap areas 0.243 (rhohv), 0.203 (texture of ZDR) and 0.081 (texture of PhiDP) that make the PhiDP texture count three times rhohv (Eq. 3 and 4, p. 1444).
Threshold. 0.6 is more permissive than either of the 0.8 and 0.7 of Krause (2016), who needed 0.8 to limit false detections owing to birds (p. 1882). Gourley et al. (2007) do not use a threshold at all.
Missing rules. Krause’s post-processing rules are not applied: gates with \(|Z_{DR}| > 4.5\) dB or \(\rho_{hv} < 0.65\) are non-meteorological, and gates with \(Z_h > 11\) dBZ at 3 km height in the previous volume are meteorological (pp. 1875-1876). Radial velocity, \(Z_h\) and SD(\(\rho_{hv}\)) are not features, so stationary clutter is not penalised by its velocity. A mean \(Z_{DR}\) of 5 dB still has a membership of 0.33 here.
Texture and aggregation of Gourley et al. The texture is computed along the ray over
windowinstead of as the root-mean-square difference to the 3 x 3 neighbours with the range correction of their Eq. 1; the memberships are trapezoids instead of density estimates; there is one meteorological score, not the maximum over the classes precipitation, ground clutter and clear air (their Eq. 3); their suppression thresholds (Table 1, p. 1446) and their despeckling of precipitation pixels on a 1 km grid (p. 1446) have no counterpart.method="gourley2007"has all of them (see below).
Method
krause2016. From the paper (Krause 2016 [2], Sect. 2, Table 1, Fig. 2, Sect. 4): the inputs \(Z_h\), \(\rho_{hv}\), radial velocity V, SD(\(\Phi_{DP}\)), SD(\(Z_{DR}\)) and SD(\(\rho_{hv}\)), the standard deviations over nine range bins centred on the gate; the weights 1, 1, 1, 2, 2, 1; the single-sided trapezoid memberships \(Z_h\) 0 at 10 and 1 at 30 dBZ, \(\rho_{hv}\) 0 at 0.75 and 1 at 0.90, SD(\(\Phi_{DP}\)) 1 up to 10 and 0 at 20 degrees, SD(\(Z_{DR}\)) 1 up to 1 and 0 at 2 dB, SD(\(\rho_{hv}\)) 1 up to 0.03 and 0 at 0.04, and the velocity membership 1 minus the inverted trapezoid that is 1 between -1.0 and 1.0 m/s and 0 beyond \(\pm\) 1.5 m/s (the corners are read from the dashed lines of Fig. 2 against its axes, the text gives none); the aggregation \(A = \sum_j W_j P_j / \sum_j W_j\) compared with 0.8 (warm season) or 0.7 (cold season); the mean \(Z_{DR}\) is not a term; then gates with \(|Z_{DR}| > 4.5\) dB or \(\rho_{hv} < 0.65\) are non-meteorological, and gates whose \(Z_h\) at 3 km height in the previous volume exceeds 11 dBZ are meteorological. The paper does not state, and radarx chooses: the standard deviation is the population standard deviation of the gates with echo and data in the window (the circular standard deviation for \(\Phi_{DP}\), which equals the ordinary one for small spread and is safe at the wrap of the phase), at least three such gates are needed (else the term is left out), the window is cut at the ends of the ray, a field that is missing at a gate drops its term from the weighted mean, the comparisons areA >= thresholdandZh_3km >= 11, the override is applied after the two rules, the rules use the value of the gate itself, and no speckle filter is applied (min_sizedefaults to 1). The paper gives neither the gate spacing of its data nor how the 3 km field is built beyond “the elevation closest to the constant altitude of 3 km” of the previous volume, sozh_3kmmust be built by the caller. The standard deviations depend on the gate spacing: over nine gates of 250 m a phase ramp of rain alone gives SD(\(\Phi_{DP}\)) of 1.3 degrees per degree/km of KDP, so that the membership starts to fall at a KDP of 7.7 degrees/km. A volume of NEXRAD data has no velocity in the surveillance cut of a split cut, so that cut is classified without the velocity term (weights 7 instead of 8).Method
gourley2007. From the paper (Gourley et al. 2007 [1], Sect. 2b and 3): the texture of \(Z_{DR}\) and \(\Phi_{DP}\) is the root-mean-square difference \(\sqrt{\sum_{i,j} (y_{a,b} - y_{a+i,b+j})^2 / (m n)}\) over the 3 (azimuth) x 3 (range) gates around the gate (Eq. 1, p. 1441); for each class (precipitation, ground clutter, clear air) the aggregation value \(Q = \sum_j \hat f_j(x_j) W_j / \sum_j W_j\) of the memberships of \(\rho_{hv}\) and the two textures (Eq. 3, p. 1444) with \(W_j \propto 1/A_j\) from the overlap areas 0.243, 0.203 and 0.081 (Eq. 4: 1 : 1.20 : 3.00); the class with the largest \(Q\) is assigned (p. 1445); the thresholds of Table 1 (p. 1446) overrule it, which “is equivalent to assigning a zero membership value”, so radarx sets the \(Q\) of the suppressed class to zero; then the despeckling (p. 1446). The memberships are the density estimates of Fig. 3 (p. 1444), of C-band data of the Trappes radar. The paper does not tabulate them, and radarx reads them from the figure:GOURLEY_MEMBERSHIPSholds piecewise linear curves through points read by eye, which reproduce the modes of the text (\(\rho_{hv}\) 0.97, 0.92, 0.42; texture of \(Z_{DR}\) 0.4, 5.2, 2.5 dB; texture of \(\Phi_{DP}\) 4, 125, 35 degrees for precipitation, ground clutter, clear air to within the point spacing) and its one worked example (at \(\rho_{hv} = 0.97\) the memberships 0.149, 0.030 and 0.007). The overlap areas of these tables are 0.22, 0.24 and 0.10 against the 0.243, 0.203 and 0.081 of the paper, an indication of the reading error. The curves are in the units of the figure, so the aggregation values are not on a scale of 0 to 1. At 3 x 3 gates the texture depends on the gate spacing and beam width of the radar (the paper’s data have 240 m gates and 0.5 degree rays), and the curves are for C band; for other radars passmembershipsrefitted on data of that radar, as the paper advises.What the paper does not state, and radarx chooses: gates without echo or without a valid value of the field are left out of the texture and of the divisor (the sum of Eq. 1 is divided by the number of gates with data, the centre included), the texture needs at least three neighbours with data, the difference of \(\Phi_{DP}\) is wrapped into [-180, 180) degrees, a variable without data at a gate leaves its term out of every class, the same weights apply to the three classes (the paper uses one weight per variable), the thresholds of Table 1 act as
rhohv < 0.7,PhiDP < -40,Z < 5andtexture(PhiDP) > 100(precipitation),zsigma > 5andabs(V) > 5(ground clutter) andZ > 30(clear air) at the gate itself, ties go to the non-meteorological class (precipitation needs a strictly larger value, ground clutter a strictly larger value than clear air), a gate with echo but with none of the three variables is class 3 and has no score, the despeckling takes all classes from the classification before it (so the order of the gates does not matter), and a clear-air gate is the only non-meteorological class that can be converted to precipitation (ground clutter is not). The classes clear air and ground clutter are not told apart inECHO_CLASS(both 2). The Doppler cuts of NEXRAD split cuts are handled as for the other methods. Compared withmethod="radarx"the method treats low reflectivity differently: below 5 dBZ every gate is non-meteorological, also light snow or drizzle with high \(\rho_{hv}\); userules={"dbz_min": None}to drop that rule.Switching the default of
echo_maskto"gourley2007"would change the classification of about 5 to 7 % of the echo gates on the NEXRAD and C-band volumes tried (see the notebookEcho_QC): mainly gates with low reflectivity or low \(\rho_{hv}\) that"radarx"keeps, and narrow radial streaks of low \(\rho_{hv}\).Dask and extra dimensions. The fields may have extra leading dimensions (for example
timeorvolume): 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). Withsplit_cuts=Truea Doppler cut of a volume takes its classes from the polarimetric cut at the same elevation, so these two cuts are computed.References
Examples
>>> qc = radarx.retrieve.echo_mask(dtree) >>> clean = dtree.radarx.apply_mask(qc)
The MetSignal algorithm of Krause (2016), with the reflectivity at 3 km of the previous volume as a field
ZH3KMof the sweep:>>> qc = radarx.retrieve.echo_mask( ... sweep, method="krause2016", zh_3km="ZH3KM" ... )