Use Pyugrid to get connectivity array


In [1]:
from __future__ import (absolute_import, division, print_function)

from pylab import *

In [2]:
import netCDF4
import pyugrid
import matplotlib.tri as tri

In [3]:
# Read connectivity array using pyugrid

# dataset from FVCOM
# big
url =  'http://testbedapps-dev.sura.org/thredds/dodsC/in/usf/fvcom/ike/ultralite/vardrag/wave/2d'
# little 
url = 'http://www.smast.umassd.edu:8080/thredds/dodsC/FVCOM/NECOFS/Forecasts/NECOFS_GOM2_FORECAST.nc'

# note: this reads the whole thing in to memory at once: maybe we don't want to do that.
print("Loading data: This could take a while...")
ug = pyugrid.UGrid.from_ncfile(url)

# What's in there?
print("There are %i nodes"%ug.nodes.shape[0])
print("There are %i edges"%ug.edges.shape[0])
print("There are %i faces"%ug.faces.shape[0])


Loading data: This could take a while...
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-3-159adfe387c8> in <module>()
      9 # note: this reads the whole thing in to memory at once: maybe we don't want to do that.
     10 print("Loading data: This could take a while...")
---> 11 ug = pyugrid.UGrid.from_ncfile(url)
     12 
     13 # What's in there?

/Users/chris.barker/PythonStuff/py_ugrid/pyugrid/pyugrid/ugrid.pyc in from_ncfile(klass, nc_url, mesh_name, load_data)
    145         grid = klass()
    146         read_netcdf.load_grid_from_ncfilename(nc_url, grid,
--> 147                                               mesh_name, load_data)
    148         return grid
    149 

/Users/chris.barker/PythonStuff/py_ugrid/pyugrid/pyugrid/read_netcdf.pyc in load_grid_from_ncfilename(filename, grid, mesh_name, load_data)
    271     """
    272 
--> 273     with netCDF4.Dataset(filename, 'r') as nc:
    274         load_grid_from_nc_dataset(nc, grid, mesh_name, load_data)

netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Dataset.__init__ (netCDF4/_netCDF4.c:9689)()

RuntimeError: NetCDF: file not found

In [ ]:
print('The start of the "connectivity array":\n', ug.faces[:5])

In [ ]:
# now read the data, because pyugrid doesn't do this yet
nc = netCDF4.Dataset(url)
ncv = nc.variables

In [ ]:
nc.variables.keys()

In [ ]:
print(ncv['zeta'])

In [ ]:
#z = ncv['zeta'][700,:]
z = ncv['zeta'][10,:]

In [ ]:
lon = ncv['lon'][:]
lat = ncv['lat'][:]

In [ ]:
triang = tri.Triangulation(lon,lat, triangles=ug.faces)

In [ ]:
figure(figsize=(12,8))
levs=linspace(floor(z.min()),ceil(z.max()),40)
gca().set_aspect(1./cos(lat.mean()*pi/180))
tricontourf(triang, z,levels=levs)
colorbar()
tricontour(triang, z, colors='k',levels=levs)