Ejemplo n.º 1
0
 def runTest(self):
     luckCalcPlot = LuckyCalculations(self.dsData,
                                      self.calib,
                                      self.integConf,
                                      self.bulbTemp,
                                      "TestData",
                                      debug=False)
     luckCalcPlot.runCalculations()
     LuckyPlots(luckCalcPlot)
     print "Test sleeping for 20s"
     time.sleep(20)
Ejemplo n.º 2
0
'''
Created on 12 Jan 2016

@author: wnm24546
'''
import os
import numpy as np
from Lucky.Calculations import LuckyCalculations

wdir = os.path.join('.','testData')
dsDataFile = os.path.join(wdir, 'T_635.txt')
usDataFile = os.path.join(wdir, 'T_636.txt')
dsCalibFile = os.path.join(wdir, 'Calib.txt')
usCalibFile = os.path.join(wdir, 'CalibF2MTW.txt')
        
        
dsData = np.loadtxt(dsDataFile, unpack=True) ##Raw file
usData = np.loadtxt(usDataFile, unpack=True)
calib = np.loadtxt('./testData/Calib.txt', unpack=True) ##Calib file
integConf = [315, 800, 200] #Values lifted out of PreLucky_Variant.py
bulbTemp = 2436

luckCalc = LuckyCalculations(dsData, calib, integConf, bulbTemp, "TestData", debug=True)
luckCalc.runCalculations()
print calib
Ejemplo n.º 3
0
class CalculationsTest(LuckyCalculationsTest):
    def setUp(self):
        LuckyCalculationsTest.setUp(self)
        
        self.luckCalc = LuckyCalculations(self.dsData, self.calib, self.integConf, self.bulbTemp, "TestData", debug=True)
        self.luckCalc.runCalculations()
        
        self.workingCalcs(self.dsData, self.calib, self.integConf)
    
    def workingCalcs(self, data, calib, integConf):
        from scipy.constants import h, c, k, pi
        ##Constants:
        Kb = k
        
        ##Session where I define all the function needed
        def Planck(x,e,T):
            x = x*10**(-9)
            a=np.expm1((h*c)/(k*x*T))#Order changed!! (h*c/k)/(x)/T
            P=e/(x)**5*(2*pi*h*c**2)*1/(a) ####NB Removed 
            return P
        #Defined Wien function
        def Wien(Int,x):
            #Order changed!!
            #W=Kb/h/c*np.log((x*10**(-9))**5*Int/2/pi/h/c**2)
            W=Kb/(h*c)*np.log((x*10**(-9))**5*Int/(2*pi*h*c**2))
            return W
        #Defined two-colour function
        def TwoCol(Int,x):
            count=len(x)
            delta=200
            k=count-delta
            TTwo=[]*count
            
            for i in range (0,k):#(0,count-1):
                f1=(h*c)/(x[i]*10**(-9)*Kb)
                f2=(h*c)/(x[i+delta]*10**(-9)*Kb)
                i1=np.log(Int[i]*(x[i]*10**(-9))**5/(2*pi*h*c**2))*(Kb/(h*c))#Order changed!!
                i2=np.log(Int[i+delta]*(x[i+delta]*10**(-9))**5/(2*pi*h*c**2))*(Kb/(h*c))#i2=np.log(Int[i]/2/pi/h/c**2/f1**5)*Kb/h/c
                TTwo.append((f1-f2)/(i2-i1))
            for i in range (k,count):
                a = float('nan')
                TTwo.append(a)
            return TTwo
        #Defined linear fit for Wien function
        def FWien(x,e,T):
            a=1/T
            b=Kb/(h*c)*np.log(e)
            W=b-a*x
            return W
        #Defined Gauss fit
        def gaus(x, a, x0, sigma):
            return np.real(a*np.exp(-(x-x0)**2/(2*sigma**2)))
        
        self.x = data[0]
        y = data[1]
        xC = calib[0]
        yC = calib[1]
        start = integConf[0]
        end = integConf[1]
        delta = integConf[2]
        
        P=Planck(self.x,1,2436)##Ideal Planck
        self.P = np.reshape(P, (1, len(P)))
        self.Norm=y/yC*P #Normalization file
        self.invX=1e9/self.x #Inverse of wavelength for Wien function (CHANGED 1/x*10**9)
        self.W=Wien(self.Norm,self.x)
        self.Two=TwoCol(self.Norm,self.x)
        Two2=np.array(self.Two,dtype='float')
        self.TwoInt=Two2[start:end]
        bins=range(1000,3000,1)
        hist=np.histogram(self.TwoInt,bins,density=False)
        self.freq=np.array(hist[0])
        control=len(hist[1])-1
        self.value=np.array(np.delete(hist[1],control,0))
        p0=[1,2000]
        #Fit Planck in the range [start:end]
        self.xp=self.x[start:end]
        self.Normp=self.Norm[start:end]
        bestP,covarP = curve_fit(Planck, self.xp, self.Normp, p0)
        TP=round(bestP[1],2)
        self.TPNR = bestP[1]
        self.eP=bestP[0]#Save planck Emissivity
        FP=Planck(self.xp,self.eP,TP)#Create the new Planck with the fit parameters
        self.FPNR = Planck(self.xp,self.eP,self.TPNR)
        PRes=abs(self.Normp-FP)#Planck Residual
        
        #Wien fit 
        self.invX1=self.invX[start:end]
        self.W1=self.W[start:end]
        #Fit Wien and control that there are no inf or nan arguments in the fit
        self.bestW,covarW = curve_fit(FWien,self.invX1[(np.isfinite(self.W1))],self.W1[(np.isfinite(self.W1))],p0=[1,self.TPNR]) #Changed - was TP
        self.Residual=self.W1-FWien(self.invX1[(np.isfinite(self.W1))],*self.bestW)
        #Save Wien temperature
        TW=round(self.bestW[1])
        
        #Gaussian fit to the histogram two-colours
        popt,pcov = curve_fit(gaus,self.value,self.freq,p0=[1000,self.TPNR,100])#Changed - was TP
        Thist=round(popt[1],2)#Save Histogram temperature
        errTot=round(popt[2])
        self.Thist = popt[1]
        self.errTot = popt[2]
Ejemplo n.º 4
0
class CalculationsTest(LuckyCalculationsTest):
    def setUp(self):
        LuckyCalculationsTest.setUp(self)

        self.luckCalc = LuckyCalculations(self.dsData,
                                          self.calib,
                                          self.integConf,
                                          self.bulbTemp,
                                          "TestData",
                                          debug=True)
        self.luckCalc.runCalculations()

        self.workingCalcs(self.dsData, self.calib, self.integConf)

    def workingCalcs(self, data, calib, integConf):
        from scipy.constants import h, c, k, pi
        ##Constants:
        Kb = k

        ##Session where I define all the function needed
        def Planck(x, e, T):
            x = x * 10**(-9)
            a = np.expm1((h * c) / (k * x * T))  #Order changed!! (h*c/k)/(x)/T
            P = e / (x)**5 * (2 * pi * h * c**2) * 1 / (a)  ####NB Removed
            return P

        #Defined Wien function
        def Wien(Int, x):
            #Order changed!!
            #W=Kb/h/c*np.log((x*10**(-9))**5*Int/2/pi/h/c**2)
            W = Kb / (h * c) * np.log(
                (x * 10**(-9))**5 * Int / (2 * pi * h * c**2))
            return W

        #Defined two-colour function
        def TwoCol(Int, x):
            count = len(x)
            delta = 200
            k = count - delta
            TTwo = [] * count

            for i in range(0, k):  #(0,count-1):
                f1 = (h * c) / (x[i] * 10**(-9) * Kb)
                f2 = (h * c) / (x[i + delta] * 10**(-9) * Kb)
                i1 = np.log(Int[i] * (x[i] * 10**(-9))**5 /
                            (2 * pi * h * c**2)) * (Kb /
                                                    (h * c))  #Order changed!!
                i2 = np.log(Int[i + delta] * (x[i + delta] * 10**(-9))**5 /
                            (2 * pi * h * c**2)) * (
                                Kb / (h * c)
                            )  #i2=np.log(Int[i]/2/pi/h/c**2/f1**5)*Kb/h/c
                TTwo.append((f1 - f2) / (i2 - i1))
            for i in range(k, count):
                a = float('nan')
                TTwo.append(a)
            return TTwo

        #Defined linear fit for Wien function
        def FWien(x, e, T):
            a = 1 / T
            b = Kb / (h * c) * np.log(e)
            W = b - a * x
            return W

        #Defined Gauss fit
        def gaus(x, a, x0, sigma):
            return np.real(a * np.exp(-(x - x0)**2 / (2 * sigma**2)))

        self.x = data[0]
        y = data[1]
        xC = calib[0]
        yC = calib[1]
        start = integConf[0]
        end = integConf[1]
        delta = integConf[2]

        P = Planck(self.x, 1, 2436)  ##Ideal Planck
        self.P = np.reshape(P, (1, len(P)))
        self.Norm = y / yC * P  #Normalization file
        self.invX = 1e9 / self.x  #Inverse of wavelength for Wien function (CHANGED 1/x*10**9)
        self.W = Wien(self.Norm, self.x)
        self.Two = TwoCol(self.Norm, self.x)
        Two2 = np.array(self.Two, dtype='float')
        self.TwoInt = Two2[start:end]
        bins = range(1000, 3000, 1)
        hist = np.histogram(self.TwoInt, bins, density=False)
        self.freq = np.array(hist[0])
        control = len(hist[1]) - 1
        self.value = np.array(np.delete(hist[1], control, 0))
        p0 = [1, 2000]
        #Fit Planck in the range [start:end]
        self.xp = self.x[start:end]
        self.Normp = self.Norm[start:end]
        bestP, covarP = curve_fit(Planck, self.xp, self.Normp, p0)
        TP = round(bestP[1], 2)
        self.TPNR = bestP[1]
        self.eP = bestP[0]  #Save planck Emissivity
        FP = Planck(self.xp, self.eP,
                    TP)  #Create the new Planck with the fit parameters
        self.FPNR = Planck(self.xp, self.eP, self.TPNR)
        PRes = abs(self.Normp - FP)  #Planck Residual

        #Wien fit
        self.invX1 = self.invX[start:end]
        self.W1 = self.W[start:end]
        #Fit Wien and control that there are no inf or nan arguments in the fit
        self.bestW, covarW = curve_fit(FWien,
                                       self.invX1[(np.isfinite(self.W1))],
                                       self.W1[(np.isfinite(self.W1))],
                                       p0=[1, self.TPNR])  #Changed - was TP
        self.Residual = self.W1 - FWien(self.invX1[(np.isfinite(self.W1))], *
                                        self.bestW)
        #Save Wien temperature
        TW = round(self.bestW[1])

        #Gaussian fit to the histogram two-colours
        popt, pcov = curve_fit(gaus,
                               self.value,
                               self.freq,
                               p0=[1000, self.TPNR, 100])  #Changed - was TP
        Thist = round(popt[1], 2)  #Save Histogram temperature
        errTot = round(popt[2])
        self.Thist = popt[1]
        self.errTot = popt[2]
Ejemplo n.º 5
0
 def runTest(self):
     luckCalcPlot = LuckyCalculations(self.dsData, self.calib, self.integConf, self.bulbTemp, "TestData", debug=False)
     luckCalcPlot.runCalculations()
     LuckyPlots(luckCalcPlot)
     print "Test sleeping for 20s"
     time.sleep(20)