In [1]:
%run matt_startup
%run -i matt_utils
button_qtconsole()
#import other needed modules in all used engines
#with dview.sync_imports():
# import os
In [27]:
filename = 'FIWT_Exp036_20150605144438.dat.npz'
def loadData():
# Read and parse raw data
global exp_data
exp_data = np.load(filename)
# Select colums
global T_cmp, da_cmp
T_cmp = exp_data['data33'][:,0]
da_cmp = exp_data['data33'][:,3]
global T_rig, phi_rig
T_rig = exp_data['data44'][:,0]
phi_rig = exp_data['data44'][:,2]
loadData()
In [28]:
text_loadData()
Click 'Check data' button to show the raw data.
Click on curves to select time point and push into queue; click 'T/s' text to pop up last point in the queue; and click 'Output' text to print time sequence table.
In [29]:
def checkInputOutputData():
#check inputs/outputs
fig, ax = plt.subplots(2,1,True)
ax[1].plot(T_cmp,da1_cmp,'r', picker=2)
ax[0].plot(T_rig,phi_rig, 'b', picker=2)
ax[1].set_ylabel('$\delta \/ / \/ ^o$')
ax[0].set_ylabel('$\phi \/ / \/ ^o/s$')
ax[1].set_xlabel('$T \/ / \/ s$', picker=True)
ax[0].set_title('Output', picker=True)
fig.canvas.mpl_connect('pick_event', onPickTime)
fig.show()
display(fig)
button_CheckData()
In [30]:
# Pick up focused time ranges
time_marks = [
[17.6940178696,117,"ramp u1"],
[118.7,230.395312673,"ramp d1"],
[258.807481992,357.486188688,"ramp u2"],
[359.463122988,459.817499014,"ramp d2"],
[461.067939262,558.784538108,"ramp d3"],
[555.553175853,658.648739191,"ramp u4"],
]
# Decide DT,U,Z and their processing method
DT=0.5
process_set = {
'Z':[(T_cmp, da_cmp,1),],
'U':[(T_rig, phi_rig,1),],
'cutoff_freq': 1 #Hz
}
U_names = ['$\phi_{a,rig} \, / \, ^o$']
Y_names = Z_names = ['$\delta_{a,cmp} \, / \, ^o$']
display_data_prepare()
For each section,
In [31]:
resample(True);
In [68]:
%%px --local
#update common const parameters in all engines
angles = range(-170,171,10)
angles_num = len(angles)
#problem size
Nx = 0
Nu = 1
Ny = 1
Npar = 2*angles_num
#reference
S_c = 0.1254 #S_c(m2)
b_c = 0.7 #b_c(m)
g = 9.81 #g(m/s2)
#static measurement
m_T = 9.585 #m_T(kg)
l_z_T = 0.0416 #l_z_T(m)
V = 30 #V(m/s)
#previous estimations
F_c = 0.06 #F_c(N*m)
#for short
qbarSb = 0.5*1.225*V*V*S_c*b_c
_m_T_l_z_T_g = -(m_T*l_z_T)*g
angles_cmpx = [-41, -35, -30, -25, -20, -15, -10, -5, 5, 10, 15, 20, 25, 30, 35, 41]
Clda_cmpx = np.array([[ 0.0565249, 0.05387389, 0.04652094, 0.03865756, 0.03113176, 0.02383392,
0.01576805, 0.00682421, -0.00514735, -0.01570602, -0.02364258, -0.02733501,
-0.0334053, -0.03834931, -0.04546589, -0.05275809],
[ 0.04793643, 0.04133362, 0.03510728, 0.02872704, 0.02349928, 0.01987537,
0.01354014, 0.00666756, -0.00498937, -0.01074795, -0.01714402, -0.02095374,
-0.02588346, -0.03155207, -0.03824692, -0.04752196],
[ 0.04250404, 0.03700739, 0.03057273, 0.02586595, 0.01989991, 0.01626642,
0.01237347, 0.00642308, -0.00551828, -0.01030141, -0.01654802, -0.02143956,
-0.0268223, -0.03110662, -0.03565326, -0.04001201,],
[ 0.03448653, 0.03160534, 0.02700394, 0.02388641, 0.01988023, 0.01532191,
0.01052986, 0.00572438, -0.00556645, -0.0101715, -0.01388348, -0.01619465,
-0.02044906, -0.02510722, -0.03134562, -0.0355593 ]])
Clda_cmp = np.sum(Clda_cmpx, axis=0)
Lda_cmp = qbarSb*Clda_cmp
Da_cmp = scipy.interpolate.interp1d(Lda_cmp, angles_cmpx)
hdr = int(1/DT)
def obs(Z,T,U,params):
s = T.size
unk_moment = scipy.interpolate.interp1d(angles, params[0:angles_num])
col_fric = scipy.interpolate.interp1d(angles, params[angles_num:angles_num*2])
phi = U[:s,0]
phi_diff = np.copysign(-1,phi[hdr:]-phi[:-hdr])
phi_diff = np.concatenate((np.ones(hdr-1)*phi_diff[0], phi_diff, np.ones(hdr-1)*phi_diff[-1]))
Da = Da_cmp(-unk_moment(phi)-col_fric(phi_diff))
return Da.reshape((-1,1))
In [69]:
display(HTML('<b>Constant Parameters</b>'))
table = ListTable()
table.append(['Name','Value','unit'])
table.append(['$S_c$',S_c,'$m^2$'])
table.append(['$b_c$',b_c,'$m$'])
table.append(['$g$',g,'$m/s^2$'])
table.append(['$m_T$',m_T,'$kg$'])
table.append(['$l_{zT}$',l_z_T,'$m$'])
table.append(['$V$',V,'$m/s$'])
display(table)
In [61]:
#initial guess
param0 = [_m_T_l_z_T_g*math.sin(a/57.3) for a in angles]+[F_c]*angles_num
param_name = ['Mu_{}'.format(angles[i]) for i in range(angles_num)] \
+ ['Fc_{}'.format(angles[i]) for i in range(angles_num)]
param_unit = ['Nm']*(2*angles_num)
NparID = Npar
opt_idx = range(Npar)
opt_param0 = [param0[i] for i in opt_idx]
par_del = [0.01]*(2*angles_num)
bounds = [(-4,4)]*(angles_num) + [(0,0.4)]*(angles_num)
display_default_params()
#select sections for training
section_idx = range(len(time_marks))
display_data_for_train()
#push parameters to engines
push_opt_param()
In [62]:
# select 4 section from training data
#idx = random.sample(section_idx, 4)
idx = section_idx[:]
# interact_guess();
update_guess();
In [63]:
display_preopt_params()
if False:
InfoMat = None
method = 'trust-ncg'
def hessian(opt_params, index):
global InfoMat
return InfoMat
dview['enable_infomat']=True
options={'gtol':1}
opt_bounds = None
else:
method = 'L-BFGS-B'
hessian = None
dview['enable_infomat']=False
options={'ftol':1e-6,'maxfun':400}
opt_bounds = bounds
cnt = 0
tmp_rslt = None
T0 = time.time()
print('#cnt, Time, |R|')
%time res = sp.optimize.minimize(fun=costfunc, x0=opt_param0, \
args=(opt_idx,), method=method, jac=True, hess=hessian, \
bounds=opt_bounds, options=options)
In [64]:
display_opt_params()
# show result
idx = range(len(time_marks))
display_data_for_test();
update_guess();
In [67]:
res_params = res['x']
params = param0[:]
for i,j in enumerate(opt_idx):
params[j] = res_params[i]
k1 = np.array(params[0:angles_num])
k2 = np.array(params[angles_num:angles_num*2])
print('angeles = ')
print(angles)
print('L_unk = ')
print(k1)
print('F_c = ')
print(k2)
%matplotlib inline
plt.figure(figsize=(12,12),dpi=300)
plt.subplot(211)
plt.plot(angles, k1, 'r')
plt.ylabel('$L_{unk} \, / \, Nm$')
plt.subplot(212)
plt.plot(angles, k2, 'g')
plt.ylabel('$F_c \, / \, Nm$')
plt.xlabel('$\phi \, / \, ^o/s$')
plt.show()
In [14]:
toggle_inputs()
button_qtconsole()
In [15]:
(-0.05-0.05)/(80/57.3)
Out[15]:
In [16]:
Clda_cmp/4
Out[16]:
In [ ]: