improver.nowcasting.forecasting module

DEPRECATED MODULE. This module has been replaced by pysteps_advection.py and is no longer called by any CLI. This module defines plugins used to create nowcast extrapolation forecasts.

class AdvectField(vel_x, vel_y, attributes_dict=None)[source]

Bases: 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 (Cube) – Cube containing a 2D array of velocities along the x coordinate axis

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

  • attributes_dict (Optional[Dict]) – Dictionary containing information for amending the attributes of the output cube.

_abc_impl = <_abc_data object>
static _add_forecast_period(advected_cube, timestep)[source]

Add or replace a forecast period on the advected cube

Return type:

None

static _add_forecast_reference_time(input_time, advected_cube)[source]

Add or replace a forecast reference time on the advected cube

Return type:

None

_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:
  • data (Union[ndarray, MaskedArray]) – 2D numpy data array to be advected

  • grid_vel_x (ndarray) – Velocity in the x direction (in grid points per second)

  • grid_vel_y (ndarray) – Velocity in the y direction (in grid points per second)

  • timestep (int) – Advection time step in seconds

Return type:

MaskedArray

Returns:

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

_create_output_cube(cube, advected_data, timestep)[source]

Create a cube and appropriate metadata to contain the advected forecast

Parameters:
  • cube (Cube) – Source cube (before advection)

  • advected_data (ndarray) – Advected data

  • timestep (timedelta) – Time difference between the advected output and the source

Return type:

Cube

Returns:

The output cube

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 (ndarray) – 2D numpy array of source data to be advected

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

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

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

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

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

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

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

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

Return type:

None

static _update_time(input_time, advected_cube, timestep)[source]

Increment validity time on the advected cube

Parameters:
  • input_time (Coord) – Time coordinate from source cube

  • advected_cube (Cube) – Cube containing advected data (modified in place)

  • timestep (timedelta) – Time difference between the advected output and the source

Return type:

None

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:
  • cube (Cube) – The 2D cube containing data to be advected

  • timestep (timedelta) – Advection time step

Return type:

Cube

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

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

Bases: 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 (Cube) – A 2D cube containing data to be advected.

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

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

  • orographic_enhancement_cube (Optional[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 (Optional[Dict]) – Dictionary containing information for amending the attributes of the output cube.

_abc_impl = <_abc_data 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.

Return type:

Cube

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

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

Return type:

CubeList

Returns:

List of forecast cubes at the required lead times