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 selectDev(devID=''): """ DES: select an open device INP: (int) device ID """ global CurrentDev, DevList if devID in DevList: ppgplot.pgslct(devID) # select the deviceID CurrentDev = ppgplot.pgqid() # store the actual pgplot deviceID else: __MessHand.error("this is not an open device: " + ` devID `) __queryDev()
def closeDev(devID='current'): """ DES: close selected device INP: (int) device ID, 'all','current' (default) """ global CurrentDev, DevList if devID in ['current', 'curren', 'curre', 'curr', 'cur']: __MessHand.longinfo("closing the current device") ppgplot.pgclos() DevList.remove(CurrentDev) if not DevList == []: ppgplot.pgslct(DevList[0]) CurrentDev = ppgplot.pgqid() # store the actual deviceID else: CurrentDev = 0 elif devID in ['all']: __MessHand.longinfo("closing all devices") for device in DevList: ppgplot.pgslct(device) ppgplot.pgclos() DevList = [] CurrentDev = 0 elif devID in DevList: __MessHand.longinfo("closing device " + ` devID `) ppgplot.pgslct(devID) ppgplot.pgclos() DevList.remove(devID) if devID == CurrentDev and DevList != []: ppgplot.pgslct(DevList[0]) CurrentDev = ppgplot.pgqid() # store the actual deviceID else: ppgplot.pgslct(CurrentDev) else: __MessHand.error("this is not an open device: " + ` devID `) __queryDev()
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 getChiSqByParameters(params, *args): global iteration, mainPlotWindow, currentPlotWindow, colour, inclination, phase print "Params:", params beta = params[0] log_lambda = params[1] scale_factor = params[2] linear_offset = params[3] print "Args:", args temperature = args[0] field = args[1] # cos(theta) = cos(i)cos(beta) - sin(i)sin(beta)cos(phi + pi/2) cosTheta = math.cos(radians(inclination)) * math.cos(radians(beta)) - math.sin(radians(inclination)) * math.sin(radians(beta))*math.cos(phase + math.pi/2.) angle = math.acos(cosTheta) / math.pi * 180 print "Angle: %f [deg], Field: %f [MG], Temperature:%f [keV], log_lambda: %f, scale: %f, offset: %f"%(angle, field, temperature, log_lambda, scale_factor, linear_offset) model = getSampledModel(observedSpectrum.wavelengths, angle, field, temperature, log_lambda) model = [m * scale_factor + linear_offset for m in model] chi = computeChiSq(observedSpectrum, model) allChiSqs.append(chi) print "Chi-squared:", chi startWavelength = min(observedSpectrum.wavelengths) endWavelength = max(observedSpectrum.wavelengths) # Draw the most recent iteration ppgplot.pgslct(currentPlotWindow) ppgplot.pgsci(1) ppgplot.pgenv(startWavelength, endWavelength, lowerFlux, upperFlux, 0, 0) ppgplot.pgline(observedSpectrum.wavelengths, observedSpectrum.flux) ppgplot.pgsci(4) ppgplot.pgline(observedSpectrum.wavelengths, model) ppgplot.pgsci(1) ppgplot.pglab("wavelength", "flux", "Current fit: %d"%iteration) # Overplot the iteration on the original diagram print "overplotting" ppgplot.pgslct(mainPlotWindow) ppgplot.pgsci(colour) ppgplot.pgline(observedSpectrum.wavelengths, model) colour += 1 if colour>15: colour = 1 ppgplot.pgsci(1) # Re-generate the Chi-Squared plot ppgplot.pgslct(chiSqPlotWindow) if iteration > 9: ppgplot.pgenv(0, iteration+1, 0, max(allChiSqs), 0, 0) else: ppgplot.pgenv(0, 10, 0, max(allChiSqs), 0, 0) iterations = range(iteration+1) ppgplot.pgpt(iterations, allChiSqs, 2) minCh = min(allChiSqs) medCh = numpy.median(allChiSqs) maxCh = max(allChiSqs) ppgplot.pglab("Iteration [n]", "Chi-squared", "Chi-squared values [%.2f, %.2f, %.2f]"%(minCh, medCh, maxCh)) iteration += 1 return chi
for xStep in range(borderMask, width - borderMask, superPixelSize): x1 = xStep x2 = xStep + superPixelSize y1 = yStep y2 = yStep + superPixelSize xpts = [x1, x1, x2, x2] ypts = [y1, y2, y2, y1] bitmapX = (x1 - borderMask) / superPixelSize bitmapY = (y1 - borderMask) / superPixelSize ppgplot.pgsfs(2) ppgplot.pgsci(4) ppgplot.pgpoly(xpts, ypts) superPixel = maskedImageCopy[y1:y2, x1:x2] if previewSuperPixel: ppgplot.pgslct(spPreview['pgplotHandle']) boostedPreview = generalUtils.percentiles( superPixel, 20, 99) ppgplot.pggray(boostedPreview, 0, superPixelSize - 1, 0, superPixelSize - 1, 0, 255, imagePlot['pgPlotTransform']) ppgplot.pgslct(imagePlot['pgplotHandle']) superPixelObject = {} mean = float(numpy.ma.mean(superPixel)) if math.isnan(mean): continue superPixelObject['mean'] = mean superPixelObject['median'] = numpy.ma.median(superPixel) superPixelObject['max'] = numpy.ma.min(superPixel) superPixelObject['min'] = numpy.ma.max(superPixel) superPixelObject['x1'] = x1
ppgplot.pgsci(1) ppgplot.pgenv(lowerWavelength, upperWavelength, lowerFlux, upperFlux, 0, 0) ppgplot.pgline(spectrum.wavelengths, spectrum.flux) ppgplot.pglab("wavelength", "flux", spectrum.objectName) observedArea = spectrum.integrate() print "Wavelength range of observations:", observedSpectrumRange # modelPlotWindow = ppgplot.pgopen(arg.device) # pgPlotTransform = [0, 1, 0, 0, 0, 1] # ppgplot.pgask(False) currentPlotWindow = ppgplot.pgopen(arg.device) ppgplot.pgask(False) pgPlotTransform = [0, 1, 0, 0, 0, 1] ppgplot.pgslct(currentPlotWindow) ppgplot.pgenv(lowerWavelength, upperWavelength, lowerFlux, upperFlux, 0, 0) ppgplot.pgline(spectrum.wavelengths, spectrum.flux) ppgplot.pglab("wavelength", "flux", "Current fit") chiSqPlotWindow = ppgplot.pgopen(arg.device) ppgplot.pgask(False) pgPlotTransform = [0, 1, 0, 0, 0, 1] ppgplot.pgslct(chiSqPlotWindow) ppgplot.pgenv(0, 10, 0, 100, 0, 0) ppgplot.pglab("Iteration [n]", "Chi-squared", "Chi-squared values") colour = 2 allChiSqs = []
objects.append(target) print "%d targets loaded"%len(objects) #for o in objects: # o.filterData('mag', 10, 16.5) if arg.ps: device = "lightcurves.ps/ps" else: device = "/xs" PGPlotWindow = ppgplot.pgopen(device) pgPlotTransform = [0, 1, 0, 0, 0, 1] ppgplot.pgslct(PGPlotWindow) ppgplot.pgsci(1) ppgplot.pgask(False) for index, o in enumerate(objects): HJD = o.getColumn('HJD') mag = o.getColumn('mag') err = o.getColumn('err') startDate = numpy.min(HJD) dates = [ d - startDate for d in HJD] endDate = numpy.max(HJD) magMax = numpy.max(mag) + err[numpy.argmax(mag)] magMin = numpy.min(mag) - err[numpy.argmin(mag)] meanError = numpy.mean(err) print "%s Start date: %f, End date: %f"%(o.id, startDate, endDate) ppgplot.pgenv(0, numpy.max(dates), magMax + meanError*2, magMin - meanError*2, 0, 0) ppgplot.pgpt(dates, mag)
ppgplot.pgsci(1) 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
data['flux_err'] = float(fields[3]) print data modelledData.appendData(data) dataFile.close() print "%d targets loaded"%len(objects) observedData.convertFluxMagnitude() modelledData.convertFluxMagnitude() if arg.ps: device = arg.name + "_lcurve.ps/ps" else: device = "/xs" PGPlotWindow = ppgplot.pgopen(device) ppgplot.pgask(True) pgPlotTransform = [0, 1, 0, 0, 0, 1] ppgplot.pgslct(PGPlotWindow) ppgplot.pgsci(1) ppgplot.pgask(False) phases = observedData.getColumn('phase') flux = observedData.getColumn('flux') flux_err = observedData.getColumn('flux_err') flux_err = [f/10 for f in flux_err] flux = [f * 3631E3 for f in flux] flux_err = [f * 3631E3 for f in flux_err] mag = observedData.getColumn('mag') err = observedData.getColumn('err') maxFlux = 0 for f, fe in zip(flux, flux_err): if f + fe > maxFlux: maxFlux = f + fe # Duplicate data out to phase 2.0
for yStep in range(borderMask, height - borderMask, superPixelSize): for xStep in range(borderMask, width - borderMask, superPixelSize): x1 = xStep x2 = xStep + superPixelSize y1 = yStep y2 = yStep + superPixelSize xpts = [x1, x1, x2, x2] ypts = [y1, y2, y2, y1] bitmapX = (x1 - borderMask) / superPixelSize bitmapY = (y1 - borderMask) / superPixelSize ppgplot.pgsfs(2) ppgplot.pgsci(4) ppgplot.pgpoly(xpts, ypts) superPixel = maskedImageCopy[y1:y2, x1:x2] if previewSuperPixel: ppgplot.pgslct(spPreview["pgplotHandle"]) boostedPreview = generalUtils.percentiles(superPixel, 20, 99) ppgplot.pggray( boostedPreview, 0, superPixelSize - 1, 0, superPixelSize - 1, 0, 255, imagePlot["pgPlotTransform"], ) ppgplot.pgslct(imagePlot["pgplotHandle"]) superPixelObject = {} mean = float(numpy.ma.mean(superPixel))
recordedData.loadFromFile(logFilename) recordedData.sortByHJD() # print recordedData """ mainPGPlotWindow = ppgplot.pgopen(arg.device) ppgplot.pgask(False) pgPlotTransform = [0, 1, 0, 0, 0, 1] yUpper = 2.5 yLower = -0.5 fitPGPlotWindow = ppgplot.pgopen(arg.device) ppgplot.pgask(False) for spectrum in spectra: ppgplot.pgslct(mainPGPlotWindow) ppgplot.pgsci(1) lowerWavelength = min(spectrum.wavelengths) upperWavelength = max(spectrum.wavelengths) lowerFlux = min(spectrum.flux) upperFlux = max(spectrum.flux) ppgplot.pgenv(lowerWavelength, upperWavelength, lowerFlux, upperFlux, 0, 0) ppgplot.pgbin(spectrum.wavelengths, spectrum.flux) ppgplot.pglab("wavelength [%s]"%spectrum.wavelengthUnits, "flux [%s]"%spectrum.fluxUnits, "%s [%s]"%(spectrum.objectName, spectrum.loadedFromFilename)) # Grab the continuum from either side of the spectrum lowerCut = 6540 upperCut = 6585 continuumSpectrum = copy.deepcopy(spectrum)
allWindows[windowIndex].addToStack(image) if arg.preview: 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 ppgplot.pgslct(mainPreview) (rows, cols) = numpy.shape(fullFrame) ppgplot.pggray(fullFrame, 0, cols-1, 0, rows-1, 0, 255, pgPlotTransform) ppgplot.pgsci(3) ppgplot.pgsfs(2) for s in allSources: (x, y) = s ppgplot.pgcirc(x, y, 10) # Now also draw the zoomed in region around the first aperture if (applyShift): (x, y) = masterApertureList[0] croppedFrame = fullFrame[y-10:y+10, x-9:x+10] ppgplot.pgslct(zoomedAperture) rows, cols = numpy.shape(croppedFrame) ppgplot.pggray(croppedFrame, 0, cols-1, 0, rows-1, 0, 255, pgPlotTransform)
timeLeftString = str(hours).zfill(2) + ":" + str(mins).zfill(2) + ":" + str(secs).zfill(2) ccdFrame = rdat() statusString = "\r%s Frame: [%d/%d]"%(timeLeftString, trueFrameNumber, frameRange) sys.stdout.write(statusString) sys.stdout.flush() windows = ccdFrame[0] for windowIndex, w in enumerate(windows): image = w._data allWindows[windowIndex].setData(image) if arg.preview: ppgplot.pgslct(bitmapView['pgplotHandle']) ppgplot.pgbbuf() 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)
timeLeftString = str(hours).zfill(2) + ":" + str(mins).zfill(2) + ":" + str(secs).zfill(2) ccdFrame = rdat() statusString = "\r%s Frame: [%d/%d]"%(timeLeftString, trueFrameNumber, frameRange) sys.stdout.write(statusString) sys.stdout.flush() windows = ccdFrame[0] for windowIndex, w in enumerate(windows): image = w._data allWindows[windowIndex].setData(image) if arg.preview: ppgplot.pgslct(bitmapView) 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 dimensions = numpy.shape(fullFrame) rows = dimensions[0] cols = dimensions[1]