radarx.retrieve.nowcasting.nowcast_model#

radarx.retrieve.nowcasting.nowcast_model(obj, model, n_steps, *, field=None, dt=None, n_input=None, offset=0.0, scale=1.0, threshold=10.0, zero_value=None, recurrent=True, x='x', y='y')[source]#

Nowcast with a learned network run by ONNX Runtime.

The last n_input frames are normalised, (dBZ - offset) / scale, and stacked as the channels of one input tensor of shape (1, n_input, ny, nx); the model returns the next frames as a tensor (1, k, ny, nx). This is the form of networks such as RainNet (Ayzel et al. 2020 [1], which predicts the next frame from four) and of the networks that predict several frames at once (DGMR, Ravuri et al. 2021 [2], uses a different input and output layout and needs an adapter to this one). With recurrent=True and a model that returns fewer than n_steps frames, the prediction is appended to the input and the model is run again, as RainNet is.

radarx ships no weights. The network, its licence and its citation come from the model registry of radarx.ml (radarx.ml.load_model(), radarx.ml.register_model()); the attributes ml_model, ml_model_version, ml_model_licence and ml_model_citation of the model are written to the result. The network must accept the grid as it is (a dynamic or an equal spatial size): the grid is not cut into patches. The wrapper, the normalisation and the recursion are radarx’s own; the checks of the two papers’ models are those of their authors, not repeated here.

Parameters:
  • obj (list of xarray.Dataset or xarray.DataArray, or xarray.Dataset) – Gridded volumes in time order, or one object with a time dimension, as for nowcast().

  • model (radarx.ml.Model or str) – An ONNX model, or the name of a registered one.

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

  • 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.

  • n_input (int, optional) – Number of frames fed to the model. Default: the size of the second dimension of the model input if it is fixed, else all frames.

  • offset, scale (float, optional) – Normalisation of the input, (dBZ - offset) / scale, and of the output (the inverse). Default 0 and 1.

  • 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.

  • recurrent (bool, optional) – Feed the predictions back to get more lead times than the model returns. Default True.

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

Returns:

xarray.DataArray – Reflectivity (dBZ) on (lead_time, y, x), float32.

Raises:
  • ValueError – If there are fewer frames than n_input, the output of the model is not (1, k, ny, nx), it returns fewer than n_steps frames and recurrent is False, or the model has more than one input.

  • ImportError – If ONNX Runtime is not installed (pip install radarx[ml]).

Notes

Dask. This function computes the dask array: it feeds the whole history to the network. The input is loaded into memory and the result is held in memory.

References

Examples

>>> model = radarx.ml.load_model("rainnet")
>>> fc = radarx.retrieve.nowcast_model(frames, model, 6, scale=10)