From e8f90a0befbdac01c12d6a3471df1514105bbaa3 Mon Sep 17 00:00:00 2001 From: Ilaria Luise Date: Fri, 19 Dec 2025 15:14:29 +0000 Subject: [PATCH 1/2] Revert "Make missing fstep 0 produce a more meaningfull error (#1444)" This reverts commit e3b29bee129f4fc764845b925324aa9eec0e0d1b. --- packages/common/src/weathergen/common/io.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/common/src/weathergen/common/io.py b/packages/common/src/weathergen/common/io.py index 3f4c67a691..220dd6d281 100644 --- a/packages/common/src/weathergen/common/io.py +++ b/packages/common/src/weathergen/common/io.py @@ -189,7 +189,7 @@ def _infer_forecast_offset(datasets: dict[str, typing.Any]) -> int: Infer forecast offset by the (non)presence of targets at fstep 0. Args: - datasets: Datasets found in a fstep 0 OutputItem (eg. ZarrIO.example_key). + datasets: Datasets found in a fstep 0 OutputItem. """ # forecast offset=1 should produce no targets at fstep 0 return 0 if "target" in datasets else 1 @@ -367,7 +367,8 @@ def _get_group(self, item: ItemKey, create: bool = False) -> zarr.Array | zarr.G group = self.data_root.create_group(item.path) else: try: - group = self.data_root[item.path] + group = self.data_root.get(item.path) + assert group is not None, f"Zarr group: {item.path} does not exist." except KeyError as e: msg = f"Zarr group: {item.path} has not been created." raise FileNotFoundError(msg) from e @@ -408,18 +409,14 @@ def forecast_offset(self) -> int: @functools.cached_property def example_key(self) -> ItemKey: - fstep = 0 try: sample, example_sample = next(self.data_root.groups()) stream, example_stream = next(example_sample.groups()) + fstep = 0 except StopIteration as e: msg = f"Data store at: {self._store_path} is empty." raise FileNotFoundError(msg) from e - assert fstep in example_stream.groups(), ( - "fstep 0 is missisg, but should always contain at least sources." - ) - return ItemKey(sample, fstep, stream) @functools.cached_property From cb59e70da13dcefa16e159d904a4ee614e134f03 Mon Sep 17 00:00:00 2001 From: Ilaria Luise Date: Fri, 21 Aug 2026 09:50:15 +0000 Subject: [PATCH 2/2] fix common io --- packages/common/src/weathergen/common/io.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/common/src/weathergen/common/io.py b/packages/common/src/weathergen/common/io.py index 947a4a0480..117d8d3775 100644 --- a/packages/common/src/weathergen/common/io.py +++ b/packages/common/src/weathergen/common/io.py @@ -521,7 +521,20 @@ def forecast_steps(self) -> list[int]: """Query available forecast steps in this zarr store.""" # assume stream/samples/forecast_steps are orthogonal _, example_sample = next(self.data_root.groups()) - _, example_stream = next(example_sample.groups()) + + # Find the first stream that actually contains forecast step groups. + # The first stream alphabetically (e.g. "latent") may be empty or + # have a different structure than the primary data streams. + example_stream = None + for _, candidate in example_sample.groups(): + child_keys = list(candidate.group_keys()) + if child_keys: + example_stream = candidate + break + + if example_stream is None: + msg = f"No stream with forecast steps found in {self._store_path}" + raise FileNotFoundError(msg) all_steps = sorted(list(example_stream.group_keys()))