Commit e9b15fa4 authored by Grospiron Louis's avatar Grospiron Louis

En collaboration avec Interpol

parent 53d7dcc2
......@@ -11,6 +11,7 @@ import matplotlib
import matplotlib.animation as animation
#FFMpegWriter = animation.writers['ffmpeg']
import scipy.ndimage as sn
import scipy.interpolate as si
import yaml
from convbox.plot.color.rainbow_desaturated import mymap2
import scipy.optimize as opt
......@@ -61,16 +62,20 @@ class TLCExperiment:
"""
Iterator computing T field from H value using calibration Calibration.
"""
A,B,C,D= Calibration.ABCD
fonc = lambda h,a,b,c: c+b*np.arctanh(a*(h-d))
A = A.repeat(Calibration.grain, axis=0).repeat(Calibration.grain, axis=1)
B = B.repeat(Calibration.grain, axis=0).repeat(Calibration.grain, axis=1)
C = C.repeat(Calibration.grain, axis=0).repeat(Calibration.grain, axis=1)
D = D.repeat(Calibration.grain, axis=0).repeat(Calibration.grain, axis=1)
# A,B,C,D= Calibration.ABCD
print('olala')
interpol = Calibration.interpol
print('ouistiti')
# A = A.repeat(Calibration.grain, axis=0).repeat(Calibration.grain, axis=1)
# B = B.repeat(Calibration.grain, axis=0).repeat(Calibration.grain, axis=1)
# C = C.repeat(Calibration.grain, axis=0).repeat(Calibration.grain, axis=1)
# D = D.repeat(Calibration.grain, axis=0).repeat(Calibration.grain, axis=1)
interpol = interpol.repeat(Calibration.grain, axis=0).repeat(Calibration.grain, axis=1)
for picture in self.pictures():
H = cv2.cvtColor(picture,cv2.COLOR_BGR2HSV)[:,:,0]
yield fonc(H,A,B,C,D)
yield interpol(H)
# yield np.array([[interpol[i,j](H[i,j]) for i in range(H.shape[0])] for j in range(H.shape[1])])
......@@ -112,6 +117,7 @@ class TLCCalibration:
Compute mean HSV picture for each calibration point.
If Imshow=True, shows mean picture.
"""
print(grain)
# Loop over calibration points
for manip in self.ListFixedTemperaturePoints:
count=0
......@@ -220,7 +226,7 @@ class TLCCalibration:
def Calibrate(self,grain):
"""
Fit T(H) = A x H + B and save arrays A and B in the file Calibration.h5.
Interpolate T(H) from (H,T)_i and save function in array A in the file Calibration.h5. (and also errors)
"""
H = np.zeros((self.ListFixedTemperaturePoints[0].shape[0]//grain,self.ListFixedTemperaturePoints[0].shape[1]//grain,len(self.ListFixedTemperaturePoints)))
T = np.zeros((self.ListFixedTemperaturePoints[0].shape[0]//grain,self.ListFixedTemperaturePoints[0].shape[1]//grain,len(self.ListFixedTemperaturePoints)))
......@@ -230,33 +236,45 @@ class TLCCalibration:
H[:,:,index] = manip.MeanHSV[:,:,0]
T[:,:,index] = (np.ones((self.ListFixedTemperaturePoints[0].shape[0]//grain,self.ListFixedTemperaturePoints[0].shape[1]//grain))*manip.MeanT).T
index+=1
print(H[300,300,:])
print(T[300,300,:])
print(H[50,50,:])
print(T[50,50,:])
fonc = lambda h,a,b,c,d: c+b*np.arctanh(a*(h-d))
A = np.zeros((H.shape[0],H.shape[1]))
B = np.zeros((H.shape[0],H.shape[1]))
C = np.zeros((H.shape[0],H.shape[1]))
D = np.zeros((H.shape[0],H.shape[1]))
# fonc = lambda h,a,b,c: c+b*np.exp(a*h)
A = np.array((H.shape[0],H.shape[1]))
print(A)
# B = np.zeros((H.shape[0],H.shape[1]))
# C = np.zeros((H.shape[0],H.shape[1]))
# D = np.zeros((H.shape[0],H.shape[1]))
erreurs=np.zeros((H.shape[0],H.shape[1]))
for i in range(H.shape[0]):
for j in range(H.shape[1]):
try:
popt, pcov = opt.curve_fit(fonc,H[i,j,:],T[i,j,:],[0.01,4,22,75])
# popt, pcov = opt.curve_fit(fonc,H[i,j,:],T[i,j,:],[0.1,0.01,18])
fonc=si.interp1d(H[i,j,:],T[i,j,:])
except ValueError as e:
erreurs[i][j]=1
continue
if i%100==0 and j%100==0:
print(popt)
A[i,j] = popt[0]
B[i,j] = popt[1]
C[i,j] = popt[2]
D[i,j] = popt[3]
if (popt == [1., 1., 1.,1.]).all():
except RuntimeError as e:
erreurs[i][j]=1
continue
if i%10==0 and j%10==0:
# print(popt)
plt.scatter(H[i,j,:],T[i,j,:])
x=np.linspace(H[i,j,:].min(),H[i,j,:].max(),50)
plt.plot(x,fonc(x))
plt.show()
A[i,j] = fonc
# B[i,j] = popt[1]
# C[i,j] = popt[2]
# D[i,j] = popt[3]
# if (popt == [1.,1.,1.]).all():
# erreurs[i][j]=1
# if (popt == [0.,0.,0.]).any():
# erreurs[i][j]=1
plt.imshow(erreurs)
plt.colorbar()
plt.show()
#if (i,j)==(300,300): #debug
#print(a0,b0) #debug
......@@ -269,18 +287,36 @@ class TLCCalibration:
except KeyError as e:
print('No old data to suppress')
f.create_dataset('A',data=A)
# try:
# del f['B']
# print('Old data suppressed')
# except KeyError as e:
# print('No old data to suppress')
# f.create_dataset('B',data=B)
# try:
# del f['C']
# print('Old data suppressed')
# except KeyError as e:
# print('No old data to suppress')
# f.create_dataset('C',data=C)
# try:
# del f['D']
# print('Old data suppressed')
# except KeyError as e:
# print('No old data to suppress'
# f.create_dataset('D',data=D)
try:
del f['B']
del f['Interpol']
print('Old data suppressed')
except KeyError as e:
print('No old data to suppress')
f.create_dataset('B',data=B)
f.create_dataset('Interpol',data=A)
try:
del f['C']
del f['Errors']
print('Old data suppressed')
except KeyError as e:
print('No old data to suppress')
f.create_dataset('C',data=C)
f.create_dataset('Errors',data=erreurs)
@property
......@@ -290,8 +326,13 @@ class TLCCalibration:
"""
with h5py.File("{}Processed_DATA/{}/Calibration.h5".format(MyPath,self.Name),'a') as f:
return f['A'][()], f['B'][()], f['C'][()], f['D'][()]
@property
def interpol(self):
"""
Return function array
"""
with h5py.File("{}Processed_DATA/{}/Calibration.h5".format(MyPath,self.Name),'a') as f:
return f['Interpol'][()]
......@@ -530,14 +571,15 @@ CalibrationTotale = TLCCalibration('CalibrationTemperature',
CalibrationTemperature_22b_C,
CalibrationTemperature_23_C,
CalibrationTemperature_24_C],
10)
64)
CalibrationPasTotale = TLCCalibration('CalibrationTemperature2',
[CalibrationTemperature_20_C,
CalibrationTemperature_21_C,
CalibrationTemperature_22a_C,
CalibrationTemperature_22b_C,
CalibrationTemperature_23_C],
10)
64)
#############################################################################################################################################
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment