def plotrand(x, y, frac=0.1, plt=None, **keys): import biggles from biggles import FramedPlot, Points if plt is None: plt = FramedPlot() x=numpy.array(x,ndmin=1,copy=False) y=numpy.array(y,ndmin=1,copy=False) if x.size != y.size: raise ValueError("x,y must be same size") nrand = int(x.size*frac) ind = numpy_util.random_subset(x.size, nrand) if 'type' not in keys: keys['type'] = 'dot' c = Points(x[ind], y[ind], **keys) plt.add(c) if 'xlabel' in keys: plt.xlabel = keys['xlabel'] if 'ylabel' in keys: plt.ylabel = keys['ylabel'] show = keys.get('show',True) if show: plt.show() return plt
def plotprimedens(n): pd = primedens(n) steps = range(len(pd)) from biggles import FramedPlot, Curve g = FramedPlot() g.add(Curve(steps,pd)) g.show() return
def plot_radec(self, type): """ ra/dec plot of all points and the matched points """ import biggles import converter from biggles import FramedPlot,Points print() dir=self.plotdir() if not os.path.exists(dir): os.makedirs(dir) psfile = self.plotfile(type) orig = self.read_original(type) mat = self.read_matched(type) plt=FramedPlot() symsize = 2 if type == 'sdss' or type == 'other': symsize = 0.25 plt.add( Points(orig['ra'],orig['dec'],type='dot', size=symsize) ) plt.add( Points(mat['ra'],mat['dec'],type='dot', color='red', size=symsize) ) plt.xlabel = 'RA' plt.ylabel = 'DEC' print("Writing eps file:", psfile) plt.write_eps(psfile) converter.convert(psfile, dpi=120, verbose=True)
def plot_masserr(self, filename): import pcolors data=eu.io.read(filename) nr200 = data.size nb = data['B'][0].size plt = FramedPlot() colors = pcolors.rainbow(nr200, 'hex') clist = [] for ri in xrange(nr200): r200 = data['r200'][ri] m200 = data['m200'][ri] p = Points(data['B'][ri], (m200-data['m200meas'][ri])/m200, type='filled circle', color=colors[ri]) crv = Curve(data['B'][ri], (m200-data['m200meas'][ri])/m200, color=colors[ri]) crv.label = 'r200: %0.2f' % r200 clist.append(crv) plt.add(p,crv) key = PlotKey(0.1,0.4,clist) plt.add(key) plt.xlabel=r'$\Omega_m \sigma_8^2 D(z)^2 b(M,z)$' plt.ylabel = r'$(M_{200}^{true}-M)/M_{200}^{true}$' epsfile = filename.replace('.rec','.eps') print 'writing eps:',epsfile plt.write_eps(eu.ostools.expand_path(epsfile))
def plot_pk(self,k,pk): from biggles import FramedPlot, Curve plt=FramedPlot() plt.add(Curve(k,pk)) plt.xlog=True plt.ylog=True plt.xlabel = r'$k [h/Mpc]$' plt.ylabel = r'$P_{lin}(k)$' plt.aspect_ratio = 1 plt.show()
def plot_xi(self, r, xi): from biggles import FramedPlot, Curve minval = 1.e-4 xi = where(xi < minval, minval, xi) plt=FramedPlot() plt.add(Curve(r,xi)) plt.xlog=True plt.ylog=True plt.xlabel = r'$r [Mpc/h]$' plt.ylabel = r'$\xi_{lin}(r)$' plt.aspect_ratio=1 plt.show()
def doplot(self, fitres, h, minmag, maxmag): tab=biggles.Table(2,1) plt=FramedPlot() plt.title='%s %.2f %.2f ' % (self.objtype, minmag, maxmag) plt.xlabel=r'$\sigma$' sprior=fitres.get_model() nrand=100000 binsize=self.binsize hplt=Histogram(h['hist'], x0=h['low'][0], binsize=binsize) hplt.label='data' srand=sprior.sample(nrand) hrand=histogram(srand, binsize=binsize, min=h['low'][0], max=h['high'][-1], more=True) hrand['hist'] = hrand['hist']*float(h['hist'].sum())/nrand hpltrand=Histogram(hrand['hist'], x0=hrand['low'][0], binsize=binsize, color='blue') hpltrand.label='rand' key=PlotKey(0.9,0.9,[hplt,hpltrand],halign='right') plt.add(hplt, hpltrand, key) tplt=fitres.plot_trials(show=False,fontsize_min=0.88888888) tab[0,0] = plt tab[1,0] = tplt if self.show: tab.show() d=files.get_prior_dir() d=os.path.join(d, 'plots') epsfile='pofs-%.2f-%.2f-%s.eps' % (minmag,maxmag,self.objtype) epsfile=os.path.join(d,epsfile) eu.ostools.makedirs_fromfile(epsfile) print epsfile tab.write_eps(epsfile) os.system('converter -d 100 %s' % epsfile) return tab
def doplot(self): tab = Table(2, 1) tab.title = self.title xfit, yfit, gprior = self.get_prior_vals() nrand = 100000 binsize = self.binsize h = self.h h1 = self.h1 h2 = self.h2 g1rand, g2rand = gprior.sample2d(nrand) grand = gprior.sample1d(nrand) hrand = histogram(grand, binsize=binsize, min=0.0, max=1.0, more=True) h1rand = histogram(g1rand, binsize=binsize, min=-1.0, max=1.0, more=True) fbinsize = xfit[1] - xfit[0] hrand["hist"] = hrand["hist"] * float(yfit.sum()) / hrand["hist"].sum() * fbinsize / binsize h1rand["hist"] = h1rand["hist"] * float(h1["hist"].sum()) / h1rand["hist"].sum() pltboth = FramedPlot() pltboth.xlabel = r"$g$" hplt1 = Histogram(h1["hist"], x0=h1["low"][0], binsize=binsize, color="red") hplt2 = Histogram(h2["hist"], x0=h2["low"][0], binsize=binsize, color="blue") hpltrand = Histogram(hrand["hist"], x0=hrand["low"][0], binsize=binsize, color="magenta") hplt1rand = Histogram(h1rand["hist"], x0=h1rand["low"][0], binsize=binsize, color="magenta") hplt1.label = r"$g_1$" hplt2.label = r"$g_2$" hplt1rand.label = "rand" hpltrand.label = "rand" keyboth = PlotKey(0.9, 0.9, [hplt1, hplt2, hplt1rand], halign="right") pltboth.add(hplt1, hplt2, hplt1rand, keyboth) tab[0, 0] = pltboth plt = FramedPlot() plt.xlabel = r"$|g|$" hplt = Histogram(h["hist"], x0=h["low"][0], binsize=binsize) hplt.label = "|g|" line = Curve(xfit, yfit, color="blue") line.label = "model" key = PlotKey(0.9, 0.9, [hplt, line, hpltrand], halign="right") plt.add(line, hplt, hpltrand, key) tab[1, 0] = plt if self.show: tab.show() return tab
def test_rainbow(): import numpy from biggles import FramedPlot, Points, Curve num = 20 plt = FramedPlot() x = numpy.linspace(0.0, 1.0, num) y = x**2 colors = rainbow(num, 'hex') for i in xrange(num): p = Points([x[i]], [y[i]], type='filled circle', color=colors[i]) c = Curve([x[i]],[y[i]], color=colors[i]) plt.add(p,c) plt.show()
def plot_drho(comb=None, r=None, drho=None, drhoerr=None, color='black',type='filled circle', nolabel=False, noshow=False, minval=1.e-5, aspect_ratio=1): """ This one stands alone. """ if comb is not None: r=comb['rdrho'] drho=comb['drho'] drhoerr=comb['drhoerr'] else: if r is None or drho is None or drhoerr is None: raise ValueError("Send a combined struct or r,drho,drhoerr") plt=FramedPlot() plt.aspect_ratio=aspect_ratio plt.xlog=True plt.ylog=True if not nolabel: plt.xlabel = r'$r$ [$h^{-1}$ Mpc]' plt.ylabel = r'$\delta\rho ~ [M_{\odot} pc^{-3}]$' od=add_to_log_plot(plt, r, drho, drhoerr, color=color, type=type, minval=minval) # for drho we need even broader yrange plt.xrange = od['xrange'] yr=od['yrange'] plt.yrange = [0.5*yr[0], 3*yr[1]] if not noshow: plt.show() od['plt'] = plt return od
def compare_all_other(self, type, show=True): fdict=self.all_other_fdict(type) # this is the original file. It has the redshifts orig = zphot.weighting.read_training(fdict['origfile']) # this is the outputs num = zphot.weighting.read_num(fdict['numfile1']) # this is the weights file weights = zphot.weighting.read_training(fdict['wfile2']) # recoverable set w_recoverable = where1(num['num'] > 0) # this is actually the indexes back into the "orig" file w_keep = num['photoid'][w_recoverable] # get the z values for these validation objects zrec = orig['z'][w_keep] binsize=0.0314 valid_dict = histogram(zrec, min=0, max=1.1, binsize=binsize, more=True) plt=FramedPlot() vhist = valid_dict['hist']/(float(valid_dict['hist'].sum())) pvhist=biggles.Histogram(vhist, x0=valid_dict['low'][0], binsize=binsize) pvhist.label = 'truth' weights_dict = histogram(weights['z'], min=0, max=1.1, binsize=binsize, weights=weights['weight'], more=True) whist = weights_dict['whist']/weights_dict['whist'].sum() pwhist=biggles.Histogram(whist, x0=weights_dict['low'][0], binsize=binsize, color='red') pwhist.label = 'weighted train' key = PlotKey(0.6,0.6,[pvhist,pwhist]) plt.add(pvhist,pwhist,key) plt.add( biggles.PlotLabel(.8, .9, type) ) plt.write_eps(fdict['zhistfile']) converter.convert(fdict['zhistfile'],dpi=90,verbose=True) if show: plt.show()
def plot_m(self, r200, c): from biggles import FramedPlot, Curve n=1000 r = numpy.linspace(0.01, 20.0,n) m = self.m(r, r200, c) plt=FramedPlot() plt.add( Curve(r,m) ) plt.xlog=True plt.ylog=True plt.show()
def plot_mass(comb=None, r=None, mass=None, masserr=None, color='black',type='filled circle', nolabel=False, noshow=False, minval=1.e11, aspect_ratio=1): if comb is not None: r=comb['rmass'] mass=comb['mass'] masserr=comb['masserr'] else: if r is None or mass is None or masserr is None: raise ValueError("Send a combined struct or r,mass,masserr") plt=FramedPlot() plt.aspect_ratio=aspect_ratio plt.xlog=True plt.ylog=True if not nolabel: plt.xlabel = r'$r$ [$h^{-1}$ Mpc]' plt.ylabel = r'$M(<r) ~ [h^{-1} M_{\odot}]$' od=add_to_log_plot(plt, r, mass, masserr, color=color, type=type, minval=minval) plt.xrange = od['xrange'] plt.yrange = od['yrange'] if not noshow: plt.show() od['plt'] = plt return od
def plot_fits(self, st): import biggles biggles.configure("default", "fontsize_min", 2) parnames = ["A", "a", "g0", "gmax"] npars = len(parnames) tab = Table(npars, 1) magmiddle = (st["minmag"] + st["maxmag"]) / 2 for i in xrange(npars): yval = st["pars"][:, i] yerr = st["perr"][:, i] ymean = yval.mean() ystd = yval.std() yrange = [ymean - 3.5 * ystd, ymean + 3.5 * ystd] pts = Points(magmiddle, yval, type="filled circle") yerrpts = SymmetricErrorBarsY(magmiddle, yval, yerr) xerrpts = ErrorBarsX(yval, st["minmag"], st["maxmag"]) plt = FramedPlot() plt.yrange = yrange plt.add(pts, xerrpts, yerrpts) plt.xlabel = "mag" plt.ylabel = parnames[i] tab[i, 0] = plt if self.show: tab.show() d = files.get_prior_dir() d = os.path.join(d, "plots") epsfile = "pofe-pars-%s.eps" % self.otype epsfile = os.path.join(d, epsfile) eu.ostools.makedirs_fromfile(epsfile) print epsfile tab.write_eps(epsfile) os.system("converter -d 100 %s" % epsfile)
def testfit(): import biggles from biggles import FramedPlot,Points,Curve import scipy from scipy.optimize import leastsq ## Parametric function: 'v' is the parameter vector, 'x' the independent varible fp = lambda v, x: v[0]/(x**v[1])*sin(v[2]*x) ## Noisy function (used to generate data to fit) v_real = [1.5, 0.1, 2.] fn = lambda x: fp(v_real, x) ## Error function e = lambda v, x, y: (fp(v,x)-y) ## Generating noisy data to fit n = 30 xmin = 0.1 xmax = 5 x = linspace(xmin,xmax,n) y = fn(x) + scipy.rand(len(x))*0.2*(fn(x).max()-fn(x).min()) ## Initial parameter value v0 = [3., 1, 4.] ## Fitting v, success = leastsq(e, v0, args=(x,y), maxfev=10000) print('Estimater parameters: ', v) print('Real parameters: ', v_real) X = linspace(xmin,xmax,n*5) plt=FramedPlot() plt.add(Points(x,y)) plt.add(Curve(X,fp(v,X),color='red')) plt.show()
def plot_fits(self,st): import biggles biggles.configure( 'default', 'fontsize_min', 2) parnames=['A','a','g0','gmax'] npars=len(parnames) tab=Table(npars,1) magmiddle=(st['minmag'] + st['maxmag'])/2 for i in xrange(npars): yval=st['pars'][:,i] yerr=st['perr'][:,i] ymean=yval.mean() ystd=yval.std() yrange=[ymean-3.5*ystd, ymean+3.5*ystd] pts=Points(magmiddle, yval, type='filled circle') yerrpts=SymmetricErrorBarsY(magmiddle,yval,yerr) xerrpts=ErrorBarsX(yval, st['minmag'], st['maxmag']) plt=FramedPlot() plt.yrange=yrange plt.add(pts,xerrpts, yerrpts) plt.xlabel='mag' plt.ylabel=parnames[i] tab[i,0] = plt if self.show: tab.show() d=files.get_prior_dir() d=os.path.join(d, 'plots') epsfile='pofe-pars-%s.eps' % self.otype epsfile=os.path.join(d,epsfile) eu.ostools.makedirs_fromfile(epsfile) print epsfile tab.write_eps(epsfile) os.system('converter -d 100 %s' % epsfile)
def plot_fits(self,st): import biggles biggles.configure( 'default', 'fontsize_min', 2) if self.objtype=='gexp': parnames=['A','a','g0','gmax'] else: parnames=['A','b','c'] npars=len(parnames) tab=Table(npars,1) magmiddle=(st['minmag'] + st['maxmag'])/2 for i in xrange(npars): yval=st['pars'][:,i] yerr=st['perr'][:,i] ymean=yval.mean() ystd=yval.std() yrange=[ymean-3.5*ystd, ymean+3.5*ystd] pts=Points(magmiddle, yval, type='filled circle') yerrpts=SymmetricErrorBarsY(magmiddle,yval,yerr) xerrpts=ErrorBarsX(yval, st['minmag'], st['maxmag']) plt=FramedPlot() plt.yrange=yrange plt.add(pts,xerrpts, yerrpts) plt.xlabel='mag' plt.ylabel=parnames[i] tab[i,0] = plt tab.show()
def plot_dsig_one(r, dsig, dsigerr, **kw): """ plot delta sigma useful if adding to an existing plot parameters ---------- r: array radius dsig: array delta sigma dsigerr: array error on delta sigma """ from biggles import FramedPlot nbin=1 _set_biggles_defs(nbin) visible=kw.get('visible',True) xlog=kw.get('xlog',True) ylog=kw.get('ylog',True) aspect_ratio=kw.get('aspect_ratio',1) is_ortho=kw.get('is_ortho',False) plt=kw.get('plt',None) if plt is None: plt=FramedPlot() plt.aspect_ratio=aspect_ratio plt.xlog=xlog plt.ylog=ylog plt.xlabel = LABELS['rproj'] if is_ortho: plt.ylabel = LABELS['osig'] else: plt.ylabel = LABELS['dsig'] xrng, yrng = _add_dsig_to_plot(plt, r, dsig, dsigerr, **kw) plt.xrange=xrng plt.yrange=yrng if visible: plt.show() return plt
def doplot(self, fitres, h1, h2, h, minmag, maxmag): tab=Table(2,1) tab.title='%s %.2f %.2f ' % (self.objtype, minmag, maxmag) #xfit,yfit,gprior = self.get_prior_vals(fitres, h) gprior=self.get_prior(fitres) nrand=100000 binsize=self.binsize g1rand,g2rand=gprior.sample2d(nrand) grand=gprior.sample1d(nrand) hrand=histogram(grand, binsize=binsize, min=0., max=1., more=True) h1rand=histogram(g1rand, binsize=binsize, min=-1., max=1., more=True) #fbinsize=xfit[1]-xfit[0] #hrand['hist'] = hrand['hist']*float(yfit.sum())/hrand['hist'].sum()*fbinsize/binsize hrand['hist'] = hrand['hist']*float(h['hist'].sum())/nrand h1rand['hist'] = h1rand['hist']*float(h1['hist'].sum())/h1rand['hist'].sum() pltboth=FramedPlot() pltboth.xlabel=r'$g$' hplt1=Histogram(h1['hist'], x0=h1['low'][0], binsize=binsize,color='red') hplt2=Histogram(h2['hist'], x0=h2['low'][0], binsize=binsize,color='blue') hpltrand=Histogram(hrand['hist'], x0=hrand['low'][0], binsize=binsize, color='magenta') hplt1rand=Histogram(h1rand['hist'], x0=h1rand['low'][0], binsize=binsize, color='magenta') hplt1.label=r'$g_1$' hplt2.label=r'$g_2$' hplt1rand.label='rand' hpltrand.label='rand' keyboth=PlotKey(0.9,0.9,[hplt1,hplt2,hplt1rand],halign='right') pltboth.add(hplt1, hplt2, hplt1rand, keyboth) tab[0,0]=pltboth plt=FramedPlot() plt.xlabel=r'$|g|$' hplt=Histogram(h['hist'], x0=h['low'][0], binsize=binsize) hplt.label='|g|' #line=Curve(xfit, yfit, color='blue') #line.label='model' #key=PlotKey(0.9,0.9,[hplt,line,hpltrand],halign='right') #plt.add(line, hplt, hpltrand, key) key=PlotKey(0.9,0.9,[hplt,hpltrand],halign='right') plt.add(hplt, hpltrand, key) tab[1,0]=plt if self.show: tab.show() return tab
def test_sigmacritinv_npts(epsfile=None): """ Test accuracy of sigmacrit inv as a function of number of points """ from biggles import FramedPlot, PlotKey, PlotLabel, Curve, FramedArray, Table c1000 = Cosmo(npts=1000) c5 = Cosmo(npts=5) c4 = Cosmo(npts=4) c3 = Cosmo(npts=3) c2 = Cosmo(npts=2) tab = Table(2, 2) tab.uniform_limits = 0 tab.cellspacing = 1 p5 = FramedPlot() p5.xlabel = 'zsource' p5.ylabel = '% diff' p4 = FramedPlot() p4.xlabel = 'zsource' p4.ylabel = '% diff' p3 = FramedPlot() p3.xlabel = 'zsource' p3.ylabel = '% diff' p2 = FramedPlot() p2.xlabel = 'zsource' p2.ylabel = '% diff' l5 = PlotLabel(0.2, 0.7, 'npts = 5') p5.add(l5) l4 = PlotLabel(0.2, 0.1, 'npts = 4') p4.add(l4) l3 = PlotLabel(0.2, 0.9, 'npts = 3') p3.add(l3) l2 = PlotLabel(0.2, 0.9, 'npts = 2') p2.add(l2) colors = [ 'black', 'violet', 'blue', 'green', 'orange', 'magenta', 'firebrick', 'red' ] zlvals = numpy.arange(0.1, 0.9, 0.1) if zlvals.size != len(colors): raise ValueError("mismatch colors and zlvals") i = 0 allc5 = [] for zl in zlvals: zs = numpy.arange(zl + 0.01, 2.0, 0.01) scinv = c1000.sigmacritinv(zl, zs) scinv5 = c5.sigmacritinv(zl, zs) scinv4 = c4.sigmacritinv(zl, zs) scinv3 = c3.sigmacritinv(zl, zs) scinv2 = c2.sigmacritinv(zl, zs) curve5 = Curve(zs, 100 * (scinv - scinv5) / scinv, color=colors[i]) curve5.label = 'zlens: %0.2f' % zl allc5.append(curve5) p5.add(curve5) curve4 = Curve(zs, 100 * (scinv - scinv4) / scinv, color=colors[i]) p4.add(curve4) curve3 = Curve(zs, 100 * (scinv - scinv3) / scinv, color=colors[i]) p3.add(curve3) curve2 = Curve(zs, 100 * (scinv - scinv2) / scinv, color=colors[i]) p2.add(curve2) i += 1 key = PlotKey(0.15, 0.5, allc5) p5.add(key) tab[0, 0] = p5 tab[0, 1] = p4 tab[1, 0] = p3 tab[1, 1] = p2 tab.show() if epsfile is not None: tab.write_eps(epsfile)
def plot_dsig(**keys): """ This one stands alone. """ comb=keys.get('comb',None) r=keys.get('r',None) dsig=keys.get('dsig',None) dsigerr=keys.get('dsigerr',None) color=keys.get('color','black') type=keys.get('type','filled circle') nolabel=keys.get('nolabel',False) show=keys.get('show',True) minval=keys.get('minval',1.e-3) xlog=keys.get('xlog',True) ylog=keys.get('ylog',True) aspect_ratio=keys.get('aspect_ratio',1) plt=keys.get('plt',None) label=keys.get('label',None) if comb is not None: r=comb['r'] dsig=comb['dsig'] dsigerr=comb['dsigerr'] else: if r is None or dsig is None or dsigerr is None: raise ValueError("Send a combined struct or r,dsig,dsigerr") if plt is None: plt=FramedPlot() plt.aspect_ratio=aspect_ratio plt.xlog=xlog plt.ylog=ylog if not nolabel: plt.xlabel = labels['rproj'] plt.ylabel = labels['dsig'] if ylog: od=add_to_log_plot(plt, r, dsig, dsigerr, color=color, type=type, minval=minval) plt.xrange = od['xrange'] plt.yrange = od['yrange'] if label: od['p'].label=label else: zpts=Curve(r, dsig*0) plt.add(zpts) pts=Points(r, dsig, type=type, color=color) if label: pts.label=label plt.add(pts) if dsigerr is not None: epts=SymErrY(r, dsig, dsigerr, color=color) plt.add(epts) yrng=keys.get('yrange',None) xrng=keys.get('xrange',None) if yrng: plt.yrange=yrng if xrng: plt.xrange=xrng else: if xlog: plt.xrange=eu.plotting.get_log_plot_range(r) if show: plt.show() if ylog: od['plt'] = plt return od else: return plt
def plot2dsig_over(r1,dsig1,dsig1err,r2,dsig2, dsig2err, **keys): ptype1=keys.get('ptype1','filled circle') ptype2=keys.get('ptype2','filled circle') size1=keys.get('size1',1) size2=keys.get('size2',1) color1=keys.get('color1','red') color2=keys.get('color2','blue') label = keys.get('label',None) label1 = keys.get('label1',None) label2 = keys.get('label2',None) xrng = keys.get('xrange',None) yrng = keys.get('yrange',None) show = keys.get('show',True) ylog = keys.get('ylog',True) plt=keys.get('plt',None) yall=numpy.concatenate((dsig1, dsig2)) yerrall=numpy.concatenate((dsig1err, dsig2err)) if yrng is None: if ylog: yrng = eu.plotting.get_log_plot_range(yall, err=yerrall, input_range=yrng) rr=numpy.concatenate((r1,r2)) if xrng is None: xrng = eu.plotting.get_log_plot_range(rr) if plt is None: plt=FramedPlot() plt.xlog=True plt.ylog=ylog plt.xrange=xrng plt.yrange=yrng plt.xlabel = labels['rproj'] plt.ylabel = labels['dsig'] dsig1_p = Points(r1, dsig1, color=color1, type=ptype1, size=size1) dsig1err_p = SymErrY(r1, dsig1, dsig1err, color=color2) dsig1_p.label=label1 dsig2_p = Points(r2, dsig2, color=color2, type=ptype2, size=size2) dsig2err_p = SymErrY(r2, dsig2, dsig2err, color=color2) dsig2_p.label=label2 plt.add(dsig1_p, dsig2_p) if ylog: # biggles chokes if you give it negative data for a log plot eu.plotting.add_log_error_bars(plt,'y',r1,dsig1,dsig1err,yrng, color=color1) eu.plotting.add_log_error_bars(plt,'y',r2,dsig2,dsig2err,yrng, color=color2) else: err1 = biggles.SymmetricErrorBarsY(r1,dsig1,dsig1err,color=color1) err2 = biggles.SymmetricErrorBarsY(r2,dsig2,dsig2err,color=color2) plt.add(err1,err2) zerop = biggles.Curve(xrng, [0,0]) plt.add(zerop) if label is not None: plt.add(PlotLabel(0.9,0.9,label,halign='right')) if label1 is not None or label2 is not None: key = PlotKey(0.9,0.15, [dsig1_p,dsig2_p], halign='right') plt.add(key) if show: plt.show() return plt
def plot_ellip_vs_field(self, field, rmag_max=21.8, fmin=None, fmax=None, nbin=20, nperbin=50000, yrange=None, show=True): self.load_data() w=where1((self['cmodelmag_dered_r'] > 18.0) & (self['cmodelmag_dered_r'] < rmag_max) ) if w.size == 0: print("no good objects") return weights = 1.0/(0.32**2 + self['uncer_rg'][w]**2) if field == 'psf_fwhm': field_data = self['psf_fwhm'][w] fstr = 'PSF FWHM (arcsec)' elif field == 'psf_sigma': field_data = self['psf_sigma'][w] fstr = r'$\sigma_{PSF}$' elif field == 'R_rg': field_data = self['r_rg'][w] fstr = 'R_rg' else: field_data = self[field][w] fstr=field print("Plotting mean e for field:",field) fstr = fstr.replace('_','\_') be1 = eu.stat.Binner(field_data, self['e1_rg'][w], weights=weights) be2 = eu.stat.Binner(field_data, self['e2_rg'][w], weights=weights) print(" hist e1") be1.dohist(nperbin=nperbin, min=fmin, max=fmax) #be1.dohist(nbin=nbin, min=fmin, max=fmax) print(" stats e1") be1.calc_stats() print(" hist e2") be2.dohist(nperbin=nperbin, min=fmin, max=fmax) #be2.dohist(nbin=nbin, min=fmin, max=fmax) print(" stats e2") be2.calc_stats() plt = FramedPlot() p1 = Points( be1['wxmean'], be1['wymean'], type='filled circle', color='blue') p1err = SymErrY( be1['wxmean'], be1['wymean'], be1['wyerr2'], color='blue') p1.label = r'$e_1$' p2 = Points( be2['wxmean'], be2['wymean'], type='filled circle', color='red') p2.label = r'$e_2$' p2err = SymErrY( be2['wxmean'], be2['wymean'], be2['wyerr2'], color='red') key = PlotKey(0.8, 0.9, [p1,p2]) plt.add(p1, p1err, p2, p2err, key) if field != 'cmodelmag_dered_r': rmag_lab = PlotLabel(0.1,0.05,'rmag < %0.2f' % rmag_max, halign='left') plt.add(rmag_lab) plab = PlotLabel(0.1,0.1, 'CH+RM', halign='left') plt.add(plab) plt.xlabel = r'$'+fstr+'$' plt.ylabel = r'$<e>$' if yrange is not None: plt.yrange=yrange if show: plt.show() epsfile = self.plotfile(field, rmag_max) print(" Writing eps file:",epsfile) plt.write_eps(epsfile)
def plot_coverage(self, region='both', show=True, dops=True): import biggles from biggles import FramedPlot, Points, PlotKey l = self.read() w,=numpy.where( (l['ra'] >= 0.0) & (l['ra'] <= 360.0) ) if w.size != l.size: print("threw out",l.size-w.size,"with bad ra") l=l[w] llam,leta = eu.coords.eq2sdss(l['ra'],l['dec']) maskflags = l['maskflags'] lammin,lammax = (-70.,70.) if region=='ngc': # a bit high to make room for the legend emin,emax=(-40,60) biggles.configure('screen','width', 1800) biggles.configure('screen','height', 1140) elif region=='sgc': emin,emax=(100,165) biggles.configure('screen','width', 1800) biggles.configure('screen','height', 1140) else: emin,emax=(-40,165) biggles.configure('screen','width', 1140) biggles.configure('screen','height', 1140) wl=where1((leta > emin) & (leta < emax)) llam=llam[wl] leta=leta[wl] maskflags=maskflags[wl] plt=FramedPlot() plt.xlabel=r'$\lambda$' plt.ylabel=r'$\eta$' print("adding all lenses") type = 'filled circle' symsize=0.2 allp = Points(llam,leta,type=type,size=symsize) allp.label='all' plt.add(allp) wquad = es_sdsspy.stomp_maps.quad_check(maskflags) print("adding quad pass") quadp = Points(llam[wquad],leta[wquad],type=type,color='red',size=symsize) quadp.label = 'quad good' plt.add(quadp) fakepoints = eu.plotting.fake_filled_circles(['all','quad good'],['black','red']) key=PlotKey(0.95,0.95,fakepoints,halign='right') plt.add(key) es_sdsspy.stomp_maps.plot_boss_geometry(color='blue',plt=plt,show=False) xrng = (lammin, lammax) yrng = (emin, emax) plt.xrange = xrng plt.yrange = yrng plt.aspect_ratio = (yrng[1]-yrng[0])/float(xrng[1]-xrng[0]) if show: plt.show() if dops: d = lensing.files.sample_dir(type='lcat',sample=self['sample']) d = os.path.join(d,'plots') if not os.path.exists(d): os.makedirs(d) epsfile = os.path.join(d, 'lcat-%s-%s-coverage.eps' % (self['sample'],region) ) print("Writing to eps file:",epsfile) plt.write_eps(epsfile) return plt
def test_interp_hybrid(): """ Send y0,y1 with one or both less than zero to test the hybrid offset scheme """ slope = -2.0 #xvals = 0.1+linspace(0.0,8.0,9) xvals = 10.0**linspace(0.0,1.0,10) yvals = xvals**slope #yerr = 0.5*yvals #yerr = sqrt(yvals) yerr = yvals.copy() yerr[:] = 0.05 #xfine = 0.1+linspace(0.0,8.0,1000) xfine = 10.0**linspace(0.0,1.0,1000) yfine = xfine**slope #yerr = yvals.copy() #yerr[:] = 2 plt=FramedPlot() plt.xrange = [0.5*xvals.min(), 1.5*xvals.max()] plt.xlog=True #plt.ylog=True plt.add(Points(xvals,yvals,type='filled circle',size=1)) plt.add(Curve(xfine,yfine,color='blue')) #w=where1( (yvals-yerr) > 1.e-5 ) #plt.add(SymmetricErrorBarsY(xvals[w],yvals[w],yerr[w])) plt.add(SymmetricErrorBarsY(xvals,yvals,yerr)) # make points in between consecutive xvals,yvals so we # can use hybrid 2-point function xi = numpy.zeros(xvals.size-1,dtype='f8') yi = numpy.zeros(xi.size,dtype='f8') for i in xrange(xi.size): logx = (log10(xvals[i+1])+log10(xvals[i]))/2.0 xi[i] = 10.0**logx yi[i],amp,slope,off = interp_hybrid(xvals[i], xvals[i+1], yvals[i], yvals[i+1], yerr[i], yerr[i+1], xi[i],more=True) print 'amp:',amp print 'slope:',slope print 'off:',off print xvals print xi print yi plt.add( Points(xi, yi, type='filled circle', size=1, color='red')) plt.show()
def plot(self, yrange=None): from biggles import FramedPlot, Points, Curve, PlotKey, Table,PlotLabel res=self.res etrue = res['etrue'] e1true = res['e1true'] e2true = res['e2true'] facvals = res['facvals'] sigma = res['sigma'] e1=res['e1'] e2=res['e2'] e=res['e'] T=res['T'] Ttrue=res['Ttrue']*facvals**2 e_pdiff = e/etrue-1 T_pdiff = T/Ttrue-1 compc= Curve(sigma, sigma*0) ce = Curve(sigma, e_pdiff, color='red') pe = Points(sigma, e_pdiff, type='filled circle') e_plt = FramedPlot() e_plt.add(ce,pe,compc) e_plt.xlabel = r'$\sigma$' e_plt.ylabel = r'$e/e_{true}-1$' cT = Curve(sigma, T_pdiff, color='red') pT = Points(sigma, T_pdiff, type='filled circle') T_plt = FramedPlot() T_plt.add(cT,pT,compc) T_plt.xlabel = r'$\sigma$' T_plt.ylabel = r'$T/T_{true}-1$' lab=PlotLabel(0.9,0.9,self.model,halign='right') T_plt.add(lab) if yrange is not None: e_plt.yrange=yrange T_plt.yrange=yrange tab=Table(2,1) tab[0,0] = T_plt tab[1,0] = e_plt tab.show()
def plot_vs_field(self, field, plot_type, rmag_min=None, rmag_max=None, fmin=None, fmax=None, nbin=20, nperbin=50000, xrng=None, yrng=None, show=True): allowed=['meane','residual'] if plot_type not in allowed: raise ValueError("plot_type should be in [%s]" % ','.join(allowed)) if plot_type == 'residual' and self.sweeptype != 'star': raise ValueError("residuals only supported for stars") if rmag_min is None: if self.sweeptype == 'gal': rmag_min=18.0 else: rmag_min=15.0 if rmag_max is None: if self.sweeptype == 'gal': rmag_max=21.8 else: rmag_max=19.0 # this will only load the main data once. self.load_data(field) print("Using rmag range: [%0.2f,%0.2f]" % (rmag_min,rmag_max)) # notes # - amflags here is really corrflags_rg for gals # - e1 is really e1_rg for gals logic = ((self['amflags'] == 0) & (self['e1'] < 4) & (self['e1'] > -4) & (self['rmag'] > rmag_min) & (self['rmag'] < rmag_max) ) if self.sweeptype == 'gal': logic = logic & (self['R'] > 1.0/3.0) & (self['R'] < 1.0) w=where1(logic) print("Number passing cuts:",w.size) minnum=31000 if w.size < minnum: print("want %d good objects, found %d" % (minnum,w.size)) return weights = 1.0/(0.32**2 + self['uncer'][w]**2) # we can try to get nice labels for some fields if field == 'fwhm_psf': field_data = self['fwhm_psf'][w] fstr = 'PSF FWHM (arcsec)' elif field == 'sigma_psf': field_data = self['sigma_psf'][w] fstr = r'\sigma_{PSF}' elif field == 'sigma': field_data = self['sigma'][w] fstr = r'\sigma_{obj+PSF}' else: field_data = self[field][w] fstr=field fstr = fstr.replace('_','\_') print("Plotting for field:",field) if plot_type == 'residual': print(' doing: residual') be1 = eu.stat.Binner(field_data, self['e1'][w]-self['e1_psf'][w], weights=weights) be2 = eu.stat.Binner(field_data, self['e2'][w]-self['e2_psf'][w], weights=weights) ylabel = r'$<e_{star}-e_{PSF}>$' else: print(' doing meane') be1 = eu.stat.Binner(field_data, self['e1'][w], weights=weights) be2 = eu.stat.Binner(field_data, self['e2'][w], weights=weights) ylabel = r'$<e>$' # regular hist for display print(" regular fixed binsize hist") xm,xe,xstd=eu.stat.wmom(field_data, weights, sdev=True) #hxmin = xm-4.0*xstd #hxmax = xm+4.0*xstd bsize = xstd/5. hist = eu.stat.histogram(field_data, binsize=bsize, weights=weights, more=True) print(" hist e1, nperbin: ",nperbin) be1.dohist(nperbin=nperbin, min=fmin, max=fmax) #be1.dohist(nbin=nbin, min=fmin, max=fmax) print(" stats e1") be1.calc_stats() print(" hist e2, nperbin: ",nperbin) be2.dohist(nperbin=nperbin, min=fmin, max=fmax) #be2.dohist(nbin=nbin, min=fmin, max=fmax) print(" stats e2") be2.calc_stats() plt = FramedPlot() if xrng is not None: plt.xrange=xrng else: if field == 'R': plt.xrange=[0.29,1.01] if yrng is not None: plt.yrange=yrng ymin = yrng[0] ymax = 0.8*yrng[1] else: ymin = min( be1['wymean'].min(),be2['wymean'].min() ) ymax = 0.8*max( be1['wymean'].max(),be2['wymean'].max() ) # this is a histogram-like object ph = eu.plotting.make_hist_curve(hist['low'], hist['high'], hist['whist'], ymin=ymin, ymax=ymax, color='grey50') plt.add(ph) p1 = Points( be1['wxmean'], be1['wymean'], type='filled circle', color='blue') p1err = SymErrY( be1['wxmean'], be1['wymean'], be1['wyerr2'], color='blue') p1.label = r'$e_1$' p2 = Points( be2['wxmean'], be2['wymean'], type='filled circle', color='red') p2.label = r'$e_2$' p2err = SymErrY( be2['wxmean'], be2['wymean'], be2['wyerr2'], color='red') key = PlotKey(0.1,0.9, [p1,p2]) plt.add(p1, p1err, p2, p2err, key) if self.camcol != 'any' and field == 'R' and plot_type=='meane': order=3 print(" getting poly order",order) coeff1 = numpy.polyfit(be1['wxmean'], be1['wymean'], order) poly1=numpy.poly1d(coeff1) coeff2 = numpy.polyfit(be2['wxmean'], be2['wymean'], order) poly2=numpy.poly1d(coeff2) ps1 = Curve( be1['wxmean'], poly1(be1['wxmean']), color='blue') ps2 = Curve( be2['wxmean'], poly2(be2['wxmean']), color='red') plt.add(ps1,ps2) polyf = self.R_polyfile(self.camcol, rmag_max) out={'coeff_e1':list([float(c) for c in coeff1]), 'coeff_e2':list([float(c) for c in coeff2])} print(" -- Writing poly coeffs to:",polyf) eu.io.write(polyf,out) if field != 'rmag': rmag_lab = \ PlotLabel(0.1,0.05,'%0.2f < rmag < %0.2f' % (rmag_min,rmag_max), halign='left') plt.add(rmag_lab) procrun_lab = PlotLabel(0.1,0.1, 'procrun: %s filter: %s' % (self.procrun, self.band), halign='left') plt.add(procrun_lab) cy=0.9 if self.run != 'any': run_lab = PlotLabel(0.9,0.9, 'run: %06i' % self.run, halign='right') plt.add(run_lab) cy=0.8 if self.camcol != 'any': run_lab = PlotLabel(0.9,cy, 'camcol: %i' % self.camcol, halign='right') plt.add(run_lab) plt.xlabel = r'$'+fstr+'$' plt.ylabel = ylabel if show: plt.show() epsfile = self.plotfile(field, rmag_max, plot_type=plot_type) eu.ostools.makedirs_fromfile(epsfile, verbose=True) print(" Writing eps file:",epsfile) plt.write_eps(epsfile) converter.convert(epsfile, verbose=True)
def doplot(self, gprior, minmag, maxmag): from lensing.util import eta1eta2_to_g1g2 tab = Table(2, 2) tab.title = "%s %.2f %.2f " % (self.otype, minmag, maxmag) h1_g, h2_g, h_g = self.do_histograms(minmag, maxmag, "g") h1_eta, h2_eta, h_eta = self.do_histograms(minmag, maxmag, "eta") nrand = 1000000 binsize_eta = self.binsize_eta binsize_g = self.binsize_g rbinsize_eta = binsize_eta * 0.2 rbinsize_g = binsize_g * 0.2 gr = gprior.sample(nrand) eta1_rand = gr[:, 0] eta2_rand = gr[:, 1] eta_rand = numpy.sqrt(eta1_rand ** 2 + eta2_rand ** 2) g1_rand, g2_rand = eta1eta2_to_g1g2(eta1_rand, eta2_rand) g_rand = numpy.sqrt(g1_rand ** 2 + g2_rand ** 2) hrand_eta = histogram(eta_rand, binsize=rbinsize_eta, min=0, max=self.max_eta, more=True) h1rand_eta = histogram(eta1_rand, binsize=rbinsize_eta, min=self.min_eta_2d, max=self.max_eta_2d, more=True) hrand_g = histogram(g_rand, binsize=rbinsize_g, min=0, max=self.max_g, more=True) h1rand_g = histogram(g1_rand, binsize=rbinsize_g, min=self.min_g_2d, max=self.max_g_2d, more=True) # eta 2d plots bratio_eta = self.binsize_eta / rbinsize_eta hrand_eta["hist"] = hrand_eta["hist"] * bratio_eta * float(h_eta["hist"].sum()) / nrand h1rand_eta["hist"] = h1rand_eta["hist"] * bratio_eta * float(h1_eta["hist"].sum()) / h1rand_eta["hist"].sum() pltboth_eta = FramedPlot() pltboth_eta.xlabel = r"$\eta$" hplt1_eta = Histogram(h1_eta["hist"], x0=h1_eta["low"][0], binsize=binsize_eta, color="darkgreen") hplt2_eta = Histogram(h2_eta["hist"], x0=h2_eta["low"][0], binsize=binsize_eta, color="blue") hpltrand_eta = Histogram(hrand_eta["hist"], x0=hrand_eta["low"][0], binsize=rbinsize_eta, color="red") hplt1rand_eta = Histogram(h1rand_eta["hist"], x0=h1rand_eta["low"][0], binsize=rbinsize_eta, color="red") hplt1_eta.label = r"$\eta_1$" hplt2_eta.label = r"$\eta_2$" hplt1rand_eta.label = "rand" hpltrand_eta.label = "rand" keyboth_eta = PlotKey(0.9, 0.9, [hplt1_eta, hplt2_eta, hplt1rand_eta], halign="right") pltboth_eta.add(hplt1_eta, hplt2_eta, hplt1rand_eta, keyboth_eta) tab[0, 0] = pltboth_eta plt1d_eta = FramedPlot() plt1d_eta.xlabel = r"$|\eta|$" hplt_eta = Histogram(h_eta["hist"], x0=h_eta["low"][0], binsize=binsize_eta) hplt_eta.label = r"$|\eta|$" key_eta = PlotKey(0.9, 0.9, [hplt_eta, hpltrand_eta], halign="right") plt1d_eta.add(hplt_eta, hpltrand_eta, key_eta) tab[1, 0] = plt1d_eta # g plots bratio_g = self.binsize_g / rbinsize_g hrand_g["hist"] = hrand_g["hist"] * bratio_g * float(h_g["hist"].sum()) / nrand h1rand_g["hist"] = h1rand_g["hist"] * bratio_g * float(h1_g["hist"].sum()) / h1rand_g["hist"].sum() pltboth_g = FramedPlot() pltboth_g.xlabel = r"$g$" hplt1_g = Histogram(h1_g["hist"], x0=h1_g["low"][0], binsize=binsize_g, color="darkgreen") hplt2_g = Histogram(h2_g["hist"], x0=h2_g["low"][0], binsize=binsize_g, color="blue") hpltrand_g = Histogram(hrand_g["hist"], x0=hrand_g["low"][0], binsize=rbinsize_g, color="red") hplt1rand_g = Histogram(h1rand_g["hist"], x0=h1rand_g["low"][0], binsize=rbinsize_g, color="red") hplt1_g.label = r"$g_1$" hplt2_g.label = r"$g_2$" hplt1rand_g.label = "rand" hpltrand_g.label = "rand" keyboth_g = PlotKey(0.9, 0.9, [hplt1_g, hplt2_g, hplt1rand_g], halign="right") pltboth_g.add(hplt1_g, hplt2_g, hplt1rand_g, keyboth_g) tab[0, 1] = pltboth_g plt1d_g = FramedPlot() plt1d_g.xlabel = r"$|g|$" hplt_g = Histogram(h_g["hist"], x0=h_g["low"][0], binsize=binsize_g) hplt_g.label = "|g|" key_g = PlotKey(0.9, 0.9, [hplt_g, hpltrand_g], halign="right") plt1d_g.add(hplt_g, hpltrand_g, key_g) tab[1, 1] = plt1d_g if self.show: tab.show() d = files.get_prior_dir() d = os.path.join(d, "plots") epsfile = "pofe-pofeta-%.2f-%.2f-%s.eps" % (minmag, maxmag, self.otype) epsfile = os.path.join(d, epsfile) eu.ostools.makedirs_fromfile(epsfile) print epsfile tab.write_eps(epsfile) os.system("converter -d 100 %s" % epsfile) return tab
def plot_coverage(self, region='both', show=True, dops=True): """ Plot a random subset of the randoms along with the boss survey geometry area as bounding boxes """ import biggles from biggles import FramedPlot, Points, PlotKey symsize=0.5 l = self.read() llam,leta = eu.coords.eq2sdss(l['ra'],l['dec']) lammin,lammax = (-70.,70.) if region=='ngc': # a bit high to make room for the legend emin,emax=(-40,60) biggles.configure('screen','width', 1800) biggles.configure('screen','height', 1140) width=1.5 elif region=='sgc': emin,emax=(125,165) biggles.configure('screen','width', 1800) biggles.configure('screen','height', 1140) width=2 else: emin,emax=(-40,165) biggles.configure('screen','width', 1140) biggles.configure('screen','height', 1140) width=2 wl=where1((leta > emin) & (leta < emax)) llam=llam[wl] leta=leta[wl] plt=FramedPlot() plt.xlabel=r'$\lambda$' plt.ylabel=r'$\eta$' xrng = (lammin, lammax) yrng = (emin, emax) plt.xrange = xrng plt.yrange = yrng print("adding random subset of randoms") ii = eu.numpy_util.random_subset(llam.size, 500000) allp = Points(llam[ii],leta[ii],type='dot',size=symsize) plt.add(allp) plt.aspect_ratio = (yrng[1]-yrng[0])/float(xrng[1]-xrng[0]) #es_sdsspy.stomp_maps.plot_boss_geometry(color='blue',plt=plt,show=False) es_sdsspy.stomp_maps.plot_boss_geometry(plt=plt,show=False,width=width) if show: plt.show() if dops: d = lensing.files.sample_dir(type='lcat',sample=self['sample']) d = os.path.join(d,'plots') if not os.path.exists(d): os.makedirs(d) epsfile = os.path.join(d, '%s-%s-coverage.eps' % ('lcat',self['sample'])) print("Writing to eps file:",epsfile) plt.write_eps(epsfile) return plt
def test_sigmacritinv_npts(epsfile=None): """ Test accuracy of sigmacrit inv as a function of number of points """ from biggles import FramedPlot, PlotKey, PlotLabel, Curve, FramedArray, Table c1000 = Cosmo(npts=1000) c5 = Cosmo(npts=5) c4 = Cosmo(npts=4) c3 = Cosmo(npts=3) c2 = Cosmo(npts=2) tab = Table( 2, 2 ) tab.uniform_limits = 0 tab.cellspacing = 1 p5 = FramedPlot() p5.xlabel = 'zsource' p5.ylabel = '% diff' p4 = FramedPlot() p4.xlabel = 'zsource' p4.ylabel = '% diff' p3 = FramedPlot() p3.xlabel = 'zsource' p3.ylabel = '% diff' p2 = FramedPlot() p2.xlabel = 'zsource' p2.ylabel = '% diff' l5 = PlotLabel(0.2,0.7,'npts = 5') p5.add(l5) l4 = PlotLabel(0.2,0.1,'npts = 4') p4.add(l4) l3 = PlotLabel(0.2,0.9,'npts = 3') p3.add(l3) l2 = PlotLabel(0.2,0.9,'npts = 2') p2.add(l2) colors = ['black','violet','blue','green','orange','magenta','firebrick','red'] zlvals = numpy.arange(0.1,0.9,0.1) if zlvals.size != len(colors): raise ValueError("mismatch colors and zlvals") i=0 allc5 = [] for zl in zlvals: zs = numpy.arange(zl+0.01, 2.0, 0.01) scinv = c1000.sigmacritinv(zl, zs) scinv5 = c5.sigmacritinv(zl, zs) scinv4 = c4.sigmacritinv(zl, zs) scinv3 = c3.sigmacritinv(zl, zs) scinv2 = c2.sigmacritinv(zl, zs) curve5 = Curve(zs, 100*(scinv-scinv5)/scinv, color=colors[i]) curve5.label = 'zlens: %0.2f' % zl allc5.append(curve5) p5.add(curve5) curve4 = Curve(zs, 100*(scinv-scinv4)/scinv, color=colors[i]) p4.add(curve4) curve3 = Curve(zs, 100*(scinv-scinv3)/scinv, color=colors[i]) p3.add(curve3) curve2 = Curve(zs, 100*(scinv-scinv2)/scinv, color=colors[i]) p2.add(curve2) i+=1 key = PlotKey(0.15,0.5,allc5) p5.add(key) tab[0,0] = p5 tab[0,1] = p4 tab[1,0] = p3 tab[1,1] = p2 tab.show() if epsfile is not None: tab.write_eps(epsfile)
def plot_coverage_bybin(self, binner, region='both', show=True, dops=True, rand=None): import pcolors import biggles import converter from biggles import FramedPlot, Points, PlotKey orig = self.read_original() lcat = self.read() all_clam,all_ceta = eu.coords.eq2sdss(orig['ra'],orig['dec']) l = orig[lcat['zindex']] clam,ceta = eu.coords.eq2sdss(lcat['ra'],lcat['dec']) clammin,clammax = (-70.,120.) if region=='ngc': # a bit high to make room for the legend emin,emax=(-40,60) biggles.configure('screen','width', 1800) biggles.configure('screen','height', 1140) clammin,clammax = (-70.,120.) elif region=='sgc': emin,emax=(105,165) biggles.configure('screen','width', 1800) biggles.configure('screen','height', 1140) clammin,clammax = (-50.,90.) else: emin,emax=(-40,165) biggles.configure('screen','width', 1140) biggles.configure('screen','height', 1140) clammin,clammax = (-70.,120.) wl=where1((all_ceta > emin) & (all_ceta < emax)) all_clam=all_clam[wl] all_ceta=all_ceta[wl] wl=where1((ceta > emin) & (ceta < emax)) clam=clam[wl] ceta=ceta[wl] l=l[wl] plt=FramedPlot() plt.xlabel=r'$\lambda$' plt.ylabel=r'$\eta$' xrng = (clammin, clammax) yrng = (emin, emax) plt.xrange = xrng plt.yrange = yrng print("adding all lenses") type = 'filled circle' symsize=0.2 colors = pcolors.rainbow(binner['nbin'],'hex') if rand is not None: clam_r,ceta_r = eu.coords.eq2sdss(rand['ra'],rand['dec']) wl=where1((ceta_r > emin) & (ceta_r < emax)) clam_r=clam_r[wl] ceta_r=ceta_r[wl] rp = Points(clam_r, ceta_r, type='dot', size=0.2) plt.add(rp) size_min=0.2 size_max=4 sizes=[] minlambda = l['lambda_zred'].min() maxlambda = l['lambda_zred'].max() for i in xrange(binner['nbin']): w=binner.select_bin(l, i) mlam=l['lambda_zred'][w].mean() # scale 0 to 1 sz=(mlam-minlambda)/maxlambda # now scale size sz = size_min + sz*(size_max-size_min) sizes.append(sz) all_plots=[] labels=[] #for i in xrange(binner['nbin']): for i in reversed(xrange(binner['nbin'])): w=binner.select_bin(l, i) #points = Points(clam[w], ceta[w],type=type,size=symsize, color=colors[i]) points = Points(clam[w], ceta[w],type=type,size=sizes[i], color=colors[i]) labels.append(binner.bin_label(i)) plt.add(points) labels.reverse() fakepoints = eu.plotting.fake_filled_circles(labels, colors) key=PlotKey(0.95,0.95,fakepoints,halign='right',size=1.5) plt.add(key) plt.aspect_ratio = (yrng[1]-yrng[0])/float(xrng[1]-xrng[0]) es_sdsspy.stomp_maps.plot_boss_geometry(color='blue',plt=plt,show=False) if show: plt.show() if dops: d = lensing.files.sample_dir(type='lcat',sample=self['sample']) d = os.path.join(d,'plots') if not os.path.exists(d): os.makedirs(d) epsfile = os.path.join(d, 'lcat-%s-coverage-bybin.eps' % self['sample']) if rand is not None: epsfile=epsfile.replace('.eps','-withrand.eps') if region in ['sgc','ngc']: epsfile=epsfile.replace('.eps','-%s.eps' % region) print("Writing to eps file:",epsfile) plt.write_eps(epsfile) print("converting to png") converter.convert(epsfile, dpi=300) return plt