improver.utilities.temporal_interpolation module¶
Class for Temporal Interpolation calculations.
-
class
improver.utilities.temporal_interpolation.TemporalInterpolation(interval_in_minutes=None, times=None, interpolation_method='linear')[source]¶ Bases:
improver.BasePluginInterpolate 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 (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 (list or tuple of datetime.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_cache= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache_version= 213¶
-
_abc_registry= <_weakrefset.WeakSet 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.
- Parameters
cube (iris.cube.Cube) – cube containing x and y axis
- Returns
- tuple containing:
- lats (numpy.ndarray):
2d Array of latitudes for each point.
- lons (numpy.ndarray):
2d Array of longitudes for each point.
- Return type
(tuple)
-
static
calc_sin_phi(dtval, lats, lons)[source]¶ Calculate sin of solar elevation
- Parameters
dtval (datetime.datetime) – Date and time.
lats (numpy.ndarray) – Array 2d of latitudes for each point
lons (numpy.ndarray) – Array 2d of longitudes for each point
- Returns
Array of sine of solar elevation at each point
- Return type
-
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
initial_time (datetime.datetime) – The start of the period over which a time list is to be constructed.
final_time (datetime.datetime) – The end of the period over which a time list is to be constructed.
- 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>])]
- Return type
list of Tuple[str, List[datetime.datetime]]
- 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.
- Parameters
interpolated_cube (iris.cube.Cube) – cube containing Linear interpolation of cube at interpolation times in time_list.
- Returns
A list of cubes interpolated to the desired times.
- Return type
-
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 (iris.cube.Cube) – The cube that will have the datatype and units for the time, forecast_reference_time and forecast_period coordinates enforced.
- Returns
Cube where the datatype and units for the time, forecast_reference_time and forecast_period coordinates have been enforced.
- Return type
-
process(cube_t0, cube_t1)[source]¶ Interpolate data to intermediate times between validity times of cube_t0 and cube_t1.
- Parameters
cube_t0 (iris.cube.Cube) – A diagnostic cube valid at the beginning of the period within which interpolation is to be permitted.
cube_t1 (iris.cube.Cube) – A diagnostic cube valid at the end of the period within which interpolation is to be permitted.
- Returns
A list of cubes interpolated to the desired times.
- Return type
- 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
diag_cube (iris.cube.Cube) – cube containing diagnostic data valid at the beginning of the period and at the end of the period.
interpolated_cube (iris.cube.Cube) – cube containing Linear interpolation of diag_cube at interpolation times in time_list.
- Returns
A list of cubes interpolated to the desired times.
- Return type
-