Skip to content

Commit

Permalink
Merge pull request #177 from SanderHulst/feature/handle_scalar_mask_i…
Browse files Browse the repository at this point in the history
…n_hamtide

⭐ ensure that griddata input is 1-dimensional
  • Loading branch information
SorooshMani-NOAA authored Aug 31, 2023
2 parents 5b5113a + 2fffb68 commit ad458b5
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions adcircpy/forcing/tides/hamtide.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,18 @@ 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()
values = griddata(
(xi[~zi.mask], yi[~zi.mask]),
zi[~zi.mask],
(xq, yq),
method='linear',
fill_value=np.nan,
)
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, 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],
(xq[nan_idxs], yq[nan_idxs]),
method='nearest',
(xi, yi), zi, (xq[nan_idxs], yq[nan_idxs]), method='nearest',
)
return values

Expand Down

0 comments on commit ad458b5

Please sign in to comment.