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 plotgal(xg,yg,final,finalsf,ncl): ppgplot.pgslw(6) ppgplot.pgsls(1) xmin = (-1.*c.pscale[ncl]*(c.xc[ncl]-1)) xmax = (c.pscale[ncl]*(c.xmax[ncl]-c.xc[ncl])) ymin = (-1.*c.pscale[ncl]*(c.yc[ncl]-1)) ymax = (c.pscale[ncl]*(c.ymax[ncl]-c.yc[ncl])) ppgplot.pgbox("",0.0,0,"L",0.0,0) dx=5. ppgplot.pgenv(xmin-dx,xmax+dx,ymin-dx,ymax+dx,0) ppgplot.pglab("\gD DEC (\")","\gD RA (\")","") ppgplot.pgtext(-4,-4,"X") r = (0.5*c.r200pix[ncl]*c.pscale[ncl]) ppgplot.pgslw(1) ppgplot.pgsls(2) ppgplot.pgsfs(2) ppgplot.pgcirc(0,0,r) #print "cluster ",ncl," r200: ",c.r200pix[ncl],c.r200Mpc[ncl], " Mpc" ppgplot.pgslw(3) ppgplot.pgsls(1) x = (xg - c.xc[ncl])*c.pscale[ncl] y = (yg - c.yc[ncl])*c.pscale[ncl] x = (N.compress((final > 0) & (finalsf < 1), xg) - c.xc[ncl])*c.pscale[ncl] y = (N.compress((final > 0) & (finalsf < 1), yg) - c.yc[ncl])*c.pscale[ncl] ppgplot.pgpt(x,y,22) x = (N.compress((final > 0) & (finalsf > 0), xg) - c.xc[ncl])*c.pscale[ncl] y = (N.compress((final > 0) & (finalsf > 0), yg) - c.yc[ncl])*c.pscale[ncl] ppgplot.pgpt(x,y,18)
def plotsigsff(sig, sf, file, nbin): psplot = file + ".ps" psplotinit(psplot) tot = N.ones(len(sf), 'f') (sigbin, sfbin) = my.binitsumequal(sig, sf, nbin) (sigbin, totbin) = my.binitsumequal(sig, tot, nbin) print sfbin print totbin (sff, sfferr) = my.ratioerror(sfbin, totbin) ppgplot.pgbox("", 0.0, 0, "L", 0.0, 0) ymin = -.05 ymax = 1.05 xmin = min(sig) - 10. #xmax=max(sig)-200. xmax = 350. ppgplot.pgenv(xmin, xmax, ymin, ymax, 0) ppgplot.pglab("\gS\d5\u (gal/Mpc\u2\d)", "Fraction EW([OII])>4 \(2078)", "") ppgplot.pgsls(1) #dotted ppgplot.pgslw(4) #line width sig = N.array(sig, 'f') sff = N.array(sff, 'f') ppgplot.pgsci(2) ppgplot.pgline(sigbin, sff) ppgplot.pgsci(1) ppgplot.pgpt(sigbin, sff, 17) my.errory(sigbin, sff, sfferr) ppgplot.pgend()
def _redrawHueGraph(self, hueI, widget, tupleToErase=None): oldFill = widget.rootWidget.plotter.lowLevelPlotter.getFill() oldColour = widget.rootWidget.plotter.lowLevelPlotter.getColour() if not tupleToErase is None: # Draw the start and end points in the frame bkg colour before drawing all points and lines in white: colour = widget.parent.widgetPlotter.bgColour widget.rootWidget.plotter.lowLevelPlotter.setColour(colour) xs = nu.array([tupleToErase[0]]) ys = nu.array([tupleToErase[1]]) xs = widget.sizes[0].range.lo * ( 1.0 - xs) + widget.sizes[0].range.hi * xs ys = widget.sizes[1].range.lo * ( 1.0 - ys) + widget.sizes[1].range.hi * ys pgplot.pgpt(xs, ys, 0) # point type 0 is squares. # Draw the canvas background: widget.widgetPlotter.draw() # Now draw the points and lines: widget.rootWidget.plotter.lowLevelPlotter.setColour('white') (xs, ys) = self.cm.hueGraphs[hueI].unpackValues() xs = widget.sizes[0].range.lo * (1.0 - xs) + widget.sizes[0].range.hi * xs ys = widget.sizes[1].range.lo * (1.0 - ys) + widget.sizes[1].range.hi * ys pgplot.pgline(xs, ys) pgplot.pgpt(xs, ys, 0) # point type 0 is squares. widget.rootWidget.plotter.lowLevelPlotter.setFill(oldFill) widget.rootWidget.plotter.lowLevelPlotter.setColour(oldColour)
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
def xysimple(x, y, xlabel, ylabel): xmax = max(x) xmin = min(x) ymax = max(y) ymin = min(y) ppgplot.pgbox("", 0.0, 0, "", 0.0, 0) ppgplot.pgenv(xmin, xmax, ymin, ymax, 0) ppgplot.pglab(xlabel, ylabel, "") ppgplot.pgpt(x, y, 3)
def drawPoints(self, xs, ys, pointStyle=None): if not self.plotDeviceIsOpened: raise ValueError("You have not yet opened a PGPLOT device.") if pointStyle is None: localPointStyle = self.pointStyle else: localPointStyle = pointStyle pgplot.pgpt(xs, ys, localPointStyle)
def drawPoint(self, x, y, pointStyle=None): if not self.plotDeviceIsOpened: raise ValueError("You have not yet opened a PGPLOT device.") if pointStyle is None: localPointStyle = self.pointStyle else: localPointStyle = pointStyle xs = nu.array([x]) ys = nu.array([y]) pgplot.pgpt(xs, ys, localPointStyle)
def dm_time_plot(dms, times, sigmas, dm_arr, sigma_arr, time_arr, Total_observed_time, xwin): """ Plot DM vs Time subplot for the spd plots. Input: dms: list of dms of single pulse events to be plotted. times: list of times of single pulse events to be plotted. sigmas: list of sigmas of single pulse events to be plotted. dm_arr: array of dms of the main single pulse group (plotted in black). sigma_arr: array of sigmas of the main single pulse group (plotted in black). time_arr: array of times of single pulse group (plotted in black). Total_observed_time: float : Total observation time xwin: True or False. Use xwin or vcps window. """ min_dm = Num.min(dms) max_dm = Num.max(dms) ppgplot.pgswin(0, Total_observed_time, min_dm, max_dm) ppgplot.pgsch(0.8) ppgplot.pgslw(3) ppgplot.pgbox("BCNST", 0, 0, "BCNST", 0, 0) ppgplot.pgslw(3) ppgplot.pgmtxt('B', 2.5, 0.5, 0.5, "Time (s)") ppgplot.pgmtxt('L', 1.8, 0.5, 0.5, "DM (pc cm\u-3\d)") snr_range = 12.0 cand_symbols = [] cand_symbols_group = [] for i in range(len(sigmas)): if sigmas[i] > 20.00: sigmas[i] = 20.0 cand_symbol = int((sigmas[i] - 5.0) / snr_range * 6.0 + 20.5) cand_symbols.append(min(cand_symbol, 26)) cand_symbols = Num.array(cand_symbols) for i in range(len(dm_arr)): cand_symbol = int((sigma_arr[i] - 5.0) / snr_range * 6.0 + 20.5) cand_symbols_group.append(min(cand_symbol, 26)) cand_symbols_group = Num.array(cand_symbols_group) dms = Num.array(dms) times = Num.array(times) dm_arr = Num.array(dm_arr) time_arr = Num.array(time_arr) for ii in [26, 25, 24, 23, 22, 21, 20]: inds = Num.nonzero(cand_symbols == ii)[0] ppgplot.pgshls(1, 0.0, 0.5, 0.0) ppgplot.pgpt(times[inds], dms[inds], ii) for ii in [26, 25, 24, 23, 22, 21, 20]: inds_1 = Num.nonzero(cand_symbols_group == ii)[0] if xwin: ppgplot.pgshls(1, 0.0, 0.8, 0.0) else: ppgplot.pgshls(1, 0.0, 0.0, 0.0) ppgplot.pgpt(time_arr[inds_1], dm_arr[inds_1], ii)
def dm_time_plot(dms, times, sigmas, dm_arr, sigma_arr, time_arr, Total_observed_time, xwin): """ Plot DM vs Time subplot for the spd plots. Input: dms: list of dms of single pulse events to be plotted. times: list of times of single pulse events to be plotted. sigmas: list of sigmas of single pulse events to be plotted. dm_arr: array of dms of the main single pulse group (plotted in black). sigma_arr: array of sigmas of the main single pulse group (plotted in black). time_arr: array of times of single pulse group (plotted in black). Total_observed_time: float : Total observation time xwin: True or False. Use xwin or vcps window. """ min_dm = Num.min(dms) max_dm = Num.max(dms) ppgplot.pgswin(0, Total_observed_time, min_dm, max_dm) ppgplot.pgsch(0.8) ppgplot.pgslw(3) ppgplot.pgbox("BCNST", 0, 0, "BCNST", 0, 0) ppgplot.pgslw(3) ppgplot.pgmtxt('B', 2.5, 0.5, 0.5, "Time (s)") ppgplot.pgmtxt('L', 1.8, 0.5, 0.5, "DM (pc cm\u-3\d)") snr_range = 12.0 cand_symbols = [] cand_symbols_group = [] for i in range(len(sigmas)): if sigmas[i] > 20.00: sigmas[i] = 20.0 cand_symbol = int((sigmas[i] - 5.0)/snr_range * 6.0 + 20.5) cand_symbols.append(min(cand_symbol, 26)) cand_symbols = Num.array(cand_symbols) for i in range(len(dm_arr)): cand_symbol = int((sigma_arr[i] - 5.0)/snr_range * 6.0 + 20.5) cand_symbols_group.append(min(cand_symbol, 26)) cand_symbols_group = Num.array(cand_symbols_group) dms = Num.array(dms) times = Num.array(times) dm_arr = Num.array(dm_arr) time_arr = Num.array(time_arr) for ii in [26, 25, 24, 23, 22, 21, 20]: inds = Num.nonzero(cand_symbols == ii)[0] ppgplot.pgshls(1, 0.0, 0.5, 0.0) ppgplot.pgpt(times[inds], dms[inds], ii) for ii in [26, 25, 24, 23, 22, 21, 20]: inds_1 = Num.nonzero(cand_symbols_group == ii)[0] if xwin: ppgplot.pgshls(1, 0.0, 0.8, 0.0) else: ppgplot.pgshls(1, 0.0, 0.0, 0.0) ppgplot.pgpt(time_arr[inds_1], dm_arr[inds_1], ii)
def drawErrorBars(self, xs, ys, yUncs, pointStyle=None): if not self.plotDeviceIsOpened: raise ValueError("You have not yet opened a PGPLOT device.") if pointStyle is None: localPointStyle = self.pointStyle else: localPointStyle = pointStyle pgplot.pgpt(xs, ys, localPointStyle) yLos = ys - yUncs yHis = ys + yUncs for i in range(len(xs)): self.drawLine(xs[i], yLos[i], xs[i], yHis[i])
def makeplot(): psplotinit("noise.ps") DATAMIN = 0. DATAMAX = 15. ppgplot.pgbox("", 0.0, 0, "L", 0.0, 0) #print "making graph, ncl = ",ncl path = os.getcwd() f = path.split('/') #print path #print f prefix = f[4] title = prefix ymin = -.05 ymax = max(aveaperr) + .1 #ymax=10. ppgplot.pgenv(DATAMIN, DATAMAX, ymin, ymax, 0) ppgplot.pglab("linear size N of aperture (pixel)", "rms in Sky (ADU/s)", title) ppgplot.pgsci(2) #red ppgplot.pgslw(4) #line width x = N.sqrt(avearea) y = aveaperr ppgplot.pgpt(x, y, 7) #errory(x,y,erry) ppgplot.pgsci(1) #black #ppgplot.pgpt(isoarea,fluxerriso,3) #x1=N.sqrt(contsubisoarea) #y1=contsuberr #x1=N.sqrt(isoarea) #y1=fluxerriso #y=n*y1 #ppgplot.pgpt(x1,y1,1) #ppgplot.pgsci(4)#blue #ppgplot.pgpt(x1,y,1) #ppgplot.pgsci(1)#black x = N.arange(0, 50, 1) y = x * (a + b * a * x) #y=N.sqrt(x)*.02 ppgplot.pgline(x, y) #errory(x,y,erry) ppgplot.pgend()
def plotsig10sffall(sigspec, sigphot, sf, file, nbin): psplot = file + ".ps" psplotinit(psplot) ppgplot.pgbox("", 0.0, 0, "L", 0.0, 0) ymin = -.01 ymax = 1.01 #xmin=min(sigspec)-10. #xmax=max(sig)-200. #xmax=400. xmin = -1. xmax = 2.7 ppgplot.pgenv(xmin, xmax, ymin, ymax, 0, 10) ppgplot.pglab("\gS\d10\u (gal/Mpc\u2\d)", "Fraction EW([OII])>4 \(2078)", "") ppgplot.pgsls(1) #dotted ppgplot.pgslw(4) #line width tot = N.ones(len(sf), 'f') (sigbin, sfbin) = my.binitsumequal(sigspec, sf, nbin) (sigbin, totbin) = my.binitsumequal(sigspec, tot, nbin) (sff, sfferr) = my.ratioerror(sfbin, totbin) #sig=N.array(sig,'f') #sff=N.array(sff,'f') ppgplot.pgsci(2) sigbin = N.log10(sigbin) ppgplot.pgline(sigbin, sff) ppgplot.pgsci(1) ppgplot.pgpt(sigbin, sff, 17) my.errory(sigbin, sff, sfferr) (sigbin, sfbin) = my.binitsumequal(sigphot, sf, nbin) (sigbin, totbin) = my.binitsumequal(sigphot, tot, nbin) (sff, sfferr) = my.ratioerror(sfbin, totbin) #sig=N.array(sig,'f') #sff=N.array(sff,'f') ppgplot.pgslw(4) #line width ppgplot.pgsci(4) sigbin = N.log10(sigbin) ppgplot.pgline(sigbin, sff) ppgplot.pgsci(1) ppgplot.pgpt(sigbin, sff, 21) #my.errory(sigbin,sff,sfferr) ppgplot.pgend()
def pgplot(slot, plotterHandle): print "We are about to plot: %s"%(slot) lightcurveView = ppgplot.pgopen('/xs') xValues = slot.photometry.times xValues = numpy.arange(0, len(xValues)) yValues = slot.getColumn("Counts") ppgplot.pgenv(min(xValues), max(xValues), min(yValues), max(yValues), 0, 0) ppgplot.pgask(False) ppgplot.pgsci(2) ppgplot.pgpt(xValues, yValues, 1) ppgplot.pgclos() return
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 dm_time_plot(dms, times, sigmas, dm_arr, sigma_arr, time_arr, Total_observed_time, xwin): """ Plot DM vs Time. """ min_dm = Num.min(dms) max_dm = Num.max(dms) ppgplot.pgsvp(0.48, 0.97, 0.1, 0.54) ppgplot.pgswin(0, Total_observed_time, min_dm, max_dm) ppgplot.pgsch(0.8) ppgplot.pgslw(3) ppgplot.pgbox("BCNST", 0, 0, "BCNST", 0, 0) ppgplot.pgslw(3) ppgplot.pgmtxt('B', 2.5, 0.5, 0.5, "Time (s)") ppgplot.pgmtxt('L', 1.8, 0.5, 0.5, "DM (pc cm\u-3\d)") snr_range = 12.0 cand_symbols = [] cand_symbols_group = [] for i in range(len(sigmas)): if sigmas[i] > 20.00: sigmas[i] = 20.0 cand_symbol = int((sigmas[i] - 5.0) / snr_range * 6.0 + 20.5) cand_symbols.append(min(cand_symbol, 26)) cand_symbols = Num.array(cand_symbols) for i in range(len(dm_arr)): cand_symbol = int((sigma_arr[i] - 5.0) / snr_range * 6.0 + 20.5) cand_symbols_group.append(min(cand_symbol, 26)) cand_symbols_group = Num.array(cand_symbols_group) dms = Num.array(dms) times = Num.array(times) dm_arr = Num.array(dm_arr) time_arr = Num.array(time_arr) for ii in [26, 25, 24, 23, 22, 21, 20]: inds = Num.nonzero(cand_symbols == ii)[0] ppgplot.pgshls(1, 0.0, 0.5, 0.0) ppgplot.pgpt(times[inds], dms[inds], ii) for ii in [26, 25, 24, 23, 22, 21, 20]: inds_1 = Num.nonzero(cand_symbols_group == ii)[0] if xwin: ppgplot.pgshls(1, 0.0, 0.8, 0.0) else: ppgplot.pgshls(1, 0.0, 0.0, 0.0) ppgplot.pgpt(time_arr[inds_1], dm_arr[inds_1], ii)
def dm_time_plot(dms, times, sigmas, dm_arr, sigma_arr, time_arr, Total_observed_time, xwin): """ Plot DM vs Time. """ min_dm = Num.min(dms) max_dm = Num.max(dms) ppgplot.pgsvp(0.48, 0.97, 0.1, 0.54) ppgplot.pgswin(0, Total_observed_time, min_dm, max_dm) ppgplot.pgsch(0.8) ppgplot.pgslw(3) ppgplot.pgbox("BCNST", 0, 0, "BCNST", 0, 0) ppgplot.pgslw(3) ppgplot.pgmtxt('B', 2.5, 0.5, 0.5, "Time (s)") ppgplot.pgmtxt('L', 1.8, 0.5, 0.5, "DM (pc cm\u-3\d)") snr_range = 12.0 cand_symbols = [] cand_symbols_group = [] for i in range(len(sigmas)): if sigmas[i] > 20.00: sigmas[i] = 20.0 cand_symbol = int((sigmas[i] - 5.0)/snr_range * 6.0 + 20.5) cand_symbols.append(min(cand_symbol, 26)) cand_symbols = Num.array(cand_symbols) for i in range(len(dm_arr)): cand_symbol = int((sigma_arr[i] - 5.0)/snr_range * 6.0 + 20.5) cand_symbols_group.append(min(cand_symbol, 26)) cand_symbols_group = Num.array(cand_symbols_group) dms = Num.array(dms) times = Num.array(times) dm_arr = Num.array(dm_arr) time_arr = Num.array(time_arr) for ii in [26, 25, 24, 23, 22, 21, 20]: inds = Num.nonzero(cand_symbols == ii)[0] ppgplot.pgshls(1, 0.0, 0.5, 0.0) ppgplot.pgpt(times[inds], dms[inds], ii) for ii in [26, 25, 24, 23, 22, 21, 20]: inds_1 = Num.nonzero(cand_symbols_group == ii)[0] if xwin: ppgplot.pgshls(1, 0.0, 0.8, 0.0) else: ppgplot.pgshls(1, 0.0, 0.0, 0.0) ppgplot.pgpt(time_arr[inds_1], dm_arr[inds_1], ii)
def compdiff(x, y, xlabel, ylabel): xmax = max(x) xmin = min(x) ymax = max(y) ymin = min(y) ave = N.average(N.compress((x < 21) & (im1.sn > 3), y)) std = scipy.stats.std(N.compress((x < 21) & (im1.sn > 3), y)) ppgplot.pgbox("", 0.0, 0, "", 0.0, 0) ppgplot.pgenv(xmin, xmax, -.8, .8, 0) ppgplot.pglab(xlabel, ylabel, "") ppgplot.pgpt(x, y, 3) x = N.arange((int(xmin) - 1), (int(xmax) + 2), 1) y = ave * x / x ppgplot.pgsci(2) ppgplot.pgline(x, y) ppgplot.pgsci(1) y1 = y - std ppgplot.pgline(x, y1) y1 = y + std ppgplot.pgline(x, y1)
def sub1plotngalmcl(x, y1, y2): schdef = 1.2 slwdef = 4 ppgplot.pgsch(schdef) xmin = -.5 xmax = 1. ymin = 0. ymax = 60. #nbin=5 ppgplot.pgslw(slwdef) #line width ppgplot.pgswin(xmin, xmax, ymin, ymax) #axes limits ppgplot.pgbox('bcnlst', 1.0, 0, 'bcvnst', 10., 2) #tickmarks and labeling ppgplot.pgmtxt( 'b', 2.5, 0.5, 0.5, "log\d10\u(10\u14\d M\dhalo\u/h\u-1\d M\d\(2281)\u)") #xlabel ppgplot.pgmtxt('l', 2.1, 0.5, 0.5, "N\dgal\u") (xbin, ybin, ybinerr) = my.biniterr(x, y1, nbin) print y1 print 'ybin for y1 = ', ybin xbin = N.log10( xbin) + 12. - 14. #add back 10^12 Msun, then divide by 10^14 ppgplot.pgsch(1.5) ppgplot.pgpt(xbin, ybin, 7) ppgplot.pgslw(3) ppgplot.pgerrb(6, xbin, ybin, ybinerr, 2.) #my.errory(xbin,ybin,ybinerr) (xbin, ybin, ybinerr) = my.biniterr(x, y2, nbin) print y2 print 'ybin = ', ybin xbin = N.log10( xbin) + 12. - 14. #add back 10^12 Msun, then divide by 10^14 ppgplot.pgsch(1.75) ppgplot.pgpt(xbin, ybin, 17) ppgplot.pgsch(schdef) ppgplot.pgerrb(6, xbin, ybin, ybinerr, 2.) ppgplot.pgslw(slwdef)
def plotsigo2(sig, o2, file, nbin): psplot = file + ".ps" psplotinit(psplot) (sigbin, o2bin) = my.binit(sig, o2, nbin) ppgplot.pgbox("", 0.0, 0, "L", 0.0, 0) ymin = -10. ymax = 2. xmin = min(sig) - 10. #xmax=max(sig)-200. xmax = 350. ppgplot.pgenv(xmin, xmax, ymin, ymax, 0) ppgplot.pglab("\gS\d5\u (gal/Mpc\u2\d)", "EW([OII]) (\(2078))", "") ppgplot.pgsls(1) #dotted ppgplot.pgslw(4) #line width sig = N.array(sig, 'f') o2 = N.array(o2, 'f') ppgplot.pgpt(sig, o2, 1) ppgplot.pgsci(2) ppgplot.pgline(sigbin, o2bin) ppgplot.pgsci(1) ppgplot.pgend()
def plotoutlierpos(): dm = 0.01 xlabel = "x position of outliers" ylabel = "y position of outliers" delta = abs(im1.magap5 - im2.magap5) x = N.compress(delta > dm, im1.x) y = N.compress(delta > dm, im1.y) xmax = max(x) xmin = min(x) ymax = max(y) ymin = min(y) ppgplot.pgbox("", 0.0, 0, "", 0.0, 0) #ppgplot.pgenv(xmin,xmax,ymin,ymax,0) ppgplot.pgenv(0, 920, 0, 875, 0) ppgplot.pglab(xlabel, ylabel, "") ppgplot.pgpt(x, y, 3) x = N.compress(delta > dm, im2.x) y = N.compress(delta > dm, im2.y) diff = N.compress(delta > dm, delta) ppgplot.pgpt(x, y, 4) for i in range(len(x)): print x[i], y[i], diff[i]
def plotsigo2all(sig, psig, o2b, file, nbin): #o2=N.zeros(len(o2b),'f') #for i in range(len(o2b)): #print i, sig[i], psig[i], o2b[i] # if o2b[i] < 0: # o2[i]=-1*o2b[i] #print "hey", o2[i] o2 = o2b psplot = file + ".ps" psplotinit(psplot) ppgplot.pgsch(0.7) (sigbin, o2bin) = my.binit(sig, o2, nbin) #print 'dude', sigbin, o2bin sigbin = N.log10(sigbin) ppgplot.pgswin(-1., 3., -.5, 10.) ppgplot.pgbox('bcnst', 0.0, 0.0, 'bcvnst', 0.0, 0.0) #tickmarks and labeling ppgplot.pgsch(1.0) ppgplot.pgmtxt('b', 2.5, 0.5, 0.5, "\gS\d10\u (gal/Mpc\u2\d)") #xlabel ppgplot.pgsch(1.2) ppgplot.pgmtxt('l', 2.6, 0.5, 0.5, 'EW([OII]) (\(2078))') ppgplot.pgsls(1) #dotted ppgplot.pgslw(4) #line width ppgplot.pgsci(2) ppgplot.pgpt(sigbin, o2bin, 17) #print 'dude2', sigbin, o2bin ppgplot.pgline(sigbin, o2bin) (sigbin, o2bin) = my.binit(psig, o2, nbin) #print 'dude', sigbin, o2bin sigbin = N.log10(sigbin) ppgplot.pgsci(4) ppgplot.pgpt(sigbin, o2bin, 21) ppgplot.pgline(sigbin, o2bin) ppgplot.pgsci(1) ppgplot.pgend()
def plotsighaall(sig, psig, o2b, file, nbin): o2b = N.array(o2b, 'f') sig = N.array(sig, 'f') psig = N.array(psig, 'f') #o2b=o2b+4. o2 = N.compress(o2b > -500., o2b) sig = N.compress(o2b > -500., sig) psig = N.compress(o2b > -500., psig) psplot = file + ".ps" psplotinit(psplot) #ppgplot.pgsch(0.7) ppgplot.pgslw(7) (sigbin, o2bin) = my.binit(sig, o2, nbin) #print 'dude', sigbin, o2bin sigbin = N.log10(sigbin) ppgplot.pgswin(-2., 2., -5., 20.) ppgplot.pgbox('blcnst', 0.0, 0.0, 'bcvnst', 0.0, 0.0) #tickmarks and labeling ppgplot.pgsch(1.0) ppgplot.pgmtxt('b', 2.5, 0.5, 0.5, "\gS\d10\u (gal/Mpc\u2\d)") #xlabel ppgplot.pgsch(1.2) ppgplot.pgmtxt('l', 2.6, 0.5, 0.5, 'EW(H\ga) (\(2078))') ppgplot.pgsls(1) #dotted ppgplot.pgslw(4) #line width ppgplot.pgpt(sigbin, o2bin, 17) ppgplot.pgpt(N.log10(sig), o2, 1) #my.errory(sigbin,o2bin,yerr) #print 'dude2', sigbin, o2bin ppgplot.pgsci(2) ppgplot.pgline(sigbin, o2bin) (sigbin, o2bin) = my.binit(psig, o2, nbin) #print 'dude', sigbin, o2bin sigbin = N.log10(sigbin) ppgplot.pgsci(1) ppgplot.pgpt(sigbin, o2bin, 21) #my.errory(sigbin,o2bin,yerr) ppgplot.pgsci(4) ppgplot.pgline(sigbin, o2bin) ppgplot.pgsci(1) ppgplot.pgend()
#! /usr/bin/env python # # pgex1: freely taken after PGDEMO1.F # import ppgplot, numpy import sys # create an array xs=numpy.array([1.,2.,3.,4.,5.]) ys=numpy.array([1.,4.,9.,16.,25.]) # creat another array yr = 0.1*numpy.array(range(0,60)) xr = yr*yr # pgplotting if len(sys.argv) > 1: # if we got an argument use the argument as devicename ppgplot.pgopen(sys.argv[1]) else: ppgplot.pgopen('/xwin') ppgplot.pgenv(0.,10.,0.,20.,0,1) ppgplot.pglab('(x)', '(y)', 'PGPLOT Example 1: y = x\u2') ppgplot.pgpt(xs,ys,9) ppgplot.pgline(xr,yr) ppgplot.pgclos()
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.pgerrb(2, dates, mag, err, 0) ppgplot.pgerrb(4, dates, mag, err, 0) ppgplot.pglab("Days since %f"%startDate, "PTF mag", "%s [%d]"%(o.id, len(HJD))) ppgplot.pgclos() # Load the ephemerides for o in objects: hasEphemeris = o.loadEphemeris() print o.ephemeris # Write the object data to a textfile for o in objects: o.computePhases()
ppgplot.pgtext(-3,2.4+n*0.06,"dec") ppgplot.pgtext(0,2.4+n*0.06,"note") # Airmass Plot with Label ##################################################################### ppgplot.pgsch(1) # character height (size) if (obj =~ "o") { ppgplot.pgsci (2) ppgplot.pgscf(2) # (1: normal, 2: roman, 3: italic, 4: script) ppgplot.pgsch(0.8) # character height (size) ppgplot.pgslw(1) # line width ppgplot.pgptxt(t_lab, 2.02, -90.0, 0.0,"id") ppgplot.pgslw(6) # line width ppgplot.pgpt(i, *T, *secz,-1) ppgplot.pgscf(2) # (1: normal, 2: roman, 3: italic, 4: script) }else{ ppgplot.pgsci (4) ppgplot.pgscf(2) # (1: normal, 2: roman, 3: italic, 4: script) ppgplot.pgslw(1) # line width ppgplot.pgscf(1) # (1: normal, 2: roman, 3: italic, 4: script) ppgplot.pgsch(0.6) # character height (size) ppgplot.pgptxt(t_lab, 2.02, -90.0, 0.0,"id") ppgplot.pgslw(2) # line width ppgplot.pgpt(i, *T, *secz,-1) ppgplot.pgscf(2) # (1: normal, 2: roman, 3: italic, 4: script) } n++
times.append(seconds) brightness.append(sinecurve(seconds, period)) seconds+= step lightCurve = lightCurve() lightCurve.initValues(times, brightness) lightCurve.period = period * 60. lightCurve.brightness[3] = 1.0 lightCurvePlot = {} lightCurvePlot['pgplotHandle'] = ppgplot.pgopen('/xs') ppgplot.pgpap(8, 0.618) ppgplot.pgenv(0., lightCurve.period, 0.0, 1.0, 0, 0) ppgplot.pglab("seconds", "brightness", "Light curve") ppgplot.pgpt(lightCurve.time, lightCurve.brightness, 2) ppgplot.pgsci(2) ppgplot.pgline(lightCurve.time, lightCurve.brightness) ppgplot.pgask(False) connectedCount = 0 connectedBulbs = [] for b in bulbs: print b if b['connected'] == True: connectedCount+= 1 connectedBulbs.append(b) print b['label'], "is connected!" print "Number of connected bulbs", connectedCount
def extract_tracks(fname, trkrmin, drdtmin, trksig, ntrkmin): # Read four frame ff = fourframe(fname) # Skip saturated frames if np.sum(ff.zavg > 240.0) / float(ff.nx * ff.ny) > 0.95: return # Read satelite IDs try: f = open(fname + ".id") except OSError: print("Cannot open", fname + ".id") else: lines = f.readlines() f.close() # ppgplot arrays tr = np.array([-0.5, 1.0, 0.0, -0.5, 0.0, 1.0]) heat_l = np.array([0.0, 0.2, 0.4, 0.6, 1.0]) heat_r = np.array([0.0, 0.5, 1.0, 1.0, 1.0]) heat_g = np.array([0.0, 0.0, 0.5, 1.0, 1.0]) heat_b = np.array([0.0, 0.0, 0.0, 0.3, 1.0]) # Loop over identifications for line in lines: # Decode id = satid(line) # Skip slow moving objects drdt = np.sqrt(id.dxdt**2 + id.dydt**2) if drdt < drdtmin: continue # Extract significant pixels x, y, t, sig = ff.significant(trksig, id.x0, id.y0, id.dxdt, id.dydt, trkrmin) # Fit tracks if len(t) > ntrkmin: # Get times tmin = np.min(t) tmax = np.max(t) tmid = 0.5 * (tmax + tmin) mjd = ff.mjd + tmid / 86400.0 # Skip if no variance in time if np.std(t - tmid) == 0.0: continue # Very simple polynomial fit; no weighting, no cleaning px = np.polyfit(t - tmid, x, 1) py = np.polyfit(t - tmid, y, 1) # Extract results x0, y0 = px[1], py[1] dxdt, dydt = px[0], py[0] xmin = x0 + dxdt * (tmin - tmid) ymin = y0 + dydt * (tmin - tmid) xmax = x0 + dxdt * (tmax - tmid) ymax = y0 + dydt * (tmax - tmid) cospar = get_cospar(id.norad) obs = observation(ff, mjd, x0, y0) iod_line = "%s" % format_iod_line(id.norad, cospar, ff.site_id, obs.nfd, obs.ra, obs.de) print(iod_line) if id.catalog.find("classfd.tle") > 0: outfname = "classfd.dat" elif id.catalog.find("inttles.tle") > 0: outfname = "inttles.dat" else: outfname = "catalog.dat" f = open(outfname, "a") f.write("%s\n" % iod_line) f.close() # Plot ppgplot.pgopen( fname.replace(".fits", "") + "_%05d.png/png" % id.norad) #ppgplot.pgopen("/xs") ppgplot.pgpap(0.0, 1.0) ppgplot.pgsvp(0.1, 0.95, 0.1, 0.8) ppgplot.pgsch(0.8) ppgplot.pgmtxt( "T", 6.0, 0.0, 0.0, "UT Date: %.23s COSPAR ID: %04d" % (ff.nfd, ff.site_id)) if (3600.0 * ff.crres[0] < 1e-3 ) | (3600.0 * ff.crres[1] < 1e-3) | ( ff.crres[0] / ff.sx > 2.0) | (ff.crres[1] / ff.sy > 2.0): ppgplot.pgsci(2) else: ppgplot.pgsci(1) ppgplot.pgmtxt( "T", 4.8, 0.0, 0.0, "R.A.: %10.5f (%4.1f'') Decl.: %10.5f (%4.1f'')" % (ff.crval[0], 3600.0 * ff.crres[0], ff.crval[1], 3600.0 * ff.crres[1])) ppgplot.pgsci(1) ppgplot.pgmtxt( "T", 3.6, 0.0, 0.0, "FoV: %.2f\\(2218)x%.2f\\(2218) Scale: %.2f''x%.2f'' pix\\u-1\\d" % (ff.wx, ff.wy, 3600.0 * ff.sx, 3600.0 * ff.sy)) ppgplot.pgmtxt( "T", 2.4, 0.0, 0.0, "Stat: %5.1f+-%.1f (%.1f-%.1f)" % (np.mean(ff.zmax), np.std(ff.zmax), ff.vmin, ff.vmax)) ppgplot.pgmtxt("T", 0.3, 0.0, 0.0, iod_line) ppgplot.pgsch(1.0) ppgplot.pgwnad(0.0, ff.nx, 0.0, ff.ny) ppgplot.pglab("x (pix)", "y (pix)", " ") ppgplot.pgctab(heat_l, heat_r, heat_g, heat_b, 5, 1.0, 0.5) ppgplot.pgimag(ff.zmax, ff.nx, ff.ny, 0, ff.nx - 1, 0, ff.ny - 1, ff.vmax, ff.vmin, tr) ppgplot.pgbox("BCTSNI", 0., 0, "BCTSNI", 0., 0) ppgplot.pgstbg(1) ppgplot.pgsci(0) if id.catalog.find("classfd.tle") > 0: ppgplot.pgsci(4) elif id.catalog.find("inttles.tle") > 0: ppgplot.pgsci(3) ppgplot.pgpt(np.array([x0]), np.array([y0]), 4) ppgplot.pgmove(xmin, ymin) ppgplot.pgdraw(xmax, ymax) ppgplot.pgsch(0.65) ppgplot.pgtext(np.array([x0]), np.array([y0]), " %05d" % id.norad) ppgplot.pgsch(1.0) ppgplot.pgsci(1) ppgplot.pgend() elif id.catalog.find("classfd.tle") > 0: # Track and stack t = np.linspace(0.0, ff.texp) x, y = id.x0 + id.dxdt * t, id.y0 + id.dydt * t c = (x > 0) & (x < ff.nx) & (y > 0) & (y < ff.ny) # Skip if no points selected if np.sum(c) == 0: continue # Compute track tmid = np.mean(t[c]) mjd = ff.mjd + tmid / 86400.0 xmid = id.x0 + id.dxdt * tmid ymid = id.y0 + id.dydt * tmid ztrk = ndimage.gaussian_filter(ff.track(id.dxdt, id.dydt, tmid), 1.0) vmin = np.mean(ztrk) - 2.0 * np.std(ztrk) vmax = np.mean(ztrk) + 6.0 * np.std(ztrk) # Select region xmin = int(xmid - 100) xmax = int(xmid + 100) ymin = int(ymid - 100) ymax = int(ymid + 100) if xmin < 0: xmin = 0 if ymin < 0: ymin = 0 if xmax > ff.nx: xmax = ff.nx - 1 if ymax > ff.ny: ymax = ff.ny - 1 # Find peak x0, y0, w, sigma = peakfind(ztrk[ymin:ymax, xmin:xmax]) x0 += xmin y0 += ymin # Skip if peak is not significant if sigma < trksig: continue # Skip if point is outside selection area if inside_selection(id, xmid, ymid, x0, y0) == False: continue # Format IOD line cospar = get_cospar(id.norad) obs = observation(ff, mjd, x0, y0) iod_line = "%s" % format_iod_line(id.norad, cospar, ff.site_id, obs.nfd, obs.ra, obs.de) print(iod_line) if id.catalog.find("classfd.tle") > 0: outfname = "classfd.dat" elif id.catalog.find("inttles.tle") > 0: outfname = "inttles.dat" else: outfname = "catalog.dat" f = open(outfname, "a") f.write("%s\n" % iod_line) f.close() # Plot ppgplot.pgopen( fname.replace(".fits", "") + "_%05d.png/png" % id.norad) ppgplot.pgpap(0.0, 1.0) ppgplot.pgsvp(0.1, 0.95, 0.1, 0.8) ppgplot.pgsch(0.8) ppgplot.pgmtxt( "T", 6.0, 0.0, 0.0, "UT Date: %.23s COSPAR ID: %04d" % (ff.nfd, ff.site_id)) ppgplot.pgmtxt( "T", 4.8, 0.0, 0.0, "R.A.: %10.5f (%4.1f'') Decl.: %10.5f (%4.1f'')" % (ff.crval[0], 3600.0 * ff.crres[0], ff.crval[1], 3600.0 * ff.crres[1])) ppgplot.pgmtxt( "T", 3.6, 0.0, 0.0, "FoV: %.2f\\(2218)x%.2f\\(2218) Scale: %.2f''x%.2f'' pix\\u-1\\d" % (ff.wx, ff.wy, 3600.0 * ff.sx, 3600.0 * ff.sy)) ppgplot.pgmtxt( "T", 2.4, 0.0, 0.0, "Stat: %5.1f+-%.1f (%.1f-%.1f)" % (np.mean(ff.zmax), np.std(ff.zmax), ff.vmin, ff.vmax)) ppgplot.pgmtxt("T", 0.3, 0.0, 0.0, iod_line) ppgplot.pgsch(1.0) ppgplot.pgwnad(0.0, ff.nx, 0.0, ff.ny) ppgplot.pglab("x (pix)", "y (pix)", " ") ppgplot.pgctab(heat_l, heat_r, heat_g, heat_b, 5, 1.0, 0.5) ppgplot.pgimag(ztrk, ff.nx, ff.ny, 0, ff.nx - 1, 0, ff.ny - 1, vmax, vmin, tr) ppgplot.pgbox("BCTSNI", 0., 0, "BCTSNI", 0., 0) ppgplot.pgstbg(1) plot_selection(id, xmid, ymid) ppgplot.pgsci(0) if id.catalog.find("classfd.tle") > 0: ppgplot.pgsci(4) elif id.catalog.find("inttles.tle") > 0: ppgplot.pgsci(3) ppgplot.pgpt(np.array([id.x0]), np.array([id.y0]), 17) ppgplot.pgmove(id.x0, id.y0) ppgplot.pgdraw(id.x1, id.y1) ppgplot.pgpt(np.array([x0]), np.array([y0]), 4) ppgplot.pgsch(0.65) ppgplot.pgtext(np.array([id.x0]), np.array([id.y0]), " %05d" % id.norad) ppgplot.pgsch(1.0) ppgplot.pgsci(1) ppgplot.pgend()
y_values = velocity y_errors = velocityError results, covariance = scipy.optimize.curve_fit(sinewave, x_values, y_values, guess, y_errors) print "Sine result:", results print "Sine errors:", covariance a0 = results[0] a1 = results[1] a2 = results[2] xFit = numpy.arange(0, 1, 0.01) yFit = sinewave(xFit, a0, a1, a2) mainPGPlotWindow = ppgplot.pgopen('/xs') pgPlotTransform = [0, 1, 0, 0, 0, 1] ppgplot.pgsci(1) ppgplot.pgenv(0, 1, min(velocity)*1.1, max(velocity)*1.1, 0, 0) ppgplot.pgpt(phases, velocity) ppgplot.pgerrb(2, phases, velocity, velocityError, 0) ppgplot.pgerrb(4, phases, velocity, velocityError, 0) ppgplot.pgsci(5) ppgplot.pgsls(2) ppgplot.pgline( [0, 1], [a0, a0]) ppgplot.pgsls(1) ppgplot.pgline(xFit, yFit) ppgplot.pgsci(1) ppgplot.pglab("phase [phi]", "velocity [km/s]", "%.0f + %.0f*sin(2*pi*[phi + %.4f])"%(a0, a1, a2)) mainPGPlotWindow = ppgplot.pgopen('pgplot.eps/ps') pgPlotTransform = [0, 1, 0, 0, 0, 1] ppgplot.pgsci(1) ppgplot.pgenv(0, 1, min(velocity)*1.1, max(velocity)*1.1, 0, 0) ppgplot.pgpt(phases, velocity)
ppgplot.pgsubp(1, xyPositionPlot['numXYPanels']) ppgplot.pgsci(5) ppgplot.pgeras() for p in range(xyPositionPlot['numXYPanels']): ppgplot.pgenv(startFrame, startFrame + frameRange, -yLimit, yLimit, 0, 0) ppgplot.pgbox('A', 1.0, 10, 'BCG', 0.0, 0) ppgplot.pglab("", "%d"%p, "") ppgplot.pgsch(currentSize) for p, a in enumerate(referenceApertures.getSources()): xValues = [log['frameNumber'] for log in a.positionLog] yValues = [log['position'][0] - a.position[0] for log in a.positionLog] yErrors = [log['positionError'][0] for log in a.positionLog] ppgplot.pgsci(2) ppgplot.pgpanl(1, p + 1) ppgplot.pgpt(xValues, yValues, 1) ppgplot.pgerry(xValues, yValues + yErrors, yValues + yErrors, 0) yValues = [log['position'][1] - a.position[1] for log in a.positionLog] ppgplot.pgsci(3) ppgplot.pgpanl(1, p + 1) ppgplot.pgpt(xValues, yValues, 1) shortXArray = [trueFrameNumber] shortYArray = [xPosition] ppgplot.pgsci(2) ppgplot.pgpanl(1, panel + 1) ppgplot.pgpt(shortXArray, shortYArray, 1) ppgplot.pgsci(3) shortYArray = [yPosition] ppgplot.pgpt(shortXArray, shortYArray, 1)
def plotxy(y, x=None, title=None, rangex=None, rangey=None, \ labx='', laby='', rangex2=None, rangey2=None, \ labx2='', laby2='', symbol=ppgplot_symbol_, \ line=ppgplot_linestyle_, width=ppgplot_linewidth_, \ color=ppgplot_color_, font=ppgplot_font_, logx=0, logy=0, \ logx2=0, logy2=0, errx=None, erry=None, id=0, noscale=0, \ aspect=0.7727, fontsize=ppgplot_font_size_, ticks='in', \ panels=[1,1], device=ppgplot_device_, setup=1): """ plotxy(y, ...) An interface to make various XY style plots using PGPLOT. 'y' is the 1D sequence object to plot. The optional entries are: x: x values (default = 0, 1, ...) title: graph title (default = None) rangex: ranges for the x-axis (default = automatic) rangey: ranges for the y-axis (default = automatic) labx: label for the x-axis (default = None) laby: label for the y-axis (default = None) rangex2: ranges for 2nd x-axis (default = None) rangey2: ranges for 2nd y-axis (default = None) labx2: label for the 2nd x-axis (default = None) laby2: label for the 2nd y-axis (default = None) logx: make the 1st x-axis log (default = 0 (no)) logy: make the 1st y-axis log (default = 0 (no)) logx2: make the 2nd x-axis log (default = 0 (no)) logy2: make the 2nd y-axis log (default = 0 (no)) errx: symmetric x errors (default = None) erry: symmetric y errors (default = None) symbol: symbol for points (default = None) line: line style (default = 1 (solid)) width: line width (default = 1 (thin)) color: line and/or symbol color (default = 'white') font: PGPLOT font to use (default = 1 (normal)) fontsize: PGPLOT font size to use (default = 1.0 (normal)) id: show ID line on plot (default = 0 (no)) noscale: turn off auto scaling (default = 0 (no)) aspect: aspect ratio (default = 0.7727 (rect)) ticks: Ticks point in or out (default = 'in') panels: Number of subpanels [r,c] (default = [1,1]) device: PGPLOT device to use (default = '/XWIN') setup: Auto-setup the plot (default = 1) Note: Many default values are defined in global variables with names like ppgplot_font_ or ppgplot_device_. """ # Make sure the input data is an array y = Num.asarray(y); # Announce the global variables we will be using global ppgplot_dev_open_, ppgplot_dev_prep_, ppgplot_colors_ # Define the X axis limits if needed if x is None: x=Num.arange(len(y), dtype='f') else: x = Num.asarray(x) # Determine the scaling to use for the first axis if rangex is None: rangex=[x.min(), x.max()] if rangey is None: if noscale: rangey=[y.min(), y.max()] else: rangey=scalerange(y) # Prep the plotting device... if (not ppgplot_dev_prep_ and setup): prepplot(rangex, rangey, title, labx, laby, \ rangex2, rangey2, labx2, laby2, \ logx, logy, logx2, logy2, font, fontsize, \ id, aspect, ticks, panels, device=device) # Choose the line color if type(color) == types.StringType: ppgplot.pgsci(ppgplot_colors_[color]) else: ppgplot.pgsci(color) # Plot symbols (and errors) if requested if not symbol is None: ppgplot.pgpt(x, y, symbol) # Error bars if errx is not None: if not logx: errx = Num.asarray(errx) if errx.size == 1: errx = errx.repeat(x.size) #ppgplot.pgerrx(x+errx, x-errx, y, 1.0) ppgplot.pgerrb(5, x, y, errx, 1.0) else: errx = 10.0**Num.asarray(errx) if errx.size == 1: errx = errx.repeat(x.size) #ppgplot.pgerrx(Num.log10(10.0**x + errx), # Num.log10(10.0**x - errx), y, 1.0) ppgplot.pgerrb(5, x, y, Num.log10(errx), 1.0) if erry is not None: if not logy: erry = Num.asarray(erry) if erry.size == 1: erry = erry.repeat(y.size) #ppgplot.pgerry(x, y+erry, y-erry, 1.0) ppgplot.pgerrb(6, x, y, erry, 1.0) else: erry = 10.0**Num.asarray(erry) if erry.size == 1: erry = erry.repeat(y.size) #ppgplot.pgerry(x, Num.log10(10.0**y + erry), # Num.log10(10.0**y - erry), 1.0) ppgplot.pgerrb(6, x, y, Num.log10(erry), 1.0) # Plot connecting lines if requested if not line is None: # Choose the line style ppgplot.pgsls(line) # Choose the line width ppgplot.pgslw(width) ppgplot.pgline(x, y)
def extract_tracks(fname, trkrmin, drdtmin, trksig, ntrkmin, path, results_path): # Read four frame ff = fourframe(fname) # Skip saturated frames if np.sum(ff.zavg > 240.0) / float(ff.nx * ff.ny) > 0.95: return # Read satelite IDs try: f = open(fname + ".id") except OSError: print("Cannot open", fname + ".id") else: lines = f.readlines() f.close() tr = np.array([-0.5, 1.0, 0.0, -0.5, 0.0, 1.0]) # Parse identifications idents = [satid(line) for line in lines] # Identify unknowns for ident0 in idents: if ident0.catalog == "unidentified": for ident1 in idents: if ident1.catalog == "unidentified": continue # Find matches p1 = inside_selection(ident1, ident0.t0, ident0.x0, ident0.y0) p2 = inside_selection(ident1, ident0.t1, ident0.x1, ident0.y1) # Match found if p1 and p2: # Copy info ident0.norad = ident1.norad ident0.catalog = ident1.catalog ident0.state = ident1.state ident1.state = "remove" break # Loop over identifications for ident in idents: # Skip superseded unknowns if ident.state == "remove": continue # Skip slow moving objects drdt = np.sqrt(ident.dxdt**2 + ident.dydt**2) if drdt < drdtmin: continue # Extract significant pixels along a track x, y, t, sig = ff.significant_pixels_along_track( trksig, ident.x0, ident.y0, ident.dxdt, ident.dydt, trkrmin) # Fit tracks if len(t) > ntrkmin: # Get times tmin = np.min(t) tmax = np.max(t) tmid = 0.5 * (tmax + tmin) mjd = ff.mjd + tmid / 86400.0 # Skip if no variance in time if np.std(t - tmid) == 0.0: continue # Very simple polynomial fit; no weighting, no cleaning px = np.polyfit(t - tmid, x, 1) py = np.polyfit(t - tmid, y, 1) # Extract results x0, y0 = px[1], py[1] dxdt, dydt = px[0], py[0] xmin = x0 + dxdt * (tmin - tmid) ymin = y0 + dydt * (tmin - tmid) xmax = x0 + dxdt * (tmax - tmid) ymax = y0 + dydt * (tmax - tmid) cospar = get_cospar(ident.norad, ff.nfd) obs = observation(ff, mjd, x0, y0) iod_line = "%s" % format_iod_line(ident.norad, cospar, ff.site_id, obs.nfd, obs.ra, obs.de) # Create diagnostic plot plot_header(fname.replace(".fits", "_%05d.png/png" % ident.norad), ff, iod_line) ppg.pgimag(ff.zmax, ff.nx, ff.ny, 0, ff.nx - 1, 0, ff.ny - 1, ff.zmaxmax, ff.zmaxmin, tr) ppg.pgbox("BCTSNI", 0., 0, "BCTSNI", 0., 0) ppg.pgstbg(1) ppg.pgsci(0) if ident.catalog.find("classfd.tle") > 0: ppg.pgsci(4) elif ident.catalog.find("inttles.tle") > 0: ppg.pgsci(3) ppg.pgpt(np.array([x0]), np.array([y0]), 4) ppg.pgmove(xmin, ymin) ppg.pgdraw(xmax, ymax) ppg.pgsch(0.65) ppg.pgtext(np.array([x0]), np.array([y0]), " %05d" % ident.norad) ppg.pgsch(1.0) ppg.pgsci(1) ppg.pgend() # Store results store_results(ident, fname, results_path, iod_line) elif ident.catalog.find("classfd.tle") > 0: # Track and stack t = np.linspace(0.0, ff.texp) x, y = ident.x0 + ident.dxdt * t, ident.y0 + ident.dydt * t c = (x > 0) & (x < ff.nx) & (y > 0) & (y < ff.ny) # Skip if no points selected if np.sum(c) == 0: store_not_seen(ident, fname, results_path) continue # Compute track tmid = np.mean(t[c]) mjd = ff.mjd + tmid / 86400.0 xmid = ident.x0 + ident.dxdt * tmid ymid = ident.y0 + ident.dydt * tmid ztrk = ndimage.gaussian_filter( ff.track(ident.dxdt, ident.dydt, tmid), 1.0) vmin = np.mean(ztrk) - 2.0 * np.std(ztrk) vmax = np.mean(ztrk) + 6.0 * np.std(ztrk) # Select region xmin = int(xmid - 100) xmax = int(xmid + 100) ymin = int(ymid - 100) ymax = int(ymid + 100) if xmin < 0: xmin = 0 if ymin < 0: ymin = 0 if xmax > ff.nx: xmax = ff.nx - 1 if ymax > ff.ny: ymax = ff.ny - 1 # Find peak x0, y0, w, sigma = peakfind(ztrk[ymin:ymax, xmin:xmax]) x0 += xmin y0 += ymin # Skip if peak is not significant if sigma < trksig: store_not_seen(ident, fname, results_path) continue # Skip if point is outside selection area if inside_selection(ident, tmid, x0, y0) is False: store_not_seen(ident, fname, results_path) continue # Format IOD line cospar = get_cospar(ident.norad, ff.nfd) obs = observation(ff, mjd, x0, y0) iod_line = "%s" % format_iod_line(ident.norad, cospar, ff.site_id, obs.nfd, obs.ra, obs.de) # Create diagnostic plot pngfile = fname.replace(".fits", "_%05d.png" % ident.norad) plot_header(pngfile + "/png", ff, iod_line) ppg.pgimag(ztrk, ff.nx, ff.ny, 0, ff.nx - 1, 0, ff.ny - 1, vmax, vmin, tr) ppg.pgbox("BCTSNI", 0., 0, "BCTSNI", 0., 0) ppg.pgstbg(1) plot_selection(ident, xmid, ymid) ppg.pgsci(0) if ident.catalog.find("classfd.tle") > 0: ppg.pgsci(4) elif ident.catalog.find("inttles.tle") > 0: ppg.pgsci(3) ppg.pgpt(np.array([ident.x0]), np.array([ident.y0]), 17) ppg.pgmove(ident.x0, ident.y0) ppg.pgdraw(ident.x1, ident.y1) ppg.pgpt(np.array([x0]), np.array([y0]), 4) ppg.pgsch(0.65) ppg.pgtext(np.array([ident.x0]), np.array([ident.y0]), " %05d" % ident.norad) ppg.pgsch(1.0) ppg.pgsci(1) ppg.pgend() # Store results store_results(ident, fname, results_path, iod_line)
def main(): parser = OptionParser(usage) parser.add_option( "-x", "--xwin", action="store_true", dest="xwin", default=False, help="Don't make a postscript plot, just use an X-window") parser.add_option("-p", "--noplot", action="store_false", dest="makeplot", default=True, help="Look for pulses but do not generate a plot") parser.add_option( "-m", "--maxwidth", type="float", dest="maxwidth", default=0.0, help="Set the max downsampling in sec (see below for default)") parser.add_option("-t", "--threshold", type="float", dest="threshold", default=5.0, help="Set a different threshold SNR (default=5.0)") parser.add_option("-s", "--start", type="float", dest="T_start", default=0.0, help="Only plot events occuring after this time (s)") parser.add_option("-e", "--end", type="float", dest="T_end", default=1e9, help="Only plot events occuring before this time (s)") parser.add_option("-g", "--glob", type="string", dest="globexp", default=None, help="Process the files from this glob expression") parser.add_option("-f", "--fast", action="store_true", dest="fast", default=False, help="Use a faster method of de-trending (2x speedup)") (opts, args) = parser.parse_args() if len(args) == 0: if opts.globexp == None: print full_usage sys.exit(0) else: args = [] for globexp in opts.globexp.split(): args += glob.glob(globexp) useffts = True dosearch = True if opts.xwin: pgplot_device = "/XWIN" else: pgplot_device = "" fftlen = 8192 # Should be a power-of-two for best speed chunklen = 8000 # Must be at least max_downfact less than fftlen detrendlen = 1000 # length of a linear piecewise chunk of data for detrending blocks_per_chunk = chunklen / detrendlen overlap = (fftlen - chunklen) / 2 worklen = chunklen + 2 * overlap # currently it is fftlen... max_downfact = 30 default_downfacts = [2, 3, 4, 6, 9, 14, 20, 30, 45, 70, 100, 150] if args[0].endswith(".singlepulse"): filenmbase = args[0][:args[0].rfind(".singlepulse")] dosearch = False elif args[0].endswith(".dat"): filenmbase = args[0][:args[0].rfind(".dat")] else: filenmbase = args[0] # Don't do a search, just read results and plot if not dosearch: info, DMs, candlist, num_v_DMstr = \ read_singlepulse_files(args, opts.threshold, opts.T_start, opts.T_end) orig_N, orig_dt = int(info.N), info.dt obstime = orig_N * orig_dt else: DMs = [] candlist = [] num_v_DMstr = {} # Loop over the input files for filenm in args: if filenm.endswith(".dat"): filenmbase = filenm[:filenm.rfind(".dat")] else: filenmbase = filenm info = infodata.infodata(filenmbase + ".inf") DMstr = "%.2f" % info.DM DMs.append(info.DM) N, dt = int(info.N), info.dt obstime = N * dt # Choose the maximum width to search based on time instead # of bins. This helps prevent increased S/N when the downsampling # changes as the DM gets larger. if opts.maxwidth > 0.0: downfacts = [ x for x in default_downfacts if x * dt <= opts.maxwidth ] else: downfacts = [x for x in default_downfacts if x <= max_downfact] if len(downfacts) == 0: downfacts = [default_downfacts[0]] if (filenm == args[0]): orig_N = N orig_dt = dt if useffts: fftd_kerns = make_fftd_kerns(downfacts, fftlen) if info.breaks: offregions = zip([x[1] for x in info.onoff[:-1]], [x[0] for x in info.onoff[1:]]) outfile = open(filenmbase + '.singlepulse', mode='w') # Compute the file length in detrendlens roundN = N / detrendlen * detrendlen numchunks = roundN / chunklen # Read in the file print 'Reading "%s"...' % filenm timeseries = Num.fromfile(filenm, dtype=Num.float32, count=roundN) # Split the timeseries into chunks for detrending numblocks = roundN / detrendlen timeseries.shape = (numblocks, detrendlen) stds = Num.zeros(numblocks, dtype=Num.float64) # de-trend the data one chunk at a time print ' De-trending the data and computing statistics...' for ii, chunk in enumerate(timeseries): if opts.fast: # use median removal instead of detrending (2x speedup) tmpchunk = chunk.copy() tmpchunk.sort() med = tmpchunk[detrendlen / 2] chunk -= med tmpchunk -= med else: # The detrend calls are the most expensive in the program timeseries[ii] = scipy.signal.detrend(chunk, type='linear') tmpchunk = timeseries[ii].copy() tmpchunk.sort() # The following gets rid of (hopefully) most of the # outlying values (i.e. power dropouts and single pulses) # If you throw out 5% (2.5% at bottom and 2.5% at top) # of random gaussian deviates, the measured stdev is ~0.871 # of the true stdev. Thus the 1.0/0.871=1.148 correction below. # The following is roughly .std() since we already removed the median stds[ii] = Num.sqrt( (tmpchunk[detrendlen / 40:-detrendlen / 40]**2.0).sum() / (0.95 * detrendlen)) stds *= 1.148 # sort the standard deviations and separate those with # very low or very high values sort_stds = stds.copy() sort_stds.sort() # identify the differences with the larges values (this # will split off the chunks with very low and very high stds locut = (sort_stds[1:numblocks / 2 + 1] - sort_stds[:numblocks / 2]).argmax() + 1 hicut = (sort_stds[numblocks / 2 + 1:] - sort_stds[numblocks / 2:-1]).argmax() + numblocks / 2 - 2 std_stds = scipy.std(sort_stds[locut:hicut]) median_stds = sort_stds[(locut + hicut) / 2] lo_std = median_stds - 4.0 * std_stds hi_std = median_stds + 4.0 * std_stds # Determine a list of "bad" chunks. We will not search these. bad_blocks = Num.nonzero((stds < lo_std) | (stds > hi_std))[0] print " pseudo-median block standard deviation = %.2f" % ( median_stds) print " identified %d bad blocks out of %d (i.e. %.2f%%)" % \ (len(bad_blocks), len(stds), 100.0*float(len(bad_blocks))/float(len(stds))) stds[bad_blocks] = median_stds print " Now searching..." # Now normalize all of the data and reshape it to 1-D timeseries /= stds[:, Num.newaxis] timeseries.shape = (roundN, ) # And set the data in the bad blocks to zeros # Even though we don't search these parts, it is important # because of the overlaps for the convolutions for bad_block in bad_blocks: loind, hiind = bad_block * detrendlen, (bad_block + 1) * detrendlen timeseries[loind:hiind] = 0.0 # Convert to a set for faster lookups below bad_blocks = set(bad_blocks) # Step through the data dm_candlist = [] for chunknum in range(numchunks): loind = chunknum * chunklen - overlap hiind = (chunknum + 1) * chunklen + overlap # Take care of beginning and end of file overlap issues if (chunknum == 0): # Beginning of file chunk = Num.zeros(worklen, dtype=Num.float32) chunk[overlap:] = timeseries[loind + overlap:hiind] elif (chunknum == numchunks - 1): # end of the timeseries chunk = Num.zeros(worklen, dtype=Num.float32) chunk[:-overlap] = timeseries[loind:hiind - overlap] else: chunk = timeseries[loind:hiind] # Make a set with the current block numbers lowblock = blocks_per_chunk * chunknum currentblocks = set(Num.arange(blocks_per_chunk) + lowblock) localgoodblocks = Num.asarray( list(currentblocks - bad_blocks)) - lowblock # Search this chunk if it is not all bad if len(localgoodblocks): # This is the good part of the data (end effects removed) goodchunk = chunk[overlap:-overlap] # need to pass blocks/chunklen, localgoodblocks # dm_candlist, dt, opts.threshold to cython routine # Search non-downsampled data first # NOTE: these nonzero() calls are some of the most # expensive calls in the program. Best bet would # probably be to simply iterate over the goodchunk # in C and append to the candlist there. hibins = Num.flatnonzero(goodchunk > opts.threshold) hivals = goodchunk[hibins] hibins += chunknum * chunklen hiblocks = hibins / detrendlen # Add the candidates (which are sorted by bin) for bin, val, block in zip(hibins, hivals, hiblocks): if block not in bad_blocks: time = bin * dt dm_candlist.append( candidate(info.DM, val, time, bin, 1)) # Prepare our data for the convolution if useffts: fftd_chunk = rfft(chunk, -1) # Now do the downsampling... for ii, downfact in enumerate(downfacts): if useffts: # Note: FFT convolution is faster for _all_ downfacts, even 2 goodchunk = fft_convolve(fftd_chunk, fftd_kerns[ii], overlap, -overlap) else: # The normalization of this kernel keeps the post-smoothing RMS = 1 kernel = Num.ones(downfact, dtype=Num.float32) / \ Num.sqrt(downfact) smoothed_chunk = scipy.signal.convolve( chunk, kernel, 1) goodchunk = smoothed_chunk[overlap:-overlap] #hibins = Num.nonzero(goodchunk>opts.threshold)[0] hibins = Num.flatnonzero(goodchunk > opts.threshold) hivals = goodchunk[hibins] hibins += chunknum * chunklen hiblocks = hibins / detrendlen hibins = hibins.tolist() hivals = hivals.tolist() # Now walk through the new candidates and remove those # that are not the highest but are within downfact/2 # bins of a higher signal pulse hibins, hivals = prune_related1( hibins, hivals, downfact) # Insert the new candidates into the candlist, but # keep it sorted... for bin, val, block in zip(hibins, hivals, hiblocks): if block not in bad_blocks: time = bin * dt bisect.insort( dm_candlist, candidate(info.DM, val, time, bin, downfact)) # Now walk through the dm_candlist and remove the ones that # are within the downsample proximity of a higher # signal-to-noise pulse dm_candlist = prune_related2(dm_candlist, downfacts) print " Found %d pulse candidates" % len(dm_candlist) # Get rid of those near padding regions if info.breaks: prune_border_cases(dm_candlist, offregions) # Write the pulses to an ASCII output file if len(dm_candlist): #dm_candlist.sort(cmp_sigma) outfile.write( "# DM Sigma Time (s) Sample Downfact\n") for cand in dm_candlist: outfile.write(str(cand)) outfile.close() # Add these candidates to the overall candidate list for cand in dm_candlist: candlist.append(cand) num_v_DMstr[DMstr] = len(dm_candlist) if (opts.makeplot): # Step through the candidates to make a SNR list DMs.sort() snrs = [] for cand in candlist: snrs.append(cand.sigma) if snrs: maxsnr = max(int(max(snrs)), int(opts.threshold)) + 3 else: maxsnr = int(opts.threshold) + 3 # Generate the SNR histogram snrs = Num.asarray(snrs) (num_v_snr, lo_snr, d_snr, num_out_of_range) = \ scipy.stats.histogram(snrs, int(maxsnr-opts.threshold+1), [opts.threshold, maxsnr]) snrs = Num.arange(maxsnr-opts.threshold+1, dtype=Num.float64) * d_snr \ + lo_snr + 0.5*d_snr num_v_snr = num_v_snr.astype(Num.float32) num_v_snr[num_v_snr == 0.0] = 0.001 # Generate the DM histogram num_v_DM = Num.zeros(len(DMs)) for ii, DM in enumerate(DMs): num_v_DM[ii] = num_v_DMstr["%.2f" % DM] DMs = Num.asarray(DMs) # open the plot device short_filenmbase = filenmbase[:filenmbase.find("_DM")] if opts.T_end > obstime: opts.T_end = obstime if pgplot_device: ppgplot.pgopen(pgplot_device) else: if (opts.T_start > 0.0 or opts.T_end < obstime): ppgplot.pgopen(short_filenmbase + '_%.0f-%.0fs_singlepulse.ps/VPS' % (opts.T_start, opts.T_end)) else: ppgplot.pgopen(short_filenmbase + '_singlepulse.ps/VPS') ppgplot.pgpap(7.5, 1.0) # Width in inches, aspect # plot the SNR histogram ppgplot.pgsvp(0.06, 0.31, 0.6, 0.87) ppgplot.pgswin(opts.threshold, maxsnr, Num.log10(0.5), Num.log10(2 * max(num_v_snr))) ppgplot.pgsch(0.8) ppgplot.pgbox("BCNST", 0, 0, "BCLNST", 0, 0) ppgplot.pgmtxt('B', 2.5, 0.5, 0.5, "Signal-to-Noise") ppgplot.pgmtxt('L', 1.8, 0.5, 0.5, "Number of Pulses") ppgplot.pgsch(1.0) ppgplot.pgbin(snrs, Num.log10(num_v_snr), 1) # plot the DM histogram ppgplot.pgsvp(0.39, 0.64, 0.6, 0.87) # Add [1] to num_v_DM in YMAX below so that YMIN != YMAX when max(num_v_DM)==0 ppgplot.pgswin( min(DMs) - 0.5, max(DMs) + 0.5, 0.0, 1.1 * max(num_v_DM + [1])) ppgplot.pgsch(0.8) ppgplot.pgbox("BCNST", 0, 0, "BCNST", 0, 0) ppgplot.pgmtxt('B', 2.5, 0.5, 0.5, "DM (pc cm\u-3\d)") ppgplot.pgmtxt('L', 1.8, 0.5, 0.5, "Number of Pulses") ppgplot.pgsch(1.0) ppgplot.pgbin(DMs, num_v_DM, 1) # plot the SNR vs DM plot ppgplot.pgsvp(0.72, 0.97, 0.6, 0.87) ppgplot.pgswin(min(DMs) - 0.5, max(DMs) + 0.5, opts.threshold, maxsnr) ppgplot.pgsch(0.8) ppgplot.pgbox("BCNST", 0, 0, "BCNST", 0, 0) ppgplot.pgmtxt('B', 2.5, 0.5, 0.5, "DM (pc cm\u-3\d)") ppgplot.pgmtxt('L', 1.8, 0.5, 0.5, "Signal-to-Noise") ppgplot.pgsch(1.0) cand_ts = Num.zeros(len(candlist), dtype=Num.float32) cand_SNRs = Num.zeros(len(candlist), dtype=Num.float32) cand_DMs = Num.zeros(len(candlist), dtype=Num.float32) for ii, cand in enumerate(candlist): cand_ts[ii], cand_SNRs[ii], cand_DMs[ii] = \ cand.time, cand.sigma, cand.DM ppgplot.pgpt(cand_DMs, cand_SNRs, 20) # plot the DM vs Time plot ppgplot.pgsvp(0.06, 0.97, 0.08, 0.52) ppgplot.pgswin(opts.T_start, opts.T_end, min(DMs) - 0.5, max(DMs) + 0.5) ppgplot.pgsch(0.8) ppgplot.pgbox("BCNST", 0, 0, "BCNST", 0, 0) ppgplot.pgmtxt('B', 2.5, 0.5, 0.5, "Time (s)") ppgplot.pgmtxt('L', 1.8, 0.5, 0.5, "DM (pc cm\u-3\d)") # Circles are symbols 20-26 in increasing order snr_range = 12.0 cand_symbols = (cand_SNRs - opts.threshold) / snr_range * 6.0 + 20.5 cand_symbols = cand_symbols.astype(Num.int32) cand_symbols[cand_symbols > 26] = 26 for ii in [26, 25, 24, 23, 22, 21, 20]: inds = Num.nonzero(cand_symbols == ii)[0] ppgplot.pgpt(cand_ts[inds], cand_DMs[inds], ii) # Now fill the infomation area ppgplot.pgsvp(0.05, 0.95, 0.87, 0.97) ppgplot.pgsch(1.0) ppgplot.pgmtxt('T', 0.5, 0.0, 0.0, "Single pulse results for '%s'" % short_filenmbase) ppgplot.pgsch(0.8) # first row ppgplot.pgmtxt('T', -1.1, 0.02, 0.0, 'Source: %s'%\ info.object) ppgplot.pgmtxt('T', -1.1, 0.33, 0.0, 'RA (J2000):') ppgplot.pgmtxt('T', -1.1, 0.5, 0.0, info.RA) ppgplot.pgmtxt('T', -1.1, 0.73, 0.0, 'N samples: %.0f' % orig_N) # second row ppgplot.pgmtxt('T', -2.4, 0.02, 0.0, 'Telescope: %s'%\ info.telescope) ppgplot.pgmtxt('T', -2.4, 0.33, 0.0, 'DEC (J2000):') ppgplot.pgmtxt('T', -2.4, 0.5, 0.0, info.DEC) ppgplot.pgmtxt('T', -2.4, 0.73, 0.0, 'Sampling time: %.2f \gms'%\ (orig_dt*1e6)) # third row if info.instrument.find("pigot") >= 0: instrument = "Spigot" else: instrument = info.instrument ppgplot.pgmtxt('T', -3.7, 0.02, 0.0, 'Instrument: %s' % instrument) if (info.bary): ppgplot.pgmtxt('T', -3.7, 0.33, 0.0, 'MJD\dbary\u: %.12f' % info.epoch) else: ppgplot.pgmtxt('T', -3.7, 0.33, 0.0, 'MJD\dtopo\u: %.12f' % info.epoch) ppgplot.pgmtxt('T', -3.7, 0.73, 0.0, 'Freq\dctr\u: %.1f MHz'%\ ((info.numchan/2-0.5)*info.chan_width+info.lofreq)) ppgplot.pgiden() ppgplot.pgend()
ppgplot.pgask(arg.ask) for index, photometry in enumerate(allData): x_values = photometry[xColumn] y_values = photometry[yColumn] y_errors = photometry[yErrors] x_lower, x_upper = (min(x_values), max(x_values)) numpoints = len(x_values) if "JD" in xColumn: x_offset = int(x_lower) x_values = [(x-x_offset) for x in x_values] xLabel= xColumn + " - %d"%x_lower ppgplot.pgsci(1) ppgplot.pgenv(min(x_values), max(x_values), lowerY, upperY, 0, 0) ppgplot.pgslw(7) ppgplot.pgpt(x_values, y_values, 1) ppgplot.pgslw(1) ppgplot.pgerrb(2, x_values, y_values, y_errors, 0) ppgplot.pgerrb(4, x_values, y_values, y_errors, 0) ppgplot.pglab(xLabel, yLabel, photometry["runName"]) ppgplot.pgclos() if not hasEphemeris: sys.exit() # Restrict the light-curve to a subset of phase phaseLimits = (0.51, 0.70) for photometry in allData: pnew = [] ynew = []
def draw_one(x): ppgplot.pgbbuf() ppgplot.pgenv(0, len(x), numpy.min(x) * 0.95, numpy.max(x) * 1.05) ppgplot.pgpt(numpy.arange(len(x)), x) ppgplot.pgebuf() time.sleep(4)
def gotoit(): nbin = 10 #c=Cluster() #g=Galaxy() clusterfile = "clusters.spec.dat" print "reading in cluster file to get cluster parameters" c.creadfiles(clusterfile) print "got ", len(c.z), " clusters" c.convarray() c.Kcorr() go2 = [] #combined arrays containing all galaxies gsf = [] #combined arrays containing all galaxies gsig5 = [] gsig10 = [] gsig52r200 = [] #spec catalogs extended out to 2xR200 gsig102r200 = [] #spec catalogs extended out to 2xR200 gsig5phot = [] gsig10phot = [] sgo2 = [] #combined arrays containing all galaxies sgha = [] #combined arrays containing all galaxies sgsf = [] #combined arrays containing all galaxies sgsig5 = [] sgsig10 = [] sgsig52r200 = [] #spec catalogs extended out to 2xR200 sgsig102r200 = [] #spec catalogs extended out to 2xR200 sgsig5phot = [] sgsig10phot = [] if (mode < 1): c.getsdssphotcats() c.getsdssspeccats() gr = [] #list of median g-r colors psplotinit('summary.ps') x1 = .1 x2 = .45 x3 = .6 x4 = .95 y1 = .15 y2 = .45 y3 = .55 y4 = .85 ppgplot.pgsch(1.2) #font size ppgplot.pgslw(2) #for i in range(len(c.z)): cl = [10] (xl, xu, yl, yu) = ppgplot.pgqvp(0) print "viewport = ", xl, xu, yl, yu complall = [] for i in range(len(c.z)): #for i in cl: gname = "g" + str(i) gname = Galaxy() gspecfile = "abell" + str(c.id[i]) + ".spec.dat" gname.greadfiles(gspecfile, i) print "number of members = ", len(gname.z) if len(gname.z) < 10: print "less than 10 members", len(gname.z) continue gname.convarray() #gname.cullmembers() #gname.getmemb()#get members w/in R200 #gr.append(N.average(gname.g-gname.r)) gspec2r200file = "abell" + str(c.id[i]) + ".spec2r200.dat" gname.greadspecfiles(gspec2r200file, c.dL[i], c.kcorr[i], i) print i, c.id[i], " getnearest, first call", len(gname.ra), len( gname.sra), sum(gname.smemb) #gname.getnearest(i) (gname.sig52r200, gname.sig102r200) = gname.getnearestgen( gname.ra, gname.dec, gname.sra, gname.sdec, i ) #measure distances from ra1, dec1 to members in catalog ra2, dec2 sig52r200 = N.compress(gname.memb > 0, gname.sig52r200) gsig52r200[len(gsig5phot):] = sig52r200 sig102r200 = N.compress(gname.memb > 0, gname.sig102r200) gsig102r200[len(gsig10phot):] = sig102r200 gphotfile = "abell" + str(c.id[i]) + ".phot.dat" gname.greadphotfiles(gphotfile, c.dL[i], c.kcorr[i]) gname.getnearest(i) #print "len of local density arrays = ",len(gname.sig5),len(gname.sig5phot) #print gspecfile, c.z[i],c.kcorr[i] (ds5, ds10) = gname.gwritefiles(gspecfile, i) o2 = N.compress(gname.memb > 0, gname.o2) go2[len(go2):] = o2 sf = N.compress(gname.memb > 0, gname.sf) gsf[len(gsf):] = sf sig5 = N.compress(gname.memb > 0, gname.sig5) gsig5[len(gsig5):] = sig5 sig10 = N.compress(gname.memb > 0, gname.sig10) gsig10[len(gsig10):] = sig10 sig5phot = N.compress(gname.memb > 0, gname.sig5phot) gsig5phot[len(gsig5phot):] = sig5phot sig10phot = N.compress(gname.memb > 0, gname.sig10phot) gsig10phot[len(gsig10phot):] = sig10phot ds5 = N.array(ds5, 'f') ds10 = N.array(ds10, 'f') #print len(ds5),len(ds10) #ppgplot.pgsvp(xl,xu,yl,yu) ppgplot.pgsvp(0.1, .9, .08, .92) ppgplot.pgslw(7) label = 'Abell ' + str( c.id[i]) + ' (z=%5.2f, \gs=%3.0f km/s)' % (c.z[i], c.sigma[i]) ppgplot.pgtext(0., 1., label) ppgplot.pgslw(2) ppgplot.pgsvp(x1, x2, y1, y2) #sets viewport #ppgplot.pgbox("",0.0,0,"",0.0) ppgplot.pgswin(-1., 3., -1., 3.) #axes limits ppgplot.pgbox('bcnst', 1, 2, 'bcvnst', 1, 2) #tickmarks and labeling ppgplot.pgmtxt('b', 2.5, 0.5, 0.5, "\gS\d10\u(phot) (gal/Mpc\u2\d)") #xlabel ppgplot.pgmtxt('l', 2.6, 0.5, 0.5, "\gS\d10\u(spec) (gal/Mpc\u2\d)") x = N.arange(-5., 10., .1) y = x ppgplot.pgsls(1) #dotted ppgplot.pgslw(4) #line width ppgplot.pgline(x, y) x = N.log10(sig10phot) y = N.log10(sig10) ppgplot.pgsch(.7) ppgplot.pgpt(x, y, 17) xp = N.array([-0.5], 'f') yp = N.array([2.5], 'f') ppgplot.pgpt(xp, yp, 17) ppgplot.pgtext((xp + .1), yp, 'spec(1.2xR200) vs phot') ppgplot.pgsci(4) xp = N.array([-0.5], 'f') yp = N.array([2.2], 'f') ppgplot.pgpt(xp, yp, 21) ppgplot.pgtext((xp + .1), yp, 'spec(2xR200) vs phot') y = N.log10(sig102r200) ppgplot.pgsch(.9) ppgplot.pgpt(x, y, 21) ppgplot.pgsch(1.2) ppgplot.pgslw(2) #line width ppgplot.pgsci(1) #ppgplot.pgenv(-200.,200.,-1.,20.,0,0) #ppgplot.pgsci(2) #ppgplot.pghist(len(ds5),ds5,-200.,200.,30,1) #ppgplot.pgsci(4) #ppgplot.pghist(len(ds10),ds10,-200.,200.,30,1) #ppgplot.pgsci(1) #ppgplot.pglab("\gD\gS","Ngal",gspecfile) #ppgplot.pgpanl(1,2) g = N.compress(gname.memb > 0, gname.g) r = N.compress(gname.memb > 0, gname.r) V = N.compress(gname.memb > 0, gname.V) dmag = N.compress(gname.memb > 0, gname.dmagnearest) dnearest = N.compress(gname.memb > 0, gname.nearest) dz = N.compress(gname.memb > 0, gname.dz) #ppgplot.pgsvp(x3,x4,y1,y2) #sets viewport #ppgplot.pgenv(-.5,3.,-1.,5.,0,0) #ppgplot.pgpt((g-V),(g-r),17) #ppgplot.pgsci(1) #ppgplot.pglab("g - M\dV\u",'g-r',gspecfile) ppgplot.pgsvp(x1, x2, y3, y4) #sets viewport #ppgplot.pgbox("",0.0,0,"",0.0) ppgplot.pgswin( (c.ra[i] + 2. * c.r200deg[i] / N.cos(c.dec[i] * N.pi / 180.)), (c.ra[i] - 2 * c.r200deg[i] / N.cos(c.dec[i] * N.pi / 180.)), (c.dec[i] - 2. * c.r200deg[i]), (c.dec[i] + 2. * c.r200deg[i])) ppgplot.pgbox('bcnst', 0.0, 0.0, 'bcvnst', 0.0, 0.0) #tickmarks and labeling ppgplot.pgmtxt('b', 2.5, 0.5, 0.5, "RA") #xlabel ppgplot.pgmtxt('l', 2.6, 0.5, 0.5, "Dec") #ppgplot.pglab("RA",'Dec',gspecfile) ppgplot.pgsfs(2) ppgplot.pgcirc(c.ra[i], c.dec[i], c.r200deg[i]) ppgplot.pgsls(4) ppgplot.pgcirc(c.ra[i], c.dec[i], 1.2 * c.r200deg[i]) ppgplot.pgsls(1) #ppgplot.pgcirc(c.ra[i],c.dec[i],c.r200deg[i]/N.cos(c.dec[i]*N.pi/180.)) ppgplot.pgsci(2) ppgplot.pgpt(gname.ra, gname.dec, 17) ppgplot.pgsci(4) ppgplot.pgpt(gname.photra, gname.photdec, 21) ppgplot.pgsci(1) #calculate completeness w/in R200 dspec = N.sqrt((gname.ra - c.ra[i])**2 + (gname.dec - c.dec[i])**2) dphot = N.sqrt((gname.photra - c.ra[i])**2 + (gname.photdec - c.dec[i])**2) nphot = 1. * len(N.compress(dphot < c.r200deg[i], dphot)) nspec = 1. * len(N.compress(dspec < c.r200deg[i], dspec)) s = "Completeness for cluster Abell %s = %6.2f (nspec=%6.1f,nphot= %6.1f)" % ( str(c.id[i]), float(nspec / nphot), nspec, nphot) print s complall.append(float(nspec / nphot)) ppgplot.pgsvp(x3, x4, y3, y4) #sets viewport #ppgplot.pgsvp(x1,x2,y3,y4) #sets viewport #ppgplot.pgbox("",0.0,0,"",0.0) ppgplot.pgswin(-0.005, .05, -1., 1.) ppgplot.pgbox('bcnst', .02, 2, 'bcvnst', 1, 4) #tickmarks and labeling ppgplot.pgsch(1.0) ppgplot.pgmtxt('b', 2.5, 0.5, 0.5, "Dist to nearest phot neighbor (deg)") #xlabel ppgplot.pgsch(1.2) ppgplot.pgmtxt('l', 2.6, 0.5, 0.5, 'M\dV\u(phot) - M\dV\u(spec)') ppgplot.pgsci(2) ppgplot.pgpt(dnearest, dmag, 17) ppgplot.pgsci(1) x = N.arange(-30., 30., 1.) y = 0 * x ppgplot.pgsci(1) ppgplot.pgsls(2) ppgplot.pgline(x, y) ppgplot.pgsls(1) ppgplot.pgsci(1) dm = N.compress(dnearest < 0.01, dmag) std = '%5.3f (%5.3f)' % (pylab.mean(dm), pylab.std(dm)) #ppgplot.pgslw(7) #label='Abell '+str(c.id[i]) #ppgplot.pgtext(0.,1.,label) ppgplot.pgslw(2) label = '\gDM\dV\u(err) = ' + std ppgplot.pgsch(.9) ppgplot.pgtext(0., .8, label) #label = "z = %5.2f"%(c.z[i]) #ppgplot.pgtext(0.,.8,label) ppgplot.pgsch(1.2) #ppgplot.pgsvp(x3,x4,y3,y4) #sets viewport #ppgplot.pgenv(-.15,.15,-3.,3.,0,0) #ppgplot.pgsci(2) #ppgplot.pgpt(dz,dmag,17) #ppgplot.pgsci(1) #ppgplot.pglab("z-z\dcl\u",'\gD Mag',gspecfile) ppgplot.pgsvp(x3, x4, y1, y2) #sets viewport ppgplot.pgswin(-3., 3., -1., 1.) ppgplot.pgbox('bcnst', 1, 2, 'bcvnst', 1, 4) #tickmarks and labeling ppgplot.pgmtxt('b', 2.5, 0.5, 0.5, "\gDv/\gs") #xlabel ppgplot.pgmtxt('l', 2.6, 0.5, 0.5, 'M\dV\u(phot) - M\dV\u(spec)') ppgplot.pgsci(2) dv = dz / (1 + c.z[i]) * 3.e5 / c.sigma[i] ppgplot.pgpt(dv, dmag, 17) ppgplot.pgsci(1) x = N.arange(-30., 30., 1.) y = 0 * x ppgplot.pgsci(1) ppgplot.pgsls(2) ppgplot.pgline(x, y) ppgplot.pgsls(1) ppgplot.pgsci(1) #ppgplot.pgsvp(x1,x2,y1,y2) #sets viewport #ppgplot.pgenv(0.,3.5,-3.,3.,0,0) #ppgplot.pgsci(4) #ppgplot.pgpt((g-r),dmag,17) #ppgplot.pgsci(1) #ppgplot.pglab("g-r",'\gD Mag',gspecfile) #ppgplot.pgsvp(x1,x2,y1,y2) #sets viewport #ppgplot.pgenv(-25.,-18.,-1.,1.,0,0) #ppgplot.pgsci(4) #ppgplot.pgpt((V),dmag,17) #x=N.arange(-30.,30.,1.) #y=0*x #ppgplot.pgsci(1) #ppgplot.pgsls(2) #ppgplot.pgline(x,y) #ppgplot.pgsls(1) #ppgplot.pgsci(1) #ppgplot.pglab("M\dV\u(spec)",'M\dV\u(phot) - M\dV\u(spec)',gspecfile) #ppgplot.pgpage() #ppgplot.pgpage() #combine galaxy data ppgplot.pgpage() (sssig5, sssig10) = gname.getnearestgen(gname.sra, gname.sdec, gname.sra, gname.sdec, i) #get spec-spec local density (spsig5, spsig10) = gname.getnearestgen(gname.sra, gname.sdec, gname.photra, gname.photdec, i) #get spec-phot local density o2 = N.compress(gname.smemb > 0, gname.so2) sgo2[len(sgo2):] = o2 ha = N.compress(gname.smemb > 0, gname.sha) sgha[len(sgha):] = ha sf = N.compress(gname.smemb > 0, gname.ssf) sgsf[len(sgsf):] = sf sig5 = N.compress(gname.smemb > 0, sssig5) sgsig5[len(sgsig5):] = sig5 sig10 = N.compress(gname.smemb > 0, sssig10) sgsig10[len(sgsig10):] = sig10 sig5phot = N.compress(gname.smemb > 0, spsig5) sgsig5phot[len(sgsig5phot):] = sig5phot sig10phot = N.compress(gname.smemb > 0, spsig10) sgsig10phot[len(sgsig10phot):] = sig10phot #gr=N.array(gr,'f') #c.assigncolor(gr) #for i in range(len(c.z)): # print c.id[i],c.z[i],c.r200[i],c.r200deg[i] print "Average Completeness w/in R200 = ", N.average(N.array( complall, 'f')) print "sig o2", len(gsig10), len(gsig10phot), len(go2) print "sig o2 large", len(sgsig10), len(sgsig10phot), len(sgo2) plotsigo2all(gsig10, gsig10phot, go2, 'o2vsig10spec', nbin) #plotsigo2(gsig5phot,-1*go2,'o2vsig5phot',nbin) plotsigsff(gsig5, gsf, 'sffvsig5spec', nbin) #sf frac versus sigma plotsigsff(gsig5phot, gsf, 'sffvsig5phot', nbin) #sf frac versus sigma plotsigsffall(gsig5, gsig5phot, gsf, 'sffvsig5all', nbin) #sf frac versus sigma plotsig10sffall(gsig10, gsig10phot, gsf, 'sffvsig10all', nbin) #sf frac versus sigma #plotsighaall(gsig10,gsig10phot,gha,'havsig10spec',20) #plotsigo2all(sgsig10,sgsig10phot,sgo2,'o2vsig10spec.large',30) plotsighaall(sgsig10, sgsig10phot, sgha, 'havsig10spec.large', 10) #plotsigsffall(sgsig5,sgsig5phot,sgsf,'sffvsig5.large',nbin)#sf frac versus sigma #plotsig10sffall(sgsig10,sgsig10phot,sgsf,'sffvsig10.large',nbin)#sf frac versus sigma psplotinit('one2one.ps') ppgplot.pgenv(-1.5, 2.5, -1.5, 2.5, 0) ppgplot.pglab("\gS\d10\u(phot) (gal/Mpc\u2\d)", "\gS\d10\u(spec) (gal/Mpc\u2\d)", "") x = N.arange(-5., 10., .1) y = x ppgplot.pgsls(1) #dotted ppgplot.pgslw(4) #line width ppgplot.pgline(x, y) x = N.log10(gsig10phot) y = N.log10(gsig10) ppgplot.pgsch(.7) ppgplot.pgpt(x, y, 17) ppgplot.pgsch(1.) ppgplot.pgsci(1) ppgplot.pgend()
else: print '# Warning: no sources found to match ', src os._exit(1) if _do_grace: # -- switch lists to arrays (should have done that to begin with) for pgplot t = Numeric.array(date) # time (in days) t = t - t0 # but relative to first date found f = Numeric.array(flux) # flux e = 3 * Numeric.array(ferr) # flux errors as 3 sigma g = Numeric.array(freq) # freq p = gracePlot.gracePlot() p.plot(t, f, e, symbols=1) p.title('Fluxes for ' + src) p.xlabel('Days since ' + d0) p.ylabel('Flux (Jy)') for r in [[70, 100], [100, 120], [120, 250]]: n, x, y, dy = get_range(t, f, e, g, r[0], r[1], cut) if n: p.plot(x, y, dy, symbols=1) p.hold(1) elif _do_pgplot: t = Numeric.array(date) # time (in days) t = t - t0 # but relative to first date found f = Numeric.array(flux) # flux ppgplot.pgopen(pgp) ppgplot.pgenv(0, 1500, 0, 80, 0, 1) ppgplot.pglab('Days since %s' % d0, 'Flux(Jy)', 'Flux for %s' % src) ppgplot.pgpt(t, f, 9) ppgplot.pgline(t, f)
#/usr/bin/env python # # pgex1: freely taken after PGDEMO1.F # import ppgplot, Numeric import sys # create an array xs=Numeric.array([1.,2.,3.,4.,5.]) ys=Numeric.array([1.,4.,9.,16.,25.]) # creat another array yr = 0.1*Numeric.array(range(0,60)) xr = yr*yr # pgplotting if len(sys.argv) > 1: # if we got an argument use the argument as devicename ppgplot.pgopen(sys.argv[1]) else: ppgplot.pgopen('?') ppgplot.pgenv(0.,10.,0.,20.,0,1) ppgplot.pglab('(x)', '(y)', 'PGPLOT Example 1: y = x\u2') ppgplot.pgpt(xs,ys,9) ppgplot.pgline(xr,yr) ppgplot.pgclos()
def main(options): debug = options.debug MSlist = [] device = options.device if device == '?': ppgplot.pgldev() return for inmspart in options.inms.split(','): for msname in glob.iglob(inmspart): MSlist.append(msname) if len(MSlist) == 0: print('Error: You must specify at least one MS name.') print(' Use "uvplot.py -h" to get help.') return if len(MSlist) > 1: print('WARNING: Antenna selection (other than all) may not work well') print(' when plotting more than one MS. Carefully inspect the') print(' listings of antenna numbers/names!') if options.title == '': plottitle = options.inms else: plottitle = options.title axlimits = options.axlimits.split(',') if len(axlimits) == 4: xmin, xmax, ymin, ymax = axlimits else: print('Error: You must specify four axis limits') return timeslots = options.timeslots.split(',') if len(timeslots) != 3: print('Error: Timeslots format is start,skip,end') return for i in range(len(timeslots)): timeslots[i] = int(timeslots[i]) if timeslots[i] < 0: print('Error: timeslots values must not be negative') return doPlotColors = options.colors antToPlotSpl = options.antennas.split(',') antToPlot = [] for i in range(len(antToPlotSpl)): tmpspl = antToPlotSpl[i].split('..') if len(tmpspl) == 1: antToPlot.append(int(antToPlotSpl[i])) elif len(tmpspl) == 2: for j in range(int(tmpspl[0]), int(tmpspl[1]) + 1): antToPlot.append(j) else: print('Error: Could not understand antenna list.') return queryMode = options.query plotLambda = options.kilolambda badval = 0.0 xaxisvals0 = numpy.array([]) yaxisvals0 = numpy.array([]) xaxisvals1 = numpy.array([]) yaxisvals1 = numpy.array([]) xaxisvals2 = numpy.array([]) yaxisvals2 = numpy.array([]) xaxisvals3 = numpy.array([]) yaxisvals3 = numpy.array([]) xaxisvals4 = numpy.array([]) yaxisvals4 = numpy.array([]) xaxisvals5 = numpy.array([]) yaxisvals5 = numpy.array([]) savex0 = numpy.array([]) savey0 = numpy.array([]) savex1 = numpy.array([]) savey1 = numpy.array([]) savex2 = numpy.array([]) savey2 = numpy.array([]) savex3 = numpy.array([]) savey3 = numpy.array([]) savex4 = numpy.array([]) savey4 = numpy.array([]) savex5 = numpy.array([]) savey5 = numpy.array([]) numPlotted = 0 ptcolor = 0 for inputMS in MSlist: # open the main table and print some info about the MS print('Getting info for', inputMS) t = pt.table(inputMS, readonly=True, ack=False) tfreq = pt.table(t.getkeyword('SPECTRAL_WINDOW'), readonly=True, ack=False) ref_freq = tfreq.getcol('REF_FREQUENCY', nrow=1)[0] ch_freq = tfreq.getcol('CHAN_FREQ', nrow=1)[0] print('Reference frequency:\t%f MHz' % (ref_freq / 1.e6)) if options.wideband: ref_wavelength = 2.99792458e8 / ch_freq else: ref_wavelength = [2.99792458e8 / ref_freq] print('Reference wavelength:\t%f m' % (ref_wavelength[0])) if options.sameuv and numPlotted > 0: print('Assuming same uvw as first MS!') if plotLambda: for w in ref_wavelength: xaxisvals0 = numpy.append( xaxisvals0, [savex0 / w / 1000., -savex0 / w / 1000.]) yaxisvals0 = numpy.append( yaxisvals0, [savey0 / w / 1000., -savey0 / w / 1000.]) xaxisvals1 = numpy.append( xaxisvals1, [savex1 / w / 1000., -savex1 / w / 1000.]) yaxisvals1 = numpy.append( yaxisvals1, [savey1 / w / 1000., -savey1 / w / 1000.]) xaxisvals2 = numpy.append( xaxisvals2, [savex2 / w / 1000., -savex2 / w / 1000.]) yaxisvals2 = numpy.append( yaxisvals2, [savey2 / w / 1000., -savey2 / w / 1000.]) xaxisvals3 = numpy.append( xaxisvals3, [savex3 / w / 1000., -savex3 / w / 1000.]) yaxisvals3 = numpy.append( yaxisvals3, [savey3 / w / 1000., -savey3 / w / 1000.]) xaxisvals4 = numpy.append( xaxisvals4, [savex4 / w / 1000., -savex4 / w / 1000.]) yaxisvals4 = numpy.append( yaxisvals4, [savey4 / w / 1000., -savey4 / w / 1000.]) xaxisvals5 = numpy.append( xaxisvals5, [savex5 / w / 1000., -savex5 / w / 1000.]) yaxisvals5 = numpy.append( yaxisvals5, [savey5 / w / 1000., -savey5 / w / 1000.]) else: print( 'Plotting more than one MS with same uv, all in meters... do you want -k?' ) xaxisvals0 = numpy.append(xaxisvals0, [savex0, -savex0]) yaxisvals0 = numpy.append(yaxisvals0, [savey0, -savey0]) xaxisvals1 = numpy.append(xaxisvals1, [savex1, -savex1]) yaxisvals1 = numpy.append(yaxisvals1, [savey1, -savey1]) xaxisvals2 = numpy.append(xaxisvals2, [savex2, -savex2]) yaxisvals2 = numpy.append(yaxisvals2, [savey2, -savey2]) xaxisvals3 = numpy.append(xaxisvals3, [savex3, -savex3]) yaxisvals3 = numpy.append(yaxisvals3, [savey3, -savey3]) xaxisvals4 = numpy.append(xaxisvals4, [savex4, -savex4]) yaxisvals4 = numpy.append(yaxisvals4, [savey4, -savey4]) xaxisvals5 = numpy.append(xaxisvals5, [savex5, -savex5]) yaxisvals5 = numpy.append(yaxisvals5, [savey5, -savey5]) continue firstTime = t.getcell("TIME", 0) lastTime = t.getcell("TIME", t.nrows() - 1) intTime = t.getcell("INTERVAL", 0) print('Integration time:\t%f sec' % (intTime)) nTimeslots = (lastTime - firstTime) / intTime print('Number of timeslots:\t%d' % (nTimeslots)) if timeslots[1] == 0: if nTimeslots >= 100: timeskip = int(nTimeslots / 100) else: timeskip = 1 else: timeskip = int(timeslots[1]) print('For each baseline, plotting one point every %d samples' % (timeskip)) if timeslots[2] == 0: timeslots[2] = nTimeslots # open the antenna subtable tant = pt.table(t.getkeyword('ANTENNA'), readonly=True, ack=False) # Station names antList = tant.getcol('NAME') if len(antToPlot) == 1 and antToPlot[0] == -1: antToPlot = list(range(len(antList))) print('Station list (only starred stations will be plotted):') for i in range(len(antList)): star = ' ' if i in antToPlot: star = '*' print('%s %2d\t%s' % (star, i, antList[i])) # Bail if we're in query mode if queryMode: return # select by time from the beginning, and only use specified antennas tsel = t.query( 'TIME >= %f AND TIME <= %f AND ANTENNA1 IN %s AND ANTENNA2 IN %s' % (firstTime + timeslots[0] * intTime, firstTime + timeslots[2] * intTime, str(antToPlot), str(antToPlot)), columns='ANTENNA1,ANTENNA2,UVW') # Now we loop through the baselines i = 0 nb = (len(antToPlot) * (len(antToPlot) - 1)) / 2 sys.stdout.write('Reading uvw for %d baselines: %04d/%04d' % (nb, i, nb)) sys.stdout.flush() for tpart in tsel.iter(["ANTENNA1", "ANTENNA2"]): ant1 = tpart.getcell("ANTENNA1", 0) ant2 = tpart.getcell("ANTENNA2", 0) if ant1 not in antToPlot or ant2 not in antToPlot: continue if ant1 == ant2: continue i += 1 sys.stdout.write('\b\b\b\b\b\b\b\b\b%04d/%04d' % (i, nb)) sys.stdout.flush() if doPlotColors: stNameStr = antList[ant1][0] + antList[ant2][0] if stNameStr == 'CC': ptcolor = 0 elif stNameStr == 'RR': ptcolor = 1 elif 'C' in stNameStr and 'R' in stNameStr: ptcolor = 2 elif 'C' in stNameStr: ptcolor = 3 elif 'R' in stNameStr: ptcolor = 4 else: ptcolor = 5 # Get the values to plot uvw = tpart.getcol('UVW', rowincr=timeskip) if numPlotted == 0: savex0 = numpy.append(savex0, [uvw[:, 0], -uvw[:, 0]]) savey0 = numpy.append(savey0, [uvw[:, 1], -uvw[:, 1]]) savex1 = numpy.append(savex1, [uvw[:, 0], -uvw[:, 0]]) savey1 = numpy.append(savey1, [uvw[:, 1], -uvw[:, 1]]) savex2 = numpy.append(savex2, [uvw[:, 0], -uvw[:, 0]]) savey2 = numpy.append(savey2, [uvw[:, 1], -uvw[:, 1]]) savex3 = numpy.append(savex3, [uvw[:, 0], -uvw[:, 0]]) savey3 = numpy.append(savey3, [uvw[:, 1], -uvw[:, 1]]) savex4 = numpy.append(savex4, [uvw[:, 0], -uvw[:, 0]]) savey4 = numpy.append(savey4, [uvw[:, 1], -uvw[:, 1]]) savex5 = numpy.append(savex5, [uvw[:, 0], -uvw[:, 0]]) savey5 = numpy.append(savey5, [uvw[:, 1], -uvw[:, 1]]) if plotLambda: for w in ref_wavelength: if ptcolor == 0: xaxisvals0 = numpy.append( xaxisvals0, [uvw[:, 0] / w / 1000., -uvw[:, 0] / w / 1000.]) yaxisvals0 = numpy.append( yaxisvals0, [uvw[:, 1] / w / 1000., -uvw[:, 1] / w / 1000.]) elif ptcolor == 1: xaxisvals1 = numpy.append( xaxisvals1, [uvw[:, 0] / w / 1000., -uvw[:, 0] / w / 1000.]) yaxisvals1 = numpy.append( yaxisvals1, [uvw[:, 1] / w / 1000., -uvw[:, 1] / w / 1000.]) elif ptcolor == 2: xaxisvals2 = numpy.append( xaxisvals2, [uvw[:, 0] / w / 1000., -uvw[:, 0] / w / 1000.]) yaxisvals2 = numpy.append( yaxisvals2, [uvw[:, 1] / w / 1000., -uvw[:, 1] / w / 1000.]) elif ptcolor == 3: xaxisvals3 = numpy.append( xaxisvals3, [uvw[:, 0] / w / 1000., -uvw[:, 0] / w / 1000.]) yaxisvals3 = numpy.append( yaxisvals3, [uvw[:, 1] / w / 1000., -uvw[:, 1] / w / 1000.]) elif ptcolor == 4: xaxisvals4 = numpy.append( xaxisvals4, [uvw[:, 0] / w / 1000., -uvw[:, 0] / w / 1000.]) yaxisvals4 = numpy.append( yaxisvals4, [uvw[:, 1] / w / 1000., -uvw[:, 1] / w / 1000.]) elif ptcolor == 5: xaxisvals5 = numpy.append( xaxisvals5, [uvw[:, 0] / w / 1000., -uvw[:, 0] / w / 1000.]) yaxisvals5 = numpy.append( yaxisvals5, [uvw[:, 1] / w / 1000., -uvw[:, 1] / w / 1000.]) else: if ptcolor == 0: xaxisvals0 = numpy.append(xaxisvals0, [uvw[:, 0], -uvw[:, 0]]) yaxisvals0 = numpy.append(yaxisvals0, [uvw[:, 1], -uvw[:, 1]]) elif ptcolor == 1: xaxisvals1 = numpy.append(xaxisvals1, [uvw[:, 0], -uvw[:, 0]]) yaxisvals1 = numpy.append(yaxisvals1, [uvw[:, 1], -uvw[:, 1]]) elif ptcolor == 2: xaxisvals2 = numpy.append(xaxisvals2, [uvw[:, 0], -uvw[:, 0]]) yaxisvals2 = numpy.append(yaxisvals2, [uvw[:, 1], -uvw[:, 1]]) elif ptcolor == 3: xaxisvals3 = numpy.append(xaxisvals3, [uvw[:, 0], -uvw[:, 0]]) yaxisvals3 = numpy.append(yaxisvals3, [uvw[:, 1], -uvw[:, 1]]) elif ptcolor == 4: xaxisvals4 = numpy.append(xaxisvals4, [uvw[:, 0], -uvw[:, 0]]) yaxisvals4 = numpy.append(yaxisvals4, [uvw[:, 1], -uvw[:, 1]]) elif ptcolor == 5: xaxisvals5 = numpy.append(xaxisvals5, [uvw[:, 0], -uvw[:, 0]]) yaxisvals5 = numpy.append(yaxisvals5, [uvw[:, 1], -uvw[:, 1]]) #if debug: # print uvw.shape # print xaxisvals.shape # print yaxisvals.shape #else: # sys.stdout.write('.') # sys.stdout.flush() sys.stdout.write(' Done!\n') numPlotted += 1 print('Plotting uv points ...') # open the graphics device, using only one panel ppgplot.pgbeg(device, 1, 1) # set the font size ppgplot.pgsch(1) ppgplot.pgvstd() xaxisvals = numpy.append( xaxisvals0, numpy.append( xaxisvals1, numpy.append( xaxisvals2, numpy.append(xaxisvals3, numpy.append(xaxisvals4, xaxisvals5))))) yaxisvals = numpy.append( yaxisvals0, numpy.append( yaxisvals1, numpy.append( yaxisvals2, numpy.append(yaxisvals3, numpy.append(yaxisvals4, yaxisvals5))))) tmpvals0 = numpy.sqrt(xaxisvals0**2 + yaxisvals0**2) tmpvals1 = numpy.sqrt(xaxisvals1**2 + yaxisvals1**2) tmpvals2 = numpy.sqrt(xaxisvals2**2 + yaxisvals2**2) tmpvals3 = numpy.sqrt(xaxisvals3**2 + yaxisvals3**2) tmpvals4 = numpy.sqrt(xaxisvals4**2 + yaxisvals4**2) tmpvals5 = numpy.sqrt(xaxisvals5**2 + yaxisvals5**2) # Plot the data if debug: print(xaxisvals0[tmpvals0 != badval]) print(yaxisvals0[tmpvals0 != badval]) ppgplot.pgsci(1) uvmax = max(xaxisvals.max(), yaxisvals.max()) uvmin = min(xaxisvals.min(), yaxisvals.min()) uvuplim = 0.02 * (uvmax - uvmin) + uvmax uvlolim = uvmin - 0.02 * (uvmax - uvmin) if xmin == '': minx = uvlolim else: minx = float(xmin) if xmax == '': maxx = uvuplim else: maxx = float(xmax) if ymin == '': miny = uvlolim else: miny = float(ymin) if ymax == '': maxy = uvuplim else: maxy = float(ymax) if minx == maxx: minx = -1.0 maxx = 1.0 if miny == maxy: miny = -1.0 maxy = 1.0 ppgplot.pgpage() ppgplot.pgswin(minx, maxx, miny, maxy) ppgplot.pgbox('BCNST', 0.0, 0, 'BCNST', 0.0, 0) if plotLambda: ppgplot.pglab('u [k\gl]', 'v [k\gl]', '%s' % (plottitle)) else: ppgplot.pglab('u [m]', 'v [m]', '%s' % (plottitle)) ppgplot.pgpt(xaxisvals0[tmpvals0 != badval], yaxisvals0[tmpvals0 != badval], 1) #if doPlotColors: ppgplot.pgmtxt('T', 1, 0.35, 0.5, 'C-C') ppgplot.pgsci(2) ppgplot.pgpt(xaxisvals1[tmpvals1 != badval], yaxisvals1[tmpvals1 != badval], 1) #if doPlotColors: ppgplot.pgmtxt('T', 1, 0.50, 0.5, 'R-R') ppgplot.pgsci(4) ppgplot.pgpt(xaxisvals2[tmpvals2 != badval], yaxisvals2[tmpvals2 != badval], 1) #if doPlotColors: ppgplot.pgmtxt('T', 1, 0.65, 0.5, 'C-R') ppgplot.pgsci(3) ppgplot.pgpt(xaxisvals3[tmpvals3 != badval], yaxisvals3[tmpvals3 != badval], 1) #if doPlotColors: ppgplot.pgmtxt('T', 1, 0.55, 0.5, 'C-I') ppgplot.pgsci(5) ppgplot.pgpt(xaxisvals4[tmpvals4 != badval], yaxisvals4[tmpvals4 != badval], 1) #if doPlotColors: ppgplot.pgmtxt('T', 1, 0.65, 0.5, 'R-I') ppgplot.pgsci(6) ppgplot.pgpt(xaxisvals5[tmpvals5 != badval], yaxisvals5[tmpvals5 != badval], 1) #if doPlotColors: ppgplot.pgmtxt('T', 1, 0.75, 0.5, 'I-I') # Close the PGPLOT device ppgplot.pgclos()
pgPlotTransform = [0, 1, 0, 0, 0, 1] ppgplot.pgslct(PGPlotWindow) ppgplot.pgsci(1) ppgplot.pgask(False) for index, o in enumerate(objects): MJD = o.getColumn('MJD') mag = o.getColumn('mag') err = o.getColumn('err') startDate = numpy.min(MJD) endDate = numpy.max(MJD) 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(startDate, endDate, magMax + meanError*2, magMin - meanError*2, 0, 0) ppgplot.pgpt(MJD, mag) ppgplot.pgerrb(2, MJD, mag, err, 0) ppgplot.pgerrb(4, MJD, mag, err, 0) ppgplot.pglab("MJD", "CRTS mag", "%s [%d]"%(o.id, len(MJD))) ppgplot.pgclos() # Compute HJDs for the observations for o in objects: hasEphemeris = o.loadEphemeris() if hasEphemeris: o.computeHJDs()
def main(options): global keepPlotting keepPlotting = True debug = options.debug inputMS = options.inms if inputMS == "": print "Error: You must specify a MS name." print ' Use "uvplot.py -h" to get help.' return if inputMS.endswith("/"): inputMS = inputMS[:-1] inputMSbasename = inputMS.split("/")[-1] if inputMSbasename == "": # The user has not specified the full path of the MS inputMSbasename = inputMS device = options.device if device == "?": ppgplot.pgldev() return xaxis = options.xaxis yaxis = options.yaxis column = options.column nx, ny = options.nxy.split(",") axlimits = options.axlimits.split(",") if len(axlimits) == 4: xmin, xmax, ymin, ymax = axlimits else: print "Error: You must specify four axis limits" return showFlags = options.flag flagCol = options.colflag showAutocorr = options.autocorr showStats = options.statistics timeslots = options.timeslots.split(",") if len(timeslots) != 2: print "Error: Timeslots format is start,end" return for i in range(len(timeslots)): timeslots[i] = int(timeslots[i]) antToPlotSpl = options.antennas.split(",") antToPlot = [] for i in range(len(antToPlotSpl)): tmpspl = antToPlotSpl[i].split("..") if len(tmpspl) == 1: antToPlot.append(int(antToPlotSpl[i])) elif len(tmpspl) == 2: for j in range(int(tmpspl[0]), int(tmpspl[1]) + 1): antToPlot.append(j) else: print "Error: Could not understand antenna list." return polarizations = options.polar.split(",") for i in range(len(polarizations)): polarizations[i] = int(polarizations[i]) convertStokes = options.stokes operation = options.operation if operation != "": operation = int(operation) if convertStokes: print "Error: Stokes conversion is not compatible with special operations" return channels = options.channels.split(",") if len(channels) != 2: print "Error: Channels format is start,end" return for i in range(len(channels)): channels[i] = int(channels[i]) if channels[1] == -1: channels[1] = None # last element even if there is only one else: channels[1] += 1 queryMode = options.query doUnwrap = options.wrap if not queryMode: # open the graphics device, use the right number of panels ppgplot.pgbeg(device, int(nx), int(ny)) # set the font size ppgplot.pgsch(1.5) ppgplot.pgvstd() # open the main table and print some info about the MS t = pt.table(inputMS, readonly=True, ack=False) firstTime = t.getcell("TIME", 0) lastTime = t.getcell("TIME", t.nrows() - 1) intTime = t.getcell("INTERVAL", 0) print "Integration time:\t%f sec" % (intTime) nTimeslots = (lastTime - firstTime) / intTime if timeslots[1] == -1: timeslots[1] = nTimeslots else: timeslots[1] += 1 print "Number of timeslots:\t%d" % (nTimeslots) # open the antenna and spectral window subtables tant = pt.table(t.getkeyword("ANTENNA"), readonly=True, ack=False) tsp = pt.table(t.getkeyword("SPECTRAL_WINDOW"), readonly=True, ack=False) numChannels = len(tsp.getcell("CHAN_FREQ", 0)) print "Number of channels:\t%d" % (numChannels) print "Reference frequency:\t%5.2f MHz" % (tsp.getcell("REF_FREQUENCY", 0) / 1.0e6) # Station names antList = tant.getcol("NAME") if len(antToPlot) == 1 and antToPlot[0] == -1: antToPlot = range(len(antList)) print "Station list (only starred stations will be plotted):" for i in range(len(antList)): star = " " if i in antToPlot: star = "*" print "%s %2d\t%s" % (star, i, antList[i]) # Bail if we're in query mode if queryMode: return # select by time from the beginning, and only use specified antennas tsel = t.query( "TIME >= %f AND TIME <= %f AND ANTENNA1 IN %s AND ANTENNA2 IN %s" % (firstTime + timeslots[0] * intTime, firstTime + timeslots[1] * intTime, str(antToPlot), str(antToPlot)) ) # values to use for each polarization plotColors = [1, 2, 3, 4] labXPositions = [0.35, 0.45, 0.55, 0.65] labYPositions = [1.0, 1.0, 1.0, 1.0] if convertStokes: polLabels = ["I", "Q", "U", "V"] else: polLabels = ["XX", "XY", "YX", "YY"] # define nicely written axis labels axisLabels = { "time": "Time", "chan": "Channel", "freq": "Frequency [MHz]", "amp": "Visibility amplitude", "real": "Real part of visibility", "imag": "Imaginary part of visibility", "phase": "Visibility phase [radians]", } # Now we loop through the baselines ppgplot.pgpage() for tpart in tsel.iter(["ANTENNA1", "ANTENNA2"]): if not keepPlotting: return ant1 = tpart.getcell("ANTENNA1", 0) ant2 = tpart.getcell("ANTENNA2", 0) if ant1 not in antToPlot or ant2 not in antToPlot: continue if ant1 == ant2: if not showAutocorr: continue # Get the values to plot, strategy depends on axis type if xaxis == "time": xaxisvals = getXAxisVals(tpart, xaxis, channels) yaxisvals = getYAxisVals( tpart, yaxis, column, operation, showFlags, flagCol, channels, doUnwrap, convertStokes ) else: xaxisvals = getXAxisVals(tsp, xaxis, channels) yaxisvals = getYAxisVals( tpart, yaxis, column, operation, showFlags, flagCol, channels, doUnwrap, convertStokes, xaxistype=1 ) if xaxisvals == None: # This baseline must be empty, go to next one print "No good data on baseline %s - %s" % (antList[ant1], antList[ant2]) continue if debug: print xaxisvals.shape print yaxisvals.shape for r in range(len(xaxisvals)): print "%s" % yaxisvals[r] if len(xaxisvals) != len(yaxisvals): # something is wrong print "Error: X and Y axis types incompatible" return # Plot the data, each polarization in a different color ppgplot.pgsci(1) if xmin == "": minx = xaxisvals.min() else: minx = float(xmin) if xmax == "": maxx = xaxisvals.max() else: maxx = float(xmax) if ymin == "": miny = yaxisvals.min() if numpy.ma.getmaskarray(yaxisvals.min()): print "All data flagged on baseline %s - %s" % (antList[ant1], antList[ant2]) continue else: miny = float(ymin) if ymax == "": maxy = yaxisvals.max() else: maxy = float(ymax) if minx == maxx: minx -= 1.0 maxx += 1.0 else: diffx = maxx - minx minx -= 0.02 * diffx maxx += 0.02 * diffx if miny == maxy: miny -= 1.0 maxy += 1.0 else: diffy = maxy - miny miny -= 0.02 * diffy maxy += 0.02 * diffy # ppgplot.pgpage() ppgplot.pgswin(minx, maxx, miny, maxy) if xaxis == "time": ppgplot.pgtbox("ZHOBCNST", 0.0, 0, "BCNST", 0.0, 0) else: ppgplot.pgbox("BCNST", 0.0, 0, "BCNST", 0.0, 0) # ppgplot.pglab(axisLabels[xaxis], axisLabels[yaxis], '%s - %s'%(antList[ant1],antList[ant2])) # ppgplot.pgmtxt('T', 3.0, 0.5, 0.5, inputMSbasename) ppgplot.pglab( axisLabels[xaxis], axisLabels[yaxis], inputMSbasename + "(" + getDataDescription(column) + "): %s - %s" % (antList[ant1], antList[ant2]), ) if operation != 0: # some operations is defined if operation == 1: label = "XX-YY" elif operation == 2: label = "XY.YX*" else: print "Special operation not defined" return ppgplot.pgsci(plotColors[0]) tmpvals = yaxisvals print "Baseline", antList[ant1], "-", antList[ant2], ": Plotting", len( tmpvals[~tmpvals.mask] ), "points of " + label ppgplot.pgpt(xaxisvals[~tmpvals.mask], tmpvals[~tmpvals.mask], 1) addInfo(showStats, tmpvals[~tmpvals.mask], label, labXPositions[1], labYPositions[1]) else: for j in polarizations: ppgplot.pgsci(plotColors[j]) tmpvals = yaxisvals[:, j] if j == polarizations[0]: print "Baseline", antList[ant1], "-", antList[ant2], ": Plotting", len( tmpvals[~tmpvals.mask] ), "points per polarization" ppgplot.pgpt(xaxisvals[~tmpvals.mask], tmpvals[~tmpvals.mask], 1) addInfo(showStats, tmpvals[~tmpvals.mask], polLabels[j], labXPositions[j], labYPositions[j]) ppgplot.pgpage() # Close the PGPLOT device ppgplot.pgclos()
pgPlotTransform = [0, 1, 0, 0, 0, 1] ppgplot.pgslct(PGPlotWindow) ppgplot.pgsci(1) ppgplot.pgask(False) for index, o in enumerate(objects): MJD = o.getColumn('MJD') mag = o.getColumn('mag') err = o.getColumn('err') startDate = numpy.min(MJD) endDate = numpy.max(MJD) 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(startDate, endDate, magMax + meanError*2, magMin - meanError*2, 0, 0) ppgplot.pgpt(MJD, mag) ppgplot.pgerrb(2, MJD, mag, err, 0) ppgplot.pgerrb(4, MJD, mag, err, 0) ppgplot.pglab("MJD", "CRTS mag", "%s [%d]"%(o.id, len(MJD))) ppgplot.pgclos() # Compute HJDs for the observations for o in objects: hasEphemeris = o.loadEphemeris() if hasEphemeris: o.computeHJDs() # Load the PTF data for o in objects:
def plotxy(y, x=None, title=None, rangex=None, rangey=None, \ labx='', laby='', rangex2=None, rangey2=None, \ labx2='', laby2='', symbol=ppgplot_symbol_, \ line=ppgplot_linestyle_, width=ppgplot_linewidth_, \ color=ppgplot_color_, font=ppgplot_font_, logx=0, logy=0, \ logx2=0, logy2=0, errx=None, erry=None, id=0, noscale=0, \ aspect=0.7727, fontsize=ppgplot_font_size_, ticks='in', \ panels=[1,1], device=ppgplot_device_, setup=1): """ plotxy(y, ...) An interface to make various XY style plots using PGPLOT. 'y' is the 1D sequence object to plot. The optional entries are: x: x values (default = 0, 1, ...) title: graph title (default = None) rangex: ranges for the x-axis (default = automatic) rangey: ranges for the y-axis (default = automatic) labx: label for the x-axis (default = None) laby: label for the y-axis (default = None) rangex2: ranges for 2nd x-axis (default = None) rangey2: ranges for 2nd y-axis (default = None) labx2: label for the 2nd x-axis (default = None) laby2: label for the 2nd y-axis (default = None) logx: make the 1st x-axis log (default = 0 (no)) logy: make the 1st y-axis log (default = 0 (no)) logx2: make the 2nd x-axis log (default = 0 (no)) logy2: make the 2nd y-axis log (default = 0 (no)) errx: symmetric x errors (default = None) erry: symmetric y errors (default = None) symbol: symbol for points (default = None) line: line style (default = 1 (solid)) width: line width (default = 1 (thin)) color: line and/or symbol color (default = 'white') font: PGPLOT font to use (default = 1 (normal)) fontsize: PGPLOT font size to use (default = 1.0 (normal)) id: show ID line on plot (default = 0 (no)) noscale: turn off auto scaling (default = 0 (no)) aspect: aspect ratio (default = 0.7727 (rect)) ticks: Ticks point in or out (default = 'in') panels: Number of subpanels [r,c] (default = [1,1]) device: PGPLOT device to use (default = '/XWIN') setup: Auto-setup the plot (default = 1) Note: Many default values are defined in global variables with names like ppgplot_font_ or ppgplot_device_. """ # Make sure the input data is an array y = Num.asarray(y) # Announce the global variables we will be using global ppgplot_dev_open_, ppgplot_dev_prep_, ppgplot_colors_ # Define the X axis limits if needed if x is None: x = Num.arange(len(y), dtype='f') else: x = Num.asarray(x) # Determine the scaling to use for the first axis if rangex is None: rangex = [x.min(), x.max()] if rangey is None: if noscale: rangey = [y.min(), y.max()] else: rangey = scalerange(y) # Prep the plotting device... if (not ppgplot_dev_prep_ and setup): prepplot(rangex, rangey, title, labx, laby, \ rangex2, rangey2, labx2, laby2, \ logx, logy, logx2, logy2, font, fontsize, \ id, aspect, ticks, panels, device=device) # Choose the line color if type(color) == types.StringType: ppgplot.pgsci(ppgplot_colors_[color]) else: ppgplot.pgsci(color) # Plot symbols (and errors) if requested if not symbol is None: ppgplot.pgpt(x, y, symbol) # Error bars if errx is not None: if not logx: errx = Num.asarray(errx) ppgplot.pgerrx(x + errx, x - errx, y, 1.0) else: errx = 10.0**Num.asarray(errx) ppgplot.pgerrx(Num.log10(10.0**x + errx), Num.log10(10.0**x - errx), y, 1.0) if erry is not None: if not logy: erry = Num.asarray(erry) ppgplot.pgerry(x, y + erry, y - erry, 1.0) else: erry = 10.0**Num.asarray(erry) ppgplot.pgerry(x, Num.log10(10.0**y + erry), Num.log10(10.0**y - erry), 1.0) # Plot connecting lines if requested if not line is None: # Choose the line style ppgplot.pgsls(line) # Choose the line width ppgplot.pgslw(width) ppgplot.pgline(x, y)
o.calculateOffsets() o.calculateFluxes() o.addWavelengths(wavelengthLookup) PGPlotWindow = ppgplot.pgopen(arg.device) pgPlotTransform = [0, 1, 0, 0, 0, 1] ppgplot.pgslct(PGPlotWindow) ppgplot.pgsci(1) ppgplot.pgask(True) for o in objects: ppgplot.pgsch(1.6) wavelengths, fluxes, fluxerrors, bands = o.getFluxData() fluxMax = max(fluxes) fluxMin = min(fluxes) wavelengthMin = min(wavelengths) wavelengthMax = max(wavelengths) ppgplot.pgenv(500,25000 , 0, fluxMax*1.2, 0) ppgplot.pglab("wavelength [\A]", "f\d\gn\u [mJy]", o.objectID) ppgplot.pgsch(1.0) ppgplot.pgpt(wavelengths, fluxes) ppgplot.pgerrb(2, wavelengths, fluxes, fluxerrors, 0) ppgplot.pgerrb(4, wavelengths, fluxes, fluxerrors, 0) ppgplot.pgclos() sys.exit()
def main(options): global keepPlotting keepPlotting = True debug = options.debug inputMS = glob.glob(options.inms) if inputMS == '': print 'Error: You must specify a MS name.' print ' Use "uvplot.py -h" to get help.' return if options.inms.endswith('/'): options.inms = options.inms[:-1] inputMSbasename = options.inms.split('/')[-1] if inputMSbasename == '': # The user has not specified the full path of the MS inputMSbasename = options.inms device = options.device if device=='?': ppgplot.pgldev() return xaxis = options.xaxis if xaxis == 'ha': print 'Adding derived columns to allow plotting hour angle...' try: pt.addDerivedMSCal(inputMS) except: print 'Failed, trying to remove and add columns...' try: pt.removeDerivedMSCal(inputMS) pt.addDerivedMSCal(inputMS) except: print 'That failed too... plotting HA seems to not be possible.' return yaxis = options.yaxis column = options.column nx, ny = options.nxy.split(',') axlimits = options.axlimits.split(',') if len(axlimits) == 4: xmin,xmax,ymin,ymax = axlimits else: print 'Error: You must specify four axis limits' return showFlags = options.flag flagCol = options.colflag showAutocorr = options.autocorr showStats = options.statistics timeslots = options.timeslots.split(',') if len(timeslots) != 2: print 'Error: Timeslots format is start,end' return for i in range(len(timeslots)): timeslots[i] = int(timeslots[i]) antToPlotSpl = options.antennas.split(',') antToPlot = [] for i in range(len(antToPlotSpl)): tmpspl = antToPlotSpl[i].split('..') if len(tmpspl) == 1: antToPlot.append(int(antToPlotSpl[i])) elif len(tmpspl) == 2: for j in range(int(tmpspl[0]),int(tmpspl[1])+1): antToPlot.append(j) else: print 'Error: Could not understand antenna list.' return polarizations = options.polar.split(',') for i in range(len(polarizations)): polarizations[i] = int(polarizations[i]) convertStokes = options.stokes operation = options.operation if operation != '': operation = int(operation) if convertStokes: print 'Error: Stokes conversion is not compatible with special operations' return channels = options.channels.split(',') if len(channels) != 2: print 'Error: Channels format is start,end' return for i in range(len(channels)): channels[i] = int(channels[i]) if channels[1] == -1: channels[1] = None # last element even if there is only one else: channels[1] += 1 queryMode = options.query doUnwrap = options.wrap if not queryMode: # open the graphics device, use the right number of panels ppgplot.pgbeg(device, int(nx), int(ny)) # set the font size ppgplot.pgsch(1.5) ppgplot.pgvstd() # open the main table and print some info about the MS t = pt.table(inputMS, readonly=True, ack=False) firstTime = t.query(sortlist='TIME',columns='TIME',limit=1).getcell("TIME", 0) lastTime = t.query(sortlist='TIME',columns='TIME',offset=t.nrows()-1).getcell("TIME", 0) intTime = t.getcell("INTERVAL", 0) print 'Integration time:\t%f sec' % (intTime) nTimeslots = (lastTime - firstTime) / intTime if timeslots[1] == -1: timeslots[1] = nTimeslots else: timeslots[1] += 1 print 'Number of timeslots:\t%d' % (nTimeslots) # open the antenna and spectral window subtables tant = pt.table(t.getkeyword('ANTENNA'), readonly=True, ack=False) tsp = pt.table(t.getkeyword('SPECTRAL_WINDOW'), readonly=True, ack=False) numChannels = len(tsp.getcell('CHAN_FREQ',0)) print 'Number of channels:\t%d' % (numChannels) print 'Reference frequency:\t%5.2f MHz' % (tsp.getcell('REF_FREQUENCY',0)/1.e6) # Station names antList = tant.getcol('NAME') if len(antToPlot)==1 and antToPlot[0]==-1: antToPlot = range(len(antList)) print 'Station list (only starred stations will be plotted):' for i in range(len(antList)): star = ' ' if i in antToPlot: star = '*' print '%s %2d\t%s' % (star, i, antList[i]) # Bail if we're in query mode if queryMode: return # select by time from the beginning, and only use specified antennas tsel = t.query('TIME >= %f AND TIME <= %f AND ANTENNA1 IN %s AND ANTENNA2 IN %s' % (firstTime+timeslots[0]*intTime,firstTime+timeslots[1]*intTime,str(antToPlot),str(antToPlot))) # values to use for each polarization plotColors = [1,2,3,4] labXPositions = [0.35,0.45,0.55,0.65] labYPositions = [1.0,1.0,1.0,1.0] if convertStokes: polLabels = ['I','Q','U','V'] else: polLabels = ['XX','XY','YX','YY'] # define nicely written axis labels axisLabels = {'time': 'Time', 'ha': 'Hour angle', 'chan': 'Channel', 'freq': 'Frequency [MHz]', 'amp': 'Visibility amplitude', 'real': 'Real part of visibility', 'imag': 'Imaginary part of visibility', 'phase': 'Visibility phase [radians]'} # Now we loop through the baselines ppgplot.pgpage() for tpart in tsel.iter(["ANTENNA1","ANTENNA2"]): if not keepPlotting: return ant1 = tpart.getcell("ANTENNA1", 0) ant2 = tpart.getcell("ANTENNA2", 0) if ant1 not in antToPlot or ant2 not in antToPlot: continue if ant1 == ant2: if not showAutocorr: continue # Get the values to plot, strategy depends on axis type if xaxis == 'time' or xaxis == 'ha': xaxisvals = getXAxisVals(tpart, xaxis, channels) yaxisvals = getYAxisVals(tpart, yaxis, column, operation, showFlags, flagCol, channels, doUnwrap, convertStokes) else: xaxisvals = getXAxisVals(tsp, xaxis, channels) yaxisvals = getYAxisVals(tpart, yaxis, column, operation, showFlags, flagCol, channels, doUnwrap, convertStokes, xaxistype=1) if xaxisvals == None: # This baseline must be empty, go to next one print 'No good data on baseline %s - %s' % (antList[ant1],antList[ant2]) continue if debug: print xaxisvals.shape print yaxisvals.shape for r in range(len(xaxisvals)): print '%s'%yaxisvals[r] if len(xaxisvals) != len(yaxisvals): # something is wrong print 'Error: X and Y axis types incompatible' return # Plot the data, each polarization in a different color ppgplot.pgsci(1) if xmin == '': minx = xaxisvals.min() else: minx = float(xmin) if xmax == '': maxx = xaxisvals.max() else: maxx = float(xmax) if ymin == '': miny = yaxisvals.min() if numpy.ma.getmaskarray(yaxisvals.min()): print 'All data flagged on baseline %s - %s' % (antList[ant1],antList[ant2]) continue else: miny = float(ymin) if ymax == '': maxy = yaxisvals.max() else: maxy = float(ymax) if minx == maxx: minx -= 1.0 maxx += 1.0 else: diffx = maxx - minx minx -= 0.02*diffx maxx += 0.02*diffx if miny == maxy: miny -= 1.0 maxy += 1.0 else: diffy = maxy - miny miny -= 0.02*diffy maxy += 0.02*diffy #ppgplot.pgpage() ppgplot.pgswin(minx,maxx,miny,maxy) if xaxis == 'time' or xaxis == 'ha': ppgplot.pgtbox('ZHOBCNST',0.0,0,'BCNST',0.0,0) else: ppgplot.pgbox('BCNST',0.0,0,'BCNST',0.0,0) #ppgplot.pglab(axisLabels[xaxis], axisLabels[yaxis], '%s - %s'%(antList[ant1],antList[ant2])) #ppgplot.pgmtxt('T', 3.0, 0.5, 0.5, inputMSbasename) ppgplot.pglab(axisLabels[xaxis], axisLabels[yaxis], inputMSbasename + '(' + getDataDescription(column) + '): %s - %s'%(antList[ant1],antList[ant2])) if operation != 0: # some operations is defined if operation == 1: label = 'XX-YY' elif operation == 2: label = 'XY.YX*' else: print 'Special operation not defined' return ppgplot.pgsci(plotColors[0]) tmpvals = yaxisvals print 'Baseline',antList[ant1],'-',antList[ant2],': Plotting',len(tmpvals[~tmpvals.mask]),'points of ' + label ppgplot.pgpt(xaxisvals[~tmpvals.mask], tmpvals[~tmpvals.mask], 1) addInfo(showStats, tmpvals[~tmpvals.mask], label, labXPositions[1], labYPositions[1]) else: for j in polarizations: ppgplot.pgsci(plotColors[j]) tmpvals = yaxisvals[:,j] if j == polarizations[0]: print 'Baseline',antList[ant1],'-',antList[ant2],': Plotting',len(tmpvals[~tmpvals.mask]),'points per polarization' ppgplot.pgpt(xaxisvals[~tmpvals.mask], tmpvals[~tmpvals.mask], 1) addInfo(showStats, tmpvals[~tmpvals.mask], polLabels[j], labXPositions[j], labYPositions[j]) ppgplot.pgpage() # Close the PGPLOT device ppgplot.pgclos() if xaxis=='ha': print 'Removing derived columns...' pt.removeDerivedMSCal(inputMS)
ppgplot.pgpt(phases, mag) ppgplot.pgerrb(2, phases, mag, err, 0) ppgplot.pgerrb(4, phases, mag, err, 0) ppgplot.pgsci(2) model = modelledData.getColumn('mag') model.extend(model) ppgplot.pgsls(2) ppgplot.pgslw(7) ppgplot.pgline(phases, model) """ ppgplot.pgsch(1.6) ppgplot.pgenv(0, 2, 0, maxFlux, 0, 0) ppgplot.pglab("Phase", "PTF flux (mJy)", "%s"%(arg.name)) ppgplot.pgsch(1.0) ppgplot.pgpt(phases, flux) ppgplot.pgerrb(2, phases, flux, flux_err, 0) ppgplot.pgerrb(4, phases, flux, flux_err, 0) ppgplot.pgsci(2) ppgplot.pgsls(2) ppgplot.pgslw(7) modelPhases = modelledData.getColumn('phase') temp = copy.deepcopy(modelPhases) for p in modelPhases: temp.append(p + 1.0) modelPhases = temp model = modelledData.getColumn('flux') model = [m * 3631E3 for m in model] model.extend(model) ppgplot.pgline(modelPhases, model) ppgplot.pgsci(1)
def main(): parser = OptionParser(usage) parser.add_option("-x", "--xwin", action="store_true", dest="xwin", default=False, help="Don't make a postscript plot, just use an X-window") parser.add_option("-p", "--noplot", action="store_false", dest="makeplot", default=True, help="Look for pulses but do not generate a plot") parser.add_option("-m", "--maxwidth", type="float", dest="maxwidth", default=0.0, help="Set the max downsampling in sec (see below for default)") parser.add_option("-t", "--threshold", type="float", dest="threshold", default=5.0, help="Set a different threshold SNR (default=5.0)") parser.add_option("-s", "--start", type="float", dest="T_start", default=0.0, help="Only plot events occuring after this time (s)") parser.add_option("-e", "--end", type="float", dest="T_end", default=1e9, help="Only plot events occuring before this time (s)") parser.add_option("-g", "--glob", type="string", dest="globexp", default=None, help="Process the files from this glob expression") parser.add_option("-f", "--fast", action="store_true", dest="fast", default=False, help="Use a faster method of de-trending (2x speedup)") parser.add_option("-b", "--nobadblocks", action="store_false", dest="badblocks", default=True, help="Don't check for bad-blocks (may save strong pulses)") parser.add_option("-d", "--detrendlen", type="int", dest="detrendfact", default=1, help="Chunksize for detrending (pow-of-2 in 1000s)") (opts, args) = parser.parse_args() if len(args)==0: if opts.globexp==None: print full_usage sys.exit(0) else: args = [] for globexp in opts.globexp.split(): args += glob.glob(globexp) useffts = True dosearch = True if opts.xwin: pgplot_device = "/XWIN" else: pgplot_device = "" fftlen = 8192 # Should be a power-of-two for best speed chunklen = 8000 # Must be at least max_downfact less than fftlen assert(opts.detrendfact in [1,2,4,8,16,32]) detrendlen = opts.detrendfact*1000 if (detrendlen > chunklen): chunklen = detrendlen fftlen = int(next2_to_n(chunklen)) blocks_per_chunk = chunklen / detrendlen overlap = (fftlen - chunklen)/2 worklen = chunklen + 2*overlap # currently it is fftlen... max_downfact = 30 default_downfacts = [2, 3, 4, 6, 9, 14, 20, 30, 45, 70, 100, 150, 220, 300] if args[0].endswith(".singlepulse"): filenmbase = args[0][:args[0].rfind(".singlepulse")] dosearch = False elif args[0].endswith(".dat"): filenmbase = args[0][:args[0].rfind(".dat")] else: filenmbase = args[0] # Don't do a search, just read results and plot if not dosearch: info, DMs, candlist, num_v_DMstr = \ read_singlepulse_files(args, opts.threshold, opts.T_start, opts.T_end) orig_N, orig_dt = int(info.N), info.dt obstime = orig_N * orig_dt else: DMs = [] candlist = [] num_v_DMstr = {} # Loop over the input files for filenm in args: if filenm.endswith(".dat"): filenmbase = filenm[:filenm.rfind(".dat")] else: filenmbase = filenm info = infodata.infodata(filenmbase+".inf") DMstr = "%.2f"%info.DM DMs.append(info.DM) N, dt = int(info.N), info.dt obstime = N * dt # Choose the maximum width to search based on time instead # of bins. This helps prevent increased S/N when the downsampling # changes as the DM gets larger. if opts.maxwidth > 0.0: downfacts = [x for x in default_downfacts if x*dt <= opts.maxwidth] else: downfacts = [x for x in default_downfacts if x <= max_downfact] if len(downfacts) == 0: downfacts = [default_downfacts[0]] if (filenm == args[0]): orig_N = N orig_dt = dt if info.breaks: offregions = zip([x[1] for x in info.onoff[:-1]], [x[0] for x in info.onoff[1:]]) # If last break spans to end of file, don't read it in (its just padding) if offregions[-1][1] == N - 1: N = offregions[-1][0] + 1 outfile = open(filenmbase+'.singlepulse', mode='w') # Compute the file length in detrendlens roundN = N/detrendlen * detrendlen numchunks = roundN / chunklen # Read in the file print 'Reading "%s"...'%filenm timeseries = Num.fromfile(filenm, dtype=Num.float32, count=roundN) # Split the timeseries into chunks for detrending numblocks = roundN/detrendlen timeseries.shape = (numblocks, detrendlen) stds = Num.zeros(numblocks, dtype=Num.float64) # de-trend the data one chunk at a time print ' De-trending the data and computing statistics...' for ii, chunk in enumerate(timeseries): if opts.fast: # use median removal instead of detrending (2x speedup) tmpchunk = chunk.copy() tmpchunk.sort() med = tmpchunk[detrendlen/2] chunk -= med tmpchunk -= med else: # The detrend calls are the most expensive in the program timeseries[ii] = scipy.signal.detrend(chunk, type='linear') tmpchunk = timeseries[ii].copy() tmpchunk.sort() # The following gets rid of (hopefully) most of the # outlying values (i.e. power dropouts and single pulses) # If you throw out 5% (2.5% at bottom and 2.5% at top) # of random gaussian deviates, the measured stdev is ~0.871 # of the true stdev. Thus the 1.0/0.871=1.148 correction below. # The following is roughly .std() since we already removed the median stds[ii] = Num.sqrt((tmpchunk[detrendlen/40:-detrendlen/40]**2.0).sum() / (0.95*detrendlen)) stds *= 1.148 # sort the standard deviations and separate those with # very low or very high values sort_stds = stds.copy() sort_stds.sort() # identify the differences with the larges values (this # will split off the chunks with very low and very high stds locut = (sort_stds[1:numblocks/2+1] - sort_stds[:numblocks/2]).argmax() + 1 hicut = (sort_stds[numblocks/2+1:] - sort_stds[numblocks/2:-1]).argmax() + numblocks/2 - 2 std_stds = scipy.std(sort_stds[locut:hicut]) median_stds = sort_stds[(locut+hicut)/2] print " pseudo-median block standard deviation = %.2f" % (median_stds) if (opts.badblocks): lo_std = median_stds - 4.0 * std_stds hi_std = median_stds + 4.0 * std_stds # Determine a list of "bad" chunks. We will not search these. bad_blocks = Num.nonzero((stds < lo_std) | (stds > hi_std))[0] print " identified %d bad blocks out of %d (i.e. %.2f%%)" % \ (len(bad_blocks), len(stds), 100.0*float(len(bad_blocks))/float(len(stds))) stds[bad_blocks] = median_stds else: bad_blocks = [] print " Now searching..." # Now normalize all of the data and reshape it to 1-D timeseries /= stds[:,Num.newaxis] timeseries.shape = (roundN,) # And set the data in the bad blocks to zeros # Even though we don't search these parts, it is important # because of the overlaps for the convolutions for bad_block in bad_blocks: loind, hiind = bad_block*detrendlen, (bad_block+1)*detrendlen timeseries[loind:hiind] = 0.0 # Convert to a set for faster lookups below bad_blocks = set(bad_blocks) # Step through the data dm_candlist = [] for chunknum in xrange(numchunks): loind = chunknum*chunklen-overlap hiind = (chunknum+1)*chunklen+overlap # Take care of beginning and end of file overlap issues if (chunknum==0): # Beginning of file chunk = Num.zeros(worklen, dtype=Num.float32) chunk[overlap:] = timeseries[loind+overlap:hiind] elif (chunknum==numchunks-1): # end of the timeseries chunk = Num.zeros(worklen, dtype=Num.float32) chunk[:-overlap] = timeseries[loind:hiind-overlap] else: chunk = timeseries[loind:hiind] # Make a set with the current block numbers lowblock = blocks_per_chunk * chunknum currentblocks = set(Num.arange(blocks_per_chunk) + lowblock) localgoodblocks = Num.asarray(list(currentblocks - bad_blocks)) - lowblock # Search this chunk if it is not all bad if len(localgoodblocks): # This is the good part of the data (end effects removed) goodchunk = chunk[overlap:-overlap] # need to pass blocks/chunklen, localgoodblocks # dm_candlist, dt, opts.threshold to cython routine # Search non-downsampled data first # NOTE: these nonzero() calls are some of the most # expensive calls in the program. Best bet would # probably be to simply iterate over the goodchunk # in C and append to the candlist there. hibins = Num.flatnonzero(goodchunk>opts.threshold) hivals = goodchunk[hibins] hibins += chunknum * chunklen hiblocks = hibins/detrendlen # Add the candidates (which are sorted by bin) for bin, val, block in zip(hibins, hivals, hiblocks): if block not in bad_blocks: time = bin * dt dm_candlist.append(candidate(info.DM, val, time, bin, 1)) # Now do the downsampling... for downfact in downfacts: if useffts: # Note: FFT convolution is faster for _all_ downfacts, even 2 chunk2 = Num.concatenate((Num.zeros(1000), chunk, Num.zeros(1000))) goodchunk = Num.convolve(chunk2, Num.ones(downfact), mode='same') / Num.sqrt(downfact) goodchunk = goodchunk[overlap:-overlap] #O qualcosa di simile, altrimenti non so perche' trova piu' candidati! Controllare! else: # The normalization of this kernel keeps the post-smoothing RMS = 1 kernel = Num.ones(downfact, dtype=Num.float32) / \ Num.sqrt(downfact) smoothed_chunk = scipy.signal.convolve(chunk, kernel, 1) goodchunk = smoothed_chunk[overlap:-overlap] #hibins = Num.nonzero(goodchunk>opts.threshold)[0] hibins = Num.flatnonzero(goodchunk>opts.threshold) hivals = goodchunk[hibins] hibins += chunknum * chunklen hiblocks = hibins/detrendlen hibins = hibins.tolist() hivals = hivals.tolist() # Now walk through the new candidates and remove those # that are not the highest but are within downfact/2 # bins of a higher signal pulse hibins, hivals = prune_related1(hibins, hivals, downfact) # Insert the new candidates into the candlist, but # keep it sorted... for bin, val, block in zip(hibins, hivals, hiblocks): if block not in bad_blocks: time = bin * dt bisect.insort(dm_candlist, candidate(info.DM, val, time, bin, downfact)) # Now walk through the dm_candlist and remove the ones that # are within the downsample proximity of a higher # signal-to-noise pulse dm_candlist = prune_related2(dm_candlist, downfacts) print " Found %d pulse candidates"%len(dm_candlist) # Get rid of those near padding regions if info.breaks: prune_border_cases(dm_candlist, offregions) # Write the pulses to an ASCII output file if len(dm_candlist): #dm_candlist.sort(cmp_sigma) outfile.write("# DM Sigma Time (s) Sample Downfact\n") for cand in dm_candlist: outfile.write(str(cand)) outfile.close() # Add these candidates to the overall candidate list for cand in dm_candlist: candlist.append(cand) num_v_DMstr[DMstr] = len(dm_candlist) if (opts.makeplot): # Step through the candidates to make a SNR list DMs.sort() snrs = [] for cand in candlist: if not Num.isinf(cand.sigma): snrs.append(cand.sigma) if snrs: maxsnr = max(int(max(snrs)), int(opts.threshold)) + 3 else: maxsnr = int(opts.threshold) + 3 # Generate the SNR histogram snrs = Num.asarray(snrs) (num_v_snr, lo_snr, d_snr, num_out_of_range) = \ scipy.stats.histogram(snrs, int(maxsnr-opts.threshold+1), [opts.threshold, maxsnr]) snrs = Num.arange(maxsnr-opts.threshold+1, dtype=Num.float64) * d_snr \ + lo_snr + 0.5*d_snr num_v_snr = num_v_snr.astype(Num.float32) num_v_snr[num_v_snr==0.0] = 0.001 # Generate the DM histogram num_v_DM = Num.zeros(len(DMs)) for ii, DM in enumerate(DMs): num_v_DM[ii] = num_v_DMstr["%.2f"%DM] DMs = Num.asarray(DMs) # open the plot device short_filenmbase = filenmbase[:filenmbase.find("_DM")] if opts.T_end > obstime: opts.T_end = obstime if pgplot_device: ppgplot.pgopen(pgplot_device) else: if (opts.T_start > 0.0 or opts.T_end < obstime): ppgplot.pgopen(short_filenmbase+'_%.0f-%.0fs_singlepulse.ps/VPS'% (opts.T_start, opts.T_end)) else: ppgplot.pgopen(short_filenmbase+'_singlepulse.ps/VPS') ppgplot.pgpap(7.5, 1.0) # Width in inches, aspect # plot the SNR histogram ppgplot.pgsvp(0.06, 0.31, 0.6, 0.87) ppgplot.pgswin(opts.threshold, maxsnr, Num.log10(0.5), Num.log10(2*max(num_v_snr))) ppgplot.pgsch(0.8) ppgplot.pgbox("BCNST", 0, 0, "BCLNST", 0, 0) ppgplot.pgmtxt('B', 2.5, 0.5, 0.5, "Signal-to-Noise") ppgplot.pgmtxt('L', 1.8, 0.5, 0.5, "Number of Pulses") ppgplot.pgsch(1.0) ppgplot.pgbin(snrs, Num.log10(num_v_snr), 1) # plot the DM histogram ppgplot.pgsvp(0.39, 0.64, 0.6, 0.87) # Add [1] to num_v_DM in YMAX below so that YMIN != YMAX when max(num_v_DM)==0 ppgplot.pgswin(min(DMs)-0.5, max(DMs)+0.5, 0.0, 1.1*max(num_v_DM+[1])) ppgplot.pgsch(0.8) ppgplot.pgbox("BCNST", 0, 0, "BCNST", 0, 0) ppgplot.pgmtxt('B', 2.5, 0.5, 0.5, "DM (pc cm\u-3\d)") ppgplot.pgmtxt('L', 1.8, 0.5, 0.5, "Number of Pulses") ppgplot.pgsch(1.0) ppgplot.pgbin(DMs, num_v_DM, 1) # plot the SNR vs DM plot ppgplot.pgsvp(0.72, 0.97, 0.6, 0.87) ppgplot.pgswin(min(DMs)-0.5, max(DMs)+0.5, opts.threshold, maxsnr) ppgplot.pgsch(0.8) ppgplot.pgbox("BCNST", 0, 0, "BCNST", 0, 0) ppgplot.pgmtxt('B', 2.5, 0.5, 0.5, "DM (pc cm\u-3\d)") ppgplot.pgmtxt('L', 1.8, 0.5, 0.5, "Signal-to-Noise") ppgplot.pgsch(1.0) cand_ts = Num.zeros(len(candlist), dtype=Num.float32) cand_SNRs = Num.zeros(len(candlist), dtype=Num.float32) cand_DMs = Num.zeros(len(candlist), dtype=Num.float32) for ii, cand in enumerate(candlist): cand_ts[ii], cand_SNRs[ii], cand_DMs[ii] = \ cand.time, cand.sigma, cand.DM ppgplot.pgpt(cand_DMs, cand_SNRs, 20) # plot the DM vs Time plot ppgplot.pgsvp(0.06, 0.97, 0.08, 0.52) ppgplot.pgswin(opts.T_start, opts.T_end, min(DMs)-0.5, max(DMs)+0.5) ppgplot.pgsch(0.8) ppgplot.pgbox("BCNST", 0, 0, "BCNST", 0, 0) ppgplot.pgmtxt('B', 2.5, 0.5, 0.5, "Time (s)") ppgplot.pgmtxt('L', 1.8, 0.5, 0.5, "DM (pc cm\u-3\d)") # Circles are symbols 20-26 in increasing order snr_range = 12.0 cand_symbols = (cand_SNRs-opts.threshold)/snr_range * 6.0 + 20.5 cand_symbols = cand_symbols.astype(Num.int32) cand_symbols[cand_symbols>26] = 26 for ii in [26, 25, 24, 23, 22, 21, 20]: inds = Num.nonzero(cand_symbols==ii)[0] ppgplot.pgpt(cand_ts[inds], cand_DMs[inds], ii) # Now fill the infomation area ppgplot.pgsvp(0.05, 0.95, 0.87, 0.97) ppgplot.pgsch(1.0) ppgplot.pgmtxt('T', 0.5, 0.0, 0.0, "Single pulse results for '%s'"%short_filenmbase) ppgplot.pgsch(0.8) # first row ppgplot.pgmtxt('T', -1.1, 0.02, 0.0, 'Source: %s'%\ info.object) ppgplot.pgmtxt('T', -1.1, 0.33, 0.0, 'RA (J2000):') ppgplot.pgmtxt('T', -1.1, 0.5, 0.0, info.RA) ppgplot.pgmtxt('T', -1.1, 0.73, 0.0, 'N samples: %.0f'%orig_N) # second row ppgplot.pgmtxt('T', -2.4, 0.02, 0.0, 'Telescope: %s'%\ info.telescope) ppgplot.pgmtxt('T', -2.4, 0.33, 0.0, 'DEC (J2000):') ppgplot.pgmtxt('T', -2.4, 0.5, 0.0, info.DEC) ppgplot.pgmtxt('T', -2.4, 0.73, 0.0, 'Sampling time: %.2f \gms'%\ (orig_dt*1e6)) # third row if info.instrument.find("pigot") >= 0: instrument = "Spigot" else: instrument = info.instrument ppgplot.pgmtxt('T', -3.7, 0.02, 0.0, 'Instrument: %s'%instrument) if (info.bary): ppgplot.pgmtxt('T', -3.7, 0.33, 0.0, 'MJD\dbary\u: %.12f'%info.epoch) else: ppgplot.pgmtxt('T', -3.7, 0.33, 0.0, 'MJD\dtopo\u: %.12f'%info.epoch) ppgplot.pgmtxt('T', -3.7, 0.73, 0.0, 'Freq\dctr\u: %.1f MHz'%\ ((info.numchan/2-0.5)*info.chan_width+info.lofreq)) ppgplot.pgiden() ppgplot.pgend()
cycles.append(upper) ocErrors.append(ocerror) for c, o, oe in zip(cycles, ocs, ocErrors): print c, o, oe plotname = "QSVir-oc" plotDevices = ["/xs", "%s.eps/ps"%plotname] for plotDevice in plotDevices: mainPGPlotWindow = ppgplot.pgopen(plotDevice) pgPlotTransform = [0, 1, 0, 0, 0, 1] ppgplot.pgpap(10, 0.618) ppgplot.pgsci(1) ppgplot.pgenv(min(cycles)*1.05, max(cycles)*1.05, min(ocs)*1.15, max(ocs)*1.15, 0, 0) ppgplot.pgslw(1) ppgplot.pgpt(cycles, ocs, 2) ppgplot.pgslw(1) ppgplot.pgerrb(2, cycles, ocs, ocErrors, 0) ppgplot.pgerrb(4, cycles, ocs, ocErrors, 0) ppgplot.pgsls(2) ppgplot.pglab("Cycle number", "O-C (seconds)", "") ppgplot.pgclos() """"# Map some colours oColours = [] for o in observatories: index = o % len(colourMap) colour = colourMap[index] oColours.append(colour) # print oColours"""
def main(options): debug = options.debug MSlist = [] for inmspart in options.inms.split(','): for msname in glob.iglob(inmspart): MSlist.append(msname) if len(MSlist) == 0: print 'Error: You must specify at least one MS name.' print ' Use "uvplot.py -h" to get help.' return if len(MSlist) > 1: print 'WARNING: Antenna selection (other than all) may not work well' print ' when plotting more than one MS. Carefully inspect the' print ' listings of antenna numbers/names!' device = options.device if device=='?': ppgplot.pgldev() return if options.title == '': plottitle = options.inms else: plottitle = options.title axlimits = options.axlimits.split(',') if len(axlimits) == 4: xmin,xmax,ymin,ymax = axlimits else: print 'Error: You must specify four axis limits' return timeslots = options.timeslots.split(',') if len(timeslots) != 3: print 'Error: Timeslots format is start,skip,end' return for i in range(len(timeslots)): timeslots[i] = int(timeslots[i]) if timeslots[i] < 0: print 'Error: timeslots values must not be negative' return antToPlotSpl = options.antennas.split(',') antToPlot = [] for i in range(len(antToPlotSpl)): tmpspl = antToPlotSpl[i].split('..') if len(tmpspl) == 1: antToPlot.append(int(antToPlotSpl[i])) elif len(tmpspl) == 2: for j in range(int(tmpspl[0]),int(tmpspl[1])+1): antToPlot.append(j) else: print 'Error: Could not understand antenna list.' return queryMode = options.query plotLambda = options.kilolambda badval = 0.0 xaxisvals = numpy.array([]) yaxisvals = numpy.array([]) savex = numpy.array([]) savey = numpy.array([]) numPlotted = 0 for inputMS in MSlist: # open the main table and print some info about the MS print 'Getting info for', inputMS t = pt.table(inputMS, readonly=True, ack=False) tfreq = pt.table(t.getkeyword('SPECTRAL_WINDOW'),readonly=True,ack=False) ref_freq = tfreq.getcol('REF_FREQUENCY',nrow=1)[0] ch_freq = tfreq.getcol('CHAN_FREQ',nrow=1)[0] print 'Reference frequency:\t%f MHz' % (ref_freq/1.e6) if options.wideband: ref_wavelength = 2.99792458e8/ch_freq else: ref_wavelength = [2.99792458e8/ref_freq] print 'Reference wavelength:\t%f m' % (ref_wavelength[0]) if options.sameuv and numPlotted > 0: print 'Assuming same uvw as first MS!' if plotLambda: for w in ref_wavelength: xaxisvals = numpy.append(xaxisvals,[savex/w/1000.,-savex/w/1000.]) yaxisvals = numpy.append(yaxisvals,[savey/w/1000.,-savey/w/1000.]) else: print 'Plotting more than one MS with same uv, all in meters... do you want -k?' xaxisvals = numpy.append(xaxisvals,[savex,-savex]) yaxisvals = numpy.append(yaxisvals,[savey,-savey]) continue firstTime = t.getcell("TIME", 0) lastTime = t.getcell("TIME", t.nrows()-1) intTime = t.getcell("INTERVAL", 0) print 'Integration time:\t%f sec' % (intTime) nTimeslots = (lastTime - firstTime) / intTime print 'Number of timeslots:\t%d' % (nTimeslots) if timeslots[1] == 0: if nTimeslots >= 100: timeskip = int(nTimeslots/100) else: timeskip = 1 else: timeskip = int(timeslots[1]) print 'For each baseline, plotting one point every %d samples' % (timeskip) if timeslots[2] == 0: timeslots[2] = nTimeslots # open the antenna subtable tant = pt.table(t.getkeyword('ANTENNA'), readonly=True, ack=False) # Station names antList = tant.getcol('NAME') if len(antToPlot)==1 and antToPlot[0]==-1: antToPlot = range(len(antList)) print 'Station list (only starred stations will be plotted):' for i in range(len(antList)): star = ' ' if i in antToPlot: star = '*' print '%s %2d\t%s' % (star, i, antList[i]) # Bail if we're in query mode if queryMode: return # select by time from the beginning, and only use specified antennas tsel = t.query('TIME >= %f AND TIME <= %f AND ANTENNA1 IN %s AND ANTENNA2 IN %s' % (firstTime+timeslots[0]*intTime,firstTime+timeslots[2]*intTime,str(antToPlot),str(antToPlot)), columns='ANTENNA1,ANTENNA2,UVW') # Now we loop through the baselines i = 0 nb = (len(antToPlot)*(len(antToPlot)-1))/2 sys.stdout.write('Reading uvw for %d baselines: %04d/%04d'%(nb,i,nb)) sys.stdout.flush() for tpart in tsel.iter(["ANTENNA1","ANTENNA2"]): ant1 = tpart.getcell("ANTENNA1", 0) ant2 = tpart.getcell("ANTENNA2", 0) if ant1 not in antToPlot or ant2 not in antToPlot: continue if ant1 == ant2: continue i += 1 sys.stdout.write('\b\b\b\b\b\b\b\b\b%04d/%04d'%(i,nb)) sys.stdout.flush() # Get the values to plot uvw = tpart.getcol('UVW', rowincr=timeskip) if numPlotted == 0: savex = numpy.append(savex,[uvw[:,0],-uvw[:,0]]) savey = numpy.append(savey,[uvw[:,1],-uvw[:,1]]) if plotLambda: for w in ref_wavelength: xaxisvals = numpy.append(xaxisvals,[uvw[:,0]/w/1000.,-uvw[:,0]/w/1000.]) yaxisvals = numpy.append(yaxisvals,[uvw[:,1]/w/1000.,-uvw[:,1]/w/1000.]) else: xaxisvals = numpy.append(xaxisvals,[uvw[:,0],-uvw[:,0]]) yaxisvals = numpy.append(yaxisvals,[uvw[:,1],-uvw[:,1]]) #if debug: # print uvw.shape # print xaxisvals.shape # print yaxisvals.shape #else: # sys.stdout.write('.') # sys.stdout.flush() sys.stdout.write(' Done!\n') numPlotted += 1 print 'Plotting uv points ...' # open the graphics device, using only one panel ppgplot.pgbeg(device, 1, 1) # set the font size ppgplot.pgsch(1) ppgplot.pgvstd() # Plot the data if debug: print xaxisvals xaxisvals = numpy.array(xaxisvals) yaxisvals = numpy.array(yaxisvals) tmpvals = numpy.sqrt(xaxisvals**2+yaxisvals**2) ppgplot.pgsci(1) uvmax = max(xaxisvals.max(),yaxisvals.max()) uvmin = min(xaxisvals.min(),yaxisvals.min()) uvuplim = 0.02*(uvmax-uvmin)+uvmax uvlolim = uvmin-0.02*(uvmax-uvmin) if xmin == '': minx = uvlolim else: minx = float(xmin) if xmax == '': maxx = uvuplim else: maxx = float(xmax) if ymin == '': miny = uvlolim else: miny = float(ymin) if ymax == '': maxy = uvuplim else: maxy = float(ymax) if minx == maxx: minx = -1.0 maxx = 1.0 if miny == maxy: miny = -1.0 maxy = 1.0 ppgplot.pgpage() ppgplot.pgswin(minx,maxx,miny,maxy) ppgplot.pgbox('BCNST',0.0,0,'BCNST',0.0,0) if plotLambda: ppgplot.pglab('u [k\gl]', 'v [k\gl]', '%s'%(plottitle)) else: ppgplot.pglab('u [m]', 'v [m]', '%s'%(plottitle)) ppgplot.pgpt(xaxisvals[tmpvals!=badval], yaxisvals[tmpvals!=badval], 1) # Close the PGPLOT device ppgplot.pgclos()
ppgplot.pgask(arg.ask) for index, photometry in enumerate(allData): x_values = photometry[xColumn] y_values = photometry[yColumn] y_errors = photometry[yErrors] x_lower, x_upper = (min(x_values), max(x_values)) numpoints = len(x_values) if "JD" in xColumn: x_offset = int(x_lower) x_values = [(x-x_offset) for x in x_values] xLabel= xColumn + " - %d"%x_lower ppgplot.pgsci(1) ppgplot.pgenv(min(x_values), max(x_values), lowerY, upperY, 0, 0) ppgplot.pgslw(7) ppgplot.pgpt(x_values, y_values, 1) ppgplot.pgslw(1) ppgplot.pgerrb(2, x_values, y_values, y_errors, 0) ppgplot.pgerrb(4, x_values, y_values, y_errors, 0) ppgplot.pglab(xLabel, yLabel, photometry["runName"]) x_values = [(x-x_offset) for x in derivative_x] # x_values = derivative_x derivPGPlotWindow = ppgplot.pgopen(plotDevice) pgPlotTransform = [0, 1, 0, 0, 0, 1] ppgplot.pgpap(5, 0.618) ppgplot.pgask(arg.ask) ppgplot.pgenv(min(x_values), max(x_values), min(derivative_y), max(derivative_y), 0, 0) ppgplot.pgsci(2)