def test_get_column() : nt = NTuple('A', 'B') for x in range(100) : nt.fill('A', x) nt.fill('B', x*100) nt.write() A = nt.column('A') ntl.assert_true(A == range(100)) B = nt.column('B') ntl.assert_true(B == [ x*100 for x in range(100)])
def test_get_with_cross_cut() : nt = NTuple('A', 'B') for x in range(100) : nt.fill('A', x) nt.fill('B', x*100) nt.write() col = nt.column('B',lambda x : x.A > 50 and x.B < 8500 ) ntl.assert_true(col == [x*100 for x in xrange(51, 85)])
def test_get_with_cut() : nt = NTuple('A', 'B') for x in range(100) : nt.fill('A', x) nt.fill('B', x*100) nt.write() col = nt.column('A',lambda x : x.A > 50 ) ntl.assert_true(col == range(51, 100))
def reference_ntuple(): nt = NTuple('x', 'sin', 'cos') for x in xrange(-50, 51): nt.fill('x', x) nt.fill('sin', math.sin(x)) nt.fill('cos', math.cos(x)) nt.write() return nt
def test_access_row() : nt = NTuple('A','B') nt.fill('A', 5) rw = nt.row(0) ntl.assert_true(rw.A == 5) nt.fill('B',6) ntl.assert_true(rw.A==5 and rw.B == 6)
def reference_ntuple() : nt = NTuple('x', 'sin', 'cos') for x in xrange(-50,51) : nt.fill('x',x) nt.fill('sin', math.sin(x)) nt.fill('cos', math.cos(x)) nt.write() return nt
''' Test suite for histogram.axis class. ''' __author__ = "Juan PALACIOS [email protected]" from random import gauss from pyhistuples.pyntuple.ntuple import NTuple from pyhistuples.pyhistoplots import ntuple_plot, histo_plot, ntuple_column_histo mu_p = 15. mu_pt = 5. sigma_p = 10. sigma_pt = 5. nt = NTuple('x', 'p', 'pt') for x in xrange(10000): nt.fill('x', x) nt.fill('p', gauss(mu_p, sigma_p)) nt.fill('pt', gauss(mu_pt, sigma_pt)) nt.write() def test_ntuple_plot(): pt_plot = ntuple_plot(nt, 'pt', show=False) p_plot = ntuple_plot(nt, 'p', errorfunction=lambda x: x.height / 2., color='red', linewidth='1.5',
import math from random import gauss from pyhistuples.pyntuple.ntuple import NTuple from matplotlib import pyplot from pyhistuples.pyhistoplots import ntuple_plot, histo_plot, ntuple_column_histo from pyhistuples.pyhistogram.histogram import Histogram, Axis mu_p = 15. mu_pt = 5. sigma_p = 10. sigma_pt = 5. nt = NTuple('x', 'p', 'pt') h_pt = Histogram(axis=Axis(100, -50, 50, label='pt')) for x in xrange(10000): val = gauss(mu_pt, sigma_pt) h_pt.fill(val) # greem plot without errors plot_pt = histo_plot(h_pt, color='green', errorfunction=None) # blue plot with default errors (poissonSigma) plot_pt_errors = histo_plot(h_pt, color='blue') print 'plot_pt range', plot_pt.axes[0].xaxis.get_view_interval() print 'plot_pt_errors range', plot_pt_errors.axes[0].xaxis.get_view_interval()
import math from random import gauss from pyhistuples.pyntuple.ntuple import NTuple from matplotlib import pyplot mu_p = 15. mu_pt = 5. sigma_p = 10. sigma_pt = 5. nt = NTuple('x', 'p', 'pt') for x in xrange(10000) : nt.fill('x',x) nt.fill('p', gauss(mu_p, sigma_p)) nt.fill('pt', gauss(mu_pt, sigma_pt)) nt.write() x = nt.column('x', lambda row : row.p > 5. and row.pt > 1.)
def test_access_latest_row() : nt = NTuple('A', 'B') nt.fill('A', 5) rw = nt.row(0) ntl.assert_true(rw.A == 5) nt.fill('A', 7) rw = nt.row(0) ntl.assert_true(rw.A == 7) nt.write() nt.fill('A', 22) rw = nt.row(1) ntl.assert_true(rw.A == 22)
def test_fill_column_twice() : nt = NTuple('A', 'B') nt.fill('A', 5) nt.fill('A', 7)
def test_illegal_tag_fails() : nt = NTuple('A','B') nt.fill('C', 5)
def test_fill_column() : nt = NTuple('A', 'B') nt.fill('A', 5)
def test_instantiate() : nt = NTuple('A', 'B') ntl.assert_true(nt is not None)
def test_illegal_add_raises_KeyError() : nt0 = NTuple('A', 'B') nt1 = NTuple('C', 'D') _ = nt0 + nt1
import math from random import gauss from pyhistuples.pyntuple.ntuple import NTuple from matplotlib import pyplot from pyhistuples.pyhistoplots import ntuple_plot, histo_plot, ntuple_column_histo mu_p = 15. mu_pt = 5. sigma_p = 10. sigma_pt = 5. nt = NTuple('x', 'p', 'pt') for x in xrange(10000) : nt.fill('x',x) nt.fill('p', gauss(mu_p, sigma_p)) nt.fill('pt', gauss(mu_pt, sigma_pt)) nt.write() pt_plot = ntuple_plot(nt, 'pt') h_pt = ntuple_column_histo(nt, 'pt') histo_plot(h_pt, color='blue')