Compute in Local Time

This notebook demonstrates how to compute daily mean 2m temperature from ERA5 for two locations in the local time zone. Local time for each location is defined by an offset to UTC, the time zone of the input data. Computations in local time are useful when alignment with the diurnal cycle is important, e.g., in the agricultural sector.

[1]:
from earthkit import data as ekd
from earthkit import transforms as ekt

# Timeseries for two locations: Reading, UK, and Vancouver, Canada.
# The locations' UTC offset is included as a dataset coordinate.
da = ekd.from_source("sample", "era5-timeseries-multiple.nc").to_xarray()["t2m"]

# Refer time_shift to the included coordinate and trim incomplete days
ekt.temporal.daily_mean(da, time_shift="utc_offset", remove_partial_periods=True)

[1]:
<xarray.DataArray 't2m' (valid_time: 3, location: 2)> Size: 24B
array([[      nan, 286.97324],
       [294.4696 , 286.78192],
       [297.33304,       nan]], dtype=float32)
Coordinates:
  * valid_time  (valid_time) datetime64[ns] 24B 2026-05-23 2026-05-24 2026-05-25
  * location    (location) <U9 72B 'Reading' 'Vancouver'
    latitude    (location) float64 16B 51.5 49.25
    longitude   (location) float64 16B -1.0 -123.0
    utc_offset  (location) timedelta64[s] 16B 01:00:00 -1 days +17:00:00
Attributes: (12/30)
    GRIB_NV:                                  0
    GRIB_Nx:                                  1440
    GRIB_Ny:                                  721
    GRIB_cfName:                              unknown
    GRIB_cfVarName:                           t2m
    GRIB_dataType:                            an
    ...                                       ...
    GRIB_totalNumber:                         0
    GRIB_typeOfLevel:                         surface
    GRIB_units:                               K
    long_name:                                2 metre temperature
    standard_name:                            unknown
    units:                                    K

Explanation

  • The input timeseries cover a three-day period from 2026-05-23 00:00 to 2026-05-25 23:00 UTC in hourly steps.

  • In Reading local time (UTC+1), the input timeseries extends from 2026-05-23 01:00 to 2026-05-26 00:00. After removal of partial periods, only the daily mean values for days 2026-05-24 and 2026-05-25 remain.

  • In Vancouver local time (UTC-7), the input timeseries extends from 2026-05-22 17:00 to 2026-05-25 16:00. After removal of partial periods, only the daily mean values for days 2026-05-23 and 2026-05-24 remain.

Missing information in the output is filled with nan values.