improver.metadata.forecast_times module#

Utilities to manipulate forecast time coordinates

_calculate_forecast_period(time_coord, frt_coord, dim_coord=False, coord_spec=(None, <class 'numpy.int32'>, 'seconds'))[source]#

Calculate a forecast period from existing time and forecast reference time coordinates.

Parameters:
  • time_coord (Coord) – Time coordinate

  • frt_coord (Coord) – Forecast reference coordinate

  • dim_coord (bool) – If true, create an iris.coords.DimCoord instance. Default is to create an iris.coords.AuxCoord.

  • coord_spec (TimeSpec) – Specification of units and dtype for the forecast_period coordinate.

Return type:

Coord

Returns:

Forecast period coordinate corresponding to the input times and forecast reference times specified

Warns:

UserWarning – If any calculated forecast periods are negative

_create_frt_type_coord(cube, point, name='forecast_reference_time')[source]#

Create a new auxiliary coordinate based on forecast reference time

Parameters:
  • cube (Cube) – Input cube with scalar forecast reference time coordinate

  • points – Single datetime point for output coord

  • name (str) – Name of aux coord to be returned

Return type:

DimCoord

Returns:

New auxiliary coordinate

_find_latest_cycletime(cubelist)[source]#

Find the latest cycletime from the cubes in a cubelist and convert it into a datetime object.

Parameters:

cubelist (Union[CubeList, List[Cube]]) – A list of cubes each containing single time step from different forecast cycles.

Return type:

datetime

Returns:

A datetime object corresponding to the latest forecast reference time in the input cubelist.

add_blend_time(cube, cycletime)[source]#

Function to add scalar blend time coordinate to a blended cube based on current cycle time. Modifies cube in place.

Args:
cubes:

Cube to add blend time coordinate

cycletime:

Required blend time in a YYYYMMDDTHHMMZ format e.g. 20171122T0100Z

Return type:

None

forecast_period_coord(cube, force_lead_time_calculation=False)[source]#

Return the lead time coordinate (forecast_period) from a cube, either by reading an existing forecast_period coordinate, or by calculating the difference between time and forecast_reference_time or blend_time.

Parameters:
  • cube (Cube) – Cube from which the lead times will be determined.

  • force_lead_time_calculation (bool) – Force the lead time to be calculated from the reference time and the time coordinates, even if the forecast_period coordinate exists. Default is False.

Return type:

Coord

Returns:

New forecast_period coord. A DimCoord is returned if the forecast_period coord is already present in the cube as a DimCoord and this coord does not need changing, otherwise it will be an AuxCoord.

rebadge_forecasts_as_latest_cycle(cubes, cycletime=None)[source]#

Function to update the forecast_reference_time and forecast_period on a list of input forecasts to match either a given cycletime, or the most recent forecast in the list (proxy for the current cycle). If a blend_time coordinate is present on any cube it will be updated on all cubes to ensure it remains consistent with the forecast_reference_time coordinate.

Parameters:
  • cubes (Union[CubeList, List[Cube]]) – Cubes that will have their forecast_reference_time and forecast_period updated.

  • cycletime (Optional[str]) – Required forecast reference time in a YYYYMMDDTHHMMZ format e.g. 20171122T0100Z. If None, the latest forecast reference time is used.

Return type:

CubeList

Returns:

Updated cubes

Raises:

ValueError – if blend_time is present on some cubes but not all.

unify_cycletime(cubes, cycletime, target_coords=['forecast_reference_time'])[source]#

Function to unify the target_coords times and update forecast_period. The target_coords variable should be a list containing one or both of “forecast_reference_time” and “blend_time”. The cycletime specified is used as the new value for the target_coord, and the forecast_period is recalculated using the time coordinate and updated target_coord.

Parameters:
  • cubes (Union[CubeList, List[Cube]]) – Cubes that will have their forecast_reference_time / blend_time and forecast_period updated. Any bounds on the forecast_reference_time / blend_time coordinate will be discarded.

  • cycletime (datetime) – Datetime for the cycletime that will be used to replace the forecast_reference_time / blend_time on the individual cubes.

  • target_coords (List[str]) – A list of coordinates that relate to cycletime that should be updated. This list can only contain one or both of forecast_reference_time or blend_time. The default is [“forecast_reference_time”].

Return type:

CubeList

Returns:

Updated cubes

Raises:
  • ValueError – if the target_coords list contains anything other than “forecast_reference_time” or “blend_time”.

  • ValueError – if forecast_reference_time or blend_time is a dimension coordinate.