Exemplo n.º 1
0
def test_compare_to_Nonsense():
    ax0 = Axis(20, -10, 10, "My first axis")
    nt.assert_true(ax0 is not None)
    nt.assert_true(not ax0 is None)
    nt.assert_true(ax0 != 1)
    nt.assert_true(ax0 != 5.0)
    nt.assert_true(ax0 != [])
Exemplo n.º 2
0
def test_axis_parameters():
    ax = Axis(100, -50, 50, "My first axis")
    nt.assert_true(ax.nbins == 100)
    nt.assert_true(ax.min == -50.)
    nt.assert_true(ax.max == 50.)
    nt.assert_true(ax.label == "My first axis")
    nt.assert_true(ax.range == (-50, 50))
Exemplo n.º 3
0
def ntuple_column_histo(ntuple, tag, cut=None, bins=100):
    '''
    Create and return a histogram.Histogram object constructed from the 
    contents of an ntuple.NTuple column.
    '''
    from pyhistuples.pyhistogram.histogram import Histogram, Axis
    col = ntuple.column(tag, cut)
    min_range = min(col)
    max_range = max(col)
    width = (max_range - min_range) / bins
    max_range += width / 2.
    max_range -= width / 2.
    histo = Histogram(axis=Axis(bins, min_range, max_range, label=tag))
    for x in col:
        histo.fill(x)
    return histo
Exemplo n.º 4
0
def test_invalid_range_gets_special_bins() :
    ax = Axis(20, -10, 10, "My first axis")
    nt.assert_true(ax.binIndex(11) == ax.overflow_bin)
    nt.assert_true(ax.binIndex(-11) == ax.underflow_bin)
Exemplo n.º 5
0
def test_invalid_bin_center_raises_IndexError() :
    ax = Axis(20, -10, 10, "My first axis")
    ax.binCentre(max(ax.underflow_bin, ax.overflow_bin)+1)
Exemplo n.º 6
0
def test_axis_bin_centre() :
    ax = Axis(20, -10, 10, "My first axis")
    reference = [x+0.5 for x in xrange(-10,10)]
    for i in xrange(10) :
        nt.assert_true(ax.binCentre(i) == reference[i])
Exemplo n.º 7
0
def test_axis_bin_width() :
    ax = Axis(100, -50, 50, "My first axis")
    nt.assert_true(ax.binWidth() == 1.)
Exemplo n.º 8
0
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()
Exemplo n.º 9
0
def test_axis_inequality():
    ax0 = Axis(20, -10, 10, "My first axis")
    ax1 = Axis(30, -10, 10, "My first axis")
    nt.assert_true(ax0 != ax1)
Exemplo n.º 10
0
def test_invalid_range_gets_special_bins():
    ax = Axis(20, -10, 10, "My first axis")
    nt.assert_true(ax.binIndex(11) == ax.overflow_bin)
    nt.assert_true(ax.binIndex(-11) == ax.underflow_bin)
Exemplo n.º 11
0
def test_invalid_bin_center_raises_IndexError():
    ax = Axis(20, -10, 10, "My first axis")
    ax.binCentre(max(ax.underflow_bin, ax.overflow_bin) + 1)
Exemplo n.º 12
0
def test_axis_bin_centre():
    ax = Axis(20, -10, 10, "My first axis")
    reference = [x + 0.5 for x in xrange(-10, 10)]
    for i in xrange(10):
        nt.assert_true(ax.binCentre(i) == reference[i])
Exemplo n.º 13
0
def test_axis_bin_width():
    ax = Axis(100, -50, 50, "My first axis")
    nt.assert_true(ax.binWidth() == 1.)
Exemplo n.º 14
0
def test_instantiate_axis():
    ax = Axis(100, -50, 50, "My first axis")
    nt.assert_true(ax is not None)