Computing tidal constituent amplitude and phase from ROMS AVERAGES_DETIDE output


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]:
[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']

In [5]:
NTC = len(ncv['tide_period'])
print NTC


9

In [6]:
print ncv['tide_period'][:]


[ 23.93446966  25.81934167  26.86835667  12.42060122  12.          12.65834824
  11.96723479   6.21030061   4.14020041]

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


In [14]:
Hcount =ncv['Hcount'][:]
print Hcount


[121021]

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]:
0.0

In [18]:
z_m2_amp.max()


Out[18]:
0.27411115895338473

In [ ]: