Esempio n. 1
0
    def testSlicing(self):
        "Axis[3:5]"
        from histogram import createContinuousAxis, arange
        axis = createContinuousAxis(
            "distance", "meter", arange( 1.0, 2.0, 0.1 ) )
        
        from histogram.SlicingInfo import SlicingInfo
        
        new = axis[ SlicingInfo( (1.1, 1.5) ) ]
        self.assertVectorAlmostEqual(
            new.storage().asList(),
            [1.05, 1.15, 1.25, 1.35, 1.45, 1.55] )

        new = axis[ SlicingInfo( (1.0, 1.9) ) ]
        self.assertVectorAlmostEqual(
            new.storage().asList(),
            axis.storage().asList() )

        
        self.assertRaises( IndexError,  axis.__getitem__, SlicingInfo( (1.0, 2.0) )  )

        # dimensional sliciing
        from histogram._units import length
        meter = length.meter
        new = axis[ SlicingInfo( (1.0*meter, 1.9*meter) ) ]
        self.assertVectorAlmostEqual(
            new.storage().asList(),
            axis.storage().asList() )
        return
Esempio n. 2
0
    def testSlicing(self):
        "Axis[3:5]"
        from histogram import createContinuousAxis, arange
        axis = createContinuousAxis("distance", "meter", arange(1.0, 2.0, 0.1))

        from histogram.SlicingInfo import SlicingInfo

        new = axis[SlicingInfo((1.1, 1.5))]
        self.assertVectorAlmostEqual(new.storage().asList(),
                                     [1.05, 1.15, 1.25, 1.35, 1.45, 1.55])

        new = axis[SlicingInfo((1.0, 1.9))]
        self.assertVectorAlmostEqual(new.storage().asList(),
                                     axis.storage().asList())

        self.assertRaises(IndexError, axis.__getitem__, SlicingInfo(
            (1.0, 2.0)))

        # dimensional sliciing
        from histogram._units import length
        meter = length.meter
        new = axis[SlicingInfo((1.0 * meter, 1.9 * meter))]
        self.assertVectorAlmostEqual(new.storage().asList(),
                                     axis.storage().asList())
        return
    def test_load(self):
        "Histogram: pickle.load"
        import pickle
        h = self._histogram
        pickle.dump( h, open( "tmp.pkl", 'w' ) )
        h1 = pickle.load( open("tmp.pkl") )
        self.assertEqual( h.name(), h1.name() )
        print ("data=%s" % h1.data().storage().asNumarray() ) 
        self.assert_( h.data().storage().compare( h1.data().storage() ) )
        print ("errors=%s" % h1.errors().storage().asNumarray() ) 
        self.assert_( h.errors().storage().compare( h1.errors().storage() ) )

        for axisName in h.axisNameList():
            print ("axis %s" % axisName)
            axis = h.axisFromName( axisName )
            axis1 = h1.axisFromName( axisName )
            self.assert_( axis.storage().compare( axis1.storage() ) )
            continue

        from histogram import histogram
        h2 = histogram(
            'h2',
            [ ('x', [1,2,3]),
              ],
            unit = 'meter' )
        pickle.dump( h2, open( "tmp.pkl", 'w' ) )
        h2a = pickle.load( open("tmp.pkl") )
        
        return
Esempio n. 4
0
    def test_load(self):
        "Histogram: pickle.load"
        import pickle
        h = self._histogram
        pickle.dump( h, open( "tmp.pkl", 'wb' ) )
        h1 = pickle.load( open("tmp.pkl", 'rb') )
        self.assertEqual( h.name(), h1.name() )
        print(("data=%s" % h1.data().storage().asNumarray() )) 
        self.assertTrue( h.data().storage().compare( h1.data().storage() ) )
        print(("errors=%s" % h1.errors().storage().asNumarray() )) 
        self.assertTrue( h.errors().storage().compare( h1.errors().storage() ) )

        for axisName in h.axisNameList():
            print(("axis %s" % axisName))
            axis = h.axisFromName( axisName )
            axis1 = h1.axisFromName( axisName )
            self.assertTrue( axis.storage().compare( axis1.storage() ) )
            continue

        from histogram import histogram
        h2 = histogram(
            'h2',
            [ ('x', [1,2,3]),
              ],
            unit = 'meter' )
        pickle.dump( h2, open( "tmp.pkl", 'wb' ) )
        h2a = pickle.load( open("tmp.pkl", 'rb') )
        
        return