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).
- _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:
- static _add_forecast_reference_time(input_time, advected_cube)[source]
Add or replace a forecast reference time on the advected cube
- Return type:
- _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:
- 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
- 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 advectedoutdata (
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 processedxdest_grid (
ndarray
) – Integer x-coordinates of all points on destination gridydest_grid (
ndarray
) – Integer y-coordinates of all points on destination gridxsrc_grid (
ndarray
) – Integer x-coordinates of all points on source gridysrc_grid (
ndarray
) – Integer y-coordinates of all points on source gridx_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:
- static _update_time(input_time, advected_cube, timestep)[source]
Increment validity time on the advected cube
- 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:
- Return type:
- 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 axisvel_y (
Cube
) – Cube containing a 2D array of velocities along the y coordinate axisorographic_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:
- 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.