In [1]:
import netCDF4
import numpy as np
from IPython.display import HTML
In [2]:
#url='http://geoport.whoi.edu/thredds/dodsC/usgs/data0/bbleh/tidal/bbleh_base_detide.nc'
url='/usgs/data0/bbleh/tidal/bbleh_base_detide.nc'
In [3]:
nc = netCDF4.Dataset(url)
ncv = nc.variables
In [4]:
ncv.keys()
Out[4]:
In [5]:
NTC = len(ncv['tide_period'])
print NTC
In [6]:
print ncv['tide_period'][:]
In [7]:
zt = ncv['zeta_tide']
print zt
In [14]:
Hcount =ncv['Hcount'][:]
print Hcount
In [8]:
"""
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.
In [9]:
i_m2sin = 1+3
i_m2cos = 1+3+NTC
In [ ]:
cosW = ncv['CosW'][:]
sinW = ncv['SinW']{}
In [15]:
# represent tide as complex
z_m2 = (zt[i_m2cos,:] + 1j* zt[i_m2sin,:]) /Hcount
In [16]:
# compute amplitude and phase
z_m2_amp = np.abs(z_m2)
z_m2_pha = np.angle(z_m2)
In [17]:
z_m2_amp.min()
Out[17]:
In [18]:
z_m2_amp.max()
Out[18]:
In [ ]: