historical_daily
drop_noncore_coords(ds: xr.Dataset) -> xr.Dataset
Drop coordinates the older and newer CDS extract formats disagree about.
Extracts pulled through the newer CDS API carry number (ensemble member) and
expver ('0001' final ERA5, '0005' preliminary ERA5T) alongside the grid coords;
older extracts carry neither, and are packed int16 rather than float32. xr.concat
refuses to join datasets whose coordinates differ, so a look-ahead that crosses from
an old extract into a new one has to be normalised first.
Which era a file belongs to tracks its download date, not its data year: surveying
the archive, valid_time covers 1950-1989 and 2024 while time covers 1990-2023. So
there are two seams, not the single 2023/2024 one this used to describe -- 1989->1990
crosses new format into old, 2023->2024 crosses old into new -- and the 1950-2023
regeneration passed through both.
Source code in src/climate_data/generate/historical_daily.py
load_variable_with_lookahead(cdata: ClimateData, variable: str, year: str, month: str, dataset: str) -> xr.Dataset
Load a month's hourly data plus the one sample that closes its final day.
Accumulation windows are stamped by their end, so the last day of a month is closed by the next month's first sample -- for December, by the next year's January. That single extra sample completes the final bin without opening a new one.
Raises if the look-ahead file is absent rather than degrading to the incomplete
23-hour window, which should stop the run rather than quietly shorten one day.
Checked before loading the target month so the run fails fast. Note this reaches one
year past the history range -- regenerating the last history year needs the following
January -- which is why the extract tasks span cdc.EXTRACT_YEARS rather than
cdc.HISTORY_YEARS.
Source code in src/climate_data/generate/historical_daily.py
trim_to_month(ds: xr.Dataset, year: str, month: int) -> xr.Dataset
Drop collapsed bins that fall outside the target month.
The interval-aware collapse labels its first bin with the previous month's last day, since that bin holds that day's closing sample. Left in place, every month contributes a duplicate date at its seam.