예제 #1
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)
예제 #2
0
 def test_hist_4d(self):
     ftmp = NamedTemporaryFile(suffix='.root', delete=False)
     try:
         h = Histogram(3, [0, 1], 3, [0, 1], 3, [0, 1], 3, [0, 1])
         with self.assertRaises(ValueError):
             h.save(ftmp.name)
     finally:
         os.remove(ftmp.name)
예제 #3
0
 def test_hist_3d(self):
     h = Histogram(3, [0, 1], 'xx', 4, [-1, 1], 'yy', 5, [5, 10], 'zz',
                   'counts', 'data')
     ftmp = NamedTemporaryFile(suffix='.root', delete=False)
     try:
         ftmp.close()
         with warnings.catch_warnings(record=True) as w:
             h.save(ftmp.name)
         self.assertEqual(len(w), 1)
         self.assertRegex(str(w[-1].message), 'label')
     finally:
         os.remove(ftmp.name)
예제 #4
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)
예제 #5
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)
예제 #6
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)
예제 #7
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)