import netCDF4
import numpy as np
from IPython.display import HTML
#url='http://geoport.whoi.edu/thredds/dodsC/usgs/data0/bbleh/tidal/bbleh_base_detide.nc'
url='/usgs/data0/bbleh/tidal/bbleh_base_detide.nc'
nc = netCDF4.Dataset(url)
ncv = nc.variables
ncv.keys()
[u'tide_period', u'tide_Ephase', u'tide_Eamp', u'tide_Cphase', u'tide_Cangle', u'tide_Cmin', u'tide_Cmax', u'Hcount', u'ocean_time', u'CosW', u'SinW', u'CosWCosW', u'SinWSinW', u'SinWCosW', u'zeta_tide', u'ubar_tide', u'vbar_tide', u'u_tide', u'v_tide']
NTC = len(ncv['tide_period'])
print NTC
9
print ncv['tide_period'][:]
[ 23.93446966 25.81934167 26.86835667 12.42060122 12. 12.65834824 11.96723479 6.21030061 4.14020041]
zt = ncv['zeta_tide']
print zt
<type 'netCDF4.Variable'> float64 zeta_tide(harmonics, eta_rho, xi_rho) long_name: time-accumulated free-surface tide harmonics units: meter coordinates: lon_rho lat_rho ocean_time field: zeta_tide, scalar _FillValue: 1e+37 unlimited dimensions: current shape = (19, 800, 160) filling off
Hcount =ncv['Hcount'][:]
print Hcount
[121021]
"""
Comments from ROMS/Modules/mod_tides.F:
! Detided time-averaged fields via least-squares fitting. Notice that !
! the harmonics for the state variable have an extra dimension of !
! size (0:2*NTC) to store several terms: !
! !
! index 0 mean term (accumulated sum) !
! 1:NTC accumulated sine terms !
! NTC+1:2*NTC accumulated cosine terms !
! !
! CosW_avg Current time-average window COS(omega(k)*t). !
! CosW_sum Time-accumulated COS(omega(k)*t). !
! SinW_avg Current time-average window SIN(omega(k)*t). !
! SinW_sum Time-accumulated SIN(omega(k)*t). !
! CosWCosW Time-accumulated COS(omega(k)*t)*COS(omega(l)*t). !
! SinWSinW Time-accumulated SIN(omega(k)*t)*SIN(omega(l)*t). !
! SinWCosW Time-accumulated SIN(omega(k)*t)*COS(omega(l)*t). !
! !
! ubar_detided Time-averaged and detided 2D u-momentum. !
! ubar_tide Time-accumulated 2D u-momentum tide harmonics. !
! vbar_detided Time-averaged and detided 2D v-momentum. !
! vbar_tide Time-accumulated 2D v-momentum tide harmonics. !
! zeta_detided Time-averaged and detided free-surface. !
! zeta_tide Time-accumulated free-surface tide harmonics. !
""";
To calculate the m2
elevation amplitude and phase from the variable zeta_tide
, we will need to add one to the tide_period index to get the sin
term, and then add the number of analyzed constituents to get the cos
term.
i_m2sin = 1+3
i_m2cos = 1+3+NTC
cosW = ncv['CosW'][:]
sinW = ncv['SinW']{}
# represent tide as complex
z_m2 = (zt[i_m2cos,:] + 1j* zt[i_m2sin,:]) /Hcount
# compute amplitude and phase
z_m2_amp = np.abs(z_m2)
z_m2_pha = np.angle(z_m2)
z_m2_amp.min()
0.0
z_m2_amp.max()
0.27411115895338473