radarx.retrieve.multidoppler.multi_doppler#

radarx.retrieve.multidoppler.multi_doppler(grids, background=None, *, field='VRADH', dbz='DBZH', weights=None, fall_speed_correction=True, freezing_level='auto', melting_depth=500.0, w_boundary='bottom', w_bottom=0.0, terrain=None, storm_motion=(0.0, 0.0), shift_winds=False, analysis_time=None, first_guess=None, levels=3, max_iterations=500, tolerance=None, solver='auto', n_threads=None, engine='auto', obs_error=None, crossing_angle_weight=False, obrien_error='linear', error=False, error_samples=32, error_seed=0)[source]#

Retrieve the three-dimensional wind from two or more Doppler radars.

The wind (u, v, w) on the grid minimises the cost function \(J = J_o + J_m + J_s + J_b + J_v\) (the structure of Gao et al. 1999 [1], see the Notes for what is and is not taken from it):

\[\begin{split}J_o &= C_o \sum_k \sum_i \left(u \cos\phi_k \sin\alpha_k + v \cos\phi_k \cos\alpha_k + (w - V_t) \sin\phi_k - v_{r,k}\right)^2 \\ J_m &= C_m \sum_i \left(\frac{h}{\rho}\left[ \frac{\partial \rho u}{\partial x} + \frac{\partial \rho v}{\partial y} + \frac{\partial \rho w}{\partial z}\right]\right)^2 \\ J_s &= C_s \sum_i \sum_{f=u,v,w} (\delta_{xx} f)^2 + (\delta_{yy} f)^2 + \frac{C_{sz}}{C_s} (\delta_{zz} f)^2 \\ J_b &= C_b \sum_i (u - u_b)^2 + (v - v_b)^2 \\ J_v &= C_v \sum_i \left(\frac{h^2}{U} R_\zeta\right)^2\end{split}\]

over the grid cells \(i\) and radars \(k\), where \(\alpha_k\), \(\phi_k\) are the beam azimuth and local elevation, \(V_t\) the fall speed (fall_speed()), \(\rho\) the air density, \(h = \sqrt{\Delta x \Delta y}\), \(\delta\) second differences in grid units and \(U = 10\) m s-1. The scaling makes every term a squared velocity, so the weights are dimensionless and per grid cell. \(R_\zeta\) is the residual of the vertical vorticity equation (Shapiro et al. 2009 [2]; Potvin et al. 2012 [3]), taken as steady in a frame moving with storm_motion,

\[R_\zeta = (u - U_s) \zeta_x + (v - V_s) \zeta_y + w \zeta_z + (\zeta + f)(u_x + v_y) + w_x v_z - w_y u_z ,\]

applied where at least two radars observe. Derivatives are centred differences (one-sided at the edges); the smoothness penalty is applied to the second derivatives in each direction (a radarx choice of discretisation; Potvin et al. 2012 [3] also use smoothness constraints).

The cost and its exact gradient are computed in one fused, multithreaded pass of a compiled kernel. Without the vorticity term the cost is quadratic and is minimised by conjugate gradients (exact steps, no line search), preconditioned with the inverse of the smoothness operator (plus a constant) in the basis of the discrete cosine transform; with the vorticity term SciPy’s L-BFGS-B is used. The minimisation runs first on grids coarsened by two horizontally (levels), each solution starting the next finer one. The first guess is the background wind with w = 0. w is held at zero at the boundaries named in w_boundary by removing those cells from the control vector.

Parameters:
  • grids (xarray.Dataset or sequence of xarray.Dataset) – Gridded, dealiased and advection-corrected radial velocities on a common grid with a radar dimension (see multi_doppler_input()): field on (radar, z, y, x) and either azimuth and elevation on (radar, z, y, x) or radar_x, radar_y and radar_altitude on radar. A sequence of per-radar Datasets is concatenated along radar.

  • background (xarray.Dataset, optional) – Background on the grid, from radarx.io.sounding.era5_column() or radarx.io.sounding.profile_to_grid(): u, v (along the grid axes), optionally w, air_density and freezing_level. Without it there is no background term and a standard density profile is used.

  • field, dbz (str, optional) – Field names. Default "VRADH" and "DBZH".

  • weights (dict, optional) – Overrides of the dimensionless weights observation (\(C_o\), default 1), mass_continuity (\(C_m\), default 10), smoothness (\(C_s\), 0.5), smoothness_vertical (\(C_{sz}\), default the same as smoothness), background (\(C_b\), 0.001), background_w (weight of w - w_b, 0) and vorticity (\(C_v\), 0, i.e. off). The defaults are DEFAULT_WEIGHTS in radarx.retrieve.multidoppler. They are radarx choices: the weights of Gao et al. (1999), Shapiro et al. (2009) and Potvin et al. (2012) belong to differently scaled terms and are not transferable, and results depend strongly on them. Without a background, background is set to 0.

  • fall_speed_correction (bool, optional) – Correct for the precipitation fall speed. Default True.

  • freezing_level ({"auto", "rain"}, float or xarray.DataArray, optional) – Height of the 0 degC level (m above sea level, or on (y, x)) that separates the rain and the snow fall speed relation of fall_speed(). "auto" (default) takes the freezing_level of the background (as returned by radarx.io.sounding.era5_column()), or the 0 degC crossing of its temperature; with neither, a RuntimeWarning is issued and the rain relation is used at all heights. "rain" is that old behaviour without the warning.

  • melting_depth (float, optional) – Depth (m) below the freezing level over which the fall speed changes from the rain to the snow relation (fall_speed()). Default 500.

  • w_boundary (str or sequence of str, optional) – Where w = 0: any of "bottom" (lowest level, default), "top" (highest level), "echo_top" (from one level above the highest echo in each column) and "obrien" (the O’Brien adjustment of the solution so that w = 0 at the highest level, see obrien_error and the Notes). None for no boundary condition. "bottom" sets w to w_bottom at the lowest grid level z[0] whatever its height; a RuntimeWarning is issued when z[0] is more than W_BOTTOM_WARN_HEIGHT (200 m) above the highest radar and w_bottom is 0; see the Notes.

  • w_bottom (float or xarray.DataArray, optional) – Value of w (m s-1, or on (y, x)) held at the lowest level for w_boundary="bottom". Default 0. With a grid that starts above the ground, give the vertical velocity at z[0] implied by the flow below, for example from the low-level divergence.

  • terrain (xarray.DataArray or array, optional) – Terrain height (m above sea level) on (y, x) of the grid, for example from a digital elevation model. The analysis then runs on levels that follow the terrain: level k of every column is at the height terrain + z[k] - z[0] above sea level, so z[0] is the ground; z[0] is typically 0 and the grid must reach the highest terrain and the top of the analysis. The radial velocities, reflectivity and background are interpolated linearly in height to these levels and the beam elevation is recomputed. The vertical velocity of the control vector is then the one relative to the levels, \(W = w - u\, \partial h/\partial x - v\, \partial h/\partial y\), so w_boundary="bottom" (W = w_bottom, default 0) is flow along the ground, and w is returned; see the Notes. The result has z as the height above the terrain, the coordinate height (above sea level, on (z, y, x)) and the variable terrain. Not available with the vorticity term. Default None: levels at constant height above sea level.

  • storm_motion (tuple of float, optional) – (u, v) of the frame in which the vorticity is steady, m s-1; also the velocity of the wind pattern for shift_winds.

  • shift_winds (bool, optional) – Evaluate the analysis winds, valid at analysis_time, at the position they had when each radar observed (x - c (t_k - t_a) with c = storm_motion) instead of advecting the radial velocities to a common time. Radial velocity is a projection on the beam direction, which changes when the pattern moves by c (t_k - t_a); advecting it as a scalar leaves an error of about |u| |c| |t_k - t_a| / r (1.4 m s-1 for 20 m s-1 wind, a 15 m s-1 pattern speed, 180 s and 40 km range). Use it with grids that were not advected (multi_doppler_input without time/motion), whose time coordinate holds the observation time of every radar. The shift is made on the observations together with their beam direction (see Notes). Default False.

  • analysis_time (datetime-like, optional) – Valid time of the analysis for shift_winds.

  • first_guess (xarray.Dataset, optional) – Start from these u, v, w instead of the background (e.g. the previous analysis of a time series); then levels is 1.

  • levels (int, optional) – Number of grid levels of the coarse-to-fine minimisation; each coarser level halves the horizontal resolution (only while the grid keeps at least 12 points). Default 3.

  • max_iterations (int, optional) – Maximum iterations per level. Default 500.

  • tolerance (float, optional) – Stopping tolerance. For "cg": the preconditioned gradient norm relative to that of the cost at zero wind (default 3e-4); for "lbfgsb": the relative reduction of the cost (ftol, default 1e-7).

  • solver ({"auto", "cg", "lbfgsb"}, optional) – Minimiser. "auto" (default) uses conjugate gradients when the vorticity term is off and L-BFGS-B otherwise.

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

  • engine ({"auto", "compiled", "numpy"}, optional) – Cost function implementation. "auto" prefers the compiled kernel.

  • obs_error (float, sequence of float, xarray.DataArray or array, optional) – Standard deviation (m s-1) of the error of the radial velocity: one number, one number per radar, or an array or DataArray that broadcasts to (radar, z, y, x) (for example velocity_error() of the signal to noise ratio and the spectrum width of the gate, see the Notes). The weight of an observation in \(J_o\) is multiplied by \(1 / \sigma^2\) (m-2 s2), so a radar with twice the error counts a quarter as much. A NaN error removes the observation. Default None: every observation has the weight weights['observation'] alone, as if \(\sigma = 1\) m s-1 (the earlier behaviour). The default weights of the other terms are tuned for errors of about 1 m s-1: if all radars have a much larger error the smoothness and mass terms win over the observations (on the test flow, errors of [0.2, 1.0] m s-1 give up to 30 % smaller errors than equal weights, while [1.0, 3.0] give larger ones), so give the relative quality of the radars unless the absolute values are what you want.

  • crossing_angle_weight (bool, optional) – Multiply the weight of every observation by \(\sin^2\beta\), where \(\beta\) is beam_crossing_angle (at least 1e-3; cells seen by one radar keep the factor 1). The error of the horizontal wind of two radars grows as \(1/\sin\beta\) (Notes), and this factor lowers the trust in observations where the geometry makes any error in them, noise or not, count most. The normal equations of \(J_o\) already contain the geometry, so this is an extra down-weighting beyond the noise model, a radarx choice that is not from a paper. Default False.

  • obrien_error ({"linear", "constant"}, optional) – Shape of the O’Brien adjustment for w_boundary="obrien": the error of the divergence grows linearly with height ("linear", default; the mass flux correction is quadratic in height) or is constant ("constant"; linear correction).

  • error (bool, optional) – Return u_error, v_error and w_error, the standard deviation of the retrieval error from the covariance of the cost function (see the Notes). Needs the quadratic cost (weights['vorticity'] = 0). Costs about error_samples times the conjugate-gradient solution on the finest grid. Default False.

  • error_samples (int, optional) – Number of random draws of the error estimate; the relative uncertainty of the standard deviation is 1 / sqrt(2 * error_samples). Default 32.

  • error_seed (int, optional) – Seed of the random draws. Default 0.

Returns:

xarray.Dataset – On (z, y, x): u, v (along the grid axes), w, fall_speed, mass_residual (anelastic mass divergence, s-1), n_radars (radars observing each cell) and, with two or more radars, beam_crossing_angle; with error=True also u_error, v_error and w_error (m s-1); vr_residual (model minus observed radial velocity) on (radar, z, y, x); cost on term (final value of every term) and cost_history on (iteration, term). attrs record the weights, iterations, convergence message and run time.

Notes

What is taken from the literature. Gao et al. (1999) [1] pose the retrieval of the three-dimensional wind from the radial velocities of Doppler radars as a variational (weak-constraint) problem; Shapiro et al. (2009) [2] and Potvin et al. (2012) [3] describe a cost function of the discrepancies between observed and analysed radial winds, errors in the anelastic mass conservation equation, errors in the anelastic vertical vorticity equation and spatial smoothness constraints, as used here. Their equations are not checked term by term. The forms of \(J_o\), \(J_m\), \(J_s\), \(J_b\) and \(J_v\) above, the scaling by \(h\), \(h^2/U\) and the grid spacing (so that the weights are dimensionless), the choice of second differences for the smoothness term, the background term \(J_b\) and all default weights are radarx’s own formulation. Unlike Shapiro et al. (2009), who use Taylor’s frozen-turbulence hypothesis to shift the analysis winds to the observation times, radarx by default advects the data to a common time beforehand (radarx.retrieve.advect()) and treats the vorticity equation as steady in the frame moving with storm_motion. With shift_winds=True the analysis winds are shifted to the observation times by -c (t_k - t_a) in the observation operator (the idea of Shapiro et al. 2009; their equations are not checked here). It is done by the equivalent move of each observation with its direction cosines in the opposite direction, so the cost function and the solvers are unchanged; the same bilinear interpolation as in radarx.retrieve.advect() is used, and observations whose shifted position lies outside the grid are dropped. The fall speed correction is described in fall_speed().

Gridding artifacts. The radial velocities enter on a Cartesian grid. Linear interpolation from the polar grid can create periodic artifacts that produce spurious vertical velocities (Collis et al. 2010 [4]); radarx’s cone gridding (radarx.grid.grid_cones()) is of that kind, so retrieved w can contain such artifacts. Their mixed-order interpolation is available as multi_doppler_input(..., velocity_interpolation="mixed") and radarx.grid.grid_cones_mixed().

Solvers. The conjugate-gradient iteration is that of Hestenes and Stiefel (1952) [5] with a preconditioner built on the discrete cosine transform (Strang 1999 [6]; the second-difference operator is diagonal in that basis except at the edge cells, so the preconditioner is approximate and only changes the speed of convergence, not the minimiser). The vorticity case uses SciPy’s L-BFGS-B, an implementation of Byrd et al. (1995) [7] and Zhu et al. (1997) [8]. The coarse-to-fine sequence (levels, a factor of two in x and y) and the stopping tolerances (3e-4 and 1e-7) are radarx choices.

Lower boundary. w_boundary="bottom" imposes w = w_bottom (default 0) at the lowest grid level z[0], whatever its height. The physical condition of a wind analysis is impermeability, w = 0 at the ground (terrain), and only a grid whose lowest level is the surface satisfies it. If z[0] lies above the ground, for example at 500 m above sea level over flat terrain near sea level as in grids built with z = np.arange(500, 12e3, 500), the true w there is generally not zero and the anelastic integration carries the error up the whole column as a column-wide offset of the order of the true w at z[0]. In a test (two radars, analytic anelastic flow u = 5 + a x, v = 2 + a y, w = -2 a H (exp(z/H) - 1), a = 2e-4 s-1, H = 10 km, no noise) the root-mean-square error of w was 0.05 m s-1 for levels 0, 500, …, 10000 m but 0.37 m s-1 (mean error 0.35 m s-1) for levels 500, 1000, …, 10500 m, where the true w at 500 m is -0.20 m s-1. Choose z[0] at the terrain height, pass the w at z[0] as w_bottom (giving the true -0.20 m s-1 in that test brings the rms error of w back to the level of the first case), or use w_boundary=None or "top"/"echo_top" and judge w accordingly. The statement that the condition belongs at the ground is the standard one for dual-Doppler analyses; it is not checked against the text of Gao et al. (1999) or Potvin et al. (2012).

Terrain-following lower boundary. With terrain the levels follow the ground, \(z = h(x, y) + z^*\), where \(z^* = z - z[0]\) is the height above the terrain (the simplest terrain-following coordinate, with the spacing of the levels the same in every column; Gal-Chen and Somerville 1975 [10] introduced the family of such transformations, whose equations are not checked here and which usually also scale the coordinate to a flat top). For a function \(f(x, y, z) = F(x, y, z^*)\), \(\partial_x f = \partial_x F - h_x\, \partial_{z^*} F\), so with the density \(\rho\) as a field of the grid the anelastic continuity equation becomes

\[\partial_x(\rho u) + \partial_y(\rho v) + \partial_{z^*}(\rho W) = 0, \qquad W = w - u\, h_x - v\, h_y ,\]

the same equation as on flat levels for the vertical velocity W relative to the levels, and the impermeability condition at the ground, \(w = u\, h_x + v\, h_y\), is \(W = 0\) at \(z^* = 0\). radarx therefore keeps the cost function, its kernel and the solvers and changes the observation operator, which becomes \((a + c\, h_x) u + (b + c\, h_y) v + c W\) for the direction cosines \((a, b, c)\) of the beam; w is returned. The derivation is elementary calculus (chain rule) and is not taken from a paper. Smoothness and background act on u, v and W in the new coordinates. The slopes \(h_x, h_y\) are centred differences of the terrain on the horizontal grid (one-sided at the edges); the terrain is not smoothed, so a terrain much rougher than the grid gives noisy slopes and a noisy w. The data are interpolated linearly in height from the original levels to the terrain-following ones (a vertical resampling of gridded velocities, with the interpolation error that has), levels above the top of the grid are missing, and over a mountain of height \(h\) the analysis reaches only \(z_{top} - h\) above the ground. The beam is not blocked by terrain: cells hidden behind a ridge have to be masked in the input (see radarx.retrieve.beam_blockage()). The vorticity term is not available with terrain.

Observation weights. With obs_error the weight of the observation of radar \(k\) in \(J_o\) is \(C_o / \sigma_k^2\). velocity_error() gives \(\sigma_k\) of the pulse-pair velocity estimate from the signal to noise ratio and the spectrum width (Doviak and Zrnic 1993, Eq. 6.22); it is the noise of the estimate of one gate, not the error of the gridded velocity, so a radar’s own noise model may be better. The error of the horizontal wind from two radars depends on the crossing angle of the beams (derived in dual_doppler_analytic()): the minimiser of \(J_o\) already weights the observations through this geometry, and crossing_angle_weight is an optional extra.

Error estimate. With all weights read as inverse variances, so that \(J\) is a chi-square (\(-2 \ln p\) of independent Gaussian errors), the covariance of the minimiser is the inverse of one half of the Hessian of \(J\) (the Gauss-Markov covariance), which does not depend on the solution because \(J\) is quadratic. radarx draws error_samples perturbations b = 2 B^T xi of all terms (observations, mass continuity, smoothness, background; the cost is \(\sum_j |B_j x - y_j|^2\)), solves \(H x = b\) by preconditioned conjugate gradients and takes the mean of \(x^2\) as the variance, the randomised solution of a linear-Gaussian posterior (not taken from a paper). It is the standard deviation of the error if the radial velocity errors have the standard deviation obs_error and the weak constraints (mass continuity, smoothness, background) are as accurate as their weights say. The weights of those terms are radarx choices, not error statistics, so u_error, v_error and w_error describe the analysis system with these weights; they do not include errors of the fall speed, the gridding, the advection, or a wrong lower boundary condition. On the synthetic flow of the tests (Beltrami flow, two radars, 0.5 m s-1 noise, obs_error=0.5, 32 draws) they are 1.44 (u), 1.27 (v) and 1.04 (w) times the root-mean-square error of the retrieval where the beams cross at more than 30 degrees. They are 1.5 to 2.1 times the standard deviation of the retrievals over 16 noise realisations, because they include the freedom that the weak constraints leave. On a 4 km grid the truncation error of the discretisation, which they do not contain, dominates the actual error and the ratio for w falls to 0.35. The Hessian of the vorticity term is not constant, so error=True needs weights['vorticity'] = 0.

O’Brien adjustment. w_boundary="obrien" (usually with "bottom") applies the adjustment of O’Brien (1970) [9] to the retrieved w after the minimisation, as described in dual_doppler_analytic(): the mass flux \(\rho w\) is reduced by the fraction \(((z - z_0)/(z_{top} - z_0))^2\) of its value at the highest grid level (obrien_error="constant": the first power), so that w = 0 there. The result is no longer the minimiser of \(J\) (the cost terms of the output are those of the adjusted state), and the one-dimensional adjustment does not change u and v. Use it when the true w is zero at the top of the grid and the retrieved w is not ("top" fixes w = 0 inside the minimisation instead). The paper was not read; see dual_doppler_analytic() for what the implementation follows.

Dask. This function computes the dask array: the wind is solved for all grid cells at once. The input is loaded into memory and the result is held in memory.

References

Examples

>>> grids = radarx.retrieve.multi_doppler_input([kgwx, kcbm], x, y, z)
>>> bg = radarx.io.sounding.era5_column(grids)
>>> wind = radarx.retrieve.multi_doppler(grids, bg)