Example #1
0
def plot_candidate_sheet(rating_objects, pdm_cand_id, cand_ratings, description):
    plot_utils.beginplot("cand_rating_report%s(%d).ps" % (currdatetime.strftime('%y%m%d'),pdm_cand_id), vertical=True)
    ppgplot.pgtext(0,1,"%d: %s" % (pdm_cand_id, description))
    top = 0.5
    first = True
    for ratobj, rating in zip(rating_objects,cand_ratings):
	if (top - PARASPACING) < 0:
	    if first:
		#
		# Add P, DM, subints, subbands?
		#
                pfd = rating_utils.get_pfd_by_cand_id(pdm_cand_id)
                prof = rating_utils.prep_profile(pfd)
                ppgplot.pgsvp(0.10, 0.90, 0.60, 0.90)
                ppgplot.pgswin(0, NUMPHASE, 1.1*np.min(prof), 1.1*np.max(prof))
                ppgplot.pgbox('BCNTS', 0.25,5,'BC',0.0,0)
		onephase = np.linspace(0,1,prof.size, endpoint=False)
		manyphase = np.resize(onephase,prof.size*NUMPHASE)+np.arange(0,NUMPHASE).repeat(prof.size)
                ppgplot.pgline(manyphase, np.resize(prof, (NUMPHASE*prof.size,)))
		first = False
	    plot_utils.nextpage(vertical=True)
	    ppgplot.pgtext(0,1,"%d: %s (cont'd)" % (pdm_cand_id, description))
	    top = 0.9
	ppgplot.pgtext(0,top, '%s: %s' % (ratobj.name, rating))
	top -= PARASPACING
    if first:
	pfd = rating_utils.get_pfd_by_cand_id(pdm_cand_id)
        prof = rating_utils.prep_profile(pfd)
        ppgplot.pgsvp(0.10, 0.90, 0.60, 0.90)
        ppgplot.pgswin(0, NUMPHASE, 1.1*np.min(prof), 1.1*np.max(prof))
        ppgplot.pgbox('BCNTS', 0.25,5,'BC',0.0,0)
        ppgplot.pgline(np.linspace(0,NUMPHASE,prof.size*NUMPHASE), np.resize(prof, (NUMPHASE*prof.size,)))
Example #2
0
    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)
Example #3
0
def plot_selection_new(ident, dt=1.0, w=10.0):
    dx, dy = ident.x1 - ident.x0, ident.y1 - ident.y0
    ang = np.mod(np.arctan2(dy, dx), 2.0 * np.pi)
    r = np.sqrt(dx**2 + dy**2)
    drdt = r / (ident.t1 - ident.t0)
    sa, ca = np.sin(ang), np.cos(ang)

    dx = np.array([-dt, -dt, ident.t1 + dt, ident.t1 + dt, -dt]) * drdt
    dy = np.array([w, -w, -w, w, w])
    x = ca * dx - sa * dy + ident.x0
    y = sa * dx + ca * dy + ident.y0

    ppg.pgline(x, y)
    ppg.pgpt1(x[0], y[0], 17)
    ppg.pgpt1(x[1], y[1], 17)
    ppg.pgsch(0.65)
    ppg.pgslw(2)
    if (x[0] < x[1]) & (ident.x0 < ident.x1):
        ppg.pgptxt(x[1], y[1] - 1.5 * w, 0.0, 0.0, " %05d" % ident.norad)
    else:
        ppg.pgptxt(x[0], y[0] + 0.5 * w, 0.0, 0.0, " %05d" % ident.norad)
    ppg.pgsch(1.0)
    ppg.pgslw(1)

    return
Example #4
0
    def plot(self, vmin, vmax, mpl=False, cmap=CMDEF, border=True):
        """
        Elementary intensity plot using either matplotlib's imshow
        or pgplot's pggray. Typically some setup may be needed
        before and after this.

        vmin   -- image value for lowest intensity
        vmax   -- image value for highest intensity
        mpl    -- True for matplotlib, otherwise pgplot
        cmap   -- colour map if mpl
        border -- plot a rectangular border around the outermost pixels or not
        """
        if border:
            x1, x2 = self.llx-0.5,self.llx+self.xbin*self.nx-0.5
            y1, y2 = self.lly-0.5,self.lly+self.ybin*self.ny-0.5

        if mpl:
            limits = self.llx-0.5,self.llx+self.xbin*self.nx-0.5,self.lly-0.5,self.lly+self.ybin*self.ny-0.5
            plt.imshow(self._data, cmap=cmap, interpolation='nearest', \
                           vmin=vmin, vmax=vmax, origin='lower', extent=limits)
            if border:
                plt.plot([x1,x2,x2,x1,x1],[y1,y1,y2,y2,y1])
        else:
            tr = np.array([self.llx-self.xbin,self.xbin,0,self.lly-self.ybin,0,self.ybin])
            pg.pggray(self._data,0,self.nx-1,0,self.ny-1,vmax,vmin,tr)
            if border:
                pg.pgline([x1,x2,x2,x1,x1],[y1,y1,y2,y2,y1])
Example #5
0
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()
Example #6
0
def plotdVdz():
    nv = 3.
    nr = 1.
    ppgplot.pgbeg("dVdz.ps/vcps", 1, 1)  #color port.
    ppgplot.pgpap(8., 1.25)
    ppgplot.pgpage
    ppgplot.pgsch(1.2)  #font size
    ppgplot.pgslw(3)  #line width

    # 1st panel with symbols w/ stddev errorbars

    x1 = .15
    x2 = .45
    x3 = .6
    x4 = .95
    y1 = .15
    y2 = .425
    y3 = .575
    y4 = .85
    xlabel = 14.1 - 14.
    ylabel = 1.15
    schdef = 1.2
    slwdef = 4
    ppgplot.pgsch(schdef)
    xmin = 0.
    xmax = 1.1
    ymin = 0.
    ymax = 1.2

    ppgplot.pgsvp(x1, x4, y1, y4)  #sets viewport
    ppgplot.pgslw(slwdef)  #line width
    ppgplot.pgswin(xmin, xmax, ymin, ymax)  #axes limits
    ppgplot.pgbox('bcnst', .2, 2, 'bcvnst', .2, 2)  #tickmarks and labeling
    ppgplot.pgmtxt('b', 2.5, 0.5, 0.5, "z")  #xlabel
    ppgplot.pgmtxt('l', 2.6, 0.5, 0.5, "(1/DH)\u3\d c dV\dc\u/dv/d\gW")

    z = N.arange(0., 5., .1)
    beta = ((1 + z)**2 - 1) / ((1 + z)**2 + 1)
    dV = N.zeros(len(z), 'd')
    for i in range(len(z)):
        #dz=dv/(1+z[i])*(1- ((1+z[i])**2 -1)/((1+z[i])**2+1))**(-2)
        #z1=z[i]-0.5*dz
        #z2=z[i]+0.5*dz
        #dV[i]=my.dL(z2,h) - my.dL(z1,h)
        dA = my.DA(z[i], h) * 206264. / 1000.
        dV[i] = DH * (1 + z[i]) * (dA)**2 / (my.E(
            z[i])) / (1 - beta[i])**2 / DH**3
        #dV[i]=DH*(1+z[i])**2*(dA)**2/(my.E(z[i]))/DH**3#for comparison w/Hogg
        if z[i] < 1:
            print i, z[i], dV[i], dV[i]**(1. / 3.)

    ppgplot.pgline(z, dV)

    ppgplot.pgend()
Example #7
0
def histogram(x, data, horizontal=True):
    """
    plot a histogram of data. The bins' left edges
    are given in x
    """

    bin_coords = x.repeat(2)
    data_coords = numpy.concatenate(([0], data.repeat(2), [0]))

    if horizontal:
        ppgplot.pgline(bin_coords, data_coords)
    else:
        ppgplot.pgline(data_coords, bin_coords)
Example #8
0
def plotold():
    xmin=2.2
    xmax=3.2
    ymin=-2.5
    ymax=-.5
    psplotinit('fSsigma3Gyr.ps')
    ppgplot.pgbox("",0.0,0,"",0.0,0)
    ppgplot.pgenv(xmin,xmax,ymin,ymax,0,30)
    ppgplot.pglab("\gs (km/s)",'fS(10\u11\d:10\u13\d)',"")
    ppgplot.pgsci(1)
    ppgplot.pgline(sigma,frac)
    ppgplot.pgsls(2)
    ppgplot.pgsci(2)
    ppgplot.pgline(sigma08,frac08)
    ppgplot.pgsls(1)
    ppgplot.pgsci(1)
    
    ppgplot.pgend()


    xmin=2.2
    xmax=3.2
    ymin=11.
    ymax=14.2
    psplotinit('maccretsigma3Gyr.ps')
    ppgplot.pgbox("",0.0,0,"",0.0,0)
    ppgplot.pgenv(xmin,xmax,ymin,ymax,0,30)
    ppgplot.pglab("\gs (km/s)",'M\dacc\u (M\d\(2281)\u)',"")
    ppgplot.pgsci(1)
    ppgplot.pgline(sigma,maccret)
    ppgplot.pgsls(2)
    ppgplot.pgsci(2)
    ppgplot.pgline(sigma08,maccret08)
    ppgplot.pgsls(1)
    ppgplot.pgsci(1)
    
    mylines=N.arange(-20.,20.,.4)
    mylineswidth=3
    ppgplot.pgsls(4)
    ppgplot.pgslw(mylineswidth)
    x=N.arange(0.,5.,1.)
    lines=mylines
    for y0 in lines:  
	y=3*x +y0 
	ppgplot.pgline(x,y)
	
	ppgplot.pgsls(1)
	ppgplot.pgend()
    os.system('cp maccretsigma.ps /Users/rfinn/SDSS/paper/.')
    os.system('cp fSsigma.ps /Users/rfinn/SDSS/paper/.')
Example #9
0
def plot_selection(id, x0, y0, dt=2.0, w=10.0):
    dx, dy = id.x1 - id.x0, id.y1 - id.y0
    ang = np.arctan2(dy, dx)
    r = np.sqrt(dx**2 + dy**2)
    drdt = r / (id.t1 - id.t0)
    sa, ca = np.sin(ang), np.cos(ang)

    dx = np.array([-dt, -dt, dt, dt, -dt]) * drdt
    dy = np.array([w, -w, -w, w, w])
    x = ca * dx - sa * dy + x0
    y = sa * dx + ca * dy + y0

    ppg.pgsci(7)
    ppg.pgline(x, y)

    return
Example #10
0
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()
Example #11
0
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()
Example #12
0
def linelabel(xlabel, ylabel, dx, ystep, dxl, dyl, label):  #draw key
    schdef = ppgplot.pgqch()
    ppgplot.pgsch(1.1)
    ppgplot.pgtext(xlabel, ylabel, label)
    ppgplot.pgsch(1.1)
    ylabel = ylabel - 2. * ystep
    xs = N.arange(xlabel, (xlabel + dx), .01)
    ys = ylabel * N.ones(len(xs), 'd')
    ppgplot.pgsls(1)
    ppgplot.pgline(xs, ys)
    ppgplot.pgtext((xlabel + dxl + dx), (ylabel - dyl), "Memb")
    ylabel = ylabel - ystep
    ys = ylabel * N.ones(len(xs), 'd')
    ppgplot.pgsls(4)
    ppgplot.pgline(xs, ys)
    ppgplot.pgtext((xlabel + dxl + dx), (ylabel - dyl), "Contam")
    ppgplot.pgsch(schdef)
    ppgplot.pgsls(1)
Example #13
0
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()
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
Example #15
0
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()
Example #16
0
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()
Example #17
0
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)
Example #18
0
    phi = 20  # Angle offset of magnetic axis to orbital axis (not used yet)

    phaseArray = []
    angleArray = []
    # Plot theta as a function of orbital phase for these parameters
    for phase in numpy.arange(0.5, 1.51, 0.01):
        theta = computeViewingAngle(phase, inclination, beta, phi)
        phaseArray.append(phase)
        angleArray.append(theta)

    mainPlotWindow = ppgplot.pgopen("/xs")
    ppgplot.pgask(False)
    pgPlotTransform = [0, 1, 0, 0, 0, 1]
    ppgplot.pgsci(1)
    ppgplot.pgenv(min(phaseArray), max(phaseArray), 0, 180, 0, 0)
    ppgplot.pgline(phaseArray, angleArray)
    ppgplot.pgsls(2)
    ppgplot.pgline([0.5, 1.5], [90, 90])
    ppgplot.pglab("orbital phase", "viewing angle",
                  "Viewing angle \gh as a function of orbital phase.")
    ppgplot.pgtext(0.6, 150,
                   "i:%2.0f \gb:%2.0f \gf:%2.0f" % (inclination, beta, phi))

    modelPlotWindow = ppgplot.pgopen("models_i_81_b_40.ps/ps")
    pgPlotTransform = [0, 1, 0, 0, 0, 1]
    ppgplot.pgask(False)
    mainFluxMax = 0
    mainFluxMin = 1E99

    for phase in numpy.arange(0.5, 1.6, 0.1):
Example #19
0
#/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()
Example #20
0
	ppgplot.pgask(False)
	ppgplot.pglab("wavelength", "flux", "spectrum")
	phases = []
	rvs = []
	wvshifts = []
	wvshiftErrors = []
	previousWavelengthFit = 8173.0
	for spectrum in spectra:
		spectrum.trimWavelengthRange(8000, 8400)
		lowerWavelength = min(spectrum.wavelengths)
		upperWavelength = max(spectrum.wavelengths)
		lowerFlux = min(spectrum.flux)
		upperFlux = max(spectrum.flux)
		ppgplot.pgsci(1)
		ppgplot.pgenv(lowerWavelength, upperWavelength, lowerFlux, upperFlux, 0, 0)
		ppgplot.pgline(spectrum.wavelengths, spectrum.flux)
		if hasEphemeris:
			phase = ephemeris.getPhase(spectrum.HJD)
			labelX = 8100
			labelY = spectrum.getNearestFlux(labelX) + 0.5
			print labelX, labelY
			ppgplot.pglab("Wavelength", "Flux", "Phase: %f"%phase)

		# Now remove the 8190 doublet from the data set
		continuum = copy.deepcopy(spectrum)
		continuum.snipWavelengthRange(8130, 8250)
		ppgplot.pgsci(3)
		ppgplot.pgline(continuum.wavelengths, continuum.flux)
		
		x_values = continuum.wavelengths
		y_values = continuum.flux
Example #21
0
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)
Example #22
0
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()
Example #23
0
			frequency, power = LombScargle(HJD, mag, err, fit_mean=True).autopower(minimum_frequency=0.01,maximum_frequency=20, samples_per_peak = 10, normalization='standard')
			print len(frequency), "points in the periodogram"
			#x = numpy.array(HJD)
			#y = numpy.array(mag)
			# Subtract the mean from the y-data
			#y_mean = numpy.mean(y)
			#y = y - y_mean
			#periods = numpy.linspace(plo, phi, 1000)
			#ang_freqs = 2 * numpy.pi / periods
			#power = signal.lombscargle(x, y, ang_freqs)
			# normalize the power
			#N = len(x)
			# power *= 2 / (N * y.std() ** 2)
	
			ppgplot.pgenv(min(frequency), max(frequency), 0, max(power), 0, 0)
			ppgplot.pgline(frequency, power)
			
			#ppgplot.pgenv(min(periods), max(periods), 0, max(power), 0, 0)
			#ppgplot.pgline(periods, power)
			ppgplot.pglab("Frequency (d\u-1\d)", "Amplitude", "Lomb-Scargle: " + o.id)
			bestFrequency = frequency[numpy.argmax(power)]
			lc = ppgplot.pgqci()
			ls = ppgplot.pgqls()
			ppgplot.pgsci(3)
			ppgplot.pgsls(2)
			ppgplot.pgline([bestFrequency, bestFrequency], [0, max(power)])
			ppgplot.pgsci(lc)
			ppgplot.pgsls(ls)
			print "Best frequency: %f cycles per day"%bestFrequency
			bestPeriod = 1/bestFrequency
			print "%s Best period: %f days or %f hours"%(o.id, bestPeriod, bestPeriod * 24.)
Example #24
0
		guess = numpy.array([a0, a1, a2])
		x_values = continuumSpectrum.wavelengths
		y_values = continuumSpectrum.flux
		y_errors = numpy.ones(len(continuumSpectrum.flux))
		results, covariance = scipy.optimize.curve_fit(quad, x_values, y_values, guess, )
		errors = numpy.sqrt(numpy.diag(covariance))
		# print "quadratic result:", results
		# print "quadratic errors:", errors
		a0 = results[0]
		a1 = results[1]
		a2 = results[2]
		xFit = spectrum.wavelengths
		yFit = quad(numpy.array(xFit), a0, a1, a2)

		ppgplot.pgsci(3)
		ppgplot.pgline(xFit, yFit)
	
		normalisedSpectrum = copy.deepcopy(spectrum)
		for index, w in enumerate(spectrum.wavelengths):			
			# print w, spectrum.flux[index], yFit[index], spectrum.flux[index]/yFit[index]
			normalisedSpectrum.flux[index] = spectrum.flux[index]/yFit[index]
		
		lowerWavelength = min(normalisedSpectrum.wavelengths)
		upperWavelength = max(normalisedSpectrum.wavelengths)
		lowerFlux = min(normalisedSpectrum.flux)
		upperFlux = max(normalisedSpectrum.flux)
	
		ppgplot.pgslct(fitPGPlotWindow)
		ppgplot.pgenv(lowerWavelength, upperWavelength, lowerFlux, upperFlux, 0, 0)
		ppgplot.pgsci(1)
		ppgplot.pgbin(normalisedSpectrum.wavelengths, normalisedSpectrum.flux)
Example #25
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")

#fdot cut
ppgplot.pgsvp(margin + imfract, 1.0 - margin / 2, margin, margin + imfract)
ppgplot.pgswin(-0.1, 1.1, min(zs), max(zs))
ppgplot.pgbox("BCNST", 0.0, 0, "BCST", 0.0, 0)
ppgplot.pgline(fdotcut, zs)
ppgplot.pgmtxt("B", 2.4, 0.5, 0.5, "Relative Power")

# f-fdot image
ppgplot.pgsvp(margin, margin + imfract, margin, margin + imfract)
ppgplot.pgswin(min(rs), max(rs), min(zs), max(zs))
ppgplot.pgmtxt("B", 2.4, 0.5, 0.5, labx)
ppgplot.pgmtxt("L", 2.0, 0.5, 0.5, laby)
lo_col_ind, hi_col_ind = ppgplot.pgqcol()
Example #26
0
#! /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()
Example #27
0
k = 1.2807e-16  #erg K

l = N.arange(2000., 50000., 1000.)  #wavelength in A
l = l * 1.e-8  #convert to cm

T = 40000.  #K
B = 2. * h * c**2 / (l**5) / (N.exp(h * c / (l * k * T)) - 1) / 1.e14
l = l * 1.e4
xmin = 1.15 * min(l)
xmax = max(l)
ymin = min(B)
ymax = 1.2 * max(B)
my.psplotinit("blackbody.ps")
ppgplot.pgbox("", 0.0, 0, "", 0.0, 0)
ppgplot.pgenv(xmin, xmax, ymin, ymax, 0, 0)
ppgplot.pglab("Wavelength", "Energy Output/second", "")
ppgplot.pgsci(4)
ppgplot.pgline(l, B)
ppgplot.pgtext(.6, 3., 'Star A')
ppgplot.pgtext(.6, -.5, 'Blue')
#T=20000.#K
#B=2.*h*c**2/(l**5)/(N.exp(h*c/(l*k*T))-1)
l = (l * 1.e-4 + 20000e-8) * 1.e4
ppgplot.pgsci(2)
ppgplot.pgline(l, B)
ppgplot.pgtext(2.6, 3., 'Star B')
ppgplot.pgtext(3.6, -.5, 'Red')
ppgplot.pgsci(1)

ppgplot.pgend()
Example #28
0
		guess = numpy.array([a0, a1, a2])
		x_values = continuumSpectrum.wavelengths
		y_values = continuumSpectrum.flux
		y_errors = continuumSpectrum.fluxErrors
		results, covariance = scipy.optimize.curve_fit(quad, x_values, y_values, guess, )
		errors = numpy.sqrt(numpy.diag(covariance))
		# print "quadratic result:", results
		# print "quadratic errors:", errors
		a0 = results[0]
		a1 = results[1]
		a2 = results[2]
		xFit = spectrum.wavelengths
		yFit = quad(numpy.array(xFit), a0, a1, a2)

		ppgplot.pgsci(3)
		ppgplot.pgline(xFit, yFit)
	
		normalisedSpectrum = copy.deepcopy(spectrum)
		for index, w in enumerate(spectrum.wavelengths):			
			# print w, spectrum.flux[index], yFit[index], spectrum.flux[index]/yFit[index]
			normalisedSpectrum.flux[index] = spectrum.flux[index]/yFit[index]
			normalisedSpectrum.fluxErrors[index] = spectrum.fluxErrors[index]/yFit[index]
		
		lowerWavelength = min(normalisedSpectrum.wavelengths)
		upperWavelength = max(normalisedSpectrum.wavelengths)
		lowerFlux = min(normalisedSpectrum.flux)
		upperFlux = max(normalisedSpectrum.flux)
	
		ppgplot.pgslct(fitPGPlotWindow)
		ppgplot.pgenv(lowerWavelength, upperWavelength, lowerFlux, upperFlux, 0, 0)
		ppgplot.pgsci(1)
Example #29
0
ymin = -.05
ymax = max(aveaperr)
#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()
Example #30
0
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");

#fdot cut
ppgplot.pgsvp(margin+imfract, 1.0-margin/2, margin, margin+imfract)
ppgplot.pgswin(-0.1, 1.1, min(zs), max(zs))
ppgplot.pgbox("BCNST", 0.0, 0, "BCST", 0.0, 0)
ppgplot.pgline(fdotcut, zs)
ppgplot.pgmtxt("B", 2.4, 0.5, 0.5, "Relative Power");

# f-fdot image
ppgplot.pgsvp(margin, margin+imfract, margin, margin+imfract)
ppgplot.pgswin(min(rs), max(rs), min(zs), max(zs))
ppgplot.pgmtxt("B", 2.4, 0.5, 0.5, labx);
ppgplot.pgmtxt("L", 2.0, 0.5, 0.5, laby);
lo_col_ind, hi_col_ind = ppgplot.pgqcol()
Example #31
0
def plot_rating_sheet(rating):
    """
    Plot a fact sheet on the ratings in the database corresponding to 'rating'.
    'rating' is a dictionary of information from the MySQL database (as returned
    by 'get_all_rating_types()'.
    """
    plot_utils.beginplot("rating_report%s.ps" % currdatetime.strftime('%y%m%d'), vertical=True)
    ch0 = ppgplot.pgqch()
    ppgplot.pgsch(0.5)
    ch = ppgplot.pgqch()
    ppgplot.pgsch(0.75)
    ppgplot.pgtext(0,1,"Rating Report for %s (%s) - page 1 of 2" % (rating["name"], currdatetime.strftime('%c')))
    ppgplot.pgsch(ch)
    
    # Plot Histograms
    
    all_ratings = get_ratings(rating["rating_id"]) 
    range = xmin,xmax = np.min(all_ratings), np.max(all_ratings)
    ppgplot.pgsci(1)
    ppgplot.pgslw(1)
    
    #===== Total/Classified/Unclassified
    # Get data
    ppgplot.pgsvp(0.1, 0.9, 0.75, 0.9)
    (tot_counts, tot_left_edges)=np.histogram(all_ratings, bins=NUMBINS, range=range)
    ppgplot.pgswin(xmin,xmax,0,np.max(tot_counts)*1.1)
    ppgplot.pgsch(0.5)
    ppgplot.pgbox("BCTS",0,5,"BCNTS",0,5)
    ppgplot.pgbin(tot_left_edges, tot_counts)
    (clsfd_counts, clsfd_left_edges)=np.histogram(get_ratings(rating["rating_id"], human_classification=(1,2,3,4,5,6,7)), bins=NUMBINS, range=range)
    ppgplot.pgsci(3) # plot classified in green
    ppgplot.pgbin(tot_left_edges, clsfd_counts)
    unclsfd_counts = tot_counts-clsfd_counts
    ppgplot.pgsci(2) # plot unclassified in red
    ppgplot.pgbin(tot_left_edges, unclsfd_counts)
    ppgplot.pgsci(1) # reset colour to black
    ppgplot.pgsch(0.75)
    ppgplot.pglab("","Counts","")

    #===== Class 1/2/3
    ppgplot.pgsvp(0.1, 0.9, 0.6, 0.75)
    (counts, left_edges)=np.histogram(get_ratings(rating["rating_id"], human_classification=(1,2,3)), bins=NUMBINS, range=range)
    ppgplot.pgswin(xmin,xmax,0,np.max(counts)*1.1)
    ppgplot.pgsch(0.5)
    ppgplot.pgbox("BCTS",0,5,"BCNTS",0,5)
    ppgplot.pgsci(1) # plot in black
    ppgplot.pgbin(tot_left_edges, counts)
    ppgplot.pgsci(1) # reset colour to black
    ppgplot.pgsch(0.75)
    ppgplot.pglab("","Class 1/2/3","")

    #===== RFI
    ppgplot.pgsvp(0.1, 0.9, 0.45, 0.6)
    rfi_ratings = get_ratings(rating["rating_id"], human_classification=(4,))
    (counts, left_edges)=np.histogram(rfi_ratings, bins=NUMBINS, range=range)
    ppgplot.pgswin(xmin,xmax,0,np.max(counts)*1.1)
    ppgplot.pgsch(0.5)
    ppgplot.pgbox("BCTS",0,5,"BCNTS",0,5)
    ppgplot.pgsci(1) # plot in black
    ppgplot.pgbin(tot_left_edges, counts)
    ppgplot.pgsci(1) # reset colour to black
    ppgplot.pgsch(0.75)
    ppgplot.pglab("","RFI","")

    #===== Noise
    ppgplot.pgsvp(0.1, 0.9, 0.3, 0.45)
    noise_ratings = get_ratings(rating["rating_id"], human_classification=(5,))
    (counts, left_edges)=np.histogram(noise_ratings, bins=NUMBINS, range=range)
    ppgplot.pgswin(xmin,xmax,0,np.max(counts)*1.1)
    ppgplot.pgsch(0.5)
    ppgplot.pgbox("BCTS",0,5,"BCNTS",0,5)
    ppgplot.pgsci(1) # plot in black
    ppgplot.pgbin(tot_left_edges, counts)
    ppgplot.pgsci(1) # reset colour to black
    ppgplot.pgsch(0.75)
    ppgplot.pglab("","Noise","")

    #===== Known/Harmonic
    ppgplot.pgsvp(0.1, 0.9, 0.15, 0.3)
    known_ratings = get_ratings(rating["rating_id"], human_classification=(6,7))
    (counts, left_edges)=np.histogram(known_ratings, bins=NUMBINS, range=range)
    ppgplot.pgswin(xmin,xmax,0,np.max(counts)*1.1)
    ppgplot.pgsch(0.5)
    ppgplot.pgbox("BCNTS",0,5,"BCNTS",0,5)
    ppgplot.pgsci(1) # plot in black
    ppgplot.pgbin(tot_left_edges, counts)
    ppgplot.pgsci(1) # reset colour to black
    ppgplot.pgsch(0.75)
    ppgplot.pglab(rating["name"],"Known/Harmonic","")

    #===== Second page for differential histograms
    plot_utils.nextpage(vertical=True)
    ppgplot.pgsch(0.75)
    ppgplot.pgtext(0,1,"Rating Report for %s (%s) - page 2 of 2" % (rating["name"], currdatetime.strftime('%c')))
    
    #===== RFI - Known
    ppgplot.pgsvp(0.1, 0.9, 0.75, 0.9)
    if rfi_ratings.size==0 or known_ratings.size==0:
        ppgplot.pgswin(0,1,0,1)
        ppgplot.pgbox("BC",0,0,"BC",0,0)
	ppgplot.pgsch(0.75)
        ppgplot.pglab("","RFI - Known","")
	ppgplot.pgsch(1.0)
	ppgplot.pgptxt(0.5, 0.5, 0.0, 0.5, "Not enough data")
    else:
        (known_counts, known_left_edges)=np.histogram(known_ratings, bins=NUMBINS, range=range, normed=True)
        (rfi_counts, rfi_left_edges)=np.histogram(rfi_ratings, bins=NUMBINS, range=range, normed=True)
        diff_counts = rfi_counts - known_counts
        ppgplot.pgswin(xmin,xmax,np.min(diff_counts)*1.1,np.max(diff_counts)*1.1)
	ppgplot.pgsch(0.5)
        ppgplot.pgbox("BCTS",0,5,"BCNTS",0,5)
        ppgplot.pgbin(tot_left_edges, diff_counts)
        ppgplot.pgsci(2) # set colour to red
        ppgplot.pgline(tot_left_edges, np.zeros_like(tot_left_edges))
        ppgplot.pgsci(1) # reset colour to black
	ppgplot.pgsch(0.75)
        ppgplot.pglab("","RFI - Known","")

    #===== RFI - Noise
    ppgplot.pgsvp(0.1, 0.9, 0.6, 0.75)
    if noise_ratings.size==0 or rfi_ratings.size==0:
        ppgplot.pgswin(0,1,0,1)
        ppgplot.pgbox("BC",0,0,"BC",0,0)
	ppgplot.pgsch(0.75)
        ppgplot.pglab("","RFI - Noise","")
	ppgplot.pgsch(1.0)
	ppgplot.pgptxt(0.5, 0.5, 0.0, 0.5, "Not enough data")
    else:
        (noise_counts, noise_left_edges)=np.histogram(noise_ratings, bins=NUMBINS, range=range, normed=True)
        (rfi_counts, rfi_left_edges)=np.histogram(rfi_ratings, bins=NUMBINS, range=range, normed=True)
        diff_counts = rfi_counts - noise_counts
        ppgplot.pgswin(xmin,xmax,np.min(diff_counts)*1.1,np.max(diff_counts)*1.1)
	ppgplot.pgsch(0.5)
        ppgplot.pgbox("BCTS",0,5,"BCNTS",0,5)
        ppgplot.pgbin(tot_left_edges, diff_counts)
        ppgplot.pgsci(2) # set colour to red
        ppgplot.pgline(tot_left_edges, np.zeros_like(tot_left_edges))
        ppgplot.pgsci(1) # reset colour to black
	ppgplot.pgsch(0.75)
        ppgplot.pglab("","RFI - Noise","")

    #===== Known - Noise
    ppgplot.pgsvp(0.1, 0.9, 0.45, 0.6)
    if noise_ratings.size==0 or known_ratings.size==0:
        ppgplot.pgswin(0,1,0,1)
        ppgplot.pgbox("BC",0,0,"BC",0,0)
	# Y-axis label is taken care of outside of if/else (below)
	ppgplot.pgsch(1.0)
	ppgplot.pgptxt(0.5, 0.5, 0.0, 0.5, "Not enough data")
    else:
        (noise_counts, noise_left_edges)=np.histogram(noise_ratings, bins=NUMBINS, range=range, normed=True)
        (known_counts, known_left_edges)=np.histogram(known_ratings, bins=NUMBINS, range=range, normed=True)
        diff_counts = known_counts - noise_counts
        ppgplot.pgswin(xmin,xmax,np.min(diff_counts)*1.1,np.max(diff_counts)*1.1)
	ppgplot.pgsch(0.5)
        ppgplot.pgbox("BCNTS",0,5,"BCNTS",0,5)
        ppgplot.pgbin(tot_left_edges, diff_counts)
        ppgplot.pgsci(2) # set colour to red
        ppgplot.pgline(tot_left_edges, np.zeros_like(tot_left_edges))
        ppgplot.pgsci(1) # reset colour to black
    ppgplot.pgswin(xmin,xmax,0,1)
    ppgplot.pgsch(0.5)
    ppgplot.pgbox("NTS",0,5,"",0,0)
    ppgplot.pgsch(0.75)
    ppgplot.pglab(rating["name"],"Known - Noise","")
    
    ppgplot.pgsch(ch0) # reset character height
	phi = 20				# Angle offset of magnetic axis to orbital axis (not used yet)
	
	phaseArray = []
	angleArray = []
	# Plot theta as a function of orbital phase for these parameters
	for phase in numpy.arange(0.5, 1.51, 0.01):
		theta = computeViewingAngle(phase, inclination, beta, phi)
		phaseArray.append(phase)
		angleArray.append(theta)
		
	mainPlotWindow = ppgplot.pgopen("/xs")	
	ppgplot.pgask(False)
	pgPlotTransform = [0, 1, 0, 0, 0, 1]
	ppgplot.pgsci(1)
	ppgplot.pgenv(min(phaseArray), max(phaseArray), 0, 180, 0, 0)
	ppgplot.pgline(phaseArray, angleArray)
	ppgplot.pgsls(2)
	ppgplot.pgline([0.5, 1.5], [90, 90])
	ppgplot.pglab("orbital phase", "viewing angle", "Viewing angle \gh as a function of orbital phase.")
	ppgplot.pgtext(0.6, 150, "i:%2.0f \gb:%2.0f \gf:%2.0f"%(inclination, beta, phi))
		
	
	modelPlotWindow = ppgplot.pgopen("models_i_81_b_40.ps/ps")	
	pgPlotTransform = [0, 1, 0, 0, 0, 1]
	ppgplot.pgask(False)
	mainFluxMax = 0
	mainFluxMin = 1E99
	
	for phase in numpy.arange(0.5, 1.6, 0.1):
		
		ppgplot.pgsci(1)
Example #33
0
def plothistsfr():
    DATAMIN = -4.
    DATAMAX = 15.
    NBIN = int((DATAMAX-DATAMIN)*2.)    
    #print "ngal = ",len(g0.sfr)
    ppgplot.pgbox("",0.0,0,"L",0.0,0)
    ppgplot.pgenv(DATAMIN,DATAMAX,0,45,0)
    ppgplot.pglab("SFR (h\d100\u\u-2\d M\d\(2281)\u yr\u-1 \d)","Number of Galaxies","")
    ppgplot.pgsls(1)#dotted
    ppgplot.pgslw(4)  #line width
    #ppgplot.pgsci(4)
    #x=N.compress((abs(g0.ew) > ewmin),g0.sfr)
    x=N.compress((g0.final > 0),g0.sfrc)
    ppgplot.pghist(len(x),x,DATAMIN,DATAMAX,NBIN,5)
    xlabel = 6.5
    ylabel = 38.
    ystep = 3.
    dy=.4
    dxl=3
    dxr=.5
    ppgplot.pgslw(deflw)  #line width
    ppgplot.pgtext(xlabel,ylabel,"CL1040")
    xlin = N.array([xlabel-dxl,xlabel-dxr],'f')
    ylin = N.array([ylabel+dy,ylabel+dy],'f')
    ppgplot.pgslw(4)  #line width
    ppgplot.pgline(xlin,ylin)

    ppgplot.pgslw(5)
    ppgplot.pgsls(3)#dot-dash-dot-dash
    #ppgplot.pgsci(3)
    #x=N.compress((abs(g1.ew) > ewmin),g1.sfr)
    x=N.compress((g1.final > 0),g1.sfrc)
    ppgplot.pghist(len(x),x,DATAMIN,DATAMAX,NBIN,5)

    ylabel = ylabel - ystep

    xlin = N.array([xlabel-dxl,xlabel-dxr],'f')
    ylin = N.array([ylabel+dy,ylabel+dy],'f')
    ppgplot.pgline(xlin,ylin)
    ppgplot.pgsls(1)
    ppgplot.pgslw(deflw)
    ppgplot.pgtext(xlabel,ylabel,"CL1054-12")
    
    ppgplot.pgsls(1)#dot-dash-dot-dash
    #ppgplot.pgsci(2)
    ppgplot.pgslw(2)  #line width
    #x=N.compress((abs(g2.ew) > ewmin),g2.sfr)
    x=N.compress((g2.final > 0),g2.sfrc)
    ppgplot.pghist(len(x),x,DATAMIN,DATAMAX,NBIN,5)
    ylabel = ylabel - ystep
    ppgplot.pgslw(deflw)  #line width
    ppgplot.pgtext(xlabel,ylabel,"CL1216")
    xlin = N.array([xlabel-dxl,xlabel-dxr],'f')
    ylin = N.array([ylabel+dy,ylabel+dy],'f')
    ppgplot.pgslw(2)  #line width
    ppgplot.pgline(xlin,ylin)


    #print "Number in g2.ratios = ",len(g2.ratio)
    #for ratio in g2.ratio:
    #    print ratio
    #drawbinned(x,y,5)
    ppgplot.pgsci(1)
Example #34
0
	i_s = []
	for line in inputfile:
		if line[0] == '#':
			continue
		data = line.split()
		replaceExpChar(data[0])
		freqs.append(float(replaceExpChar(data[0])))
		i_0s.append(float(replaceExpChar(data[1])))
		i_1s.append(float(replaceExpChar(data[2])))
		i_s.append(float(replaceExpChar(data[3])))
		
		
	lowerFreq = min(freqs)
	upperFreq = max(freqs)
	upper_i0 = max(i_0s)
	lower_i0 = max(i_0s)
	upper_i1 = max(i_1s)
	lower_i1 = min(i_1s)
	upper_i = max(i_s)
	lower_i = min(i_s)
	
	mainPGPlotWindow = ppgplot.pgopen('/xs')	
	pgPlotTransform = [0, 1, 0, 0, 0, 1]
	ppgplot.pgenv(lowerFreq, upperFreq, lower_i, upper_i, 0, 0)
	ppgplot.pgsci(1)
	
	ppgplot.pgline(freqs, i_s)
	ppgplot.pglab("frequency", "i_", "")
		
			
Example #35
0
	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)
	ppgplot.pgsls(1)
	ppgplot.pgslw(1)

	# Plot the inset subplot showing the eclipse
	subFlux = []
	subFluxErr = []
	subPhases = []
	subModelPhases = []
	subModel = []
	startPhase = 0.96
	endPhase = 1.04
	print "maxFlux:", maxFlux
	for index, phase in enumerate(phases):
		if phase > startPhase and phase < endPhase:
Example #36
0
	fig.savefig(runStr +'_%s.png'%fileappendix,dpi=100, format='png')
	
	plotDevices = ["/xs", "%s.eps/ps"%fileappendix]
	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(x_values), max(x_values), yLims[0], yLims[1], 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.pgsls(2)
		ppgplot.pgline(xFit, yFit)
		ppgplot.pgsls(3)
		ppgplot.pgline([a3, a3], [yLims[0], yLims[1]])
		ppgplot.pgsls(1)
		ppgplot.pglab(xColumn + " - " + str(JDoffset), "flux ratio", "")
		ppgplot.pgclos()
	time.sleep(3)
	
	times = []
	sharpness = []
	random.seed()
	for n in range(arg.iterations):
		# Give all the points a random bump...
		y_perturbed = []
		for y, y_error in zip(y_values, y_errors):
			y_p = numpy.random.normal(y, y_error)
Example #37
0
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 main(args):
    with open(os.path.join(os.path.dirname(__file__),
        'precisiondata.cpickle')) as filedata:
        exptimes, crosspoints, satpoints = pickle.load(filedata)

    x_range = [9, 14]

    interpcross = interp1d(exptimes, crosspoints, kind='linear')
    interpsat = interp1d(exptimes, satpoints, kind='linear')


    N = 5
    colours = np.arange(2, 2 + N, 1)
    exptimes = np.arange(1, N + 1) * 10
    if args.besancon:
        all_vmags = get_besancon_mag_data()
        yhigh = 0.3
        title = 'Besancon'
    else:
        all_vmags = get_nomad_mag_data()
        yhigh = 0.4
        title = 'NOMAD'

    ytot = yhigh * len(all_vmags)


    with pgh.open_plot(args.output):

        pg.pgvstd()


        pg.pgswin(x_range[0], x_range[1], 0, yhigh)
        for exptime, colour in zip(exptimes, colours):
            satpoint = interpsat(exptime)
            crosspoint = interpcross(exptime)

            selected = all_vmags[(all_vmags > satpoint) & (all_vmags <=
                crosspoint)]
            print(exptime, len(selected))


            xdata, ydata = cumulative_hist(np.array(selected),
                    min_val=x_range[0], max_val=x_range[1], norm=len(all_vmags))
            ydata /= float(len(all_vmags))

            with pgh.change_colour(colour):
                pg.pgbin(xdata, ydata, False)


        pg.pgbox('bcnst', 0, 0, 'bcnst', 0, 0)
        pg.pglab(r'V magnitude', 'High precision fraction', title)
        # Label the right hand side
        pg.pgswin(x_range[0], x_range[1], 0, ytot)
        pg.pgbox('', 0, 0, 'smt', 0, 0)
        pg.pgmtxt('r', 2., 0.5, 0.5, 'N')

        # Create the legend
        pg.pgsvp(0.7, 0.9, 0.1, 0.3)
        pg.pgswin(0., 1., 0., 1.)

        for i, (exptime, colour) in enumerate(zip(exptimes, colours)):
            yval = 0.1 + 0.8 * i / len(exptimes)

            with pgh.change_colour(colour):
                pg.pgline(np.array([0.2, 0.4]), np.ones(2) * yval)

            pg.pgtext(0.5, yval, r'{:d} s'.format(exptime))
		upperFlambda = max(modelSpectrum.flux)
		lowerFlambda = 0
		
		lowerFlux = 0
		upperFlux = 0
		
		for s in modelSpectra:
			fmax = max(s.flux)
			if fmax>upperFlux:
				upperFlux = fmax
		
		ppgplot.pgenv(lowerWavelength, upperWavelength, lowerFlux, upperFlux, 0, 0)
		colour = 1
		for s in modelSpectra:
			ppgplot.pgsci(colour)
			ppgplot.pgline(s.wavelengths, s.flux)
			plotx = 8500
			ploty = s.getNearestFlux(plotx)
			ppgplot.pgptxt(plotx, ploty, 0, 0, "%2.0f'"%(s.angle)) 
			colour+= 1
			if colour>15: colour = 1
			
		ppgplot.pgsci(1)	
		label = "B=%.0f MG, T=%.1f keV"%(field, temperature)
		ppgplot.pglab("wavelength", "i_0", label)
		
	ppgplot.pgclos()

	if arg.device!=None:
		# Write to an additional output devide	
		mainPGPlotWindow = ppgplot.pgopen(arg.device)	
Example #40
0
	else: device = "/xs"
	pgramPlotWindow = ppgplot.pgopen(device)  
	pgPlotTransform = [0, 1, 0, 0, 0, 1]
	ppgplot.pgslct(pgramPlotWindow)   
	ppgplot.pgask(True)

	for o in objects:
		HJD = o.getColumn('HJD')
		mag = o.getColumn('mag')
		err = o.getColumn('err')
		frequency, power = LombScargle(HJD, mag, err).autopower(nyquist_factor=20)
		bestFrequency = frequency[numpy.argmax(power)]
		period = 1/bestFrequency
		ppgplot.pgenv(numpy.min(frequency) ,numpy.max(frequency) , numpy.min(power), numpy.max(power), 0, 0)
		ppgplot.pglab("Frequency (days\u-1\d)", "Power", "Periodogram: %s period: %f"%(o.id, period) )
		ppgplot.pgline(frequency, power)
		print "Best frequency for %s is %f cycles/day or a period of %f days."%(o.id, bestFrequency, period) 
	ppgplot.pgclos()
	
	##########################################################################################################################
	# Phase Plots 
	##########################################################################################################################
	if arg.ps: device = "phaseplots.ps/ps"
	else: device = "/xs"
	phasePlotWindow = ppgplot.pgopen(device)  
	pgPlotTransform = [0, 1, 0, 0, 0, 1]
	ppgplot.pgslct(phasePlotWindow)   
	ppgplot.pgsci(1)
	ppgplot.pgpap(10, 0.618)
	ppgplot.pgask(True)
	
Example #41
0
    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)
	# Snip out Halpha 
	spectrum.snipWavelengthRange(6550, 6570)
	
	lowerWavelength = min(spectrum.wavelengths)
	upperWavelength = max(spectrum.wavelengths)
	observedSpectrumRange = (lowerWavelength, upperWavelength)
	lowerFlux = min(spectrum.flux)
	upperFlux = max(spectrum.flux)
	lowerFlux = 0
	
	mainPlotWindow = ppgplot.pgopen(arg.device)	
	ppgplot.pgask(False)
	pgPlotTransform = [0, 1, 0, 0, 0, 1]
	ppgplot.pgsci(1)
	ppgplot.pgenv(lowerWavelength, upperWavelength, lowerFlux, upperFlux, 0, 0)
	ppgplot.pgline(spectrum.wavelengths, spectrum.flux)
	ppgplot.pglab("wavelength", "flux", spectrum.objectName)
	
	observedArea = spectrum.integrate()
	print "Wavelength range of observations:", observedSpectrumRange
		
	# modelPlotWindow = ppgplot.pgopen(arg.device)	
	# pgPlotTransform = [0, 1, 0, 0, 0, 1]	
	# ppgplot.pgask(False)
	
	currentPlotWindow = ppgplot.pgopen(arg.device)	
	ppgplot.pgask(False)
	pgPlotTransform = [0, 1, 0, 0, 0, 1]	
	ppgplot.pgslct(currentPlotWindow)
	ppgplot.pgenv(lowerWavelength, upperWavelength, lowerFlux, upperFlux, 0, 0)
	ppgplot.pgline(spectrum.wavelengths, spectrum.flux)
Example #43
0
		
	mainPGPlotWindow = ppgplot.pgopen('/xs')	
	ppgplot.pgask(True)
	pgPlotTransform = [0, 1, 0, 0, 0, 1]
	yUpper = 2.5
	yLower = -0.5
	
	newSpectra = []
	for spectrum in spectra:
		ppgplot.pgsci(1)
		lowerWavelength = min(spectrum.wavelengths)
		upperWavelength = max(spectrum.wavelengths)
		lowerFlux = min(spectrum.flux)
		upperFlux = max(spectrum.flux)
		ppgplot.pgenv(lowerWavelength, upperWavelength, yLower, yUpper, 0, 0)
		ppgplot.pgline(spectrum.wavelengths, spectrum.flux)
		if hasEphemeris:
			ppgplot.pglab("wavelength", "flux", "%s [%f]"%(spectrum.objectName, ephemeris.getPhase(spectrum.HJD)))
		else:
			ppgplot.pglab("wavelength", "flux", spectrum.objectName)
	
		ppgplot.pgsls(3)
		ppgplot.pgline( [tio1Range[0], tio1Range[0]], [yLower, yUpper])
		ppgplot.pgline( [tio1Range[1], tio1Range[1]], [yLower, yUpper])
		ppgplot.pgline( [tio2Range[0], tio2Range[0]], [yLower, yUpper])
		ppgplot.pgline( [tio2Range[1], tio2Range[1]], [yLower, yUpper])
		ppgplot.pgsls(1)
		
		tio1measure = spectrum.integrate(wavelengthrange = tio1Range)
		tio2measure = spectrum.integrate(wavelengthrange = tio2Range)
		tioMeasuredRatio = tio1measure / tio2measure
Example #44
0
    def drawPolyLine(self, xs, ys):
        if not self.plotDeviceIsOpened:
            raise ValueError("You have not yet opened a PGPLOT device.")

        pgplot.pgline(xs, ys)
				(x, y) = s
				ppgplot.pgcirc(x, y, 10)
				
			# Now also draw the zoomed in region around the first aperture
			if (applyShift):
				(x, y) = masterApertureList[0]
				croppedFrame = fullFrame[y-10:y+10, x-9:x+10]
				ppgplot.pgslct(zoomedAperture)
				rows, cols = numpy.shape(croppedFrame)
				ppgplot.pggray(croppedFrame, 0, cols-1, 0, rows-1, 0, 255, pgPlotTransform)
				ppgplot.pgsci(3)
				ppgplot.pgsfs(2)
				ppgplot.pgcirc(11, 11, 1)
				xLine = [11, 11+xr]
				yLine = [11, 11+yr]
				ppgplot.pgline(xLine, yLine)
				
			
			
			
		if arg.sleep!=0:
			time.sleep(arg.sleep)
	sys.stdout.write("\rProcessed %d frames      \n"%frameRange)
	sys.stdout.flush()
	
	ppgplot.pgclos()
		
	################################################################################################
	""" We have run through all of the images now. """
	################################################################################################
	
Example #46
0
def joy_division_plot(pulses, timeseries, downfactor=1, hgt_mult=1):
    """Plot each pulse profile on the same plot separated
        slightly on the vertical axis.
        'timeseries' is the Datfile object dissected.
        Downsample profiles by factor 'downfactor' before plotting.
        hgt_mult is a factor to stretch the height of the paper.
    """
    first = True
    ppgplot.pgbeg("%s.joydiv.ps/CPS" % \
                    os.path.split(timeseries.basefn)[1], 1, 1)
    ppgplot.pgpap(10.25, hgt_mult*8.5/11.0) # Letter landscape
    # ppgplot.pgpap(7.5, 11.7/8.3) # A4 portrait, doesn't print properly
    ppgplot.pgiden()
    ppgplot.pgsci(1)
    
    # Set up main plot
    ppgplot.pgsvp(0.1, 0.9, 0.1, 0.8)
    ppgplot.pglab("Profile bin", "Single pulse profiles", "")
    to_plot = []
    xmin = 0
    xmax = None
    ymin = None
    ymax = None
    for pulse in pulses:
        vertical_offset = (pulse.number-1)*JOYDIV_SEP
        copy_of_pulse = pulse.make_copy()
        if downfactor > 1:
            # Interpolate before downsampling
            interp = ((copy_of_pulse.N/downfactor)+1)*downfactor
            copy_of_pulse.interpolate(interp)
            copy_of_pulse.downsample(downfactor)
            # copy_of_pulse.scale()
        if first:
            summed_prof = copy_of_pulse.profile.copy()
            first = False
        else:
            summed_prof += copy_of_pulse.profile
        prof = copy_of_pulse.profile + vertical_offset
        min = prof.min()
        if ymin is None or min < ymin:
            ymin = min
        max = prof.max()
        if ymax is None or max > ymax:
            ymax = max
        max = prof.size-1
        if xmax is None or max > xmax:
            xmax = max
        to_plot.append(prof)
    yspace = 0.1*ymax
    ppgplot.pgswin(0, xmax, ymin-yspace, ymax+yspace)
    for prof in to_plot:
        ppgplot.pgline(np.arange(0,prof.size), prof)
    ppgplot.pgbox("BNTS", 0, 0, "BC", 0, 0)

    # Set up summed profile plot
    ppgplot.pgsvp(0.1, 0.9, 0.8, 0.9)
    ppgplot.pglab("", "Summed profile", "Pulses from %s" % timeseries.datfn)
    summed_prof = summed_prof - summed_prof.mean()
    ppgplot.pgswin(0, xmax, summed_prof.min(), summed_prof.max())
    ppgplot.pgline(np.arange(0, summed_prof.size), summed_prof)
    ppgplot.pgbox("C", 0, 0, "BC", 0, 0)
    ppgplot.pgclos()
Example #47
0
		
	for s1, s2 in zip(spectra1, spectra2):
		combinedSpectrum = copy.deepcopy(s1)
		combinedSpectrum.appendNewData(s2)
	
		ppgplot.pgsci(1)
		lowerWavelength = min(combinedSpectrum.wavelengths)
		upperWavelength = max(combinedSpectrum.wavelengths)
		lowerFlux = min(combinedSpectrum.flux)
		upperFlux = max(combinedSpectrum.flux)
		lowerFlux = 0
		upperFlux = 2.5
		ppgplot.pgenv(lowerWavelength, upperWavelength, lowerFlux, upperFlux, 0, 0)
		
		ppgplot.pgsci(2)
		ppgplot.pgline(s1.wavelengths, s1.flux)
		ppgplot.pgsci(3)
		ppgplot.pgline(s2.wavelengths, s2.flux)
		
		
		ppgplot.pgsci(1)
		
		if hasEphemeris:
			ppgplot.pglab("wavelength", "flux", "%s [%f]"%(s1.objectName, ephemeris.getPhase(s1.HJD)))
		else:
			ppgplot.pglab("wavelength", "flux", s1.objectName)
	
		if hasEphemeris:
			filename = "combined_%f.json"%(ephemeris.getPhase(combinedSpectrum.HJD))
			if arg.suffix!=None:
					filename = "combined_%f_%s.json"%(ephemeris.getPhase(combinedSpectrum.HJD), arg.suffix)
Example #48
0
def mratiopg():
    ppgplot.pgbeg("maccratio.ps/vcps",1,1)  #color port.
    ppgplot.pgpap(8.,1.)
    ppgplot.pgpage
    ppgplot.pgsch(1.3) #font size
    ppgplot.pgslw(7)   #line width

    # 1st panel with symbols w/ stddev errorbars
    #ylabel="SFR (M\d\(2281) \u yr\u-1\d)"
    ylabel="L(H\ga) (10\u41\d  erg s\u-1\d)"
    xlabel="M\dr\u "
    x1=.15
    x2=.5
    x3=.5
    x4=.85
    y1=x1
    y2=x2
    y3=x3
    y4=x4
    emarker=18
    smarker=23
    xmin=N.log10(1.e14)
    xmax=N.log10(2.5e15)
    #ymin=-1.
    #ymax=3.
    ymin=0.
    ymax=25.
    ppgplot.pgsvp(x1,x4,y1,y4)  #sets viewport
    ppgplot.pgswin(xmin,xmax,ymin,ymax) #axes limits
    ppgplot.pgbox('blncst',1.,2,'bcvnst',2.,2)  #tickmarks and labeling


    for i in range(len(lz1lm.mass)):
	m=lz1lm.mass[i]
	l=lz1lm.maccret[i]
	h=hz1lm.maccret[i]
	r=h/l
	print i,m,l,h,r
    #print lz1lm.maccret
    #print hz1lm.maccret
    #print hz3lm.maccret
    r3lm=(hz3lm.maccret)/(lz3lm.maccret)
    r3hm=(hz3hm.maccret)/(lz3hm.maccret)
    #for i in range(len(r3)):
#	print i,lz3.sigma[i],hz3.sigma[i],lz3.mass[i],hz3.mass[i]
#	print i,lz01.sigma[i],hz01.sigma[i],lz01.mass[i],hz01.mass[i]
    r1lm=hz1lm.maccret/lz1lm.maccret
    r1hm=hz1hm.maccret/lz1hm.maccret
    #ra=N.array(hz01.maccret,'d')
    #rb=N.array(lz01.maccret,'d')
    #r01=ra/rb
    #for i in range(len(r01)):
	#print "ratio ",hz01.maccret[i],lz01.maccret[i],ra[i],rb[i],r01[i]
    ppgplot.pgsci(14)
    ppgplot.pgsls(1)
    ppgplot.pgline(N.log10(lz3lm.mass),r3lm)
    ppgplot.pgsls(2)
    ppgplot.pgline(N.log10(lz3hm.mass),r3hm)

    ppgplot.pgsci(1)
    ppgplot.pgsls(1)
    ppgplot.pgline(N.log10(lz1lm.mass),r1lm)
    ppgplot.pgsls(2)
    ppgplot.pgline(N.log10(lz1hm.mass),r1hm)

    xlabel='M\dcl\u (M\d\(2281)\u)'
    ylabel='M\dacc\u(z=0.75) / M\dacc\u(z=0.07)'

    ppgplot.pgsch(1.8)
    ppgplot.pgslw(7)
    ppgplot.pgmtxt('b',2.2,0.5,0.5,ylabel)    #xlabel
    ppgplot.pgmtxt('l',2.5,0.5,0.5,xlabel)

    ppgplot.pgend()
Example #49
0
		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

	params = {
		"color": "kelvin:2700",
			
				# Graph of the x-direction
				ppgplot.pgsvp(0.1, 0.7, 0.1, 0.2)
				yMax = numpy.max(xCollapsed) * 1.1
				yMin = numpy.min(xCollapsed) * 0.9
				ppgplot.pgswin(-margins, margins, yMin, yMax)
				ppgplot.pgsci(1)
				ppgplot.pgbox('ABI', 1.0, 10, 'ABI', 0.0, 0)
				xPoints = [x - margins for x in range(len(xCollapsed))]
				ppgplot.pgsci(2)
				ppgplot.pgbin(xPoints, xCollapsed, True)
				numPolyPoints = 50
				xFit = [float(i) * len(xCollapsed)/numPolyPoints for i in range(numPolyPoints)]
				yFit = [xPoly[0]*x*x + xPoly[1]*x + xPoly[2] for x in xFit]
				ppgplot.pgsci(3)
				ppgplot.pgline([x - margins for x in xFit], yFit)
				ppgplot.pgsls(2)
				ppgplot.pgline([newxPeak-margins, newxPeak-margins], [yMin, yMax]) 
				ppgplot.pgsci(4)
				ppgplot.pgline([xBestOffset, xBestOffset], [yMin, yMax])
				ppgplot.pgsls(1)
				ppgplot.pgline(xGaussian, xGaussianFit)
				
				# Graph of the y-direction
				ppgplot.pgsvp(0.8, 0.9, 0.3, 0.9)
				yMax = numpy.max(yCollapsed) * 1.1
				yMin = numpy.min(yCollapsed) * 0.9
				ppgplot.pgswin(yMin, yMax, -margins, margins)
				ppgplot.pgsci(1)
				ppgplot.pgbox('ABI', 0.0, 0, 'ABI', 1.0, 10)
				xPoints = [x - margins for x in range(len(yCollapsed))]
Example #51
0
		print "initial guess", guess
		result, covariance = scipy.optimize.curve_fit(func, x_values, derivative_y, guess, derivative_y_errors)
		parameters = result
		errors = numpy.sqrt(numpy.diag(covariance))
		print "Covariance:", covariance
		m_err = errors[0]
		c_err = errors[1]
		m_fit = parameters[0]
		c_fit = parameters[1]
		print "Fit m:%4.8f  c:%4.8f"%(m_fit, c_fit), "errors:", m_err, c_err
		y0 =  -c_fit/m_fit
		y0_error = y0 * math.sqrt((m_err/m_fit)**2 + (c_err/c_fit)**2)
		print "y0 - intercept:", y0, "[%f]"%y0_error, "BMJD: ",  y0 + x_offset, "[%s]"%y0_error
	
		ppgplot.pgsci(3)
		ppgplot.pgline([min(x_values), max(x_values)], [func(min(x_values), m_fit, c_fit), func(max(x_values), m_fit, c_fit)])
			
		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 = []
		yenew = []
		for (p, y, ye) in zip(photometry["phase"], photometry[yColumn], photometry[yErrors]):
			if p>phaseLimits[0] and p<phaseLimits[1]:
				pnew.append(p)