In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
import os
import math

In [3]:
#--default matplotlib 
rcParams['font.sans-serif']          = 'Arial'
rcParams['font.serif']               = 'Times'
rcParams['font.cursive']             = 'Zapf Chancery'
rcParams['font.fantasy']             = 'Comic Sans MS'
rcParams['font.monospace']           = 'Courier New'
rcParams['pdf.compression']          = 0
rcParams['pdf.fonttype']             = 42
rcParams['mathtext.default'] = 'regular'

ticksize = 8
rcParams['legend.fontsize']  = 8
rcParams['axes.labelsize']   = 8
rcParams['xtick.labelsize']  = ticksize
rcParams['ytick.labelsize']  = ticksize

Problem dimensions


In [4]:
days = 7.
ntimes = int(days) * 24 * 12
a = 1.0
period = 0.5
omega = 2 * pi / period
offset = -pi/2.0

In [5]:
#--times
t = linspace(0.,7.,ntimes)
#--angle
rad = multiply(t, omega)
rad = subtract(rad, offset)
#print rad
#--tidal signal
v = sin(rad)
v2 = sin(rad+offset/1)
#print v
plot(t, v, color='blue', linewidth=1.0)
plot(t, v2, color='red', linewidth=0.5)
ylim((-1.25, 1.25))
xlim((0,1))
show()


Calculate the tidal signal using:

$h(t) = a \times sin(\omega t + \theta)$


In [6]:
days = 7.
times = linspace(0.,days,ntimes)
delt = days / float(ntimes)
delti = 1. / delt
rad = multiply(t, omega)
rad = subtract(rad, offset)
tide = a * sin(rad)

In [7]:
plot(times, tide, color='blue', linewidth=1.0)
xlim((0.,days))
ylim((-a * 1.25,a * 1.25))
xlim((0,1))
show()


Create points to evaluate tidal efficiency and lag


In [8]:
ncol = 1000
dx = np.empty(ncol, np.float)
xcell = np.empty(ncol, np.float)
xmax = 100000.
dxmult = 1.05
dx[0] = xmax * ((dxmult-1) / (math.pow(dxmult, float(ncol)) - 1))
xcell[0] = dx[0] / 2.
for idx in xrange(1, ncol):
    dx[idx] = dx[idx-1] * dxmult
    xcell[idx] = xcell[idx-1] + 0.5 * (dx[idx-1] + dx[idx])
x2coast = np.copy(xcell) - dx[0] / 2.

In [9]:
plot(x2coast, zeros(ncol, float), color='blue', linewidth=0.0, marker='o', markersize=2)
xlim((0.,xmax))
ylim((-0.25,0.25))
xlim((0,xmax))
show()



In [21]:
all_hd = array([0.1, 1., 10., 100., 1000., 10000.])
#all_hd = array([1.])
all_dist = array([1., 5., 10., 50., 100., 500., 1000.])
cl = ['blue', 'cyan', 'green', 'yellow', 'orange', 'red', 'magenta', 'black']

In [22]:
fig = figure()
ifig = 1
for idx, hd in enumerate(all_hd):
    ax = subplot(2,3,ifig)
    ax.text(0.5, 0.05, 'D = {0}'.format(hd),
        ha='center',
        va='bottom',
        size=10,
        transform=ax.transAxes)
    ax.plot(times, tide, color=cl[0], linewidth=2.0)
    for jdx, d in enumerate(all_dist):
        alpha = exp(-d * sqrt(omega / (2. * hd)))
        dtau = d * sqrt(1. / (2. * omega * hd))
        t = a * alpha * sin(rad - dtau)
        ax.plot(times, t, linewidth=1.0, color=cl[jdx+1])
    ax.set_ylim((-a * 1.5,a * 1.5))
    ax.set_xlim((0,1))
    ifig += 1
show()


Calculate tidal efficiency ($\alpha$) and phase differences ($\Delta \tau$) as a function of distance ($x$):

$\hspace{15pt} \alpha = exp(-x \sqrt{\frac{\omega}{2D}})$

$\hspace{15pt} \Delta \tau = x \sqrt{\frac{1}{2 \omega D}}$


In [12]:
fig = figure()
ax1 = subplot(2,1,1)
ax2 = subplot(2,1,2)
alpha = empty(ncol, float)
dtau = empty(ncol, float)
for idx, hd in enumerate(all_hd):
    tm = sqrt(omega / (2. * hd))
    alpha.fill(0.0)
    dtau.fill(nan)
    for jdx, x in enumerate(x2coast):
        alpha[jdx] = exp(-x * sqrt(omega / (2. * hd)))
        if alpha[jdx] > 1e-9:
            dtau[jdx] = x * sqrt(1. / (2. * omega * hd)) * 24.
    #--plot values
    ax1.semilogx(x2coast, dtau, linewidth=1.0, linestyle='-', label='_None')
    ax2.semilogx(x2coast, alpha, linewidth=1.0, linestyle='-', label='_None')

#print alpha
#print dtau
ax1.set_xlim((1.e-4,xmax))
ax1.set_ylim((0,30))
ax1.set_ylabel('Time offset, minutes')
ax2.set_xlim((1.e-4,xmax))
ax2.set_ylabel(r'$\Delta$ amplitude, meters')
ax2.set_xlabel('Distance from coast, meters')
show()



In [12]:


In [12]: