Pyugrid test: extract elevation at nodes


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

In [2]:
# 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

In [3]:
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

In [4]:
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'

In [5]:
nc = netCDF4.Dataset(url)
ncv = nc.variables

In [6]:
nc.variables.keys()


Out[6]:
[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']

In [7]:
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


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

In [9]:
print z.min()
print z.max()


-1.00254822095
6.33337428446

In [10]:
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

In [ ]: