<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Calibrating TTim model to hypothetical pumping test
Step1:  Use observation times from Oude Korendijk
Step2:  Generate data
Step3:  See if TTim can find aquifer parameters back
Step4:  Fit with scipy.least_squares (not recommended)
Step5:  Calibrate parameters in multiple layers
Example showing how parameters can be optimized when multiple layers share the same parameter value.
Step6:  Generate data for head measured in well
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from ttim import *
Explanation: Calibrating TTim model to hypothetical pumping test
End of explanation
drawdown = np.loadtxt('data/oudekorendijk_h30.dat')
tobs = drawdown[:,0] / 60 / 24
robs = 30
Q = 788
Explanation: Use observation times from Oude Korendijk
End of explanation
ml = ModelMaq(kaq=60, z=(-18, -25), Saq=1e-4, tmin=1e-5, tmax=1)
w = Well(ml, xw=0, yw=0, rw=0.1, tsandQ=[(0, 788)], layers=0)
ml.solve()
np.random.seed(2)
hobs = ml.head(robs, 0, tobs)[0] + 0.05 * np.random.randn(len(tobs))
Explanation: Generate data
End of explanation
cal = Calibrate(ml)
cal.set_parameter(name='kaq0', initial=100)
cal.set_parameter(name='Saq0', initial=1e-3)
cal.series(name='obs1', x=robs, y=0, layer=0, t=tobs, h=hobs)
cal.fit()
cal.parameters
print('rmse:', cal.rmse())
hm = ml.head(robs, 0, tobs, 0)
plt.semilogx(tobs, hobs, '.k')
plt.semilogx(tobs, hm[0], 'r')
print('correlation matrix')
print(cal.fitresult.covar)
Explanation: See if TTim can find aquifer parameters back
End of explanation
cal = Calibrate(ml)
cal.set_parameter(name='kaq0', initial=100)
cal.set_parameter(name='Saq0', initial=1e-3)
cal.series(name='obs1', x=robs, y=0, layer=0, t=tobs, h=hobs)
cal.fit_least_squares(report=True)
Explanation: Fit with scipy.least_squares (not recommended)
End of explanation
ml = ModelMaq(kaq=[10., 10.], z=(-10, -16, -18, -25), c=[10.], Saq=[0.1, 1e-4], tmin=1e-5, tmax=1)
w = Well(ml, xw=0, yw=0, rw=0.1, tsandQ=[(0, 788)], layers=1)
ml.solve()
hobs0 = ml.head(robs, 0, tobs, layers=[0])[0]
hobs1 = ml.head(robs, 0, tobs, layers=[1])[0]
cal.parameters
cal = Calibrate(ml)
cal.set_parameter(name='kaq0_1', initial=20., pmin=0., pmax=30.)  # layers 0 and 1 have the same k-value
cal.set_parameter(name='Saq0', initial=1e-3, pmin=1e-5, pmax=0.2)
cal.set_parameter(name='Saq1', initial=1e-3, pmin=1e-5, pmax=0.2)
cal.set_parameter(name='c1', initial=1., pmin=0.1, pmax=200.)
cal.series(name='obs0', x=robs, y=0, layer=0, t=tobs, h=hobs0)
cal.series(name='obs1', x=robs, y=0, layer=1, t=tobs, h=hobs1)
cal.fit(report=False)
display(cal.parameters)
plt.semilogx(tobs, hobs0, '.C0', label="obs layer 0")
plt.semilogx(tobs, hobs1, '.C1', label="obs layer 1")
hm = ml.head(robs, 0, tobs)
plt.semilogx(tobs, hm[0], 'C0', label="modelled head layer 0")
plt.semilogx(tobs, hm[1], 'C1', label="modelled head layer 1")
plt.legend(loc="best")
Explanation: Calibrate parameters in multiple layers
Example showing how parameters can be optimized when multiple layers share the same parameter value.
End of explanation
tobs2 = np.hstack((tobs, np.arange(0.61, 1, 0.01)))
ml = ModelMaq(kaq=60, z=(-18, -25), Saq=1e-4, tmin=1e-5, tmax=1)
w = Well(ml, xw=0, yw=0, rw=0.3, res=0.02, tsandQ=[(0, 788), (0.6, 0)], layers=0)
ml.solve()
np.random.seed(2)
hobs2 = w.headinside(tobs2)[0] + 0.05 * np.random.randn(len(tobs2))
cal = Calibrate(ml)
cal.set_parameter(name='kaq0', initial=100)
cal.set_parameter(name='Saq0', initial=1e-3)
cal.set_parameter_by_reference(name='res', parameter=w.res[:], initial=0.05)
cal.seriesinwell(name='obs1', element=w, t=tobs2, h=hobs2)
cal.fit()
hm = w.headinside(tobs2)
plt.semilogx(tobs2, hobs2, '.k')
plt.semilogx(tobs2, hm[0], 'r')
Explanation: Generate data for head measured in well
End of explanation
<END_TASK>