Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scan_grib cannot handle GRIB attributes that are arrays #518

Open
juntyr opened this issue Oct 21, 2024 · 0 comments
Open

scan_grib cannot handle GRIB attributes that are arrays #518

juntyr opened this issue Oct 21, 2024 · 0 comments

Comments

@juntyr
Copy link

juntyr commented Oct 21, 2024

... since zarr doesn't support attributes that are not JSON-serializable (including numpy arrays). This can be fixed like this (I don't have time to submit a PR myself right now):

diff --git a/kerchunk/grib2.py b/kerchunk/grib2.py
index e3a927b..0aa2ee6 100644
--- a/kerchunk/grib2.py
+++ b/kerchunk/grib2.py
@@ -103,7 +104,10 @@ def _store_array(store, z, data, var, inline_threshold, offset, size, attr):
             overwrite=True,
         )
         store[f"{var}/" + ".".join(["0"] * len(shape))] = ["{{u}}", offset, size]
-    d.attrs.update(attr)
+    d.attrs.update({
+        k: v.tolist() if isinstance(v, np.ndarray) else v
+        for k, v in attr.items()
+    })
 
 
 def scan_grib(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant