Skip to content

Instantly share code, notes, and snippets.

@renexdev
Last active August 23, 2016 13:30
Show Gist options
  • Save renexdev/5390c76cccd7dd1bd045882948d5c4cf to your computer and use it in GitHub Desktop.
Save renexdev/5390c76cccd7dd1bd045882948d5c4cf to your computer and use it in GitHub Desktop.
Correct LS336 calibration points
#!/usr/bin/env python
##################################################################################
# script function: rename files in a folder
#
# rel. date: 08/2016
# Dr. Rene Cejas Bolecek
# Low Temperatures Laboratory, CAB, Argentina.
# email: [email protected]
# licence: MIT. http://opensource.org/licenses/MIT
##################################################################################
import numpy as np
#Datos Med. Iman a corregir calibracion
#Format
#time (s)| Temp(K) | V_LIA(check units) | Phase_Lia (degrees)
relPath = ""
filename = 'barrido-H0Tb'
filename = 'barrido-H0Tc'
filename = 'barrido-H3T'
filename = 'barrido-H4T'
filename = 'barrido-H5T'
filename = 'barrido-H6T'
filename = 'barrido-H7p5T'
filename = 'barrido-H9T'
filename = 'barrido-H9Tb'
filename = 'barrido-H12T'
filename = 'test-H0'
#Agrega un columna con la Temperatura corregida a la estructura original del archivo
filenameOut = filename+'_pp'
f_write = open(relPath+filenameOut+".dat", "w")
TbCoIn5 = np.loadtxt(relPath+filename+".dat")
#Guarda T vs Tcorr
filenameOut = filename+'_corr'
f_write1 = open(relPath+filenameOut+".dat", "w")
#Load T column
TbCoIn5_T = np.array([TbCoIn5[i,1] for i in range(len(TbCoIn5[:,0]))])
#Add Calibration Temperature points to correct
T = np.array([1.60000E+1,1.70000E+1,1.80000E+1,1.90000E+1])
#Add log10Resistance previous points. Ex. if 2 are bad points add 4 points : (good, bad , bad, good)
#in order to make a proper correction
log10R_wrong = np.array([3.00701E+0,2.98530E+0,2.95572E+0,2.93227E+0])
#fromLS336_CX09872
#2.93227E+0 1.90000E+1
#2.95572E+0 1.80000E+1
#2.98530E+0 1.70000E+1
#3.00701E+0 1.60000E+1
#Add log10Resistance new points
log10R_fine = np.array([3.00699201e+00,2.98047152e+00,2.95563484e+00,2.93227078e+00])
#from TermVsResCernox09872_parsed
#16.000000 1.01623000e+03 3.00699201e+00
#17.000000 9.56030000e+02 2.98047152e+00
#18.000000 9.02890000e+02 2.95563484e+00
#19.000000 8.55600000e+02 2.93227078e+00
#FUncion de correccion: se utiliza una interpolacion lineal entre 2 puntos en el LS334
corrT = lambda TIn,x,yf,yw,i: (((yw[i+1]-yw[i])/(x[i+1]-x[i])*(TIn-x[i])+(yw[i]-yf[i]))*(x[i+1]-x[i])/(yf[i+1]-yf[i]))+x[i]
#Funcion para obtener indices que cumplen una determina condicion (puntos que pertenecen al intervalo [T0,Ti)
getIdx = lambda x,T0,T1: np.where((x>=T0)*(x< T1))
####################################################################################
#Se utilizo en el debug
#Tcorr = []
#idxCorr = []
#for i in range(0,len(T)-1):
#el, = getIdx(TbCoIn5_T,T[i],T[i+1])
#print el
#print "i:", i
#for j in range(len(el)):
#print "i:", i
#print el[j]
#print TbCoIn5_T[el[j]]
#print T[i]
#print log10R_fine[i]
#print log10R_wrong[i]
#print corrT(TbCoIn5_T[el[j]],T,log10R_fine,log10R_wrong,i)
#Tcorr.append(corrT(TbCoIn5_T[el[j]],T,log10R_fine,log10R_wrong,i))
#print Tcorr
####################################################################################
print len(T)-1
#Puntos sin corregir del intervalo [0,T0)
el, = getIdx(TbCoIn5_T,0,T[0])
print "T < 16K",len(el)
for i in range(len(el)):
f_write.write("%.8e\t%.8e\t%.8e\t%.8e\t%.8e\n" % (TbCoIn5[el[i],0],TbCoIn5[el[i],1],TbCoIn5[el[i],2],TbCoIn5[el[i],3],TbCoIn5[el[i],1]))
#Puntos a corregir del intervalo [T0,T1)
for i in range(0,len(T)-1):
el, = getIdx(TbCoIn5_T,T[i],T[i+1])
print "T > 16K y T < 19K",len(el)
for j in range(len(el)):
corrTemp =corrT(TbCoIn5_T[el[j]],T,log10R_fine,log10R_wrong,i)
f_write1.write("%.8e\t%.8e\t%.8e\n" % (TbCoIn5[el[j],1],corrTemp,(TbCoIn5[el[j],1]-corrTemp)))
f_write.write("%.8e\t%.8e\t%.8e\t%.8e\t%.8e\n" % (TbCoIn5[el[j],0],TbCoIn5[el[j],1],TbCoIn5[el[j],2],TbCoIn5[el[j],3],corrTemp))
#Puntos a corregir del intervalo [T1,300)
el, = getIdx(TbCoIn5_T,T[len(T)-1],300.)
print "T > 19K",len(el)
for i in range(len(el)):
f_write.write("%.8e\t%.8e\t%.8e\t%.8e\t%.8e\n" % (TbCoIn5[el[i],0],TbCoIn5[el[i],1],TbCoIn5[el[i],2],TbCoIn5[el[i],3],TbCoIn5[el[i],1]))
f_write.close()
f_write1.close()
print "Total puntos: ",len(TbCoIn5_T)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment