Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    def setUp(self):
        rc.overwrite.overwrite = 'always'
        np.random.seed(1)
        h = Histogram(100,[0,10],'Δx', 'y', 'title')
        h.fill(np.random.normal(5,2,10000))
        h.uncert = np.sqrt(h.data)

        if sys.version_info < (3,0):
            def _to_unicode(s):
                if not isinstance(s,unicode):
                    return unicode(s,'utf-8')
                else:
                    return s
            h.title = _to_unicode(h.title)
            h.label = _to_unicode(h.label)
            for ax in h.axes:
                ax.label = _to_unicode(ax.label)

        self.h = h