...
 
Commits (3)
# file containing output folder path
MyPath: "/Xnfs/convection/Stage_LG_2020/Documents/Celsius_Temporaire"
\ No newline at end of file
MyPath: "/Xnfs/convection/Stage_LG_2020/"
This diff is collapsed.
......@@ -16,7 +16,7 @@ from convbox.plot.color.rainbow_desaturated import mymap2
import scipy.optimize as opt
# Loading of output folder path
MyPath = yaml.load(open('celsius/.celsius.yml'),Loader=yaml.FullLoader)['MyPath']
MyPath = yaml.load(open('.celsius.yml'),Loader=yaml.FullLoader)['MyPath']
#######################################################################################################
......@@ -53,13 +53,17 @@ class TLCExperiment:
break
return shape
def H2T(self, H, Calibration):
def H2T(self, Calibration):
"""
Compute T field from H value using calibration Calibration
Iterator computing T field from H value using calibration Calibration.
"""
A,B = Calibration.AB
return A.repeat(H.shape[0]//grain, axis=0).repeat(H.shape[1]//grain, axis=1) * H + B.repeat(H.shape[0]//grain, axis=0).repeat(H.shape[1]//grain, axis=1)
A = A.repeat(H.shape[0]//grain, axis=0).repeat(H.shape[1]//grain, axis=1)
B = B.repeat(H.shape[0]//grain, axis=0).repeat(H.shape[1]//grain, axis=1)
for picture in self.pictures:
H = cv2.cvtColor(picture,cv2.COLOR_BGR2HSV)[:,:,0]
yield A*H + B
......@@ -123,6 +127,7 @@ class TLCCalibration:
MoyenneTXY=np.array(MoyenneTXY,dtype=np.uint8)
MoyenneTXYHSV=cv2.cvtColor(MoyenneTXY,cv2.COLOR_BGR2HSV)
if Imshow==True:
plt.figure(figsize=(10,10))
plt.imshow(MoyenneTXY)
......@@ -137,6 +142,9 @@ class TLCCalibration:
except KeyError:
print("No old data to suppress")
f.create_dataset('ImHSV_{}_degre'.format(manip.Temperature),data=MoyenneTXYHSV)
print('Treatment of point {} degre done'.format(manip.Temperature))
def ThermocouplePointage(self):
"""
......@@ -146,7 +154,6 @@ class TLCCalibration:
plt.figure()
for manip in self.ListFixedTemperaturePoints:
coords=[]
print(manip.Temperature)
for picture in manip.FixedPictures():
plt.title('T = {}'.format(manip.Temperature))
plt.imshow(cv2.cvtColor(picture,cv2.COLOR_BGR2RGB))
......@@ -164,7 +171,7 @@ class TLCCalibration:
f.create_dataset('Coord_{}_degre'.format(manip.Temperature),data=coords)
plt.close()
def computeMeanT(self,grain,Plot=False):
def ComputeMeanT(self,grain,Plot=False):
"""
Compute mean temperature profil. Provides a 1D array composed of the temperature along the vertical axis in each small square defined for averaging. To get the 2D array it is necessary to replicate it as we assume horizontal homogeneity.
Saves all of these profils in a file MeanT.h5
......@@ -177,29 +184,34 @@ class TLCCalibration:
j = coord[:,1]
I = i//grain
J = j//grain
print('i = {}, j = {}, I = {}, J = {}'.format(i,j,I,J))
print(len(J))
print(manip.T_FixedPicture)
Shape = manip.shape
# Here we suppose we have a vertical profil (J = constant) and J[0] corresponds to the thermocouple at the bottom (high value because the origin is at the top)
T = np.zeros(Shape[1]//grain)
for index in range(len(J)-1):
T[J[index+1]:J[index]+1] = np.linspace(manip.T_FixedPicture[index+1],manip.T_FixedPicture[index],J[index]-J[index+1]+1) # Index okay attention J decreases...
T[0:J[-1]] = [T[J[-1]]+n*(T[J[-1]]-T[J[-1]+1]) for n in range(J[-1],0,-1)]
T[J[0]+1::] = [T[J[0]]-n*(T[J[0]-1]-T[J[0]]) for n in range(1,Shape[1]//grain-J[0])]
with h5py.File("{}Processed_DATA/{}/MeanT.h5".format(MyPath,self.Name),'a'):
try:
T = np.zeros(Shape[1]//grain)
for index in range(len(J)-1):
T[J[index+1]:J[index]+1] = np.linspace(manip.T_FixedPicture[index+1],manip.T_FixedPicture[index],J[index]-J[index+1]+1) # Index okay attention J decreases...
T[0:J[-1]] = [T[J[-1]]+n*(T[J[-1]]-T[J[-1]+1]) for n in range(J[-1],0,-1)]
T[J[0]+1::] = [T[J[0]]-n*(T[J[0]-1]-T[J[0]]) for n in range(1,Shape[1]//grain-J[0])]
except ValueError:
return I,J,T,index,manip.T_FixedPicture[:]
with h5py.File("{}Processed_DATA/{}/MeanT.h5".format(MyPath,self.Name),'a') as f:
try:
del f['T_{}_degre'.format(manip.Temperature)]
print('Old data suppressed')
except KeyError as e:
print('No old data to suppress')
f.create_dataset('T_{}_degre'.format(manip.Temperature),data=T)
if Plot==True:
plt.figure()
plt.plot(T)
plt.show()
print('Treatment of point {} degre done'.format(manip.Temperature))
def calibrate(self,grain):
def Calibrate(self,grain):
"""
Fit T(H) = A x H + B and save arrays A and B in the file Calibration.h5.
"""
......@@ -209,17 +221,20 @@ class TLCCalibration:
index = 0
for manip in self.ListFixedTemperaturePoints:
H[:,:,index] = manip.MeanHSV[:,:,0]
T[:,:,index] = (np.ones((manip.shape))*manip.T).T
T[:,:,index] = np.ones((self.ListFixedTemperaturePoints[0].shape[0]//grain,self.ListFixedTemperaturePoints[0].shape[1]//grain))*manip.MeanT
index+=1
A = np.zeros((H.shape[0],H.shape[1]))
B = np.zeros((H.shape[0],H.shape[1]))
for i in range(H.shape[0]):
for j in range(H.shape[1]):
a0,a_err, b0, b_err = fit_affine(H[i,j,:], T[i,j,:],1e-9,1e-9)
a0,a_err, b0, b_err, plat = fit_affine(H[i,j,:], T[i,j,:],1e-9,1e-9)
A[i,j] = a0
B[i,j] = b0
if plat == 1 :
print((i,j))
with h5py.File("{}Processed_DATA/{}/Calibration.h5".format(MyPath,self.Name),'a'):
with h5py.File("{}Processed_DATA/{}/Calibration.h5".format(MyPath,self.Name),'a') as f:
f.create_dataset('A',data=A)
f.create_dataset('B',data=B)
......@@ -228,7 +243,7 @@ class TLCCalibration:
"""
Return array A and B
"""
with h5py.File("{}Processed_DATA/{}/Calibration.h5".format(MyPath,self.Name),'a'):
with h5py.File("{}Processed_DATA/{}/Calibration.h5".format(MyPath,self.Name),'a') as f:
return f['A'][()], f['B'][()]
......@@ -266,7 +281,7 @@ class TLCTempCalibrate(TLCExperiment):
Return Mean HSV picture for this experiment
"""
with h5py.File("{}Processed_DATA/{}/MeanHSV.h5".format(MyPath,self.CalibrationName),'a') as f:
return f['ImHSV_{}_degre'.format(manip.Temperature)][()]
return f['ImHSV_{}_degre'.format(self.Temperature)][()]
@property
def MeanT(self):
......@@ -274,7 +289,7 @@ class TLCTempCalibrate(TLCExperiment):
Return mean T vertical profil
"""
with h5py.File("{}Processed_DATA/{}/MeanT.h5".format(MyPath,self.CalibrationName),'a') as f:
return f['T_{}_degre'.format(manip.Temperature)][()]
return f['T_{}_degre'.format(self.Temperature)][()]
class RBTLCExperiment(TLCExperiment):
......@@ -334,13 +349,16 @@ def fit_affine(x,y,dx,dy):
# Meilleur estimation des parametres
(a0, b0) = result[0]
# Incertitudes sur les parametres
(a_err, b_err) = np.sqrt(np.abs(np.diagonal(result[1])))
if not result[1] is None:
(a_err, b_err) = np.sqrt(np.abs(np.diagonal(result[1])))
# # Valeur du chi2 reduit
# chi2 = sum(residual([a0,b0],x,y,dx,dy)**2)/(N-2)
# Retourne les parametres et le chi2
# return (a0, a_err, b0, b_err, chi2)
return (a0, a_err, b0, b_err)
return (a0, a_err, b0, b_err, 0)
else:
return (a0, 0, b0, 0, 1)
######################################################################################################
......