def timePL(tstamp,obsPath,centroidPath): obs = ObsFile(obsPath) obs.loadAllCals() obs.setWvlCutoffs(3000,11000) obs.loadCentroidListFile(centroidPath) writePhotonList(obs,photListDescription=PulsarPhotonList,checkForExisting=False) del obs
def centroidObs(obsPath,centroidPath,centroidRa,centroidDec,haOffset,xGuess,yGuess,savePath,tstamp): obs = ObsFile(obsPath) # if not os.path.exists(hotPath): # hp.findHotPixels(obsFile=obs,outputFileName=hotPath) obs.loadAllCals() # obs.loadHotPixCalFile(hotPath,switchOnMask=True) # obs.loadBestWvlCalFile() # obs.loadFlatCalFile(flatPath) obs.setWvlCutoffs(3000,11000) obs.loadCentroidListFile(centroidPath) ctrdFile = obs.centroidListFile sliceTimes = ctrdFile.root.centroidlist.times.read() xPositions = ctrdFile.root.centroidlist.xPositions.read() yPositions = ctrdFile.root.centroidlist.yPositions.read() intTime = sliceTimes[1]-sliceTimes[0] for iTime,time in enumerate(sliceTimes): x = xPositions[iTime] y = yPositions[iTime] title='centroid_{}_{}s'.format(tstamp,time) imgDict = obs.getPixelCountImage(firstSec=time,integrationTime=intTime,weighted=True) imgPath=os.path.join(savePath,title+'.png') pop = PopUp(showMe=False) pop.plotArray(imgDict['image'],title=title) pop.axes.plot(x,y,color='g',marker='d') pop.fig.savefig(imgPath) print 'saved to',imgPath del obs
def testWritePhotonList(outputFileName=None,firstSec=0,integrationTime=-1,doPixRemap=True): ''' Test run of obsFile.writePhotonList. fileName can be used to specify the output file name. If not specified, default name/location is used. Now includes test for pixel remapping.... ''' #Details of example obs file to run test on. # run = 'PAL2012' # date = '20121207' # tstamp = '20121208-074649' # calTstamp='20121208-070505' # fluxTstamp='20121208-133002' run = 'PAL2012' date = '20121208' tstamp = '20121209-120530' centroidTstamp = '20121209-120530' calTstamp='20121209-131132' fluxTstamp='20121209-020416' flatTstamp='20121209-021036' if doPixRemap==True: pixRemapFileName = FileName(run=run).pixRemap() else: pixRemapFileName = None #Load up the obs file obsFileName = FileName(run=run, date=date, tstamp=tstamp) obsFile = ObsFile(obsFileName.obs()) #Load up associated calibrations obsFile.loadWvlCalFile(FileName(run=run,date=date,tstamp=calTstamp).calSoln()) obsFile.loadFlatCalFile(FileName(run=run,date=date,tstamp=flatTstamp).flatSoln()) obsFile.loadFluxCalFile(FileName(run=run,date=date,tstamp=fluxTstamp).fluxSoln()) obsFile.loadTimeAdjustmentFile(FileName(run=run,date=date,tstamp=tstamp).timeAdjustments()) obsFile.loadHotPixCalFile(FileName(run=run,date=date,tstamp=tstamp).timeMask()) obsFile.loadCentroidListFile(FileName(run=run,date=date,tstamp=tstamp).centroidList()) #And write out the results.... obsFile.writePhotonList(outputFileName,firstSec,integrationTime, pixRemapFileName=pixRemapFileName)
obsFN = FileName(run=run,date=date,tstamp=tstamp) obsPath = obsFN.obs() flatPath = FileName(run=run,date=date).flatSoln() hotPath = obsFN.timeMask() centroidPath = obsFN.centroidList() fluxPath = FileName(run='PAL2012',date='20121211',tstamp='absolute_021727').fluxSoln() obs = ObsFile(obsPath) if not os.path.exists(hotPath): hp.findHotPixels(obsPath,hotPath) obs.loadHotPixCalFile(hotPath,switchOnMask=False) obs.loadBestWvlCalFile() obs.loadFlatCalFile(flatPath) obs.loadFluxCalFile(fluxPath) obs.loadCentroidListFile(centroidPath) obs.setWvlCutoffs(3000,11000) centroidRa = '03:37:43.826' centroidDec = '14:15:14.828' haOffset = 150. # imgDict = obs.getPixelCountImage(integrationTime=60,scaleByEffInt=True) # plotArray(imgDict['image']) xGuess = 18 #col yGuess = 15 #row #cc.centroidCalc(obs,centroidRa,centroidDec,guessTime=300,integrationTime=30,secondMaxCountsForDisplay=2000,HA_offset=haOffset,xyapprox=[xGuess,yGuess],outputFileName=centroidPath)
def testWritePhotonList(outputFileName=None,firstSec=0,integrationTime=-1,doPixRemap=False): ''' Test run of obsFile.writePhotonList. fileName can be used to specify the output file name. If not specified, default name/location is used. Now includes test for pixel remapping.... ''' #Details of example obs file to run test on. # run = 'PAL2012' # date = '20121207' # tstamp = '20121208-074649' # calTstamp='20121208-070505' # fluxTstamp='20121208-133002' run = 'PAL2013' date = '20131209' tstamp = '20131209-115553' centroidTstamp = tstamp calTstamp='20131209-132225' fluxTstamp='ones' flatTstamp='20131209' if doPixRemap==True: pixRemapFileName = FileName(run=run).pixRemap() else: pixRemapFileName = None #Load up the obs file obsFileName = FileName(run=run, date=date, tstamp=tstamp) obsFile = ObsFile(obsFileName.obs()) obsFile.loadWvlCalFile(FileName(run=run,date=date,tstamp=calTstamp).calSoln()) obsFile.loadFlatCalFile(FileName(run=run,date=date,tstamp=flatTstamp).flatSoln()) obsFile.loadFluxCalFile(FileName(run=run,date=date,tstamp=fluxTstamp).fluxSoln()) HotPixFile = FileName(run=run,date=date,tstamp=tstamp).timeMask() if not os.path.exists(HotPixFile): #check if hot pix file already exists hp.findHotPixels(obsFileName.obs(),HotPixFile) print "Flux file pixel mask saved to %s"%(HotPixFile) obsFile.loadHotPixCalFile(HotPixFile) print "Hot pixel mask loaded %s"%(HotPixFile) #hz21 location alpha(2000) = 12h 13m 56.42s , delta(2000) = +32d 56' 30.8'' centroid_RA = '12:13:56.42' centroid_DEC = '32:56:30.8' CentFile = FileName(run=run,date=date,tstamp=tstamp).centroidList() #print "checking centroid file", CentFile #if not os.path.exists(CentFile): #check if cent pix file already exists cent.centroidCalc(obsFile, centroid_RA, centroid_DEC, outputFileName = CentFile, guessTime=10, integrationTime=10) # print "Flux file centroid cal saved to %s"%(CentFile) obsFile.loadCentroidListFile(CentFile) print "Centroid File loaded %s"%(CentFile) #Load up associated calibrations #obsFile.loadTimeAdjustmentFile(FileName(run=run,date=date,tstamp=tstamp).timeAdjustments()) #obsFile.loadHotPixCalFile(FileName(run=run,date=date,tstamp=tstamp).timeMask()) #obsFile.loadCentroidListFile(FileName(run=run,date=date,tstamp=tstamp).centroidList()) #And write out the results.... obsFile.writePhotonList(outputFileName,firstSec,integrationTime, pixRemapFileName=pixRemapFileName) #Read the results back in.... #photFile = photList.PhotFile(outputFilename) print "Wrote photon list file: ", outputFileName
flatTstamp='20131209' obsFileName = FileName(run=run, date=date, tstamp=tstamp) obsFile = ObsFile(obsFileName.obs()) frames = [] print '-----------------------' print tstamp for i in xrange(30): print "making frame ", i frame = obsFile.getFrame(10*i,10) #plt.matshow(frame,vmin=10000,vmax=40000,cmap=plt.cm.gray) #plt.show() frames.append(frame) makeMovie(frames,frameTitles=np.arange(30)*10,cbar=True,outName='%s.gif'%(tstamp), normMin=400, normMax=4000) CentFile = FileName(run=run,date=date,tstamp=tstamp).centroidList() obsFile.loadCentroidListFile(CentFile) xs = obsFile.centroidListFile.getNode('/centroidlist/xPositions').read() ys = obsFile.centroidListFile.getNode('/centroidlist/yPositions').read() plt.figure() ax1 = plt.subplot(111) plt.plot(np.arange(len(xs)),xs,label="xs") plt.plot(np.arange(len(ys)),ys,label='ys') plt.legend() plt.title(tstamp) #plt.show() plt.savefig(tstamp)