improver.utilities.temporal module
General utilities for parsing and extracting cubes at times
- cycletime_to_datetime(cycletime, cycletime_format='%Y%m%dT%H%MZ')[source]
Convert a string representating the cycletime of the format YYYYMMDDTHHMMZ into a datetime object.
- cycletime_to_number(cycletime, cycletime_format='%Y%m%dT%H%MZ', time_unit='hours since 1970-01-01 00:00:00', calendar='gregorian')[source]
Convert a cycletime of the format YYYYMMDDTHHMMZ into a numeric time value.
- Parameters:
cycletime (
str
) – A cycletime that can be converted into a datetime using the cycletime_format supplied.cycletime_format (
str
) – String containg the appropriate directives to indicate how the output datetime should display.time_unit (
str
) – String representation of the cycletime units.calendar (
str
) – String describing the calendar used for defining the cycletime. The choice of calendar must be supported by cf_units.CALENDARS.
- Return type:
- Returns:
A numeric value to represent the datetime using assumed choices for the unit of time and the calendar.
- datetime_constraint(time_in, time_max=None)[source]
Constructs an iris equivalence constraint from a python datetime object.
- Parameters:
- Return type:
- Returns:
An iris constraint to be used in extracting data at the given time from a cube.
- datetime_to_cycletime(adatetime, cycletime_format='%Y%m%dT%H%MZ')[source]
Convert a datetime object into a string representing the cycletime of the format YYYYMMDDTHHMMZ.
- datetime_to_iris_time(dt_in)[source]
Convert python datetime.datetime or cftime.DatetimeGregorian object into seconds since 1970-01-01 00Z.
- extract_cube_at_time(cubes, time, time_extract)[source]
Extract a single cube at a given time from a cubelist.
- Parameters:
cubes (
CubeList
) – CubeList of a given diagnostic over several times.time (
datetime
) – Time at which forecast data is needed.time_extract (
Constraint
) – Iris constraint for the desired time.
- Return type:
- Returns:
Cube of data at the desired time.
- Raises:
ValueError if the desired time is not available within the cubelist. –
- extract_nearest_time_point(cube, dt, time_name='time', allowed_dt_difference=0)[source]
Find the nearest time point to the time point provided.
- Parameters:
cube (
Cube
) – Cube or CubeList that will be extracted from using the supplied time_pointdt (
datetime
) – Datetime representation of a time that will be used within the extraction from the cube supplied.time_name (
str
) – Name of the “time” coordinate that will be extracted. This must be “time” or “forecast_reference_time”.allowed_dt_difference (
int
) – An int in seconds to define a limit to the maximum difference between the datetime provided and the time points available within the cube. If this limit is exceeded, then an error is raised. This must be defined in seconds. Default is 0.
- Return type:
- Returns:
Cube following extraction to return the cube that is nearest to the time point supplied.
- Raises:
ValueError – The requested datetime is not available within the allowed difference.
- iris_time_to_datetime(time_coord, point_or_bound='point')[source]
Convert iris time to python datetime object. Working in UTC.