Test out UGRID-0.9 compliant unstructured grid model datasets with PYUGRID


In [1]:
import matplotlib.tri as tri
import datetime as dt
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

In [2]:
import iris
iris.FUTURE.netcdf_promote = True
from iris.fileformats.cf import reference_terms

In [3]:
import cartopy.crs as ccrs
import pyugrid
%matplotlib inline

In [4]:
#ADCIRC
#url =  'http://comt.sura.org/thredds/dodsC/data/comt_1_archive/inundation_tropical/UND_ADCIRC/Hurricane_Ike_3D_final_run_with_waves'

#FVCOM
#url = 'http://www.smast.umassd.edu:8080/thredds/dodsC/FVCOM/NECOFS/Forecasts/NECOFS_GOM3_FORECAST.nc'

#SELFE
url = 'http://comt.sura.org/thredds/dodsC/data/comt_1_archive/inundation_tropical/VIMS_SELFE/Hurricane_Ike_3D_final_run_with_waves'

In [5]:
ucube = iris.load_cube(url,'eastward_sea_water_velocity')
vcube = iris.load_cube(url,'northward_sea_water_velocity')


/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/iris/fileformats/cf.py:1040: UserWarning: Ignoring formula terms variable u'elev' referenced by data variable u'v' via variable u'sigma': Dimensions (u'time', u'node') do not span (u'time2', u'sigma', u'node')
  warnings.warn(msg)
/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/iris/fileformats/cf.py:1040: UserWarning: Ignoring formula terms variable u'elev' referenced by data variable u'u' via variable u'sigma': Dimensions (u'time', u'node') do not span (u'time2', u'sigma', u'node')
  warnings.warn(msg)
/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/iris/fileformats/_pyke_rules/compiled_krb/fc_rules_cf_fc.py:1300: UserWarning: Ignoring netCDF variable u'ele' invalid units u'non-dimensional'
  warnings.warn(msg.encode('ascii', errors='backslashreplace'))
/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/iris/fileformats/netcdf.py:441: UserWarning: Unable to find coordinate for variable u'elev'
  '{!r}'.format(name))
/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/iris/fileformats/netcdf.py:558: UserWarning: Unable to construct Ocean s-coordinate, generic form 1 factory due to insufficient source coordinates.
  warnings.warn('{}'.format(e))

In [6]:
reference_terms['ocean_s_coordinate_g1'] = ['s', 'c', 'eta', 'depth', 'depth_c']
zcube = iris.load_cube(url,'depth_below_geoid')
z = zcube.data


/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/iris/fileformats/cf.py:1040: UserWarning: Ignoring formula terms variable u'depth' referenced by data variable u'Cs' via variable u'sigma': Dimensions (u'node',) do not span (u'sigma',)
  warnings.warn(msg)
/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/iris/fileformats/cf.py:1040: UserWarning: Ignoring formula terms variable u'elev' referenced by data variable u'Cs' via variable u'sigma': Dimensions (u'time', u'node') do not span (u'sigma',)
  warnings.warn(msg)
/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/iris/fileformats/cf.py:1040: UserWarning: Ignoring formula terms variable u'depth' referenced by data variable u'sigma' via variable u'sigma': Dimensions (u'node',) do not span (u'sigma',)
  warnings.warn(msg)
/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/iris/fileformats/cf.py:1040: UserWarning: Ignoring formula terms variable u'elev' referenced by data variable u'sigma' via variable u'sigma': Dimensions (u'time', u'node') do not span (u'sigma',)
  warnings.warn(msg)
/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/iris/fileformats/netcdf.py:441: UserWarning: Unable to find coordinate for variable u'depth'
  '{!r}'.format(name))

In [7]:
# Desired time for snapshot
# ....right now (or some number of hours from now) ...
start = dt.datetime.utcnow() + dt.timedelta(hours=6)
# ... or specific time (UTC)
#start = dt.datetime(2013,3,2,15,0,0)

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


There are 592761 nodes

In [9]:
ug.data


Out[9]:
{}

In [10]:
lon = ug.nodes[:,0]
lat = ug.nodes[:,1]
nv = ug.faces[:]

In [11]:
triang = tri.Triangulation(lon,lat,triangles=nv)

In [11]:


In [12]:
# skip trying to find the closest time index to requested time, because it's messy
ind = -1 # just take the last time index for now
zcube = cube[ind]


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-12-11d87c8b382c> in <module>()
      1 # skip trying to find the closest time index to requested time, because it's messy
      2 ind = -1 # just take the last time index for now
----> 3 zcube = cube[ind]

NameError: name 'cube' is not defined

In [ ]:
plt.figure(figsize=(12,12))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([-90, -60, 5, 50])
ax.coastlines()
levs = np.arange(0,5,.2)
plt.tricontourf(triang, z, levels=[10, 20, 50, 100, 200, 500, 1000, 2000])
plt.colorbar()
plt.tricontour(triang, z, colors='k',levels=levs)
tvar = ucube.coord('time')
tstr = tvar.units.num2date(tvar.points[ind])
gl = ax.gridlines(draw_labels=True)
gl.xlabels_top = False
gl.ylabels_right = False
plt.title('%s: Depth (m): %s' % (ucube.attributes['title'],tstr));

In [ ]: