From a67d3a15c88f58967c2c5ee4694d5465e4a74055 Mon Sep 17 00:00:00 2001 From: Michiel Van Ginderachter <81358394+mpvginde@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:25:31 +0200 Subject: [PATCH] Bugfix/adjust (#92) * bugfix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update changelog --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- CHANGELOG.md | 3 +++ src/anemoi/datasets/data/misc.py | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ee89500..ce17238e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ Keep it human-readable, your future self will thank you! ## [Unreleased](https://github.com/ecmwf/anemoi-datasets/compare/0.5.7...HEAD) +### Changed + +- Bugfix in `auto_adjust` ### Added diff --git a/src/anemoi/datasets/data/misc.py b/src/anemoi/datasets/data/misc.py index 8c7cfc04..ef68469d 100644 --- a/src/anemoi/datasets/data/misc.py +++ b/src/anemoi/datasets/data/misc.py @@ -235,16 +235,21 @@ def _auto_adjust(datasets, kwargs): if set(d.variables) != variables: subset_kwargs[i]["select"] = sorted(variables) + if "start" or "end" in adjust_set: + common = datasets[0].dates + for d in datasets[0:]: + common = np.intersect1d(common, d.dates) + if "start" in adjust_set: assert "start" not in kwargs, "Cannot use 'start' in adjust and kwargs" - start = max(d.dates[0] for d in datasets).astype(object) + start = min(common).astype(object) for i, d in enumerate(datasets): if start != d.dates[0]: subset_kwargs[i]["start"] = start if "end" in adjust_set: assert "end" not in kwargs, "Cannot use 'end' in adjust and kwargs" - end = min(d.dates[-1] for d in datasets).astype(object) + end = max(common).astype(object) for i, d in enumerate(datasets): if end != d.dates[-1]: subset_kwargs[i]["end"] = end