Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
Add logging to grib_decoder (#118)
Browse files Browse the repository at this point in the history
## Purpose

Add log events to grib_decoder module
  • Loading branch information
cfkanesan authored Feb 29, 2024
1 parent b3946f3 commit b300ca3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/idpi/grib_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,6 +18,8 @@
# Local
from . import data_source, tasking

logger = logging.getLogger(__name__)

DIM_MAP = {
"level": "z",
"perturbationNumber": "eps",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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] = {}
Expand All @@ -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
Expand Down

0 comments on commit b300ca3

Please sign in to comment.