Tryouts


In [5]:
import numpy as np
import matplotlib.pyplot as plt

Compare $sin(x) + cos(x)$ with $\sqrt 2 \, sin(x + \pi/4)$


In [19]:
x = np.pi * 2 * np.linspace(0, 361) / 360

fig, ax = plt.subplots()
fig.set_size_inches(11, 6)
ax.grid(True)
ax.set_title('sin, cos, sin + cos')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.plot(x, np.sin(x), label='sin(x)')
ax.plot(x, np.cos(x), label='cos(x)')
ax.plot(x, np.sin(x) + np.cos(x), label='sin(x) + cos(x)')
ax.plot(x, np.sqrt(2) * np.sin(x + np.pi/4), '.', label = '$\sqrt{2} \, sin(x + \pi/4)$')
ax.legend()


Out[19]:
<matplotlib.legend.Legend at 0x11f6baa58>

Sinusoidal fluctuations


In [38]:
def newfig(title='title', xlabel='xlabel', ylabel='ylabel', xscale='linear', yscale='linear',
           xlim=None, ylim=None):
    '''Return fig, ax of a new figure
    '''
    fig, ax = plt.subplots()
    fig.set_size_inches(11, 6)
    
    ax.grid(True)
    
    ax.set_title(title)
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)
    if xlabel: ax.set_xlabel(xlabel)
    if ylabel: ax.set_ylabel(ylabel)
    ax.set_xscale(xscale)
    ax.set_yscale(yscale)

    return ax

In [63]:
kD = 600 # transmissivity m2/d
S = 0.001 # storage coefficient [-]
x_ = np.linspace(0, 2000, 201) # distances in m
t_ = np.linspace(0, 1, 201) # times in d
omega = 4 * np.pi # rad/d
A = 1.5 # amplitude of tide [m]
beta = 2/24 * (4 * np.pi) # radians, 2h delay (2 hours of 4 pi per day)

a = np.sqrt(omega * S / (2 * kD)) # damping [1/d]

# for all x at t=0
t, x = 0, x_
ax = newfig(title='s(x, t=varies)', xlabel='x [m]', ylabel='s [m]')
for dt in np.arange(0, 24., 2):
    beta =  dt / 24 * (2 * np.pi)
    ax.plot(x, A * np.exp(-a * x) * np.sin(omega * t - a * x + beta), label='t={:5.1f} h'.format(dt))
ax.plot(x, + A * np.exp(-a * x), '-.', lw=1.0, label='upper limit (upper envelope)')
ax.plot(x, - A * np.exp(-a * x), '-.', lw=1.0, label='lower limit (lower envelope)')
ax.legend(loc='upper right')

# for all t at x = 500
t, beta = t_, 0
ax1 = newfig(title='s(x=varies, t)', xlabel='t [d]', ylabel='s [m]')
for x in np.arange(200, 1500, 200):
    ax1.plot(t, A * np.exp(-a * x) * np.sin(omega * t - a * x + beta), label='x={:5.0f} m'.format(x))
ax1.legend(loc='best')

# discharges for all t at x = 500
t, beta = t_, 0
ax2 = newfig(title='Q(x=varies, t) [m2/d]', xlabel='t [d]', ylabel='Q [m2/d]')
for x in np.arange(200, 1500, 200):
    ax2.plot(t, a * kD * A * np.sqrt(2) * np.exp(-a * x) * np.sin(omega * t - a * x + beta + np.pi/4), label='x={:5.0f} m'.format(x))
ax2.legend(loc='best')


Out[63]:
<matplotlib.legend.Legend at 0x11e243e48>

In [ ]:
Head and discharge