Commit 53d7dcc2 authored by Grospiron Louis's avatar Grospiron Louis

Passage a arctanh

parent cbefe809
......@@ -9,11 +9,15 @@ from progressbar import ProgressBar
import os
import matplotlib
import matplotlib.animation as animation
FFMpegWriter = animation.writers['ffmpeg']
#FFMpegWriter = animation.writers['ffmpeg']
import scipy.ndimage as sn
import yaml
from convbox.plot.color.rainbow_desaturated import mymap2
import scipy.optimize as opt
from matplotlib import cm
#from colorspacious import cspace_converter
from collections import OrderedDict
cmaps = OrderedDict()
# Loading of output folder path
MyPath = yaml.load(open('.celsius.yml'),Loader=yaml.FullLoader)['MyPath']
......@@ -57,13 +61,16 @@ class TLCExperiment:
"""
Iterator computing T field from H value using calibration Calibration.
"""
A,B = Calibration.AB
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)
for picture in self.pictures():
H = cv2.cvtColor(picture,cv2.COLOR_BGR2HSV)[:,:,0]
yield A*H + B
yield fonc(H,A,B,C,D)
......@@ -80,7 +87,6 @@ class TLCPlumeExperiment(TLCExperiment):
self.U = U
#-------------------------------------------------------------------------------
class TLCCalibration:
"""
Class which assembles all calibration points used for a TLC calibration
......@@ -227,17 +233,34 @@ class TLCCalibration:
print(H[300,300,:])
print(T[300,300,:])
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]))
erreurs=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, plat = fit_affine(H[i,j,:], T[i,j,:],1e-5,1e-5)
A[i,j] = a0
B[i,j] = b0
# if (i,j)==(300,300): #debug
# print(a0,b0) #debug
# if plat == 1 :
# print((i,j))
try:
popt, pcov = opt.curve_fit(fonc,H[i,j,:],T[i,j,:],[0.01,4,22,75])
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():
erreurs[i][j]=1
plt.imshow(erreurs)
plt.show()
#if (i,j)==(300,300): #debug
#print(a0,b0) #debug
with h5py.File("{}Processed_DATA/{}/Calibration.h5".format(MyPath,self.Name),'a') as f:
try:
......@@ -251,16 +274,22 @@ class TLCCalibration:
print('Old data suppressed')
except KeyError as e:
print('No old data to suppress')
f.create_dataset('B',data=B)
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)
@property
def AB(self):
def ABCD(self):
"""
Return array A and B
Return array A, B, C, D
"""
with h5py.File("{}Processed_DATA/{}/Calibration.h5".format(MyPath,self.Name),'a') as f:
return f['A'][()], f['B'][()]
return f['A'][()], f['B'][()], f['C'][()], f['D'][()]
......
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