def _plot_single(data, samples, comps, do_ylog=False): import biggles import esutil as eu import pcolors valmin=data.min() valmax=data.max() std = data.std() binsize=0.05*std ph,be,harr = biggles.make_histc(data, min=valmin, max=valmax, binsize=binsize, ylog=do_ylog, norm=1, get_hdata=True) sample_ph,sbe,sharr= biggles.make_histc(samples, min=valmin, max=valmax, binsize=binsize, color='red', ylog=do_ylog, norm=1, get_hdata=True) ph.label='data' sample_ph.label='fit' key = biggles.PlotKey(0.1, 0.9, [ph, sample_ph], halign='left') plt = biggles.FramedPlot() plt.add( ph, sample_ph, key ) w,=where( (harr > 0) & (sharr > 0) ) yrange=[min(harr[w].min(), sharr[w].min()), 1.1*max(harr[w].max(), sharr[w].max())] if do_ylog: plt.ylog=True # now add the components h,rev=eu.stat.histogram(comps, rev=True) print(h) w,=where(h > 0) ncolors = w.size colors=pcolors.rainbow(ncolors) icolor=0 for i in xrange(h.size): if rev[i] != rev[i+1]: w=rev[ rev[i]:rev[i+1] ] frac=float(w.size)/comps.size ph = biggles.make_histc(samples[w], #min=valmin, max=valmax, binsize=binsize, color=colors[icolor], ylog=do_ylog, norm=frac) plt.add(ph) icolor += 1 plt.yrange=yrange 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()