import netCDF4
import pyugrid
import matplotlib.tri as tri
# dataset form FVcom...
# big
url = 'http://comt.sura.org/thredds/dodsC/data/testbed/inundation_tropical/UND_ADCIRC/Hurricane_Ike_2D_final_run_with_waves'
# little
#url = 'http://www.smast.umassd.edu:8080/thredds/dodsC/FVCOM/NECOFS/Forecasts/NECOFS_GOM2_FORECAST.nc'
url='http://geoport.whoi.edu/thredds/dodsC/usgs/data2/rsignell/estofs/estofs.ncml'
# get the datasets:
# 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...
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-2-d2e60be69c8c> in <module>() 8 # note: this reads the whole thing in to memory at once: maybe we don't want to do that. 9 print "Loading data: This could take a while..." ---> 10 ug = pyugrid.UGrid.from_ncfile(url) 11 12 # What's in there? NameError: name 'pyugrid' is not defined
lon = ug.nodes[:,0]
lat = ug.nodes[:,1]
nv = ug.faces[:]
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-3-e48852a0b395> in <module>() ----> 1 lon = ug.nodes[:,0] 2 lat = ug.nodes[:,1] 3 nv = ug.faces[:] NameError: name 'ug' is not defined
triang = tri.Triangulation(lon,lat,triangles=nv)
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-4-5a998c08168e> in <module>() ----> 1 triang = tri.Triangulation(lon,lat,triangles=nv) AttributeError: 'function' object has no attribute 'Triangulation'
nc = netCDF4.Dataset(url)
ncv = nc.variables
nc.variables.keys()
[u'depth', u'element', u'ibtype', u'ibtypee', u'max_nvdll', u'max_nvell', u'nbdv', u'nbvv', u'nvdll', u'nvell', u'x', u'y', u'neta', u'nvel', u'time', u'zeta', u'adcirc_mesh']
print ncv['zeta']
<type 'netCDF4.Variable'> float64 zeta(time, node) long_name: water surface elevation above geoid standard_name: sea_surface_height_above_geoid units: m _FillValue: -99999.0 coordinates: time x y location: node mesh: adcirc_mesh coverage_content_type: modelResult unlimited dimensions: current shape = (192, 254565) filling off
#z = ncv['zeta'][700,:]
z = ncv['zeta'][10,:]
print z.min()
print z.max()
-1.00254822095 6.33337428446
figure(figsize=(12,8))
levs=arange(-1,5,.2)
gca().set_aspect(1./cos(lat.mean()*pi/180))
tricontourf(triang, z,levels=levs)
colorbar()
tricontour(triang, z, colors='k',levels=levs)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-10-3e8f125cd203> in <module>() 1 figure(figsize=(12,8)) 2 levs=arange(-1,5,.2) ----> 3 gca().set_aspect(1./cos(lat.mean()*pi/180)) 4 tricontourf(triang, z,levels=levs) 5 colorbar() NameError: name 'lat' is not defined