From c4f757638ea3e78c635cc130ed965d47c32c1d9e Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Wed, 13 Nov 2024 12:23:41 +0000 Subject: [PATCH] Fix issue related to removal/change of private function imported in `diag_scripts/shared/_supermeans.py` (deprecation in iris=3.11) (#3810) --- esmvaltool/diag_scripts/shared/_supermeans.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/esmvaltool/diag_scripts/shared/_supermeans.py b/esmvaltool/diag_scripts/shared/_supermeans.py index 7099ba4725..8543ca99cf 100644 --- a/esmvaltool/diag_scripts/shared/_supermeans.py +++ b/esmvaltool/diag_scripts/shared/_supermeans.py @@ -13,7 +13,6 @@ import cf_units import iris import iris.coord_categorisation -from iris.coord_categorisation import _pt_date import numpy as np @@ -206,6 +205,28 @@ def add_start_hour(cube, coord, name='diurnal_sampling_hour'): _add_categorised_coord(cube, name, coord, start_hour_from_bounds) +# lifted from iris==3.10 last iris to have it in iris.coord_categorisation +# Private "helper" function +def _pt_date(coord, time): + """Return the datetime of a time-coordinate point. + + Parameters + ---------- + coord : Coord + Coordinate (must be Time-type). + time : float + Value of a coordinate point. + + Returns + ------- + cftime.datetime + + """ + # NOTE: All of the currently defined categorisation functions are + # calendar operations on Time coordinates. + return coord.units.num2date(time, only_use_cftime_datetimes=True) + + def start_hour_from_bounds(coord, _, bounds): """Add hour from bounds.""" return np.array([_pt_date(coord, _bounds[0]).hour for _bounds in bounds])