-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplineDef.py
76 lines (57 loc) · 1.86 KB
/
SplineDef.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 16 20:18:08 2012
@author: sebastien
Create a Cp/Ct table interpolation with sensitivity generation
"""
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import scipy.io
from SplineGen import *
# Cp table
mat = scipy.io.loadmat('CpData.mat')
beta = mat['beta_Data']
lambda_ = mat['lambda_Data']
beta = beta.reshape(beta.shape[1],)
lambda_ = lambda_.reshape(lambda_.shape[1],)
Cp = mat['Cp_Data']
tck, betagrid, lambdagrid = SplineGen(beta,lambda_,Cp,'Cp')
Dic = {'Coefs':tck[2], 'beta':tck[0], 'lambda':tck[1]}
#scipy.io.savemat('SplineData', Dic, oned_as = 'row')
#assert(0==1)
##Ct table
#mat = scipy.io.loadmat('CtData.mat')
#
#beta = mat['beta_Data']
#lambda_ = mat['lambda_Data']
#beta = beta.reshape(beta.shape[1],)
#lambda_ = lambda_.reshape(lambda_.shape[1],)
#
#Ct = mat['Ct_Data']
#
#tck, betagrid, lambdagrid = SplineGen(beta,lambda_,Ct,'Ct')
############################### END OF PURE PYTHON CODE ###############################
x = 5.
y = 3.
z = interpolate.bisplev(x, y, tck)
dzdx = interpolate.bisplev(x, y, tck, dx = 1, dy = 0)
dzdy = interpolate.bisplev(x, y, tck, dx = 0, dy = 1)
dzdx2 = interpolate.bisplev(x, y, tck, dx = 2, dy = 0)
dzdy2 = interpolate.bisplev(x, y, tck, dx = 0, dy = 2)
dzdxy = interpolate.bisplev(x, y, tck, dx = 1, dy = 1)
print "Compare spline interp", z
print "Compare x derivative", dzdx
print "Compare y derivative", dzdy
print "Compare x2 derivative", dzdx2
print "Compare y2 derivative", dzdy2
print "Compare xy derivative", dzdxy
x,y = np.mgrid[beta[0]:beta[-1]:0.25,lambda_[0]:lambda_[-1]:0.25]
z = interpolate.bisplev(x[:,0],y[0,:],tck)
fig = plt.figure(1)
ax = fig.gca(projection='3d')
ax.plot_wireframe(betagrid,lambdagrid,np.max(Cp,0.))
plt.title("Cp table")
#ax.plot_wireframe(x,y,z,color='r')
plt.hold
plt.show()