radarx.retrieve.nowcasting.nowcast#

radarx.retrieve.nowcasting.nowcast(obj, n_steps, *, method='steps', field=None, dt=None, motion=None, observed=None, n_members=20, ar_order=None, n_levels=6, threshold=10.0, zero_value=None, mask_radius=20000.0, mask_growth=0.0, probability_matching=True, motion_perturbation=None, pad=0.25, seed=None, x='x', y='y', n_threads=None, engine='auto')[source]#

Nowcast of a gridded reflectivity field, deterministic or as an ensemble.

The forecast is made in the frame of the moving precipitation (the Lagrangian frame) and then advected to the grid with advect():

  1. The motion is estimated from the last two frames with estimate_motion() (or given as motion). Earlier frames are advected forward to the time of the last frame.

  2. Reflectivity is used as it is (dBZ is a logarithmic scale, as the dB rain rate of Pulkkinen et al. 2019 [3]); values below threshold and missing values are set to zero_value.

  3. The field is decomposed into n_levels scales with Gaussian band filters in the Fourier domain (Seed 2003 [1]; Bowler et al. 2006 [2]). Each level is normalised to unit variance.

  4. Every level follows an autoregressive process of order 2, Z(t+1) = phi1 Z(t) + phi2 Z(t-1) + gain e(t), whose parameters come from the lag-1 and lag-2 correlations of the level in the Lagrangian frame through the Yule-Walker equations. The innovation has the variance 1 - phi1 rho1 - phi2 rho2 so that the process keeps unit variance (the factor is the square root of that number; the published formula for the noise coefficient has no square root, which gives a variance of (1 - phi1 rho1 - phi2 rho2)**2; a simulation in the tests shows the unit variance). Scales with low correlation, the small ones, decay fast.

  5. method="sprog" stops here (e(t) = 0). With "steps" the innovation e(t) is white noise filtered by the amplitude spectrum of the latest field (Seed et al. 2013 [4] as used by Pulkkinen et al. 2019 [3]), so that it has the spatial structure of the observed field, and split into the same levels. Each member draws its own noise.

  6. The forecast of each lead time is limited to the neighbourhood of the observed echo (the rain mask of Pulkkinen et al. 2019 [3]; cells farther than mask_radius + mask_growth * lead from echo above the threshold are set to zero_value), and its distribution is matched to that of the last observation (probability_matching; Bowler et al. 2006 [2]), which restores the variance the smoothing removes.

  7. With motion_perturbation each member moves with a perturbed motion (Bowler et al. 2006 [2]): a shift along and across the mean motion, drawn from a Laplace distribution of unit variance and scaled by a t**b + c (t in minutes).

  8. The fields of all lead times are advected from the Lagrangian frame to the grid in one step: the displacement of a lead time is the motion times the lead time, with the implicit midpoint iteration of advect() for a spatially varying motion.

method="extrapolation" skips steps 3 to 7 and advects the last field.

The Fourier transforms are done with scipy.fft (multithreaded); the autoregressive step and the sum over the levels of all members run in a compiled kernel with a NumPy equivalent.

The central wavenumbers and widths of the band filters, the limits on the correlations (lag 1 in 0.001 to 0.999, lag 2 between 2 rho1**2 - 1 and rho1), the padding of the domain, the defaults of the rain mask and the choice to evaluate the cascade in the Fourier domain are radarx’s own. The perturbation parameters have no default: Bowler et al. (2006) fitted them to the advection errors of a radar network, and radarx cannot fit them to yours.

Parameters:
  • obj (list of xarray.Dataset or xarray.DataArray, or xarray.Dataset) – Gridded volumes (or fields) in time order, the last one is the analysis time; or one object with a time dimension. Evenly spaced x and y coordinates in metres (e.g. from radarx.grid.grid_radar()). Three frames are needed for the autoregressive model of order 2, two for order 1. Extra dimensions (z) are reduced to the column maximum.

  • n_steps (int) – Number of lead times. They are dt, 2 dt, ..., n_steps dt.

  • method ({"steps", "sprog", "extrapolation"}, optional) – Default "steps".

  • field (str, optional) – Reflectivity field in dBZ. Default: the first reflectivity field found.

  • dt (float or timedelta, optional) – Time between the frames in seconds. Default: from their time.

  • motion (xarray.Dataset or tuple, optional) – Storm motion (m/s) from estimate_motion() or optical_flow(), or a tuple (u, v). Default: estimated from the last two frames with estimate_motion().

  • observed (xarray.DataArray of bool, optional) – Cells that were observed. Default: all cells, so missing values mean no echo. Pass the coverage of the radar when missing values mean not observed; the forecast is NaN where it would come from outside.

  • n_members (int, optional) – Members of the ensemble ("steps"). Default 20.

  • ar_order ({1, 2}, optional) – Order of the autoregressive model. Default: 2 with three or more frames, else 1.

  • n_levels (int, optional) – Number of scales of the cascade (at least 3). Default 6.

  • threshold (float, optional) – Reflectivity (dBZ) below which there is no echo. Default 10.

  • zero_value (float, optional) – Reflectivity assigned to no echo, also in the result. Default: threshold - 5.

  • mask_radius (float or None, optional) – Distance (m) from the echo beyond which the forecast is set to zero_value at the first lead time. None switches the mask off. Default 20 km.

  • mask_growth (float, optional) – Growth of that distance with lead time (m/s). Default 0.

  • probability_matching (bool, optional) – Match the distribution of the forecast to the last observation. Default True.

  • motion_perturbation (dict, optional) – {"parallel": (a, b, c), "perpendicular": (a, b, c)}, the standard deviations (m/s) of the shift of the motion along and across it, a t**b + c with t in minutes. Default: no perturbation.

  • pad (float, optional) – Padding of the domain on each side, as a fraction of its size, for the Fourier transforms. Default 0.25.

  • seed (int, optional) – Seed of the random numbers. A seed gives the same ensemble for any n_threads and engine.

  • x, y (str, optional) – Names of the horizontal coordinates. Default "x" and "y".

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

  • engine ({"auto", "compiled", "numpy"}, optional) – Implementation of the interpolation and of the autoregressive step.

Returns:

xarray.DataArray – Reflectivity (dBZ) on (member, lead_time, y, x) for "steps", (lead_time, y, x) otherwise, float32, with the coordinate valid_time and the scalar time of the analysis (when the frames have times). No echo is zero_value; NaN is where the forecast comes from outside the observed area.

Raises:
  • ValueError – For unknown options, fewer frames than the order needs, frames on different grids or not evenly spaced in time, or a motion with NaN.

  • ImportError – If engine="compiled" and a kernel is not available.

Notes

Dask. This function computes the dask array: it needs the whole history of the forecast. The input is loaded into memory and the result is held in memory.

See also

exceedance_probability, estimate_motion, optical_flow, advect

References

Examples

>>> frames = [grid0, grid1, grid2]
>>> ens = radarx.retrieve.nowcast(frames, 12, seed=1)
>>> prob = radarx.retrieve.exceedance_probability(ens, 35.0)