From ced7fa2c1ddafec6eaa7cf7608cff1cb65c4e926 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20M=C3=BCller?= <mueller.seb@posteo.de>
Date: Mon, 18 Nov 2024 10:25:02 +0100
Subject: [PATCH] gird: to_/from_canonical: allow additional dimensions

---
 src/finam/data/grid_base.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/finam/data/grid_base.py b/src/finam/data/grid_base.py
index 0ca332a4..72251f99 100644
--- a/src/finam/data/grid_base.py
+++ b/src/finam/data/grid_base.py
@@ -519,7 +519,9 @@ class StructuredGrid(Grid):
         ValueError
             When data has wrong shape.
         """
-        if not np.array_equal(np.shape(data), self.data_shape):
+        rev = -1 if self.axes_reversed else 1
+        d_shp, in_shp, shp_len = self.data_shape, np.shape(data), len(self.data_shape)
+        if not np.array_equal(d_shp[::rev], in_shp[::rev][:shp_len]):
             msg = "to_canonical: data has wrong shape."
             raise ValueError(msg)
         if self.axes_reversed and np.ndim(data) > 1:
@@ -552,7 +554,8 @@ class StructuredGrid(Grid):
             When data has wrong shape.
         """
         rev = -1 if self.axes_reversed else 1
-        if not np.array_equal(np.shape(data)[::rev], self.data_shape):
+        d_shp, in_shp, shp_len = self.data_shape, np.shape(data), len(self.data_shape)
+        if not np.array_equal(d_shp[::rev], in_shp[:shp_len]):
             msg = "from_canonical: data has wrong shape."
             raise ValueError(msg)
         for i, inc in enumerate(self.axes_increase):
-- 
GitLab