improver.nowcasting.forecasting module

This module defines plugins used to create nowcast extrapolation forecasts.

class improver.nowcasting.forecasting.AdvectField(vel_x, vel_y, attributes_dict=None)[source]

Bases: improver.BasePlugin

Class to advect a 2D spatial field given velocities along the two vector dimensions

__init__(vel_x, vel_y, attributes_dict=None)[source]

Initialises the plugin. Velocities are expected to be on a regular grid (such that grid spacing in metres is the same at all points in the domain).

Parameters
  • vel_x (iris.cube.Cube) – Cube containing a 2D array of velocities along the x coordinate axis

  • vel_y (iris.cube.Cube) – Cube containing a 2D array of velocities along the y coordinate axis

  • attributes_dict (dict) – Dictionary containing information for amending the attributes of the output cube.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 213
_abc_registry = <_weakrefset.WeakSet object>
_advect_field(data, grid_vel_x, grid_vel_y, timestep)[source]

Performs a dimensionless grid-based extrapolation of spatial data using advection velocities via a backwards method. Points where data cannot be extrapolated (ie the source is out of bounds) are given a fill value of np.nan and masked.

Parameters
Returns

2D float array of advected data values with masked “no data” regions

Return type

numpy.ma.MaskedArray

static _increment_output_array(indata, outdata, cond, xdest_grid, ydest_grid, xsrc_grid, ysrc_grid, x_weight, y_weight)[source]

Calculate and add contribution to the advected array from one source grid point, for all points where boolean condition “cond” is valid.

Parameters
  • indata (numpy.ndarray) – 2D numpy array of source data to be advected

  • outdata (numpy.ndarray) – 2D numpy array for advected output, modified in place by this method (is both input and output).

  • cond (numpy.ndarray) – 2D boolean mask of points to be processed

  • xdest_grid (numpy.ndarray) – Integer x-coordinates of all points on destination grid

  • ydest_grid (numpy.ndarray) – Integer y-coordinates of all points on destination grid

  • xsrc_grid (numpy.ndarray) – Integer x-coordinates of all points on source grid

  • ysrc_grid (numpy.ndarray) – Integer y-coordinates of all points on source grid

  • x_weight (numpy.ndarray) – Fractional contribution to destination grid of source data advected along the x-axis. Positive definite.

  • y_weight (numpy.ndarray) – Fractional contribution to destination grid of source data advected along the y-axis. Positive definite.

process(cube, timestep)[source]

Extrapolates input cube data and updates validity time. The input cube should have precisely two non-scalar dimension coordinates (spatial x/y), and is expected to be in a projection such that grid spacing is the same (or very close) at all points within the spatial domain. The input cube should also have a “time” coordinate.

Parameters
Returns

New cube with updated time and extrapolated data. New data are filled with np.nan and masked where source data were out of bounds (ie where data could not be advected from outside the cube domain).

Return type

iris.cube.Cube

class improver.nowcasting.forecasting.CreateExtrapolationForecast(input_cube, vel_x, vel_y, orographic_enhancement_cube=None, attributes_dict=None)[source]

Bases: improver.BasePlugin

Class to create a nowcast extrapolation forecast using advection. For precipitation rate forecasts, orographic enhancement must be used.

__init__(input_cube, vel_x, vel_y, orographic_enhancement_cube=None, attributes_dict=None)[source]

Initialises the object. This includes checking if orographic enhancement is provided and removing the orographic enhancement from the input file ready for extrapolation. An error is raised if the input cube is precipitation rate but no orographic enhancement cube is provided.

Parameters
  • input_cube (iris.cube.Cube) – A 2D cube containing data to be advected.

  • vel_x (iris.cube.Cube) – Cube containing a 2D array of velocities along the x coordinate axis

  • vel_y (iris.cube.Cube) – Cube containing a 2D array of velocities along the y coordinate axis

  • orographic_enhancement_cube (iris.cube.Cube) – Cube containing the orographic enhancement fields. May have data for multiple times in the cube. The orographic enhancement is removed from the input_cube before advecting, and added back on after advection.

  • attributes_dict (dict) – Dictionary containing information for amending the attributes of the output cube.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 213
_abc_registry = <_weakrefset.WeakSet object>
extrapolate(leadtime_minutes)[source]

Produce a new forecast cube for the supplied lead time. Creates a new advected forecast and then reapplies the orographic enhancement if it is supplied.

Parameters

leadtime_minutes (float) – The forecast leadtime we want to generate a forecast for in minutes.

Returns

New cube with updated time and extrapolated data. New data are filled with np.nan and masked where source data were out of bounds (ie where data could not be advected from outside the cube domain).

Return type

iris.cube.Cube

Raises

ValueError – If no leadtime_minutes are provided.

process(interval, max_lead_time)[source]

Generate nowcasts at required intervals up to the maximum lead time

Parameters
  • interval (int) – Lead time interval, in minutes

  • max_lead_time (int) – Maximum lead time required, in minutes

Returns

List of forecast cubes at the required lead times

Return type

iris.cube.CubeList