def view_mbobs_list(fofid, mbobs_list, **kw): import biggles import images import plotting show = kw.get('show', False) save = kw.get('save', False) for i, mbobs in enumerate(mbobs_list): id = mbobs[0][0].meta['id'] for band, obslist in enumerate(mbobs): grid = plotting.Grid(len(obslist)) plt = biggles.Table( grid.nrow, grid.ncol, ) aratio = grid.nrow/(grid.ncol*2) plt.aspect_ratio = aratio plt.title = 'FoF: %d id: %d band: %d' % (fofid, id, band) for iobs, obs in enumerate(obslist): im = obs.image wt = obs.weight im = im/im.max() row, col = grid(iobs) implt = images.view(im, nonlinear=0.4, show=False) wtplt = images.view(wt, show=False) tab = biggles.Table(1, 2) tab[0, 0] = implt tab[0, 1] = wtplt tab.title = 'id: %d band: %d obs: %d' % (id, band, iobs) plt[row, col] = tab if save: pltname = 'images-fof%06d-id%06d-band%d.png' % \ (fofid, id, band) logger.info('writing: %s' % pltname) plt.write_img(3000, 3000*aratio, pltname) if show: plt.show(width=2000, height=2000*aratio) return plt
def plot_voltages(fs, vecs): import biggles all_values = np.concatenate( vecs ) hi = all_values.max() lo = all_values.min() plot = biggles.Table(len(vecs), 1) plot.cellpadding = 0 plot.cellspacing = 0 for i,vec in enumerate(vecs): p = biggles.Plot() p.add( biggles.Curve(wv.t(fs, vec), vec) ) p.yrange = (lo, hi) plot[i,0] = p p.add( biggles.LineX(0) ) p.add( biggles.Label(0, (hi+lo)/2, "%.2f mV" % (hi-lo), halign='left') ) p.add( biggles.LineY(lo) ) p.add( biggles.Label((len(vec)/fs/2), lo, "%.1f ms" % (1000*len(vec)/fs), valign='bottom') ) return plot
def _plot_shears(shears, show=True, eps=None, png=None): import biggles import esutil as eu tab = biggles.Table(2, 1) std = shears.std(axis=0) plt1 = eu.plotting.bhist(shears[:, 0], binsize=0.2 * std[0], color='blue', show=False, xlabel=r'$\gamma_1$') plt2 = eu.plotting.bhist(shears[:, 1], binsize=0.2 * std[1], color='red', show=False, xlabel=r'$\gamma_2$') tab[0, 0] = plt1 tab[1, 0] = plt2 if png is not None: print(png) tab.write_img(800, 800, png) if eps is not None: print(eps) tab.write_eps(eps) if show: tab.show()
def view_mbobs_list(mbobs_list, **kw): import biggles import images import plotting weight = kw.get('weight', False) nband = len(mbobs_list[0]) if weight: grid = plotting.Grid(len(mbobs_list)) plt = biggles.Table( grid.nrow, grid.ncol, ) for i, mbobs in enumerate(mbobs_list): if nband == 3: im = make_rgb(mbobs) else: im = mbobs[0][0].image wt = mbobs[0][0].weight row, col = grid(i) tplt = images.view_mosaic([im, wt], show=False) plt[row, col] = tplt plt.show() else: if nband == 3: imlist = [make_rgb(mbobs) for mbobs in mbobs_list] else: imlist = [mbobs[0][0].image for mbobs in mbobs_list] plt = images.view_mosaic(imlist, **kw) return plt
def get_page(self, page): pr, pc = self.page_shape filename = self.filename % page plot = biggles.Table(1, pc) for i in range(pc): plot[0, i] = biggles.FramedArray(pr, 1) self.canvas = { 'filename': filename, 'plot': plot, }
def get_page(self, page): pr, pc = self.page_shape filename = self.filename % page plot = biggles.Table(pr, pc) for i in range(pc): for j in range(pr): plot[j, i] = biggles.FramedPlot() self.canvas = { 'filename': filename, 'plot': plot, }
def _plot_compare_model(gmix, tobs): import biggles import images model_im = gmix.make_image(tobs.image.shape, jacobian=tobs.jacobian) imdiff = model_im - tobs.image tab = biggles.Table(2, 2, aspect_ratio=1.0) tab[0, 0] = images.view(tobs.image, show=False, title='im') tab[0, 1] = images.view(model_im, show=False, title='model') tab[1, 0] = images.view(imdiff, show=False, title='diff') tab.show() if input('hit a key (q to quit): ') == 'q': stop
def test_example9(self): def mag(vec): return numpy.sqrt(numpy.sum(vec**2, -1)) def make_coloredpoints_plot(): # This is the magic recipe for an array of points from (0,0) to (10,10) (x, y) = numpy.reshape(numpy.indices([10 + 1, 10 + 1]), (2, -1)) # Let's color the points by their distance from the point (3,7) center = (3, 7) rad = mag(numpy.transpose([x, y]) - center) scaledrad = (1 - rad / numpy.max(rad))[:, numpy.newaxis] # Go from light blue to intense red. minColor = numpy.array([0.6, 0.9, 1.0]) maxColor = numpy.array([1.0, 0.2, 0.2]) colorrad = minColor + scaledrad * (maxColor - minColor) cp = biggles.ColoredPoints(x, y, colorrad, type='filled circle', size=6) # make plot p = biggles.FramedPlot() p.title = "Colored Points Plot" p.add(cp) return p def make_density_plot(): a = numpy.reshape(numpy.arange(90.0), (5, 6, 3)) a[..., 1] = 100 - a[..., 1] d = biggles.Density(1 - (a / numpy.max(a)), [[0, 0], [5, 10]]) # make plot p = biggles.FramedPlot() p.title = "Density" p.add(d) return p p1 = make_coloredpoints_plot() p2 = make_density_plot() t = biggles.Table(1, 2) t.aspect_ratio = 0.5 t[0, 0] = p1 t[0, 1] = p2 _write_example(9, t)
def test_example3(self): x = numpy.arange(0, 3 * numpy.pi, numpy.pi / 10) y = numpy.sin(x) p = biggles.FramedPlot() p.title = "Title" p.xlabel = "X axis" p.ylabel = "Y axis" p.add(biggles.Histogram(y)) p.add(biggles.PlotLabel(.5, .5, "Histogram", color=0xcc0000)) t1 = biggles.Table(1, 2) t1[0, 0] = p t1[0, 1] = p t2 = biggles.Table(2, 1) t2[0, 0] = t1 t2[1, 0] = p _write_example(3, p)
def create_hpage_spotted(self): V, H, S, M, N = self.target_shape v, h, m, n = self.pointer page = biggles.Table(N, M) for i in range(M): if self.col_labels: page[0, i].title = 'Cols %2i-%2i' % (c1, c2) for j in range(N): page[j, i] = biggles.FramedPlot() r, c = self.to_rowcol((v, h, i, j)) if self.rowcol_labels: page[j, i].title = 'Row %i Col %i' % (r, c) if self.title is not None: page.title = self.title return page
def test_xi_converge_nplk(epsfile=None): """ Test how xi converges with the number of k points per log10(k) Note we should test other convergence factors too! """ import biggles tab = biggles.Table(2, 1) pltbig = biggles.FramedPlot() pltzoom = biggles.FramedPlot() pltbig.xlabel = "r" pltbig.ylabel = "xi(r)" pltbig.xlog = True pltbig.ylog = True pltzoom.xlabel = "r" pltzoom.ylabel = "xi(r)" lin = Linear() r = 10.0**np.linspace(0.0, 2.3, 1000) nplk_vals = [20, 60, 100, 140, 160] color_vals = ["blue", "skyblue", "green", "orange", "magenta", "red"] plist = [] lw = 2.4 for nplk, color in zip(nplk_vals, color_vals): print("nplk:", nplk) xi = lin.xi(r, nplk=nplk) limxi = np.where(xi < 1.0e-5, 1.0e-5, xi) climxi = biggles.Curve(r, limxi, color=color, linewidth=lw) climxi.label = "nplk: %i" % nplk pltbig.add(climxi) plist.append(climxi) w, = np.where(r > 50.0) cxi = biggles.Curve(r[w], xi[w], color=color, linewidth=lw) pltzoom.add(cxi) key = biggles.PlotKey(0.7, 0.8, plist) pltzoom.add(key) tab[0, 0] = pltbig tab[1, 0] = pltzoom if epsfile is not None: tab.write_eps(epsfile) else: tab.show()
def plot_fits(pars, samples, comps, dolog=True, show=False, eps=None, par_labels=None): """ """ import esutil as eu import biggles import images biggles.configure('screen','width', 1400) biggles.configure('screen','height', 800) num=pars.shape[0] ndim=pars.shape[1] nrow,ncol = images.get_grid(ndim) tab=biggles.Table(nrow,ncol) for dim in xrange(ndim): plt = _plot_single(pars[:,dim], samples[:,dim], comps, do_ylog=True) if par_labels is not None: plt.xlabel=par_labels[dim] else: plt.xlabel=r'$P_%s$' % dim row=(dim)/ncol col=(dim) % ncol tab[row,col] = plt tab.aspect_ratio=nrow/float(ncol) if eps: import converter print(eps) d=os.path.dirname(eps) if not os.path.exists(d): os.makedirs(d) tab.write_eps(eps) converter.convert(eps, verbose=True, dpi=200) if show: tab.show()
def savePlot(self, fileName): currRow = 0 Table = biggles.Table(self.rows, 1) if self.bPlotRaster: for rasterPlot in self.r: Table[currRow, 0] = rasterPlot currRow += 1 if self.bPlotMean: Table[currRow, 0] = self.mean currRow += 1 if self.bPlotCOV: Table[currRow, 0] = self.cov currRow += 1 Table.aspect_ratio = 0.5 Table.write_img(1600, 800, fileName)
def _create_hpage_stacked(self): V, H, S, M, N = self.target_shape v, h, m, n = self.pointer page = biggles.Table(1, M) for i in range(M): page[0, i] = biggles.FramedArray(N, 1) if self.xlabel is not None: page[0, i].xlabel = self.xlabel if self.ylabel is not None: page[0, i].ylabel = self.ylabel r, c1, _, c2 = self.to_rowcol((v, h, i, 0)) + self.to_rowcol( (v, h, i, N - 1)) if self.rowcol_labels: page[0, i].title = 'Row %2i Cols %2i-%2i' % (r, c1, c2) if self.col_labels: page[0, i].title = 'Cols %2i-%2i' % (c1, c2) if self.row_labels: page[0, i].title = 'Rows %2i-%2i' % (c1, c2) # :P if self.title is not None: page.title = self.title return page
#!/usr/bin/env python import biggles import math import numpy x = numpy.arange(0, 3 * math.pi, math.pi / 10) y = numpy.sin(x) p = biggles.FramedPlot() p.title = "Title" p.xlabel = "X axis" p.ylabel = "Y axis" p.add(biggles.Histogram(y)) p.add(biggles.PlotLabel(.5, .5, "Histogram", color=0xcc0000)) t1 = biggles.Table(1, 2) t1[0, 0] = p t1[0, 1] = p t2 = biggles.Table(2, 1) t2[0, 0] = t1 t2[1, 0] = p t2.write("example3.png", dpi=55) t2.write("example3.eps") t2.write("example3.pdf") t2.show()
def plot_fits(self): means = self.means if means.size == 1: return else: import biggles biggles.configure('default', 'fontsize_min', 1.5) fits = self.fits args = self.args #Q=calc_q(fits) if args.yrange is not None: yrange = [float(r) for r in args.yrange.split(',')] else: yrange = [-0.01, 0.01] xrng = args.xrange if xrng is not None: xrng = [float(r) for r in args.xrange.split(',')] tab = biggles.Table(1, 2) tab.aspect_ratio = 0.5 diff = means['shear'] - means['shear_true'] plts = [] for i in [0, 1]: x = means['shear_true'][:, i] plt = biggles.plot( x, diff[:, i], xlabel=r'$\gamma_{%d}$ true' % (i + 1, ), ylabel=r'$\Delta \gamma_{%d}$' % (i + 1, ), yrange=yrange, xrange=xrng, visible=False, ) yfit = fits['m'][0, i] * x + fits['c'][0, i] z = biggles.Curve(x, x * 0, color='black') c = biggles.Curve(x, yfit, color='red') plt.add(z, c) ''' mstr='m%d: %.2g +/- %.2g' % (i+1,fits['m'][0,i],fits['merr'][0,i]) cstr='c%d: %.2g +/- %.2g' % (i+1,fits['c'][0,i],fits['cerr'][0,i]) mlab=biggles.PlotLabel(0.1,0.9, mstr, halign='left') clab=biggles.PlotLabel(0.1,0.85, cstr, halign='left') plt.add(mlab,clab) ''' if False and i == 0: Qstr = 'Q: %d' % (int(Q), ) Qlab = biggles.PlotLabel(0.1, 0.8, Qstr, halign='left') plt.add(Qlab) tab[0, i] = plt fname = self._get_fit_plot_file() eu.ostools.makedirs_fromfile(fname) print("writing:", fname) tab.write_eps(fname) if args.show: tab.show(width=1000, height=1000)
def compare_rgb_images(image, model, diffim, seg=None, weight=None, width=1000, chi2per=None, rng=None, title=None, show=False): """ make a comparison of the image with the model """ import biggles import images if chi2per is not None: diff_title = 'chi2/dof: %.2f' % chi2per else: diff_title = None imrow, imcol = 0, 0 modrow, modcol = 0, 1 nrows = 2 if seg is not None and weight is not None: ncols = 3 arat = image.shape[1] / image.shape[0] * 2 / 3 diffrow, diffcol = 0, 2 segrow, segcol = 1, 0 wtrow, wtcol = 1, 1 else: ncols = 2 arat = image.shape[1] / image.shape[0] diffrow, diffcol = 1, 0 if seg is not None: segrow, segcol = 1, 1 elif weight is not None: wtrow, wtcol = 1, 1 tab = biggles.Table(nrows, ncols, aspect_ratio=arat) tab[imrow, imcol] = images.view( image, # /maxval, show=False, title='image', ) tab[modrow, modcol] = images.view( model, # /maxval, show=False, title='model', ) tab[diffrow, diffcol] = images.view( diffim, show=False, title=diff_title, ) if seg is not None: tab[segrow, segcol] = plot_seg(seg, rng=rng, width=width, title='seg') if weight is not None: tab[wtrow, wtcol] = images.view(weight, show=False, title='weight') if title is not None: tab.title = title if show: fname = tempfile.mktemp(suffix='.png') tab.write_img(width, width * arat, fname) show_image(fname) return tab
def fillemup_mine(gwhich): x = [] y = [] yerr1 = [] yerr2 = [] for i, n in enumerate(names): if n == "CLEO-III '05": x.append(i) y.append(gwhich[n][0]) yerr1.append(gwhich[n][1]) yerr2.append(sqrt(gwhich[n][1]**2 + gwhich[n][2]**2)) return x, y, yerr1, yerr2 p = biggles.Table(1, 3) p[0, 0] = biggles.FramedPlot() p[0, 0].add(biggles.LineX(1.216, linetype="longdashed", linecolor="black")) p[0, 0].add(biggles.LineX(1.216 + 0.027, linetype="dotted", linecolor="black")) p[0, 0].add(biggles.LineX(1.216 - 0.027, linetype="dotted", linecolor="black")) p[0, 0].add(biggles.LineY(0.5)) p[0, 0].add( biggles.PlotLabel(0.1, 0.95, r"$\Upsilon(1S)$", texthalign="left", textvalign="top", fontsize=5.)) x, y, yerr1, yerr2 = fillemup(g1) p[0, 0].add(biggles.Points(y, x, symboltype="filled circle", symbolsize=1.5)) p[0, 0].add(biggles.SymmetricErrorBarsX(y, x, yerr1))
import biggles as bg # testing, testing... filters = [ ('hi-pass butter', highPassButterworth(fc=50., order=4)), ('lo-pass butter', lowPassButterworth(fc=50., order=4)), ('hi-pass sine', highPassSine(fc=50., df=50.)), ('lo-pass sine', lowPassSine(fc=50., df=50.)), ('gaussian band', gaussianBand(fc=100., df=20.)), ('box-car', boxcar(width=0.02)), ] n, f_samp = 1000, 400. # Paneling n_cols = 3 n_rows = (len(filters) + n_cols - 1) // n_cols # Spectra table = bg.Table(n_rows, n_cols) for i, (name, filt) in enumerate(filters): fexec = filt.getExecFor(n=n, f=f_samp) x, y = fexec.getFreqs(shift=True), fexec.getFourierForm(shift=True) fg = bg.FramedPlot() fg.add(bg.Curve(x, abs(y))) fg.title = name table[i % n_rows, i // n_rows] = fg table.show() # Green functions -- shorter time interval, same density n, dt = n, 1e-4 table = bg.Table(n_rows, n_cols) for i, (name, filt) in enumerate(filters): fexec = filt.getExecFor(n=n, dt=dt) x, y = fexec.getTimes(positive=False), fexec.getImpulseResponse( positive=False)
elif run_number < 122900: return 6 else: return 7 for i in range(len(had3)): print putitin(cont3[i]) - 1 rehad3[putitin(cont3[i]) - 1] += had3[i] rehad3err[putitin(cont3[i]) - 1] += had3err[i]**2 reenn3[putitin(cont3[i]) - 1] += 1 for i in range(len(rehad3err)): rehad3[i] = float(rehad3[i]) / float(reenn3[i]) rehad3err[i] = float(math.sqrt(rehad3err[i])) / float(reenn3[i]) print zip(recont3, rehad3, rehad3err) p4 = biggles.Table(2, 1) p4[0, 0] = biggles.FramedPlot() p4[0, 0].add( biggles.Points(cont3, had3, symboltype="filled circle", symbolsize=0.2)) p4[0, 0].add(biggles.SymmetricErrorBarsY(cont3, had3, had3err)) p4[0, 0].add(biggles.LineX(122000, linetype="longdashed")) p4[0, 0].add(biggles.LineX(122200, linetype="longdashed")) p4[0, 0].add(biggles.LineX(122350, linetype="longdashed")) p4[0, 0].add(biggles.LineX(122500, linetype="longdashed")) p4[0, 0].add(biggles.LineX(122700, linetype="longdashed")) p4[0, 0].add(biggles.LineX(122900, linetype="longdashed")) p4[0, 0].yrange = 5.5, 7 p4[0, 0].y1.label = r"below $\Upsilon(3S)$ hadronic $\sigma$, arb. units" p4[0, 0].xlabel = "Run number" p4[1, 0] = biggles.FramedPlot() p4[1, 0].add(
# from Numeric import * from Scientific.IO.NetCDF import * import biggles import sys fname = sys.argv[1] of = NetCDFFile(fname) ntb = of.dimensions['ntb'] nrows = 2 if of.variables.has_key('chcore'): nrows = nrows + 1 t = biggles.Table(nrows, 1) delta = of.variables['reduced_vlocal'].Reduced_vlocal_delta[0] r = arange(1, ntb + 1) * float(delta) p = biggles.FramedPlot() p.title = "Reduced Vlocal" p.add(biggles.Curve(r, of.variables['reduced_vlocal'][:])) t.set(0, 0, p) delta = of.variables['chlocal'].Chlocal_delta[0] r = arange(1, ntb + 1) * float(delta) p = biggles.FramedPlot() p.title = "Chlocal" p.add(biggles.Curve(r, of.variables['chlocal'][:])) t.set(1, 0, p)
t_cx = t_cx.compressAtoms( t_cx.ref.maskCA() ) t_ca = t_ca.compressAtoms( t_ca.ref.maskCA() ) ## get CA fluct profiles for Xplor and Amber Traj fx = t_cx.ref.profile('fluct_global') fa = t_ca.ref.profile('fluct_global') ## Plotting p = biggles.FramedPlot() p.add( biggles.Curve( range( len( fx ) ), fx, color='blue' ) ) p.yrange = (0,1.5) p.add( biggles.Curve( range( len( fa ) ), fa, color='black') ) p.add( biggles.Curve( range( len( fbahar)), fbahar, color='red') ) return p ########## MAIN ############## p11 = go( '~/interfaces/c11', '~/interfaces/a11' ) p02 = go( '~/interfaces/c02', '~/interfaces/a02' ) p17 = go( '~/interfaces/c17', '~/interfaces/a17' ) p = biggles.Table( 3, 1 ) p[0,0] = p02 p[1,0] = p11 p[2,0] = p17
if __name__ == '__main__': if len(sys.argv) < 2: _use() # options = test() options = cmdDict(_defOptions()) ## options and variables cgList = toList(options['cg']) plotList = [] dist = '' info = '' ## table t = biggles.Table(len(cgList) + 1, 1) t.cellspacing = 1.2 #default 2.0 biggles.configure('fontsize_min', 0.7) for cg in cgList: ## path and name cgFile = os.path.abspath(cg) cgName = nameFromPath(cgFile) print 'Working on ', cgName ## collect data group = load(cgFile) data, clst_range = clustInfo(group) ## create framedArray
for s in scandef: makelines2(start, end, s, p) p.x2.label = "Week of "+time.strftime("%a %d %B %Y", time.localtime(start)) p.y1.range = 0, 1 p.y1.draw_ticklabels = 0 p.x1.range = 0, 604800 p.x2.ticks = map(lambda x: x*604800./7. + 604800./7./2., range(7)) p.x2.ticklabels = ["Wed", "Thu", "Fri", "Sat", "Sun", "Mon", "Tue"] p.x1.ticks = map(lambda x: x*604800./7., range(8)) p.x1.ticklabels = map(firstafter, map(lambda x: x*604800./7. + start, range(8))) p.aspect_ratio = 0.15 return p p = biggles.Table(5,1) p[0,0] = lookat(2001, 44+3) p[1,0] = lookat(2001, 44+4) p[2,0] = lookat(2001, 44+5) p[3,0] = lookat(2001, 44+6) p[4,0] = lookat(2001, 44+7) p.aspect_ratio = 11./8.5 p.show() p.write_eps("/home/mccann/antithesis/clns/scan_periods1.eps") p = biggles.Table(5,1) p[0,0] = lookat(2002, 0) p[1,0] = lookat(2002, 1) p[2,0] = lookat(2002, 2) p[3,0] = lookat(2002, 4) p[4,0] = lookat(2002, 5)
def compare_images_mosaic(im1, im2, **keys): import biggles import copy import images show = keys.get('show', True) ymin = keys.get('min', None) ymax = keys.get('max', None) color1 = keys.get('color1', 'blue') color2 = keys.get('color2', 'orange') colordiff = keys.get('colordiff', 'red') nrow = 2 ncol = 3 label1 = keys.get('label1', 'im1') label2 = keys.get('label2', 'im2') cen = keys.get('cen', None) if cen is None: cen = [(im1.shape[0] - 1) / 2., (im1.shape[1] - 1) / 2.] labelres = '%s-%s' % (label1, label2) biggles.configure('default', 'fontsize_min', 1.) if im1.shape != im2.shape: raise ValueError("images must be the same shape") #resid = im2-im1 resid = im1 - im2 # will only be used if type is contour tab = biggles.Table(2, 1) if 'title' in keys: tab.title = keys['title'] tkeys = copy.deepcopy(keys) tkeys.pop('title', None) tkeys['show'] = False tkeys['file'] = None tkeys['nonlinear'] = None # this has no effect tkeys['min'] = resid.min() tkeys['max'] = resid.max() mosaic = np.zeros((im1.shape[0], 3 * im1.shape[1])) ncols = im1.shape[1] mosaic[:, 0:ncols] = im1 mosaic[:, ncols:2 * ncols] = im2 mosaic[:, 2 * ncols:3 * ncols] = resid residplt = images.view(mosaic, **tkeys) dof = im1.size chi2per = (resid**2).sum() / dof lab = biggles.PlotLabel(0.9, 0.9, r'$\chi^2/npix$: %.3e' % chi2per, color='red', halign='right') residplt.add(lab) cen0 = int(cen[0]) cen1 = int(cen[1]) im1rows = im1[:, cen1] im1cols = im1[cen0, :] im2rows = im2[:, cen1] im2cols = im2[cen0, :] resrows = resid[:, cen1] rescols = resid[cen0, :] him1rows = biggles.Histogram(im1rows, color=color1) him1cols = biggles.Histogram(im1cols, color=color1) him2rows = biggles.Histogram(im2rows, color=color2) him2cols = biggles.Histogram(im2cols, color=color2) hresrows = biggles.Histogram(resrows, color=colordiff) hrescols = biggles.Histogram(rescols, color=colordiff) him1rows.label = label1 him2rows.label = label2 hresrows.label = labelres key = biggles.PlotKey(0.1, 0.9, [him1rows, him2rows, hresrows]) rplt = biggles.FramedPlot() rplt.add(him1rows, him2rows, hresrows, key) rplt.xlabel = 'Center Rows' cplt = biggles.FramedPlot() cplt.add(him1cols, him2cols, hrescols) cplt.xlabel = 'Center Columns' rplt.aspect_ratio = 1 cplt.aspect_ratio = 1 ctab = biggles.Table(1, 2) ctab[0, 0] = rplt ctab[0, 1] = cplt tab[0, 0] = residplt tab[1, 0] = ctab images._writefile_maybe(tab, **keys) images._show_maybe(tab, **keys) return tab
tmp = biggles.Curve(x / 1000., y, linetype=linetype, linewidth=linewidth) p.add(tmp) return tmp def adddata_pull(p, data, shift, f): x = [] y = [] for (e, h, herr) in data: x.append((e * 2000. + shift) / 1000.) y.append((h - f(e * 2000. + shift)) / herr) p.add(biggles.Points(x, y, symboltype="filled circle", symbolsize=0.8)) return y p = biggles.Table(1, 3) pull = biggles.Table(1, 3) myarea, myrmsbeam, myback, myjan16, myjan30, myfeb06, myfeb13, myfeb20, myfeb27, mymar06, mymar13, myapr08, myapr09, myapr10, myfullgam, myyint, myphi, mybtautau, mytauyint, mytauphi, mytwophofrac, myrjan, myrfeb, myrapr2 = fitrecord[ 1].values thefunc = lambda w: u1func(myarea, myrmsbeam, myback, myfullgam, myyint, myphi, mybtautau, mytauyint, mytauphi, mytwophofrac, w) thefunc_bkgnd = lambda w: u1func_bkgndonly( myarea, myrmsbeam, myback, myfullgam, myyint, myphi, mybtautau, mytauyint, mytauphi, mytwophofrac, w) q = biggles.FramedPlot() adddata(q, [None], u1data["high"], 0.) addfunc(q, thefunc, u1data["high"][0][0] * 2000. - 5., u1data["high"][0][0] * 2000. + 5.) addfunc(q,
def compare_images(im1_in, im2_in, wt_in, **keys): import biggles import copy import images """ wt = wt_in.copy() maxwt = wt.max() noiseval = np.sqrt(1.0/maxwt) w = np.where(wt <= 0.0) if w[0].size > 0: wt[w] = maxwt noise = np.random.normal(size=wt.shape) noise *= np.sqrt(1.0/wt) """ if im1_in.shape != im2_in.shape: raise ValueError("images must be the same shape") color1 = keys.get('color1', 'blue') color2 = keys.get('color2', 'orange') colordiff = keys.get('colordiff', 'red') label1 = keys.get('label1', 'im1') label2 = keys.get('label2', 'im2') resid = (im1_in - im2_in) im1 = im1_in im2 = im2_in cen = [(im1.shape[0]-1)/2., (im1.shape[1]-1)/2.] labelres = '%s-%s' % (label1, label2) biggles.configure('default', 'fontsize_min', 1.) # will only be used if type is contour tab = biggles.Table(2, 3) if 'title' in keys: tab.title = keys['title'] tkeys = copy.deepcopy(keys) tkeys.pop('title', None) tkeys['show'] = False tkeys['file'] = None autoscale = True tab[0, 0] = images.view(im1, autoscale=autoscale, **tkeys) tab[0, 1] = images.view(im2, autoscale=autoscale, **tkeys) tab[0, 2] = residplt = images.view( resid*np.sqrt(wt_in.clip(min=0)), **tkeys ) wgood = np.where(wt_in > 0.0) dof = wgood[0].size chi2per = (resid**2 * wt_in).sum()/dof lab = biggles.PlotLabel(0.9, 0.9, r'$\chi^2/dof$: %.2f' % chi2per, color='red', halign='right') residplt.add(lab) cen0 = int(cen[0]) cen1 = int(cen[1]) im1rows = im1_in[:, cen1] im1cols = im1_in[cen0, :] im2rows = im2_in[:, cen1] im2cols = im2_in[cen0, :] resrows = resid[:, cen1] rescols = resid[cen0, :] him1rows = biggles.Histogram(im1rows, color=color1) him1cols = biggles.Histogram(im1cols, color=color1) him2rows = biggles.Histogram(im2rows, color=color2) him2cols = biggles.Histogram(im2cols, color=color2) hresrows = biggles.Histogram(resrows, color=colordiff) hrescols = biggles.Histogram(rescols, color=colordiff) him1rows.label = label1 him2rows.label = label2 hresrows.label = labelres key = biggles.PlotKey(0.1, 0.9, [him1rows, him2rows, hresrows]) rplt = biggles.FramedPlot() rplt.add(him1rows, him2rows, hresrows, key) rplt.xlabel = 'Center Rows' cplt = biggles.FramedPlot() cplt.add(him1cols, him2cols, hrescols) cplt.xlabel = 'Center Columns' rplt.aspect_ratio = 1 cplt.aspect_ratio = 1 tab[1, 0] = rplt tab[1, 1] = cplt images._writefile_maybe(tab, **keys) images._show_maybe(tab, **keys) return tab
def plot_m_c_vs(self, res, name, xlog=True, show=False, combine=False, xrng=None): """ result from fit_m_c_vs parameters ---------- res: dict result from running fit_m_c_vs name: string Name for the variable binned against, e.g. s/n or whatever This is used for the x axis xlog: bool, optional If True, use a log x axis show: bool, optional If True, show the plot on the screen returns ------- biggles plot object """ import biggles biggles.configure('default', 'fontsize_min', 2.0) tab = biggles.Table(2, 1) xvals = res['mean'] if xrng is None: if xlog: xrng = [0.5 * xvals.min(), 1.5 * xvals.max()] else: xrng = [0.9 * xvals.min(), 1.1 * xvals.max()] mplt = biggles.FramedPlot() mplt.xlabel = name mplt.ylabel = 'm' mplt.xrange = xrng mplt.yrange = [-0.01, 0.01] mplt.xlog = xlog cplt = biggles.FramedPlot() cplt.xlabel = name cplt.ylabel = 'c' cplt.xrange = xrng cplt.yrange = [-0.0015, 0.0015] cplt.xlog = xlog if combine: m = 0.5 * (res['m1'] + res['m2']) c = 0.5 * (res['c1'] + res['c2']) merr = array([ min(m1err, m2err) for m1err, m2err in zip(res['m1err'], res['m2err']) ]) cerr = array([ min(c1err, c2err) for c1err, c2err in zip(res['c1err'], res['c2err']) ]) merr /= sqrt(2) cerr /= sqrt(2) mc = biggles.Points(xvals, m, type='filled circle', color='blue') merrc = biggles.SymmetricErrorBarsY(xvals, m, merr, color='blue') cc = biggles.Points(xvals, c, type='filled circle', color='blue') cerrc = biggles.SymmetricErrorBarsY(xvals, c, cerr, color='blue') zc = biggles.Curve(xrng, [0, 0]) mplt.add(zc, mc, merrc) cplt.add(zc, cc, cerrc) else: m1c = biggles.Points(xvals, res['m1'], type='filled circle', color='blue') m1c.label = 'm1' m1errc = biggles.SymmetricErrorBarsY(xvals, res['m1'], res['m1err'], color='blue') m2c = biggles.Points(xvals, res['m2'], type='filled circle', color='red') m2c.label = 'm2' m2errc = biggles.SymmetricErrorBarsY(xvals, res['m2'], res['m2err'], color='red') mkey = biggles.PlotKey(0.9, 0.9, [m1c, m2c], halign='right') c1c = biggles.Points(xvals, res['c1'], type='filled circle', color='blue') c1c.label = 'c1' c1errc = biggles.SymmetricErrorBarsY(xvals, res['c1'], res['c1err'], color='blue') c2c = biggles.Points(xvals, res['c2'], type='filled circle', color='red') c2c.label = 'c2' c2errc = biggles.SymmetricErrorBarsY(xvals, res['c2'], res['c2err'], color='red') ckey = biggles.PlotKey(0.9, 0.9, [c1c, c2c], halign='right') zc = biggles.Curve(xvals, xvals * 0) mplt.add(zc, m1c, m1errc, m2c, m2errc, mkey) cplt.add(zc, c1c, c1errc, c2c, c2errc, ckey) tab[0, 0] = mplt tab[1, 0] = cplt if show: tab.show() return tab
def view_mbobs_list(mbobs_list, **kw): import biggles import images import plotting weight = kw.get('weight', False) nband = len(mbobs_list[0]) if weight: grid = plotting.Grid(len(mbobs_list)) plt = biggles.Table( grid.nrow, grid.ncol, ) aratio = grid.nrow / (grid.ncol * 2) plt.aspect_ratio = aratio for i, mbobs in enumerate(mbobs_list): if nband == 3: im = make_rgb(mbobs) else: im = mbobs[0][0].image wt = mbobs[0][0].weight row, col = grid(i) tplt = images.view_mosaic([im, wt], show=False) plt[row, col] = tplt plt.show(width=2000, height=2000 * aratio) else: if nband == 6: grid = plotting.Grid(len(mbobs_list)) plt = biggles.Table( grid.nrow, grid.ncol, ) #if grid.nrow==1: # plt.aspect_ratio = grid.nrow/grid.ncol #else: #plt.aspect_ratio = grid.nrow/(grid.ncol*2) plt.aspect_ratio = grid.nrow / grid.ncol for i, mbobs in enumerate(mbobs_list): des_im = make_rgb(mbobs[1:1 + 3]) des_wt = mbobs[2][0].weight cosmos_im = mbobs[4][0].image cosmos_wt = mbobs[4][0].weight tplt = images.view_mosaic( [cosmos_im, des_im, cosmos_wt, des_wt], titles=['cosmos', 'DES', 'cosmos wt', 'DES wt'], show=False, ) row, col = grid(i) plt[row, col] = tplt else: imlist = [mbobs[0][0].image for mbobs in mbobs_list] plt = images.view_mosaic(imlist, **kw) return plt
def compare(self, run): import biggles import pcolors pdata, mdata = self.load_data(run) if len(pdata) == 0: print("no princeton data found") return if len(mdata) == 0: print("no my data found") return tab = biggles.Table(2, 2) pcos_plt = biggles.FramedPlot() psin_plt = biggles.FramedPlot() mcos_plt = biggles.FramedPlot() msin_plt = biggles.FramedPlot() pcos_plots = [] psin_plots = [] mcos_plots = [] msin_plots = [] colors = pcolors.rainbow(6, 'hex') for camcol in xrange(1, 6 + 1): # first princeton wp = where1(pdata['camcol'] == camcol) bcos = eu.stat.Binner(pdata['field'][wp], cos(2 * pdata['phi_offset'][wp])) bcos.dohist(binsize=1.0) bcos.calc_stats() wgood_cos = where1(bcos['hist'] > 0) pcos = biggles.Curve(bcos['xmean'][wgood_cos], bcos['ymean'][wgood_cos], color=colors[camcol - 1]) pcos.label = 'princ camcol %s' % camcol pcos_plt.add(pcos) pcos_plots.append(pcos) bsin = eu.stat.Binner(pdata['field'][wp], sin(2 * pdata['phi_offset'][wp])) bsin.dohist(binsize=1.0) bsin.calc_stats() wgood_sin = where1(bsin['hist'] > 0) psin = biggles.Curve(bsin['xmean'][wgood_sin], bsin['ymean'][wgood_sin], color=colors[camcol - 1]) psin.label = 'princ camcol %s' % camcol psin_plt.add(psin) psin_plots.append(psin) # now mine wm = where1(mdata['camcol'] == camcol) mpcos = biggles.Curve(mdata['field'][wm], cos(2 * mdata['angle'][wm, 2]), color=colors[camcol - 1]) mpcos.label = 'mine camcol %s' % camcol mcos_plt.add(mpcos) mcos_plots.append(mpcos) wm = where1(mdata['camcol'] == camcol) mpsin = biggles.Curve(mdata['field'][wm], sin(2 * mdata['angle'][wm, 2]), color=colors[camcol - 1]) mpsin.label = 'mine camcol %s' % camcol msin_plt.add(mpsin) msin_plots.append(mpsin) # princeton stuff pcos_key = biggles.PlotKey(0.1, 0.9, pcos_plots) pcos_plt.add(pcos_key) pcos_plt.xlabel = 'Field' pcos_plt.title = 'Run: %s' % run pcos_plt.ylabel = 'cos(2*angle)' psin_key = biggles.PlotKey(0.1, 0.9, psin_plots) psin_plt.add(psin_key) psin_plt.xlabel = 'Field' psin_plt.title = 'Run: %s' % run psin_plt.ylabel = 'sin(2*angle)' tab[0, 0] = pcos_plt tab[0, 1] = psin_plt # my stuff mcos_key = biggles.PlotKey(0.1, 0.9, mcos_plots) mcos_plt.add(mcos_key) mcos_plt.xlabel = 'Field' mcos_plt.title = 'Run: %s' % run mcos_plt.ylabel = 'cos(2*angle)' msin_key = biggles.PlotKey(0.1, 0.9, msin_plots) msin_plt.add(msin_key) msin_plt.xlabel = 'Field' msin_plt.title = 'Run: %s' % run msin_plt.ylabel = 'sin(2*angle)' tab[1, 0] = mcos_plt tab[1, 1] = msin_plt tab.show()