diff --git a/src/idpi/grib_decoder.py b/src/idpi/grib_decoder.py index f36fef4a..4bf49f49 100644 --- a/src/idpi/grib_decoder.py +++ b/src/idpi/grib_decoder.py @@ -3,6 +3,7 @@ # Standard library import datetime as dt import io +import logging import typing from collections.abc import Mapping, Sequence from itertools import product @@ -17,6 +18,8 @@ # Local from . import data_source, tasking +logger = logging.getLogger(__name__) + DIM_MAP = { "level": "z", "perturbationNumber": "eps", @@ -45,6 +48,16 @@ def _gather_coords(field_map, dims): coord_values = zip(*field_map) unique = (sorted(set(values)) for values in coord_values) coords = {dim: c for dim, c in zip(dims[:-2], unique)} + + if missing := [ + combination + for combination in product(*coords.values()) + if combination not in field_map + ]: + msg = f"Missing combinations: {missing}" + logger.exception(msg) + raise RuntimeError(msg) + ny, nx = next(iter(field_map.values())).shape shape = tuple(len(v) for v in coords.values()) + (ny, nx) return coords, shape @@ -147,6 +160,7 @@ def _load_param( self, req: Request, ): + logger.info("Retrieving request: %s", req) fs = self.data_source.retrieve(req) hcoords: dict[str, xr.DataArray] = {} @@ -162,6 +176,7 @@ def _load_param( else ("step", "level") ) key = field.metadata(*dim_keys) + logger.debug("Received field for key: %s", key) field_map[key] = field.to_numpy(dtype=np.float32) step = key[-2] # assume all members share the same time steps