improver.utilities.temporal_interpolation module
Class for Temporal Interpolation calculations.
- class TemporalInterpolation(interval_in_minutes=None, times=None, interpolation_method='linear')[source]
Bases:
BasePlugin
Interpolate data to intermediate times between the validity times of two cubes. This can be used to fill in missing data (e.g. for radar fields) or to ensure data is available at the required intervals when model data is not available at these times.
- __init__(interval_in_minutes=None, times=None, interpolation_method='linear')[source]
Initialise class.
- Parameters:
interval_in_minutes (
Optional
[int
]) –Specifies the interval in minutes at which to interpolate between the two input cubes. A number of minutes which does not divide up the interval equally will raise an exception.
e.g. cube_t0 valid at 03Z, cube_t1 valid at 06Z,interval_in_minutes = 60 –> interpolate to 04Z and 05Z.times (
Optional
[List
[datetime
]]) – A list of datetime objects specifying the times to which to interpolate.interpolation_method (
str
) – Method of interpolation to use. Default is linear. Only methods in known_interpolation_methods can be used.
- Raises:
ValueError – If neither interval_in_minutes nor times are set.
ValueError – If interpolation method not in known list.
- _abc_impl = <_abc_data object>
- static calc_lats_lons(cube)[source]
Calculate the lats and lons of each point from a non-latlon cube, or output a 2d array of lats and lons, if the input cube has latitude and longitude coordinates.
- construct_time_list(initial_time, final_time)[source]
A function to construct a list of datetime objects formatted appropriately for use by iris’ interpolation method.
- Parameters:
- Return type:
- Returns:
A list containing a tuple that specifies the coordinate and a list of points along that coordinate to which to interpolate, as required by the iris interpolation method, e.g.:
[('time', [<datetime object 0>, <datetime object 1>])]
- Raises:
ValueError – If list of times provided falls outside the range specified by the initial and final times.
ValueError – If the interval_in_minutes does not divide the time range up equally.
- static daynight_interpolate(interpolated_cube)[source]
Set linearly interpolated data to zero for parameters (e.g. solar radiation parameters) which are zero if the sun is below the horizon.
- static enforce_time_coords_dtype(cube)[source]
Enforce the data type of the time, forecast_reference_time and forecast_period within the cube, so that time coordinates do not become mis-represented. The units of the time and forecast_reference_time are enforced to be “seconds since 1970-01-01 00:00:00” with a datatype of int64. The units of forecast_period are enforced to be seconds with a datatype of int32. This functions modifies the cube in-place.
- Parameters:
cube (
Cube
) – The cube that will have the datatype and units for the time, forecast_reference_time and forecast_period coordinates enforced.- Return type:
- Returns:
Cube where the datatype and units for the time, forecast_reference_time and forecast_period coordinates have been enforced.
- process(cube_t0, cube_t1)[source]
Interpolate data to intermediate times between validity times of cube_t0 and cube_t1.
- Parameters:
- Return type:
- Returns:
A list of cubes interpolated to the desired times.
- Raises:
TypeError – If cube_t0 and cube_t1 are not of type iris.cube.Cube.
CoordinateNotFoundError – The input cubes contain no time coordinate.
ValueError – Cubes contain multiple validity times.
ValueError – The input cubes are ordered such that the initial time cube has a later validity time than the final cube.
- solar_interpolate(diag_cube, interpolated_cube)[source]
Temporal Interpolation code using solar elevation for parameters (e.g. solar radiation parameters like Downward Shortwave (SW) radiation or UV index) which are zero if the sun is below the horizon and scaled by the sine of the solar elevation angle if the sun is above the horizon.
- Parameters:
- Return type:
- Returns:
A list of cubes interpolated to the desired times.