def test_root_2d(self):
        ftmp = NamedTemporaryFile(suffix='.root', delete=False)
        try:
            ftmp.close()
            h = Histogram(3, [0, 3], 4, [0, 4])
            h.data[:] = [[-3, 0, 5, 3], [-2, 0, 4, 2], [-1, 0, 3, 1024]]
            h.uncert = np.sqrt(np.abs(
                h.data))  # ROOT will always return uncert
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.axes[0].label = 'x (cm)'
            h.axes[1].label = 'y (cm)'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.label = 'counts'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.title = 'title'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

        finally:
            os.remove(ftmp.name)
    def test_npz_2d(self):
        ftmp = NamedTemporaryFile(suffix='.npz', delete=False)
        try:
            ftmp.close()
            h = Histogram(3, [0, 3], 4, [0, 4])
            h.data[:] = [[-3, 0, 5, 3], [-2, 0, 4, 2], [-1, 0, 3, 1024]]
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.axes[0].label = 'x (cm)'
            h.axes[1].label = 'y (cm)'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.label = 'counts'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.title = 'title'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

        finally:
            os.remove(ftmp.name)
Beispiel #3
0
    def test_hist_1d(self):
        ftmp = NamedTemporaryFile(suffix='.h5', delete=False)
        try:
            ftmp.close()
            h = Histogram(3, [0, 3])
            h.data[:] = [-3, 0, 5]
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.axes[0].label = 'x (cm)'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            #print(type(h.axes[0].label), h.axes[0].label)
            #print(type(htmp.axes[0].label), htmp.axes[0].label)
            self.assertTrue(h.isidentical(htmp))

            h.label = 'counts'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.title = 'title'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.uncert = [2, 3, 4]
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

        finally:
            os.remove(ftmp.name)
    def test___init__(self):
        assert_raises(TypeError,Histogram)

        h1a = Histogram(100,[0,10])
        h1b = Histogram(100,[0,10],'x')
        h1c = Histogram(100,[0,10],'x','label')
        h1d = Histogram(100,[0,10],'x','label','title')

        h2a = Histogram(np.linspace(0,10,101))
        h2b = Histogram(np.linspace(0,10,101),'x')
        h2c = Histogram(np.linspace(0,10,101),'x','label')
        h2d = Histogram(np.linspace(0,10,101),'x','label','title')

        h3a = Histogram((np.linspace(0,10,101),))
        h3b = Histogram((np.linspace(0,10,101),'x'))
        h3c = Histogram((np.linspace(0,10,101),'x'),'label')
        h3d = Histogram((np.linspace(0,10,101),'x'),'label','title')

        assert_true(h1a.isidentical(h2a))
        assert_true(h1b.isidentical(h2b))
        assert_true(h1c.isidentical(h2c))
        assert_true(h1d.isidentical(h2d))

        assert_true(h1a.isidentical(h3a))
        assert_true(h1b.isidentical(h3b))
        assert_true(h1c.isidentical(h3c))
        assert_true(h1d.isidentical(h3d))
    def test_unicode(self):
        ftmp = NamedTemporaryFile(suffix='.npz', delete=False)
        try:
            h = Histogram(3, [0, 3])
            h.data[:] = [-3, 0, 5]
            h.title = 'χ-squared'
            h.label = 'αβγ'
            h.axes[0].label = 'θ'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

        finally:
            os.remove(ftmp.name)
    def test_unicode(self):
        ftmp = NamedTemporaryFile(suffix='.root', delete=False)
        try:
            ftmp.close()
            h = Histogram(3, [0, 3])
            h.data[:] = [-3, 0, 5]
            h.uncert = np.sqrt(np.abs(
                h.data))  # ROOT will always return uncert
            h.title = 'χ-squared'
            h.label = 'αβγ'
            h.axes[0].label = 'θ'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

        finally:
            os.remove(ftmp.name)