예제 #1
0
    def testBranch(self):
        one = Histogram(5, -3.0, 7.0, lambda x: x)
        two = Count()
        three = Deviate(lambda x: x + 100.0)

        branching = Branch(one, two, three)

        for _ in self.simple:
            branching.fill(_)

        self.assertEqual(branching.i0.numericalValues,
                         [3.0, 2.0, 2.0, 1.0, 0.0])
        self.assertEqual(branching.i0.numericalUnderflow, 1.0)
        self.assertEqual(branching.i0.numericalOverflow, 1.0)
        self.assertEqual(branching.i0.numericalNanflow, 0.0)

        self.assertEqual(branching.i1.entries, 10.0)

        self.assertAlmostEqual(branching.i2.entries, 10.0)
        self.assertAlmostEqual(branching.i2.mean, 100.33)
        self.assertAlmostEqual(branching.i2.variance, 10.8381)

        self.checkScaling(branching)
        self.checkScaling(branching.toImmutable())
        self.checkJson(branching)
        self.checkPickle(branching)
        self.checkName(branching)
예제 #2
0
    def testPlotStack(self):
        one = Histogram(5, -3.0, 7.0, lambda x: x)
        two = Histogram(5, -3.0, 7.0, lambda x: x)

        labeling = Label(one=one, two=two)
        map(lambda _: labeling.fill(_), self.simple)

        try:
            if sys.version_info[0] == 2 and sys.version_info[1] == 6:
                raise ImportError  # Bokeh is not compatible with Python 2.6
            from histogrammar.plot.bokeh import plot, save
            s = Stack.build(one, two)
            glyph = s.plot.bokeh()
            c = plot(glyph)
            save(c, "plot_stack.html")
            # self.checkHtml("example.html")
        except ImportError:
            pass
예제 #3
0
    def testIndex(self):
        one = Histogram(5, -3.0, 7.0, lambda x: x)
        two = Histogram(10, 0.0, 10.0, lambda x: x)
        three = Histogram(5, -3.0, 7.0, lambda x: 2 * x)

        indexing = Index(one, two, three)

        for _ in self.simple:
            indexing.fill(_)

        self.assertEqual(
            indexing(0).numericalValues, [3.0, 2.0, 2.0, 1.0, 0.0])
        self.assertEqual(
            indexing(1).numericalValues,
            [2.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0])
        self.assertEqual(
            indexing(2).numericalValues, [0.0, 2.0, 0.0, 2.0, 1.0])

        self.checkScaling(indexing)
        self.checkScaling(indexing.toImmutable())
        self.checkJson(indexing)
        self.checkPickle(indexing)
        self.checkName(indexing)
예제 #4
0
    def testUntypedLabel(self):
        one = Histogram(5, -3.0, 7.0, lambda x: x)
        two = Histogram(10, 0.0, 10.0, lambda x: x)
        three = Histogram(5, -3.0, 7.0, lambda x: 2 * x)

        labeling = UntypedLabel(one=one, two=two, three=three)

        for _ in self.simple:
            labeling.fill(_)

        self.assertEqual(
            labeling("one").numericalValues, [3.0, 2.0, 2.0, 1.0, 0.0])
        self.assertEqual(
            labeling("two").numericalValues,
            [2.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0])
        self.assertEqual(
            labeling("three").numericalValues, [0.0, 2.0, 0.0, 2.0, 1.0])

        self.checkScaling(labeling)
        self.checkScaling(labeling.toImmutable())
        self.checkJson(labeling)
        self.checkPickle(labeling)
        self.checkName(labeling)
예제 #5
0
    def testFractionHistogram(self):
        fracking = Fraction(lambda x: x > 0.0,
                            Histogram(5, -3.0, 7.0, lambda x: x))
        for _ in self.simple:
            fracking.fill(_)

        self.assertEqual(fracking.numerator.numericalValues,
                         [0.0, 0.0, 2.0, 1.0, 0.0])
        self.assertEqual(fracking.denominator.numericalValues,
                         [3.0, 2.0, 2.0, 1.0, 0.0])

        self.checkScaling(fracking)
        self.checkScaling(fracking.toImmutable())
        self.checkJson(fracking)
        self.checkPickle(fracking)
        self.checkName(fracking)
예제 #6
0
    def testUntypedLabelMultipleTypes(self):
        one = Histogram(5, -3.0, 7.0, lambda x: x)
        two = Sum(lambda x: 1.0)
        three = Deviate(named("something", lambda x: x + 100.0))

        mapping = UntypedLabel(one=one, two=two, three=three)

        for _ in self.simple:
            mapping.fill(_)

        self.assertEqual(
            mapping("one").numericalValues, [3.0, 2.0, 2.0, 1.0, 0.0])
        self.assertEqual(mapping("two").sum, 10.0)
        self.assertAlmostEqual(mapping("three").entries, 10.0)
        self.assertAlmostEqual(mapping("three").mean, 100.33)
        self.assertAlmostEqual(mapping("three").variance, 10.8381)

        self.checkScaling(mapping)
        self.checkScaling(mapping.toImmutable())
        self.checkJson(mapping)
        self.checkPickle(mapping)
        self.checkName(mapping)