In [1]:
from pylab import *
import netCDF4
In [2]:
url = 'http://testbedapps-dev.sura.org/thredds/dodsC/alldata/Shelf_Hypoxia/tamu/roms/tamu_roms.nc'
#url = 'http://tds.ve.ismar.cnr.it:8080/thredds/dodsC/ismar/model/field2/run1/Field_2km_1108_out30min_his_0724.nc'
#url='http://tds.ve.ismar.cnr.it:8080/thredds/dodsC/field2_test/run1/his'
#url='http://ourocean.jpl.nasa.gov:8080/thredds/dodsC/SCBfcst/scb_latest_fcst_roms.nc'
#url='http://geoport.whoi.edu/thredds/dodsC/examples/bora_feb.nc'
#####################################################################################
nc = netCDF4.Dataset(url)
mask = nc.variables['mask_rho'][:]
# read longitude, latitude
lon_rho = nc.variables['lon_rho'][:]
lat_rho = nc.variables['lat_rho'][:]
# read water depth
depth = nc.variables['h'][:,:]
'''
z(n,k,j,i) = eta(n,j,i)*(1+s(k)) + depth_c*s(k) +
(depth(j,i)-depth_c)*C(k)
C(k) = (1-b)*sinh(a*s(k))/sinh(a) +
b*[tanh(a*(s(k)+0.5))/(2*tanh(0.5*a)) - 0.5]
formula_terms: s: s_rho eta: zeta depth: h a: theta_s b: theta_b depth_c: hc
'''
Out[2]:
In [3]:
s = nc.variables['s_rho'][:]
a = nc.variables['theta_s'][:]
b = nc.variables['theta_b'][:]
depth_c = nc.variables['hc'][:]
C = (1-b)*sinh(a*s)/sinh(a) + b*[tanh(a*(s+0.5))/(2*tanh(0.5*a)) - 0.5]
In [7]:
nc.variables.keys()
print nc.variables['s_rho']
In [4]:
# Reshape 1D vertical variables so we can broadcast
C.shape = (np.size(C), 1, 1)
s.shape = (np.size(s), 1, 1)
In [7]:
tidx = -1 # just get the final time step, for now.
# read a 3D temperature field at specified time step
temp = nc.variables['temp'][tidx, :, :, :]
# read a 2D water level (height of ocean surface) at specified time step
eta = nc.variables['zeta'][tidx, :, :]
# calculate the 3D field of z values (vertical coordinate) at this time step
z = eta*(1+s) + depth_c*s + (depth-depth_c)*C
In [18]:
shape(s)
Out[18]:
In [9]:
# plot surface temperature
pcolormesh(lon_rho,lat_rho,temp[-1,:,:])
Out[9]:
In [10]:
shape(temp)
Out[10]:
In [11]:
shape(z)
Out[11]:
In [12]:
shape(lon_rho)
Out[12]:
In [13]:
# are there tools in EPD to plot an isosurface of this
# curvilinear, stretched vertical coordinate temperature field?
In [19]:
lon3d=lon_rho*ones(20).shape(20,1,1)
In [20]:
onez=ones(20)
onez.shape=(20,1,1)
In [21]:
shape(onez)
Out[21]:
In [22]:
lon3d = lon_rho*onez
In [23]:
shape(lon3d)
Out[23]:
In [24]:
lon3d[:,30,20]
Out[24]:
In [ ]: