In [3]:
import netCDF4
import datetime as dt

In [4]:
url = 'http://www.smast.umassd.edu:8080/thredds/dodsC/FVCOM/NECOFS/Forecasts/NECOFS_FVCOM_OCEAN_MASSBAY_FORECAST.nc'
nc = netCDF4.Dataset(url)

In [5]:
nc.variables['h'][0]


Out[5]:
10.137

In [6]:
nc.variables['zeta'][0][0]


Out[6]:
-0.9639281

In [7]:
nc.variables['siglev'][:,0]


Out[7]:
array([ 0.        , -0.10000002, -0.19999999, -0.30000007, -0.40000004,
       -0.5       , -0.60000008, -0.70000005, -0.80000007, -0.90000004, -1.        ], dtype=float32)

In [8]:
# the vertical coordinate for variables that have dimension 'siglay', like "temperature" and "salt"
tz = nc.variables['siglay'][:,0] * (nc.variables['zeta'][0][0] + nc.variables['h'][0]) + nc.variables['zeta'][0][0]

In [9]:
# is this the resulting depth for the ppoint i=0 at the timestamp=0 for a total of qo levels ?

In [10]:
tz


Out[10]:
array([-1.42258179, -2.33988905, -3.25719643, -4.1745038 , -5.0918107 ,
       -6.00911856, -6.92642593, -7.84373283, -8.76103973, -9.67834663], dtype=float32)

In [11]:
# the vertical coordinate for variables that have dimension 'siglev', like "vertical velocity"
wz =  nc.variables['siglev'][:,0] * (nc.variables['zeta'][0][0] + nc.variables['h'][0]) + nc.variables['zeta'][0][0]

In [12]:
wz


Out[12]:
array([ -0.9639281 ,  -1.88123548,  -2.7985425 ,  -3.71585035,
        -4.63315725,  -5.55046415,  -6.46777201,  -7.38507891,
        -8.30238628,  -9.21969318, -10.13700008], dtype=float32)

The vertical coordinate for "u" and "v" velocity is a bit tricky since velocity is defined at face centers, while the vertical coordinate is defined at nodes


In [14]:
nv = nc.variables['nv'][:].T - 1
print shape(nv)


(165095, 3)

In [16]:
tz = nc.variables['siglay'][:]* (nc.variables['zeta'][0][:] + nc.variables['h'][:]) + nc.variables['zeta'][0][:]
print shape(tz)


(10, 98432)

In [25]:
# so here are the z values for the "u" and "v" variables
uz = mean(tz[:,nv],axis=2)
print shape(uz)


(10, 165095)

In [27]:
# depth at the center of element 0
uz[:,0]


Out[27]:
array([ -1.55788386,  -2.74849248,  -3.93910146,  -5.12971067,
        -6.32031965,  -7.51092863,  -8.70153809,  -9.89214611,
       -11.08275318, -12.27336216], dtype=float32)

In [ ]: