Skip to content

Commit

Permalink
Fix issue related to removal/change of private function imported in `…
Browse files Browse the repository at this point in the history
…diag_scripts/shared/_supermeans.py` (deprecation in iris=3.11) (#3810)
  • Loading branch information
valeriupredoi authored Nov 13, 2024
1 parent eb62759 commit c4f7576
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion esmvaltool/diag_scripts/shared/_supermeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import cf_units
import iris
import iris.coord_categorisation
from iris.coord_categorisation import _pt_date
import numpy as np


Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit c4f7576

Please sign in to comment.