From 8f7cff93cd8ba465456f8000620c1a7575e95cbe Mon Sep 17 00:00:00 2001 From: sanderh Date: Thu, 31 Aug 2023 16:55:43 +0200 Subject: [PATCH 1/2] :star: ensure that griddata input is 1-dimensional --- adcircpy/forcing/tides/hamtide.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/adcircpy/forcing/tides/hamtide.py b/adcircpy/forcing/tides/hamtide.py index b4de0191..a7b21114 100644 --- a/adcircpy/forcing/tides/hamtide.py +++ b/adcircpy/forcing/tides/hamtide.py @@ -113,21 +113,25 @@ def _get_interpolation( dy = (self.y[-1] - self.y[0]) / len(self.y) yidx = np.logical_and(self.y >= np.min(yq) - 2.0 * dy, self.y <= np.max(yq) + 2.0 * dy) xi, yi = np.meshgrid(self.x[xidx], self.y[yidx]) - xi = xi.flatten() - yi = yi.flatten() dataset = self._get_dataset(variable, constituent) - zi = dataset[netcdf_variable][yidx, xidx].flatten() + zi = dataset[netcdf_variable][yidx, xidx] + mask = ~zi.mask + if mask.size == 1: + mask = np.array(zi * mask, dtype=bool) + xi = xi[mask].flatten() + yi = yi[mask].flatten() + zi = zi[mask].flatten() values = griddata( - (xi[~zi.mask], yi[~zi.mask]), - zi[~zi.mask], + (xi, yi), + zi, (xq, yq), method='linear', fill_value=np.nan, ) nan_idxs = np.where(np.isnan(values)) values[nan_idxs] = griddata( - (xi[~zi.mask], yi[~zi.mask]), - zi[~zi.mask], + (xi, yi), + zi, (xq[nan_idxs], yq[nan_idxs]), method='nearest', ) From 2fffb68aee537c88c53c68b33d5b44159541d239 Mon Sep 17 00:00:00 2001 From: sanderh Date: Thu, 31 Aug 2023 21:11:11 +0200 Subject: [PATCH 2/2] :art: reformat using oitnb --- adcircpy/forcing/tides/hamtide.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/adcircpy/forcing/tides/hamtide.py b/adcircpy/forcing/tides/hamtide.py index a7b21114..1b5abea8 100644 --- a/adcircpy/forcing/tides/hamtide.py +++ b/adcircpy/forcing/tides/hamtide.py @@ -121,19 +121,10 @@ def _get_interpolation( xi = xi[mask].flatten() yi = yi[mask].flatten() zi = zi[mask].flatten() - values = griddata( - (xi, yi), - zi, - (xq, yq), - method='linear', - fill_value=np.nan, - ) + values = griddata((xi, yi), zi, (xq, yq), method='linear', fill_value=np.nan,) nan_idxs = np.where(np.isnan(values)) values[nan_idxs] = griddata( - (xi, yi), - zi, - (xq[nan_idxs], yq[nan_idxs]), - method='nearest', + (xi, yi), zi, (xq[nan_idxs], yq[nan_idxs]), method='nearest', ) return values