def plot(self, vmin, vmax, mpl=False, cmap=CMDEF, border=True): """ Elementary intensity plot using either matplotlib's imshow or pgplot's pggray. Typically some setup may be needed before and after this. vmin -- image value for lowest intensity vmax -- image value for highest intensity mpl -- True for matplotlib, otherwise pgplot cmap -- colour map if mpl border -- plot a rectangular border around the outermost pixels or not """ if border: x1, x2 = self.llx-0.5,self.llx+self.xbin*self.nx-0.5 y1, y2 = self.lly-0.5,self.lly+self.ybin*self.ny-0.5 if mpl: limits = self.llx-0.5,self.llx+self.xbin*self.nx-0.5,self.lly-0.5,self.lly+self.ybin*self.ny-0.5 plt.imshow(self._data, cmap=cmap, interpolation='nearest', \ vmin=vmin, vmax=vmax, origin='lower', extent=limits) if border: plt.plot([x1,x2,x2,x1,x1],[y1,y1,y2,y2,y1]) else: tr = np.array([self.llx-self.xbin,self.xbin,0,self.lly-self.ybin,0,self.ybin]) pg.pggray(self._data,0,self.nx-1,0,self.ny-1,vmax,vmin,tr) if border: pg.pgline([x1,x2,x2,x1,x1],[y1,y1,y2,y2,y1])
def redraw(): ppgplot.pgslct(imagePlot['pgplotHandle']) ppgplot.pgslw(3) ppgplot.pggray(boostedImage, xlimits[0], xlimits[1] - 1, ylimits[0], ylimits[1] - 1, imageMinMax[0], imageMinMax[1], imagePlot['pgPlotTransform']) if plotSources: plotCircles(dr2Objects, margins) if plotHa: reduceddr2cat = [] for selected in extendedHaSources: reduceddr2cat.append(dr2Objects[selected]) plotCircles(reduceddr2cat, margins) if plotGrid: print("Plotting grid") ppgplot.pgsci(6) xVals = [p[0] for p in pixelGrid] yVals = [p[1] for p in pixelGrid] ppgplot.pgpt(xVals, yVals, 2) if plotPointings: ppgplot.pgsfs(2) ppgplot.pgslw(10) for p in pointings: if p['type'] == "Maximum": ppgplot.pgsci(2) if p['type'] == "Minimum": ppgplot.pgsci(4) ppgplot.pgcirc(p['x'], p['y'], 30) ppgplot.pgslw(1) if plotBrightStars: ppgplot.pgsci(3) ppgplot.pgsfs(2) ppgplot.pgslw(10) for b in brightStars: ppgplot.pgcirc(b['x'], b['y'], 40)
def drawMask(mask): print ("Drawing the mask.") if "pgplotHandle" not in maskPlot.keys(): maskPlot["pgplotHandle"] = ppgplot.pgopen("/xs") maskPlot["pgPlotTransform"] = [0, 1, 0, 0, 0, 1] else: ppgplot.pgslct(maskPlot["pgplotHandle"]) ppgplot.pgpap(paperSize, aspectRatio) ppgplot.pgsvp(0.0, 1.0, 0.0, 1.0) ppgplot.pgswin(0, width, 0, height) ppgplot.pggray(mask, 0, width - 1, 0, height - 1, 0, 255, maskPlot["pgPlotTransform"]) ppgplot.pgslct(imagePlot["pgplotHandle"])
def drawMask(mask): print("Drawing the mask.") if 'pgplotHandle' not in maskPlot.keys(): maskPlot['pgplotHandle'] = ppgplot.pgopen('/xs') maskPlot['pgPlotTransform'] = [0, 1, 0, 0, 0, 1] else: ppgplot.pgslct(maskPlot['pgplotHandle']) ppgplot.pgpap(paperSize, aspectRatio) ppgplot.pgsvp(0.0, 1.0, 0.0, 1.0) ppgplot.pgswin(0, width, 0, height) ppgplot.pggray(mask, 0, width - 1, 0, height - 1, 0, 255, maskPlot['pgPlotTransform']) ppgplot.pgslct(imagePlot['pgplotHandle'])
def redraw(): ppgplot.pgslct(imagePlot["pgplotHandle"]) ppgplot.pgslw(3) ppgplot.pggray( boostedImage, xlimits[0], xlimits[1] - 1, ylimits[0], ylimits[1] - 1, imageMinMax[0], imageMinMax[1], imagePlot["pgPlotTransform"], ) if plotSources: plotCircles(dr2Objects, margins) if plotHa: reduceddr2cat = [] for selected in extendedHaSources: reduceddr2cat.append(dr2Objects[selected]) plotCircles(reduceddr2cat, margins) if plotGrid: print ("Plotting grid") ppgplot.pgsci(6) xVals = [p[0] for p in pixelGrid] yVals = [p[1] for p in pixelGrid] ppgplot.pgpt(xVals, yVals, 2) if plotPointings: ppgplot.pgsfs(2) ppgplot.pgslw(10) for p in pointings: if p["type"] == "Maximum": ppgplot.pgsci(2) if p["type"] == "Minimum": ppgplot.pgsci(4) ppgplot.pgcirc(p["x"], p["y"], 30) ppgplot.pgslw(1) if plotBrightStars: ppgplot.pgsci(3) ppgplot.pgsfs(2) ppgplot.pgslw(10) for b in brightStars: ppgplot.pgcirc(b["x"], b["y"], 40)
def pggray(self, nccd, imin, imax): """ Plots a CCD using pgplot's pggray function. The plot should have been opened and setup. nccd -- the CCD to plot (0,1,2 ...) imin -- minimum intensity imax -- maximum intensity """ for nw in xrange(len(self.data[nccd])): (ny,nx) = self.data[nccd][nw].shape tr = numpy.empty((6),float) tr[0] = self.off[nccd][nw][0]-1 tr[1] = self.xbin tr[2] = 0. tr[3] = self.off[nccd][nw][1]-1 tr[4] = 0. tr[5] = self.ybin ppgplot.pggray(self.data[nccd][nw], 0, nx-1, 0, ny-1, imin, imax, tr)
def pggray(self, nccd, imin, imax): """ Plots a CCD using pgplot's pggray function. The plot should have been opened and setup. nccd -- the CCD to plot (0,1,2 ...) imin -- minimum intensity imax -- maximum intensity """ for nw in xrange(len(self.data[nccd])): (ny, nx) = self.data[nccd][nw].shape tr = numpy.empty((6), float) tr[0] = self.off[nccd][nw][0] - 1 tr[1] = self.xbin tr[2] = 0. tr[3] = self.off[nccd][nw][1] - 1 tr[4] = 0. tr[5] = self.ybin ppgplot.pggray(self.data[nccd][nw], 0, nx - 1, 0, ny - 1, imin, imax, tr)
(height, width) = numpy.shape(imageData) aspectRatio = float(height) / float(width) print(aspectRatio) """ Set up the PGPLOT windows """ imagePlot = {} imagePlot['pgplotHandle'] = ppgplot.pgopen('/xs') ppgplot.pgpap(paperSize, aspectRatio) ppgplot.pgsvp(0.0, 1.0, 0.0, 1.0) ppgplot.pgswin(0, width, 0, height) # ppgplot.pgenv(0., width,0., height, 1, -2) imagePlot['pgPlotTransform'] = [0, 1, 0, 0, 0, 1] boostedImage = generalUtils.percentiles(imageData, 20, 99) ppgplot.pggray(boostedImage, 0, width - 1, 0, height - 1, 0, 255, imagePlot['pgPlotTransform']) # Determine the RA, DEC of the centre of the image, using the WCS solution found in the FITS header imageCentre = [width / 2, height / 2] ra, dec = wcsSolution.all_pix2world([imageCentre], 1)[0] positionString = generalUtils.toSexagesimal((ra, dec)) print("RA, DEC of image centre is: ", positionString, ra, dec) margins = wcsSolution.all_pix2world([[0, 0], [width, height]], 1) margins = checkMargins(margins) print("ra, dec limits:", margins) print("Looking for bright stars") brightStars = getBrightStars(ra, dec, 0.5)
def redraw(): ppgplot.pggray(boostedImage, xlimits[0], xlimits[1] - 1, ylimits[0], ylimits[1] - 1, imageMinMax[0], imageMinMax[1], imagePlot['pgPlotTransform'])
(height, width) = numpy.shape(imageData) aspectRatio = float(height) / float(width) print aspectRatio """ Set up the PGPLOT windows """ imagePlot = {} imagePlot['pgplotHandle'] = ppgplot.pgopen('/xs') ppgplot.pgpap(paperSize, aspectRatio) ppgplot.pgsvp(0.0, 1.0, 0.0, 1.0) ppgplot.pgswin(0, width, 0, height) # ppgplot.pgenv(0., width,0., height, 1, -2) imagePlot['pgPlotTransform'] = [0, 1, 0, 0, 0, 1] boostedImage = generalUtils.percentiles(imageData, 20, 99) ppgplot.pggray(boostedImage, 0, width - 1, 0, height - 1, 0, 255, imagePlot['pgPlotTransform']) # Determine the RA, DEC of the centre of the image, using the WCS solution found in the FITS header imageCentre = [width / 2, height / 2] ra, dec = wcsSolution.all_pix2world([imageCentre], 1)[0] positionString = generalUtils.toSexagesimal((ra, dec)) print "RA, DEC of image centre is: ", positionString, ra, dec margins = wcsSolution.all_pix2world([[0, 0], [width, height]], 1) margins = checkMargins(margins) print "ra, dec limits:", margins xlimits = (0, width) ylimits = (0, height)
def redraw(): ppgplot.pggray(boostedImage, xlimits[0], xlimits[1]-1, ylimits[0], ylimits[1]-1, imageMinMax[0], imageMinMax[1], imagePlot['pgPlotTransform'])
aspectRatio = float(height)/float(width) print aspectRatio """ Set up the PGPLOT windows """ imagePlot = {} imagePlot['pgplotHandle'] = ppgplot.pgopen('/xs') ppgplot.pgpap(paperSize, aspectRatio) ppgplot.pgsvp(0.0, 1.0, 0.0, 1.0) ppgplot.pgswin(0, width, 0, height) # ppgplot.pgenv(0., width,0., height, 1, -2) imagePlot['pgPlotTransform'] = [0, 1, 0, 0, 0, 1] boostedImage = generalUtils.percentiles(imageData, 20, 99) ppgplot.pggray(boostedImage, 0, width-1, 0, height-1, 0, 255, imagePlot['pgPlotTransform']) # Determine the RA, DEC of the centre of the image, using the WCS solution found in the FITS header imageCentre = [ width/2, height/2] ra, dec = wcsSolution.all_pix2world([imageCentre], 1)[0] positionString = generalUtils.toSexagesimal((ra, dec)) print "RA, DEC of image centre is: ", positionString, ra, dec margins = wcsSolution.all_pix2world([[0, 0], [width, height]], 1) margins = checkMargins(margins) print "ra, dec limits:", margins xlimits = (0, width)
ppgplot.pgenv(0.,fullFramexsize,0.,fullFrameysize, 1, 0) pgPlotTransform = [0, 1, 0, 0, 0, 1] ppgplot.pglab("x", "y", "Initial 10 frame stacked image.") # Display the image on the user's screen image = matplotlib.pyplot.imshow(boostedFullFrame, cmap='gray_r') for s in allSources: x, y = s[0], s[1] matplotlib.pyplot.gca().add_artist(matplotlib.pyplot.Circle((x,y), 10, color='green', fill=False, linewidth=1.0)) if applyShift: for s in topSources: x, y = s[0], s[1] matplotlib.pyplot.gca().add_artist(matplotlib.pyplot.Circle((x,y), 10, color='blue', fill=False, linewidth=1.0)) rows, cols = numpy.shape(boostedFullFrame) ppgplot.pggray(boostedFullFrame, 0, cols-1, 0, rows-1, 0, 255, pgPlotTransform) ppgplot.pgsfs(2) # Set fill style to 'outline' ppgplot.pgsci(3) # Set the colour to 'green' for s in allSources: x, y = s[0], s[1] ppgplot.pgcirc(x,y, 10) """ End of the prework """ rdat.set(1) # Reset back to the first frame frameRange = maximumFrames - startFrame + 1 if arg.numframes!=None: requestedNumFrames = arg.numframes
aspectRatio = float(height) / float(width) print (aspectRatio) """ Set up the PGPLOT windows """ imagePlot = {} imagePlot["pgplotHandle"] = ppgplot.pgopen("/xs") ppgplot.pgpap(paperSize, aspectRatio) ppgplot.pgsvp(0.0, 1.0, 0.0, 1.0) ppgplot.pgswin(0, width, 0, height) # ppgplot.pgenv(0., width,0., height, 1, -2) imagePlot["pgPlotTransform"] = [0, 1, 0, 0, 0, 1] boostedImage = generalUtils.percentiles(imageData, 20, 99) ppgplot.pggray(boostedImage, 0, width - 1, 0, height - 1, 0, 255, imagePlot["pgPlotTransform"]) # Determine the RA, DEC of the centre of the image, using the WCS solution found in the FITS header imageCentre = [width / 2, height / 2] ra, dec = wcsSolution.all_pix2world([imageCentre], 1)[0] positionString = generalUtils.toSexagesimal((ra, dec)) print ("RA, DEC of image centre is: ", positionString, ra, dec) margins = wcsSolution.all_pix2world([[0, 0], [width, height]], 1) margins = checkMargins(margins) print ("ra, dec limits:", margins) print ("Looking for bright stars") brightStars = getBrightStars(ra, dec, 0.5)
ppgplot.pgenv(0, width-1, 0, height-1, 0, 0) redReference = numpy.array(images[0].split()[0]) redTotal = numpy.zeros(numpy.shape(redReference)) greenTotal = numpy.zeros(numpy.shape(redReference)) blueTotal = numpy.zeros(numpy.shape(redReference)) for frameIndex, image in enumerate(images): redData, greenData, blueData = image.split() # redData.show() # print redData redData = numpy.array(redData) ppgplot.pgslct(previewWindow) ppgplot.pggray(redData, 0, width-1, 0, height-1, 0, 255, pgPlotTransform) # correlation = scipy.signal.correlate2d(redData, redReference, mode='same', boundary='symm') shift = phase_cor(redData, redReference) y, x = numpy.unravel_index(numpy.argmax(shift), shift.shape) if x > width/2: xd = width - x else: xd = -x if y > height/2: yd = height - y else: yd = -y print "Offset from first frame:", x, y, xd, yd
mainPGPlotWindow = ppgplot.pgopen(arg.device) ppgplot.pgask(True) ppgplot.pgpap(3.0, 1.8) # pgPlotTransform = [0, 1, 0, 0, 0, 1] spectrum = spectra[0] xScale = (max(spectrum.wavelengths) - min(spectrum.wavelengths)) / xSize if hasEphemeris: yScale = numPhaseBins else: yScale = len(spectra) pgPlotTransform = [min(spectrum.wavelengths), xScale, 0, 0, 0, 1/float(yScale)] lowerWavelength = min(spectrum.wavelengths) upperWavelength = max(spectrum.wavelengths) ppgplot.pgenv( min(spectrum.wavelengths), max(spectrum.wavelengths), 0, 2, 0, 0) ppgplot.pggray(generalUtils.percentiles(trailBitmap, 20, 99), 0, xSize-1 , 0, ySize-1 , 255, 0, pgPlotTransform) # ppgplot.pggray(trailBitmap, 0, xSize-1 , 0, ySize-1 , numpy.max(trailBitmap), numpy.min(trailBitmap), pgPlotTransform) epochs = [s.HJD for s in spectra] startHJD = min(epochs) endHJD = max(epochs) if arg.title is None: title = "" else: title = arg.title if hasEphemeris: # ppgplot.pglab("wavelength [%s]"%spectrum.wavelengthUnits, "Phase", "%s - %s"%(str(startHJD), str(endHJD))) ppgplot.pglab("wavelength [%s]"%spectrum.wavelengthUnits, "Phase", title) else: #ppgplot.pglab("wavelength [%s]"%spectrum.wavelengthUnits, "Spectrum number", "%s - %s"%(str(spectra[0].HJD), str(spectra[-1].HJD))) ppgplot.pglab("wavelength [%s]"%spectrum.wavelengthUnits, "Spectrum number", title)
fullFrame = numpy.zeros((fullFrameysize, fullFramexsize)) for w in allWindows: if (arg.stack): boostedImage = ultracamutils.percentiles(w.stackedData, 20, 99) else: boostedImage = ultracamutils.percentiles(w.data, 20, 99) xll = w.xll/w.xbin - xmin xsize = w.nx yll = w.yll/w.ybin - ymin ysize = w.ny fullFrame[yll:yll+ysize, xll:xll+xsize] = fullFrame[yll:yll+ysize, xll:xll+xsize] + boostedImage rows, cols = numpy.shape(fullFrame) # Draw the grayscale bitmap ppgplot.pggray(fullFrame, 0, cols-1 , 0, rows-1 , 0, 255, pgPlotTransform) # Draw the full reference aperture list ppgplot.pgsci(3) for s in sourceList.getSources(): (x, y) = s.abs_position ppgplot.pgcirc(x, y, 10) # ppgplot.pgslct(bitmapView) ppgplot.pgsci(2) for index, s in enumerate(referenceApertures.getSources()): window = allWindows[s.windowIndex] center = s.latestPosition if s.recentFail:
if (arg.stack): boostedImage = ultracamutils.percentiles(w.stackedData, 20, 99) else: boostedImage = ultracamutils.percentiles(w.data, 20, 99) xll = w.xll/w.xbin - xmin xsize = w.nx yll = w.yll/w.ybin - ymin ysize = w.ny fullFrame[yll:yll+ysize, xll:xll+xsize] = fullFrame[yll:yll+ysize, xll:xll+xsize] + boostedImage dimensions = numpy.shape(fullFrame) rows = dimensions[0] cols = dimensions[1] # Draw the grayscale bitmap ppgplot.pggray(fullFrame, 0, cols-1 , 0, rows-1 , 0, 255, pgPlotTransform) # Draw the full reference aperture list ppgplot.pgsci(3) for s in sourceList.getSources(): (x, y) = s.abs_position ppgplot.pgcirc(x, y, 10) margins = 10 if arg.preview: ppgplot.pgslct(bitmapView) ppgplot.pgsci(2) plotColour = [1, 2, 3, 4, 5, 6] for index, s in enumerate(referenceApertures.getSources()):