improver.metadata.forecast_times module¶
Utilities to manipulate forecast time coordinates
-
improver.metadata.forecast_times.find_latest_cycletime(cubelist)[source]¶ Find the latest cycletime from the cubes in a cubelist and convert it into a datetime object.
- Parameters
cubelist (iris.cube.CubeList) – A list of cubes each containing single time step from different forecast cycles.
- Returns
A datetime object corresponding to the latest forecast reference time in the input cubelist.
- Return type
-
improver.metadata.forecast_times.forecast_period_coord(cube, force_lead_time_calculation=False, result_units='seconds')[source]¶ Return or calculate the lead time coordinate (forecast_period) within a cube, either by reading the forecast_period coordinate, or by calculating the difference between the time (points and bounds) and the forecast_reference_time. The units of the forecast_period, time and forecast_reference_time coordinates are converted, if required. The final coordinate will have units of seconds.
- Parameters
cube (iris.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 forecast_reference_time and the time coordinate, even if the forecast_period coordinate exists. Default is False.
result_units (str or cf_units.Unit) – Desired units for the resulting forecast period coordinate.
- Returns
Describing the points and their units for ‘forecast_period’. 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. Units are result_units.
- Return type
-
improver.metadata.forecast_times.rebadge_forecasts_as_latest_cycle(cubes, cycletime)[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).
- Parameters
cubes (iris.cube.CubeList) – Cubes that will have their forecast_reference_time and forecast_period updated.
cycletime (str or None) – Required forecast reference time in a YYYYMMDDTHHMMZ format e.g. 20171122T0100Z. If None, the latest forecast reference time is used.
- Returns
Updated cubes
- Return type
-
improver.metadata.forecast_times.unify_cycletime(cubes, cycletime)[source]¶ Function to unify the forecast_reference_time and update forecast_period. The cycletime specified is used as the forecast_reference_time, and the forecast_period is recalculated using the time coordinate and updated forecast_reference_time.
- Parameters
cubes (iris.cube.CubeList) – Cubes that will have their forecast_reference_time and forecast_period updated. Any bounds on the forecast_reference_time coordinate will be discarded.
cycletime (datetime.datetime) – Datetime for the cycletime that will be used to replace the forecast_reference_time on the individual cubes.
- Returns
Updated cubes
- Return type
- Raises
ValueError – if forecast_reference_time is a dimension coordinate