Exemplo n.º 1
0
    def testCosmicTimeMasking(self):
        """
        tests the cosmic time masking function
        """
        ymax = sys.float_info.max/100.0
        run = 'PAL2012'
        sundownDate = '20121211'
        obsDate = '20121212'
        seq = '121229'
        fn = FileName.FileName(run, sundownDate, obsDate+"-"+seq)
        beginTime = 123.247400
        endTime   = 123.248400
        cosmic = Cosmic(fn, beginTime=beginTime, endTime=endTime)

        stride = 10
        threshold = 100
        populationMax=2000
        nSigma=10
        dictionary0 = cosmic.findCosmics(stride=stride,
                                         threshold=threshold,
                                         populationMax=populationMax,
                                         nSigma=nSigma)
        interval = dictionary0['interval']
        plt.clf()
        plt.plot(dictionary0['timeHgValues'])
        for oneInt in interval:
            x0 = (oneInt[0]-beginTime)*cosmic.file.ticksPerSec
            x1 = (oneInt[1]-beginTime)*cosmic.file.ticksPerSec
            plt.fill_between((x0,x1),(0,0),(ymax,ymax),alpha=0.2,color='red')
        plt.title("timeHgValues stride=%d  threshold=%d nSigma=%d"%(stride,threshold,nSigma))
        plt.xlabel("ticks after t=%f seconds"%beginTime)
        plt.yscale("symlog",linthreshy=0.5)
        plt.ylim(0,dictionary0['timeHgValues'].max())
        plt.savefig("testCosmicTimeMasking-0.png")
        ObsFile.ObsFile.writeCosmicIntervalToFile(interval, 
                                                cosmic.file.ticksPerSec,
                                                'junk.h5')
      
        cosmic.file.loadCosmicMask('junk.h5')
        dictionary1 = cosmic.findCosmics(populationMax=1000)
        
        plt.clf()
        hist = dictionary0['populationHg'][0]
        bins = np.arange(len(hist))
        plt.plot(bins, hist)
        plt.ylabel("no mask")
        plt.xscale('log')
        plt.yscale('log')
       
        hist = dictionary1['populationHg'][0]
        bins = np.arange(len(hist))
        plt.plot(bins, hist, color='g')
        plt.ylabel("cosmic mask") 
        plt.xscale('log')
        plt.yscale('log')
        plt.savefig("testCosmicTimeMasking.png")
Exemplo n.º 2
0
    def testSecondBoundary2(self):
        run = 'PAL2012'
        sundownDate = '20121211'
        obsDate = '20121212'
        seq = '121229'
        t0 = 123
        t1 = 133

        nSigma = 1
        stride = 1
        threshold = 15
        fn = FileName.FileName(run, sundownDate, obsDate+"-"+seq)
        cosmic = Cosmic(fn, beginTime=t0, endTime=t1, 
                        loggingLevel=logging.CRITICAL)

        fc = cosmic.findCosmics(stride=stride, 
                                threshold=threshold, 
                                populationMax=2000,
                                nSigma=nSigma)
        print "len if timeHgValues=",len(fc['timeHgValues'])
        plt.clf()
        t = np.arange(len(fc['timeHgValues']))/1e6
        plt.plot(t,fc['timeHgValues'])
        plt.ylabel("number of photons per tick")
        plt.xlabel("time after %.1f (sec)"%t0)
        plt.title("run=%s obsDate=%s seq=%s t0=%d t1=%d"%(run,obsDate,seq,t0,t1))
        plt.grid(axis='x')
        #plt.yscale('symlog', linthreshy=0.9)
        plt.yscale('log')
        plt.ylim(ymin=-0.1)
        plt.savefig(inspect.stack()[0][3]+".png")
Exemplo n.º 3
0
    def findv1(self):
        populationMax=2000
        ySum = np.zeros(populationMax)
        frameSum = 'none'
        seq5 = self.s['seq5'].split()
        for seq in seq5:
            print "seq=",seq
            outfileName = "cosmicTimeList-"+seq+".pkl"
            if not os.path.exists(outfileName):
                fn = FileName(self.s['run'], 
                              self.s['sundownDate'], 
                              self.s['obsDate']+"-"+str(seq))
                cosmic = Cosmic(fn, 
                                beginTime=self.s['beginTime'],
                                endTime=self.s['endTime'],
                                loggingLevel = logging.INFO)

                fc = cosmic.findCosmics(stride=int(self.s['stride']), 
                                        threshold=int(self.s['threshold']), 
                                        populationMax=populationMax,
                                        nSigma=float(self.s['nSigma']))
                outfile = open(outfileName, "wb")
                pickle.dump(fc['cosmicTimeList'],outfile)
                pickle.dump(fc['binContents'],outfile)
                outfile.close()
                cfn = "cosmicMask-%s.h5"%seq
                ObsFile.writeCosmicIntervalToFile(fc['interval'],1.0e6, cfn,
                                                  self.s['beginTime'],
                                                  self.s['endTime'],
                                                  int(self.s['stride']),
                                                  int(self.s['threshold']),
                                                  float(self.s['nSigma']),
                                                  populationMax)

                del cosmic
    def run(self):
        for obs in self.param['obsSequence']:
            fn = FileName.FileName(run=self.param['run'],
                                   date=self.param['sunsetDate'],
                                   tstamp = obs)


            cosmic = Cosmic(fn,
                            loggingLevel=logging.INFO,
                            beginTime=self.s['beginTime'],
                            endTime=self.s['endTime'])


            fc = cosmic.findCosmics(stride=int(self.s['stride']), 
                                    threshold=int(self.s['threshold']), 
                                    populationMax=int(self.s['populationMax']),
                                    nSigma=float(self.s['nSigma']),
                                    writeCosmicMask=True)

            cosmic = Cosmic(fn,
                            loggingLevel=logging.INFO,
                            beginTime=self.s['beginTime'],
                            endTime=self.s['endTime'],
                            applyCosmicMask=True)

            fcm = cosmic.findCosmics(stride=int(self.s['stride']), 
                                     threshold=int(self.s['threshold']), 
                                     populationMax=int(self.s['populationMax']),
                                     nSigma=float(self.s['nSigma']),
                                     writeCosmicMask=False)
            
            p = {
                'populationHg':fc['populationHg'][0],
                'populationHgM':fcm['populationHg'][0],
                'pps':fc['pps'],
                'ppsM':fcm['pps'],
                'ppmMasked':fc['ppmMasked'],
                'ppsTime':fc['ppsTime'],
                'beginTime':cosmic.beginTime,
                'endTime':cosmic.endTime
                }

            outfileName = "cosmic-summary-"+obs+".pkl"
            outfile = open(outfileName, "wb")
            pickle.dump(p,outfile)
            outfile.close()
Exemplo n.º 5
0
 def test_findCosmics(self):
     run = 'PAL2012'
     obsDate = '20121211'
     seq = '20121212-113212'
     fn = FileName.FileName(run, obsDate, seq)
     cosmic = Cosmic(fn, beginTime= 222, endTime=232,\
                              nBinsPerSec = 10, loggingLevel=logging.FATAL)
     stride = 10
     threshold = 20
     populationMax = 2000
     fc = cosmic.findCosmics(stride, threshold, populationMax)
     cosmicTimeList = fc['cosmicTimeList']        
     # 4 events found on 2013-09-27
     self.assertEquals(4,len(cosmicTimeList))
Exemplo n.º 6
0
 def testExponAndGaussFit(self):
     run = 'PAL2012'
     sundownDate = '20121211'
     obsDate = '20121212'
     seq = '131254'
     fn = FileName(run, sundownDate, obsDate+"-"+seq)
     beginTime=79.248482
     endTime = beginTime+200*1e-6
     cosmic = Cosmic(fn, beginTime=beginTime,endTime=endTime)
     dictionary = cosmic.findCosmics(populationMax=1000)
 
     hist = np.array(dictionary['timeHgValues'])
     bins = np.arange(len(hist))
     plt.plot(bins, hist)
     plt.savefig(inspect.stack()[0][3]+".png")
Exemplo n.º 7
0
    def testSecondBoundary(self):
        run = 'PAL2012'
        sundownDate = '20121211'
        obsDate = '20121212'
        seq = '121229'
        t0 = 123
        t1 = 133

        nSigma = 1
        stride = 1
        threshold = 15
        fn = FileName.FileName(run, sundownDate, obsDate+"-"+seq)
        tsum = None
        for t in range(t0,t1,1):
            beginTime = t-15e-5
            endTime = t+15e-5
            cosmic = Cosmic(fn, beginTime=beginTime, endTime=endTime, 
                            loggingLevel=logging.CRITICAL)

            fc = cosmic.findCosmics(stride=stride, 
                                    threshold=threshold, 
                                    populationMax=2000,
                                    nSigma=nSigma)

            if tsum == None:
                tsum = np.array(fc['timeHgValues'])
            else:
                tsum += np.array(fc['timeHgValues'])
        plt.clf()

        dt = (endTime-beginTime)
        x0 = (t-beginTime)*(len(tsum)-1)/dt
        print "dt=",dt
        print "x0=",x0
        print "len(tsum)=",len(tsum)
        x = np.arange(len(tsum))-x0
        plt.plot(x,tsum, drawstyle='steps-mid')
        ymin = -1
        ymax = 1.1*tsum.max()
        xAtMax = tsum.argmax()-x0
        #plt.vlines(xAtMax, ymin, ymax, linestyles='dotted', label="beginning of second")
        plt.text(xAtMax+10,ymax/2, "t at max=%.1f"%xAtMax, ha="left",va="center")
        plt.ylim(-1,ymax)
        plt.ylabel("number of photons per time tick")
        plt.xlabel("ticks since beginning of second")
        plt.title("run=%s obsDate=%s seq=%s t0=%d t1=%d"%(run,obsDate,seq,t0,t1))
        plt.savefig(inspect.stack()[0][3]+".png")
    def testCosmic(self):
        run = 'PAL2012'
        sundownDate = '20121211'
        obsDate = '20121212'
        seq = '121229'
        fn = FileName.FileName(run, sundownDate, obsDate+"-"+seq)
        cosmic = Cosmic(fn, beginTime=123, endTime=125)

        dictionary0 = cosmic.findCosmics(threshold=500, populationMax=2000)
        print "dictionary0 keyst=",dictionary0.keys()
        print "interval=",dictionary0['interval']

        hist = dictionary0['populationHg'][0]
        bins = np.arange(len(hist))
        plt.plot(bins, hist, label="no mask")
        
        plt.xscale('log')
        plt.yscale('log')
        plt.legend()
        plt.savefig(inspect.stack()[0][3]+".png")
Exemplo n.º 9
0
#seq5 = ['133303']

nSigma = 7
stride = 10
threshold = 50
populationMax=2000
ySum = np.zeros(populationMax)
frameSum = 'none'

for seq in seq5:
    print "seq=",seq
    fn = FileName(run, sundownDate, obsDate+"-"+seq)
    #cosmic = Cosmic(fn, endTime='exptime')
    cosmic = Cosmic(fn, beginTime=0)
    fc = cosmic.findCosmics(stride=stride, 
                            threshold=threshold, 
                            populationMax=populationMax,
                            nSigma=nSigma)
    if frameSum == 'none':
        frameSum = fc['frameSum']
    else:
        frameSum += fc['frameSum']
    outfile = open("cosmicTimeList-"+seq+".pkl", "wb")
    pickle.dump(fc['cosmicTimeList'],outfile)
    pickle.dump(fc['binContents'],outfile)
    outfile.close()
    cfn = "cosmicMax-%s.h5"%seq
    ObsFile.writeCosmicIntervalToFile(fc['interval'],1.0e6, cfn)
    populationHg = fc['populationHg']
    yPlot = populationHg[0].astype(np.float)
    ySum += yPlot
    norm = yPlot.sum()
threshold = 25
stride = 10
populationMax = 1000

nlist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
         21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 
         38, 39, 40]

nlist2 = [10, 20, 30]

for n in nlist:
    
    beginTime = n-1
    endTime = n
    cosmic = Cosmic(fn, beginTime, endTime)
    dictionary0 = cosmic.findCosmics(nSigma, threshold, stride, populationMax)
    interval = dictionary0['interval']
   
    hist0 = dictionary0['populationHg'][0]
    bins0 = np.arange(len(hist0))

    
    muNum = (bins0*hist0).sum()
    muDen = float(hist0.sum())
    mu1 = muNum/muDen
    mu1Err = np.sqrt(mu1/muDen)
    print "mu1=",mu1," mu1Err=",mu1Err," muNum=",muNum," muDen=",muDen
    mean.append(mu1)
    meanErr.append(mu1Err)

for n in nlist2:
Exemplo n.º 11
0
import pickle
run = 'PAL2013'
sundownDate = '20131204'
obsDate = '20131205'
seq = '033506'

populationMax=1000


beginTime = 0
expTime = 300


fn = FileName(run, sundownDate, obsDate+"-"+seq)
cosmic = Cosmic(fn, beginTime=0, endTime=10, loggingLevel=logging.INFO)
fcd = cosmic.findCosmics(nSigma=10, stride=10, threshold=15)
print "done:  fcd.keys=",fcd.keys()
maskedTime = Cosmic.countMaskedBins(fcd['interval'])
maskedPercent = 100*maskedTime/(cosmic.endTime-cosmic.beginTime)
print "maskedPercent=",maskedPercent

cosmic.file.setCosmicMask(fcd['interval'])
fcd2 = cosmic.findCosmics()

#plt.xkcd() 
plt.plot(fcd['populationHg'][0],drawstyle='steps-mid',label="all data")
plt.plot(fcd2['populationHg'][0],drawstyle='steps-mid',label="cosmics masked")
plt.xlim(xmax=1000)
plt.xscale('symlog',linthreshx=0.9)
plt.yscale('symlog',linthreshy=0.5)
plt.title('%s %s %s %s'%(run,sundownDate,obsDate,seq))
Makes a plot for the entire file showing the mean for every ten seconds of
data and the cosmic events. This plot is saved as MeanAndCosmicEvents.png

Makes a scatter plot of the number of cosmics masked out and the mean which is
saved as scatter.png
"""

#loads the file
run = 'PAL2012'
sundownDate = '20121211'
obsDate = '20121212'
seq = '121229'
fn = FileName.FileName(run, sundownDate, obsDate+"-"+seq)
#this particular plot is for only ten seconds of data
cosmic = Cosmic(fn, beginTime=123, endTime=133)
dictionary0 = cosmic.findCosmics(nSigma=6, threshold=15, populationMax=1000)


interval = dictionary0['interval']
ObsFile.ObsFile.writeCosmicIntervalToFile(interval, 
                                          cosmic.file.ticksPerSec,
                                          'junk.h5')

cosmic.file.loadCosmicMask('junk.h5')
dictionary1 = cosmic.findCosmics(nSigma=6, threshold=15, populationMax=1000)
nSigma = 6
threshold = 15

plt.clf()
hist0 = dictionary0['populationHg'][0]
bins0 = np.arange(len(hist0))