From c67b866dcc555a175a31d4bab78c5fc934a73c5b Mon Sep 17 00:00:00 2001 From: George Breyiannis Date: Sun, 1 Oct 2023 15:27:42 +0200 Subject: [PATCH] pplot: make contourf more robust --- pyposeidon/utils/pplot.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pyposeidon/utils/pplot.py b/pyposeidon/utils/pplot.py index bd914b00..7b7a8ad8 100644 --- a/pyposeidon/utils/pplot.py +++ b/pyposeidon/utils/pplot.py @@ -372,7 +372,18 @@ def contourf(self, ax=None, it=None, **kwargs): pass var = kwargs.get("var", "depth") - z = kwargs.get("z", self._obj[var].data[it, :].flatten()) + + if len(self._obj[var].shape) == 1: + zv = self._obj[var].data.flatten() + elif len(self._obj[var].shape) == 2: + if t_var in self._obj[var].coords: + zv = self._obj[var][it, :].data.flatten() + else: + raise Exception(f"{t_var} not in {var} dims") + else: + raise Exception(f"{var} dimension is larger than 2, please subset") + + z = kwargs.get("z", zv) nv = kwargs.get("nv", 10)