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
示例#2
0
文件: checkTiles.py 项目: bmazin/SDR
def phaseMap(tile,nPhases,nSlopes,maxSlope=10,displayMap=False,minFreqSep=.5):
    phases = np.linspace(0.,2.*np.pi,nPhases)
    slopes = np.linspace(0.5,maxSlope,nSlopes)
    pmap = np.zeros((nSlopes,nPhases))
    for iSlope,slope in enumerate(slopes):
        if iSlope % 100 == 0:
            print iSlope
        for iPhase,phase in enumerate(phases):
            tileWithGrad = addGradient(tile,slope,phase)
            #plotArray(tileWithGrad,title='slope {} angle {}'.format(slope,phase))
            pmap[iSlope,iPhase] = countCollisions(tileWithGrad,minFreqSep=minFreqSep)

    percentMap = 100.*pmap/len(np.ravel(tile))
    print 'median unusable pixels (%) above slope {}: {}'.format(slopes[0],np.median(percentMap.ravel()))
    print 'sdev unusable pixels (%) above slope {}: {}'.format(slopes[0],np.std(percentMap.ravel()))
    print 'min,max unusable pixels (%) above slope {}: {} {}'.format(slopes[0],np.min(percentMap.ravel()),np.max(percentMap.ravel()))
    hist,binEdges = np.histogram(percentMap,bins=150)
    plt.plot(binEdges[0:-1],hist)
    plt.show()

    if displayMap:
        pop = PopUp(showMe=False)
        pop.plotArray(percentMap,cbarLabel='Unusable Pixels (%)')
        xticks = np.array(pop.axes.get_xticks(),dtype=np.int)
        yticks = np.array(pop.axes.get_yticks(),dtype=np.int)
        print xticks
        print yticks

        pop.axes.set_xticklabels(['{:.0f}'.format(phase*180./np.pi) for phase in phases[xticks[0:-1]]])
        pop.axes.set_yticklabels(['{:.1f}'.format(slope) for slope in slopes[yticks[0:-1]]])
        pop.axes.set_xlabel('Gradient Angle (${}^{\circ}$)')
        pop.axes.set_ylabel('Gradient Slope (MHz/pixel)')
        pop.axes.xaxis.tick_bottom()
        pop.show()
    return {'numberUnusablePixels':pmap,'gradientAnglesDeg':(phases*180./np.pi),'gradientSlopesMHz':slopes,'percentUnusable':percentMap}
data = np.load(dataPath)

pixelImages = data['pixelImages']
labels = data['obsTimestamps']

apertures = []
psfDicts = []
for iObs,(img,label) in enumerate(zip(pixelImages,labels)):
    centroidGuess = np.unravel_index(np.argmax(img),np.shape(img))
    centroidGuess = centroidGuess[::-1] #switch from (row,col) to (x,y)
    psfPhot = PSFphotometry(img,centroid=[centroidGuess],verbose=False,showPlot=False)
    psfDict = psfPhot.PSFfit(aper_radius=5)
    params = psfDict['parameters']
    sigma = psfDict['parameters'][4]
    flux = psfDict['flux']
    optimalApertureRadius = 1.6*sigma
    print int(psfDict['flag']),label,'sigma',sigma,'flux',flux,'aperture',optimalApertureRadius
    psfDict2 = data['psfFits'][iObs]
    print int(psfDict2['flag']),label,'sigma',psfDict2['parameters'][4],'flux',psfDict2['flux'],'aperture',1.6*psfDict2['parameters'][4]
    apertures.append(optimalApertureRadius)
    psfDicts.append(psfDict)

    imgPath = os.path.join(os.path.join(savePath,'pics/'),'apert'+label+'.png')
    pop = PopUp(showMe=False)
    pop.plotArray(img,title=label+' \sigma={},f={}'.format(sigma,flux),vmax=np.max(img))
    pop.fig.savefig(imgPath)

apertures = np.array(apertures)


    dateMasks = []
    phaseProfilesByDate = []
    for iDate,obsSeq in enumerate(obsSequences):
        dateMask = np.array([tstamp in obsSeq for tstamp in tstamps])
        phaseProfilesOnDate  = phaseProfiles[dateMask]
        combineProfiles(phaseBinEdges,phaseProfilesOnDate,label=sunsetDates[iDate])
        dateMasks.append(dateMask)
    combineProfiles(phaseBinEdges,phaseProfiles,label='total')
    
    #print '20140924',tstamps[0:17]
    #print '20140925',tstamps[17:47]
    #print '20141021',tstamps[47:]
    #profileErrors = dataDict['profileErrors']
    pop = PopUp(showMe=False)
    pop.plotArray(phaseProfiles,aspect=2.)
    pop.axes.set_yticks(np.arange(np.shape(phaseProfiles)[0]))
    pop.axes.tick_params(axis='both', which='major', labelsize=7)
    pop.axes.set_yticklabels(tstamps)
    pop.show()

    #plotArray(phaseProfiles)

#    combineProfiles(phaseBinEdges,phaseProfiles,label='total')
#    combineProfiles(phaseBinEdges,phaseProfiles[0:15],label='20140924')
#    combineProfiles(phaseBinEdges,phaseProfiles[17:47],label='20140925')
#    combineProfiles(phaseBinEdges,phaseProfiles[47:],label='20141021')
    timeProfile = np.mean(phaseProfiles,axis=1)
    fig,(ax,ax2,ax3,ax4) = plt.subplots(4,1,sharex='col')
    ax.plot(apertureRadiusList)
    ax2.plot([psfFit['flux'] for psfFit in psfFits])
示例#5
0
        return '0'

yWvlTickLocations = np.append(3600,np.arange(4000,12000,1000))
xWvlTickLocations = np.array([3600,4000,5000,7000,11000])

yIdxTickLocations = np.array([wvlToIdx(wvl) for wvl in yWvlTickLocations])
xIdxTickLocations = np.array([wvlToIdx(wvl) for wvl in xWvlTickLocations])

tickFormatter = FuncFormatter(wvlFormatter)
xTickLocator = FixedLocator(xIdxTickLocations)
yTickLocator = FixedLocator(yIdxTickLocations)

np.savez('metricImg.npz',metricImg=metricImg,wvlLimits=wvlLimits,wvlStartList=wvlStartList,wvlStopList=wvlStopList)

pop = PopUp(showMe=False)
pop.plotArray(metricImg,cbarLabel='h metric',cbarShrink=.82,cbarAspect=15,cbarPad=.05,vmax=13,cmap='hot')
#pop.axes.set_yticks(np.arange(np.shape(wvlLimits)[0]))
pop.axes.tick_params(axis='both', which='major', labelsize=11,labelbottom=True,labeltop=False)
pop.axes.xaxis.set_major_formatter(tickFormatter)
pop.axes.yaxis.set_major_formatter(tickFormatter)
pop.axes.xaxis.set_major_locator(xTickLocator)
pop.axes.yaxis.set_major_locator(yTickLocator)
pop.axes.set_xlabel('upper wavelength limit ($\AA$)')
pop.axes.set_ylabel('lower wavelength limit ($\AA$)')
pop.fig.subplots_adjust(left=.18,right=.93,top=1.0,bottom=None)
pop.fig.set_size_inches(5,4)
#pop.fig.set_tight_layout({})
#pop.fig.tight_layout()
#pop.axes.set_title('H Metric')

#for tick in pop.axes.xaxis.get_major_ticks():
 def showArrayLaserImage(self):
     getImageOutput = self.cal.getPixelCountImage(getRawCount=True,weighted=False)
     frame = getImageOutput['image']
     #self.popUpArray(image=self.rawFrame,title='raw image')
     pop = PopUp(parent=self,title='showArrayLaserImage')
     pop.plotArray(image=frame,title='laser cal raw image')