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

contourf breaking with suntans accessor #10

Open
apatlpo opened this issue Jul 3, 2023 · 0 comments
Open

contourf breaking with suntans accessor #10

apatlpo opened this issue Jul 3, 2023 · 0 comments

Comments

@apatlpo
Copy link

apatlpo commented Jul 3, 2023

contourf breaks when called via the suntans accessor:

ds = xr.open_zarr(...)

da = ds["eta"][1, ...]
vmin, vmax = float(da.min()), float(da.max())
lvls = np.arange(vmin,vmax,.01)
fig, ax, tri, cbar = ds.suntans.contourf(da, clevs=lvls, cmap="RdBu")

produces

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[8], line 6
      4 lvls = np.arange(-1,1,.1)
      5 lvls = np.arange(vmin,vmax,.01)
----> 6 fig, ax, tri, cbar = ds.suntans.contourf(da, clevs=lvls, cmap="RdBu")

File ~/nwa/nwatools/uplot.py:143, in Plot.contourf(self, zdata, clevs, xlims, ylims, colorbar, filled, **kwargs)
    137 def contourf(self, zdata, clevs=20, \
    138     xlims=None, ylims=None, colorbar=True, filled=True,\
    139     **kwargs):
    140     """
    141     Filled contour plot
    142     """
--> 143     self.build_tri_voronoi()
    145     fig = plt.gcf()
    146     ax = fig.gca()

File ~/nwa/nwatools/uplot.py:294, in Plot.build_tri_voronoi(self)
    292     print('Computing delaunay triangulation and computing mask...')
    293 pts = np.vstack([self.xv,self.yv]).T
--> 294 D = spatial.Delaunay(pts)
    295 self._triv =tri.Triangulation(self.xv,self.yv,D.simplices)
    297 # Compute a mask by removing triangles outside of the polygon

File _qhull.pyx:1841, in scipy.spatial._qhull.Delaunay.__init__()

File _qhull.pyx:280, in scipy.spatial._qhull._Qhull.__init__()

ValueError: Points cannot contain NaN

Pocking around a bit indicates self.xv and self.yv are both None.

A quick fix seems to assign values in the suntans accessor instantiation, e.g.:

        UPlot.__init__(self, self._obj['xp'].values, 
                       self._obj['yp'].values, self._obj['cells'].values, 
                       nfaces=self._obj['nfaces'].values,
            _FillValue=-999999)
        self.xv = self._obj['xv'].values
        self.yv = self._obj['yv'].values
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