def pop_interpolatedImage(self,LC,ind): #These should really be saved in the photometry file and grabbed from there... interpolation = "linear" aper_radius = 5 annulus_inner = 10 annulus_outer = 15 image = LC.im_dict['images'][ind] centroid = LC.centroids[ind] interpImage = utils.interpolateImage(image, method=interpolation) angleArray = np.linspace(0,2*np.pi,180) self.plotArray(image=interpImage, title='Interpolated Image',cmap=matplotlib.cm.gnuplot2) for star_i in range(len(centroid)): self.axes.plot(centroid[star_i][0]+aper_radius*np.cos(angleArray), centroid[star_i][1] + aper_radius*np.sin(angleArray), 'b-') self.axes.plot(centroid[star_i][0]+annulus_inner*np.cos(angleArray), centroid[star_i][1] + annulus_inner*np.sin(angleArray), 'r-') self.axes.plot(centroid[star_i][0]+annulus_outer*np.cos(angleArray), centroid[star_i][1] + annulus_outer*np.sin(angleArray), 'r-')
def pop_interpolatedImage(self,LC,ind): interpolation = LC.photometry_dict['interpolation'][ind] aper_radius = LC.photometry_dict['apertureRad'][ind] annulus_inner = LC.photometry_dict['annulusInnerRad'][ind] annulus_outer = LC.photometry_dict['annulusOuterRad'][ind] image = LC.im_dict['images'][ind] centroids = LC.centroids[ind] interpImage = utils.interpolateImage(image, method=interpolation) angleArray = np.linspace(0,2*np.pi,180) self.plotArray(image=interpImage, title='Interpolated Image',cmap=matplotlib.cm.gnuplot2) for star_i in range(len(centroids)): self.axes.plot(centroids[star_i][0]+aper_radius[star_i]*np.cos(angleArray), centroids[star_i][1] + aper_radius[star_i]*np.sin(angleArray), 'b-') self.axes.plot(centroids[star_i][0]+annulus_inner[star_i]*np.cos(angleArray), centroids[star_i][1] + annulus_inner[star_i]*np.sin(angleArray), 'r-') self.axes.plot(centroids[star_i][0]+annulus_outer[star_i]*np.cos(angleArray), centroids[star_i][1] + annulus_outer[star_i]*np.sin(angleArray), 'r-') self.axes.plot(centroids[star_i][0],centroids[star_i][1],'gx')
def AperPhotometry(self, aper_radius=5, sky_sub="median", annulus_inner=10, annulus_outer=15, interpolation="linear"): ''' Inputs: aper_radius - double or list of doubles of the same length as self.centroid. Number of pixels around the star to be used in aperture sky_sub - indicates type of sky subtraction to be performed. "median" - to use median sky value in annulus "fit" - to mask objects and estimate sky in aperture with polynomial fit annulus_inner - double or list of doubles of same length as self.centroid. Gives radius of inner part of sky annulus for use in "median" sky sub. Ignored if sky_sub is not "median" [target_apertureRad, ref0_apertureRad, ...] annulus_outer - double or list of doubles of same length as self.centroid. Gives radius of outer part of sky annulus for use in "median" sky sub. Ignored if sky_sub is not "median" interpolation - select type of interpolation to perform on image before doing photometry None - to skip interpolation "cubic" - to do 2D cubic interpolation "linear" - to do 2D linear interpolation (default) Returns: Dictionary with keywords. These keywords should be the same as in aperPhotometryDataDescription in headers.DisplayStackHeaders flux - array of flux values. [target_flux, target_sky_flux, ref0_flux, ...] skyFlux - array of sky flux values, scaled to same n_pix as object flux. [target_sky, ref0_sky, ...] flag - flag to indicate successful analysis. 0 is good apertureRad - same as input annulusInnerRad - same as input annulusOuterRad - same as input interpolation - same as input ''' flux = [] sky = [] apRadOut = [] annInOut = [] annOutOut = [] flag = 0 #if sky fitting is selected for sky subtraction, do masking and produce polynomial sky image if sky_sub == "fit": warnings.warn("Sky fitting not well debugged. Use with extreme caution",UserWarning) skyIm = self.fitMaskedSky(self.image, aper_radius) if interpolation != None: if self.verbose: print "Performing %s interpolation on image"%interpolation try: interpImage = utils.interpolateImage(self.image, method=interpolation) except ValueError: interpImage = np.zeros(np.shape(self.image),dtype=float) print "Empty frame encountered on interpolation, filled with zeros" if self.showPlot: plotArray(title='Before interpolation', image=self.image) plotArray(title='After interpolation', image=interpImage) else: interpImage = self.image if self.showPlot: totalAngles = 100 angleArray = np.linspace(0,2*np.pi,totalAngles) form=PopUp(title='Aperture photometry',showMe=False) form.plotArray(interpImage) #step through each star in centroid list: [target, ref0, ref1, ...] for star_i in range(len(self.centroid)): try: #check if different aperture radii are set for each star radius=aper_radius[star_i] except TypeError: radius=aper_radius try: #check if different annulus radii are set for each star ann_in=annulus_inner[star_i] except TypeError: ann_in=annulus_inner try: #check if different annulus radii are set for each star ann_out=annulus_outer[star_i] except TypeError: ann_out=annulus_outer objectFlux, nObjPix = self.getApertureCounts(interpImage,radius,self.centroid[star_i]) if self.showPlot: #add aperture to output image if showPlot is true form.axes.plot(self.centroid[star_i][0]+radius*np.cos(angleArray), self.centroid[star_i][1] + radius*np.sin(angleArray), 'b') if sky_sub == "fit": skyFlux, nSkyPix = self.getApertureCounts(skyIm,radius,self.centroid[star_i]) ann_in = 0 ann_out = 0 else: skyFlux, nSkyPix = self.getAnnulusCounts(interpImage,ann_in,ann_out,self.centroid[star_i]) if self.showPlot: #add annulus to output image if showPlot is true form.axes.plot(self.centroid[star_i][0]+ann_in*np.cos(angleArray), self.centroid[star_i][1] + ann_in*np.sin(angleArray), 'r') form.axes.plot(self.centroid[star_i][0]+ann_out*np.cos(angleArray), self.centroid[star_i][1] + ann_out*np.sin(angleArray), 'r') flux.append(objectFlux) sky.append(skyFlux*(float(nObjPix)/float(nSkyPix))) #output radii used for aperture and annuli for bookkeeping apRadOut.append(radius) annInOut.append(ann_in) annOutOut.append(ann_out) if self.showPlot: form.show() return {'flux': np.asarray(flux), 'skyFlux': np.asarray(sky), 'apertureRad':np.asarray(apRadOut), 'annulusInnerRad':np.asarray(annInOut), 'annulusOuterRad':np.asarray(annOutOut), 'flag':flag, 'interpolation':interpolation}
stack = stackDict['stack'] wvls = stackDict['wvls'] fitImgList = [] for iFrame in range(0,np.shape(stack)[0]): frame = stack[iFrame,:,:] frame[frame>70] = 70 fig = plt.figure() ax = fig.add_subplot(111) ax.set_title(wvls[iFrame]) im = ax.matshow(frame, cmap = cm.get_cmap('rainbow')) fig.colorbar(im) #plt.show() intFrame = utils.interpolateImage(frame, 'linear') fig = plt.figure() ax = fig.add_subplot(111) ax.set_title(wvls[iFrame]) im = ax.matshow(intFrame, cmap = cm.get_cmap('rainbow'))#, vmax = 40) fig.colorbar(im) plt.show() fitImgList.append(intFrame) cube = np.array(fitImgList) #np.savez(npzfitpsf,cube=cube,wvls=wvls) print 'saved' #utils.makeMovie(fitImgList,frameTitles=wvls, cbar=True, outName=giffitpsf, normMin=0, normMax=50)
print fname stackFile = tables.openFile(fname, mode="r") stackNode = stackFile.root.stack stack = np.array(stackNode.stack.read()) jd = np.array(stackNode.time.read()[0]) stackFile.close() print "Stack length = ", np.shape(stack) print "JD length = ", np.shape(jd) for i in xrange(len(stack[0, 0, :])): print "Interpolating Frame ", i, " in stack" frame = stack[:, :, i] nanMask = np.isnan(frame) frame[nanMask] = 0.0 imageStacks.append(frame) try: interpFrame = utils.interpolateImage(frame, method="linear") except ValueError: interpFrame = np.zeros(np.shape(frame), dtype=float) print "Empty frame encountered, filled with zeros" interpolatedStacks.append(interpFrame) times.append(jd[i]) # inspect some interpolated frames """ if i%20==0: fig = plt.figure() ax = fig.add_subplot(111) ax.set_title(jd[i]) im = ax.matshow(frame, cmap = cm.get_cmap('rainbow'), vmax = 500) fig.colorbar(im) fig = plt.figure()