def resizeDev(): """ Des: resize plot area after resizing window with mouse ABB: resize """ __MessHand.info("resizing plot page") ppgplot.pgpage()
def nextplotpage(reset=1): """ nextplotpage(): Advance the plotting device to a new page. The optional entry is: reset: reset defaults or not (default = 1 (yes)) """ global ppgplot_dev_open_, ppgplot_dev_prep_ if (ppgplot_dev_open_): ppgplot.pgpage() ppgplot_dev_prep_ = 0 else: print "Can't go to the next plot page unless a plotting device is open." if (reset): resetdefaults()
def nextplotpage(reset=0): """ nextplotpage(): Advance the plotting device to a new page. The optional entry is: reset: reset defaults or not (default = 0 (no)) """ global ppgplot_dev_open_, ppgplot_dev_prep_ if (ppgplot_dev_open_): ppgplot.pgpage() ppgplot_dev_prep_ = 0 else: print "Can't go to the next plot page unless a plotting device is open." if (reset): resetdefaults()
def nextpage(vertical=False): """ Start a new page in the currently opened device. Default is to orient paper horizontally (landscape). If vertical is True then the paper will be oriented vertically. """ # New page if ppgplot.pgqid()!=0: ppgplot.pgpage() ppgplot.pgswin(0,1,0,1) if vertical: ppgplot.pgpap(7.9, 11.0/8.5) else: ppgplot.pgpap(10.25, 8.5/11.0) ppgplot.pgiden() else: sys.stderr.write("Cannot start new page. No pgplot device open.\n") raise "No open pgplot device"
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()
def prepplot(rangex, rangey, title=None, labx=None, laby=None, \ rangex2=None, rangey2=None, labx2=None, laby2=None, \ logx=0, logy=0, logx2=0, logy2=0, font=ppgplot_font_, \ fontsize=ppgplot_font_size_, id=0, aspect=1, ticks='in', \ panels=[1,1], device=ppgplot_device_): """ prepplot(rangex, rangey, ...) Open a PGPLOT device for plotting. 'rangex' and 'rangey' are sequence objects giving min and max values for each axis. The optional entries are: title: graph title (default = None) 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)) 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)) aspect: Aspect ratio (default = 1 (square)) ticks: Ticks point in or out (default = 'in') panels: Number of subpanels [r,c] (default = [1,1]) device: PGPLOT device to use (default = '/XWIN') Note: Many default values are defined in global variables with names like ppgplot_font_ or ppgplot_device_. """ global ppgplot_dev_open_, ppgplot_dev_prep_ # Check if we will use second X or Y axes # Note: if using a 2nd X axis, the range should correspond # to the minimum and maximum values of the 1st X axis. If # using a 2nd Y axis, the range should correspond to the # scalerange() values of the 1st Y axis. if rangex2 is None: rangex2=rangex otherxaxis=0 else: otherxaxis=1 if rangey2 is None: rangey2=rangey otheryaxis=0 else: otheryaxis=1 # Open the plot device if (not ppgplot_dev_open_): ppgplot.pgopen(device) # My little add-on to switch the background to white if device == '/XWIN': reset_colors() if device == '/AQT': ppgplot.pgsci(0) # Let the routines know that we already have a device open ppgplot_dev_open_ = 1 # Set the aspect ratio ppgplot.pgpap(0.0, aspect) if (panels != [1,1]): # Set the number of panels ppgplot.pgsubp(panels[0], panels[1]) ppgplot.pgpage() # Choose the font ppgplot.pgscf(font) # Choose the font size ppgplot.pgsch(fontsize) # Choose the font size ppgplot.pgslw(ppgplot_linewidth_) # Plot the 2nd axis if needed first if otherxaxis or otheryaxis: ppgplot.pgvstd() ppgplot.pgswin(rangex2[0], rangex2[1], rangey2[0], rangey2[1]) # Decide how the axes will be drawn if ticks=='in': env = "CMST" else: env = "CMSTI" if logx2: lxenv='L' else: lxenv='' if logy2: lyenv='L' else: lyenv='' if otherxaxis and otheryaxis: ppgplot.pgbox(env+lxenv, 0.0, 0, env+lyenv, 0.0, 0) elif otheryaxis: ppgplot.pgbox("", 0.0, 0, env+lyenv, 0.0, 0) else: ppgplot.pgbox(env+lxenv, 0.0, 0, "", 0.0, 0) # Now setup the primary axis ppgplot.pgvstd() ppgplot.pgswin(rangex[0], rangex[1], rangey[0], rangey[1]) # Decide how the axes will be drawn if ticks=='in': env = "ST" else: env = "STI" if logx: lxenv='L' else: lxenv='' if logy: lyenv='L' else: lyenv='' if otherxaxis and otheryaxis: ppgplot.pgbox("BN"+env+lxenv, 0.0, 0, "BN"+env+lyenv, 0.0, 0) elif otheryaxis: ppgplot.pgbox("BCN"+env+lxenv, 0.0, 0, "BN"+env+lyenv, 0.0, 0) elif otherxaxis: ppgplot.pgbox("BN"+env+lxenv, 0.0, 0, "BCN"+env+lyenv, 0.0, 0) else: ppgplot.pgbox("BCN"+env+lxenv, 0.0, 0, "BCN"+env+lyenv, 0.0, 0) # My little add-on to switch the background to white if device == '/AQT' or device == '/XWIN': reset_colors() # Add labels if not title is None: ppgplot.pgmtxt("T", 3.2, 0.5, 0.5, title) ppgplot.pgmtxt("B", 3.0, 0.5, 0.5, labx) ppgplot.pgmtxt("L", 2.6, 0.5, 0.5, laby) if otherxaxis: ppgplot.pgmtxt("T", 2.0, 0.5, 0.5, labx2) if otheryaxis: ppgplot.pgmtxt("R", 3.0, 0.5, 0.5, laby2) # Add ID line if required if (id==1): ppgplot.pgiden() # Let the routines know that we have already prepped the device ppgplot_dev_prep_ = 1
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)
def prepplot(rangex, rangey, title=None, labx=None, laby=None, \ rangex2=None, rangey2=None, labx2=None, laby2=None, \ logx=0, logy=0, logx2=0, logy2=0, font=ppgplot_font_, \ fontsize=ppgplot_font_size_, id=0, aspect=1, ticks='in', \ panels=[1,1], device=ppgplot_device_): """ prepplot(rangex, rangey, ...) Open a PGPLOT device for plotting. 'rangex' and 'rangey' are sequence objects giving min and max values for each axis. The optional entries are: title: graph title (default = None) 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)) 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)) aspect: Aspect ratio (default = 1 (square)) ticks: Ticks point in or out (default = 'in') panels: Number of subpanels [r,c] (default = [1,1]) device: PGPLOT device to use (default = '/XWIN') Note: Many default values are defined in global variables with names like ppgplot_font_ or ppgplot_device_. """ global ppgplot_dev_open_, ppgplot_dev_prep_ # Check if we will use second X or Y axes # Note: if using a 2nd X axis, the range should correspond # to the minimum and maximum values of the 1st X axis. If # using a 2nd Y axis, the range should correspond to the # scalerange() values of the 1st Y axis. if rangex2 is None: rangex2 = rangex otherxaxis = 0 else: otherxaxis = 1 if rangey2 is None: rangey2 = rangey otheryaxis = 0 else: otheryaxis = 1 # Open the plot device if (not ppgplot_dev_open_): ppgplot.pgopen(device) # Let the routines know that we already have a device open ppgplot_dev_open_ = 1 # Set the aspect ratio ppgplot.pgpap(0.0, aspect) if (panels != [1, 1]): # Set the number of panels ppgplot.pgsubp(panels[0], panels[1]) ppgplot.pgpage() # Choose the font ppgplot.pgscf(font) # Choose the font size ppgplot.pgsch(fontsize) # Choose the font size ppgplot.pgslw(ppgplot_linewidth_) # Plot the 2nd axis if needed first if otherxaxis or otheryaxis: ppgplot.pgvstd() ppgplot.pgswin(rangex2[0], rangex2[1], rangey2[0], rangey2[1]) # Decide how the axes will be drawn if ticks == 'in': env = "CMST" else: env = "CMSTI" if logx2: lxenv = 'L' else: lxenv = '' if logy2: lyenv = 'L' else: lyenv = '' if otherxaxis and otheryaxis: ppgplot.pgbox(env + lxenv, 0.0, 0, env + lyenv, 0.0, 0) elif otheryaxis: ppgplot.pgbox("", 0.0, 0, env + lyenv, 0.0, 0) else: ppgplot.pgbox(env + lxenv, 0.0, 0, "", 0.0, 0) # Now setup the primary axis ppgplot.pgvstd() ppgplot.pgswin(rangex[0], rangex[1], rangey[0], rangey[1]) # Decide how the axes will be drawn if ticks == 'in': env = "ST" else: env = "STI" if logx: lxenv = 'L' else: lxenv = '' if logy: lyenv = 'L' else: lyenv = '' if otherxaxis and otheryaxis: ppgplot.pgbox("BN" + env + lxenv, 0.0, 0, "BN" + env + lyenv, 0.0, 0) elif otheryaxis: ppgplot.pgbox("BCN" + env + lxenv, 0.0, 0, "BN" + env + lyenv, 0.0, 0) elif otherxaxis: ppgplot.pgbox("BN" + env + lxenv, 0.0, 0, "BCN" + env + lyenv, 0.0, 0) else: ppgplot.pgbox("BCN" + env + lxenv, 0.0, 0, "BCN" + env + lyenv, 0.0, 0) # Add labels if not title is None: ppgplot.pgmtxt("T", 3.2, 0.5, 0.5, title) ppgplot.pgmtxt("B", 3.0, 0.5, 0.5, labx) ppgplot.pgmtxt("L", 2.6, 0.5, 0.5, laby) if otherxaxis: ppgplot.pgmtxt("T", 2.0, 0.5, 0.5, labx2) if otheryaxis: ppgplot.pgmtxt("R", 3.0, 0.5, 0.5, laby2) # Add ID line if required if (id == 1): ppgplot.pgiden() # Let the routines know that we have already prepped the device ppgplot_dev_prep_ = 1
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()
freqcut = pffdot[np / 2, :] fdotcut = pffdot[:, np / 2] image = 'antirainbow' device = 'ffdot_combined.eps/VCPS' device = '/XWIN' labx = 'Fourier Frequency Offset (bins)' laby = 'Fourier Frequency Derivative (bins)' contours = num.asarray([0.1, 0.3, 0.5, 0.7, 0.9]) imfract = 0.65 margin = 0.08 ppgplot.pgopen(device) ppgplot.pgpap(0.0, 1.0) ppgplot.pgpage() # Give z and w values and power change ppgplot.pgsvp(margin + imfract, 1.0 - margin / 2, margin + imfract, 1.0 - margin / 2) ppgplot.pgswin(0.0, 1.0, 0.0, 1.0) ppgplot.pgtext(0.1, 0.8, "Frac Recovered" % frp) ppgplot.pgtext(0.2, 0.65, "Power = %.3f" % frp) ppgplot.pgtext(0.1, 0.4, "signal z = %.1f" % z) ppgplot.pgtext(0.1, 0.25, "signal w = %.1f" % w) # freq cut ppgplot.pgsvp(margin, margin + imfract, margin + imfract, 1.0 - margin / 2) ppgplot.pgswin(min(rs), max(rs), -0.1, 1.1) ppgplot.pgbox("BCST", 0.0, 0, "BCNST", 0.0, 0) ppgplot.pgline(rs, freqcut)
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()
freqcut = pffdot[np/2, :] fdotcut = pffdot[:, np/2] image='antirainbow' device='ffdot_combined.eps/VCPS' device='/XWIN' labx='Fourier Frequency Offset (bins)' laby='Fourier Frequency Derivative (bins)' contours = num.asarray([0.1, 0.3, 0.5, 0.7, 0.9]) imfract = 0.65 margin = 0.08 ppgplot.pgopen(device) ppgplot.pgpap(0.0, 1.0) ppgplot.pgpage() # Give z and w values and power change ppgplot.pgsvp(margin+imfract, 1.0-margin/2, margin+imfract, 1.0-margin/2) ppgplot.pgswin(0.0, 1.0, 0.0, 1.0) ppgplot.pgtext(0.1, 0.8, "Frac Recovered" % frp) ppgplot.pgtext(0.2, 0.65, "Power = %.3f" % frp) ppgplot.pgtext(0.1, 0.4, "signal z = %.1f" % z) ppgplot.pgtext(0.1, 0.25, "signal w = %.1f" % w) # freq cut ppgplot.pgsvp(margin, margin+imfract, margin+imfract, 1.0-margin/2) ppgplot.pgswin(min(rs), max(rs), -0.1, 1.1) ppgplot.pgbox("BCST", 0.0, 0, "BCNST", 0.0, 0) ppgplot.pgline(rs, freqcut) ppgplot.pgmtxt("L", 2.0, 0.5, 0.5, "Relative Power");
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()