コード例 #1
0
def test_3(**kwds):

    from histogram.Axis import Axis

    name = 'test'
    unit = '1'
    attributes = {
        'plottable': True,
        'nifty': False,
        'pi': 3.14159,
        3.14159: 'pi'
    }
    length = 23
    dtype = 6  # double

    binBounds = [i + 1.0 for i in range(length + 1)]
    storage = ndArray(dtype, binBounds)

    axis = Axis(name, unit, attributes, length, storage)

    passed = storage.asList() == axis.binBoundariesAsList()
    if not passed:
        log("binBoundariesAsList(): expected {0!s}, got {1!s}".format(
            storage.asList(), axis.binBoundariesAsList()))

    return passed
コード例 #2
0
    def testContinuousMapper(self):
        "Axis: ContinuousMapper"
        from histogram.EvenlyContinuousAxisMapper import EvenlyContinuousAxisMapper as AxisMapper
        min = 0.5
        delta = 1.0
        nBins = 3
        binBoundaries = calcBinBoundaries(min, delta, nBins)
        storage = ndArray("double", binBoundaries)

        self.assertVectorEqual(binBoundaries, [0.0, 1.0, 2.0, 3.0])
        axisMapper = AxisMapper(binBoundaries=binBoundaries)

        axis = Axis('x',
                    unit='1',
                    attributes={},
                    length=nBins,
                    storage=storage,
                    mapper=axisMapper)

        self.assertEqual(axis.cellIndexFromValue(0.5), 0)
        self.assertEqual(axis.cellIndexFromValue(0.), 0)
        self.assertEqual(axis.cellIndexFromValue(1.), 1)
        self.assertEqual(axis.cellIndexFromValue(2.), 2)
        self.assertEqual(axis.cellIndexFromValue(0.9), 0)
        self.assertEqual(axis.cellIndexFromValue(1.9), 1)
        self.assertRaises(IndexError, axis.cellIndexFromValue, -0.5)
        self.assertRaises(IndexError, axis.cellIndexFromValue, 3.5)
        self.assertVectorEqual(axis.binCenters(), [0.5, 1.5, 2.5])
        return
コード例 #3
0
def test_1(**kwds):

    from histogram.Axis import Axis

    name = 'test'
    unit = '1'
    attributes = {
        'plottable': True,
        'nifty': False,
        'pi': 3.14159,
        3.14159: 'pi'
    }
    length = 23
    dtype = 6  # double

    binBounds = [i + 1.0 for i in range(length + 1)]
    storage = ndArray(dtype, binBounds)

    axis = Axis(name, unit, attributes, length, storage)

    expected = [i + 1.5 for i in range(23)]
    passed = utilities.compareFPLists(expected, axis.binCenters(), 1e-15, log)
    if not passed:
        log("binCenters(): expected {0!s}, got {1!s}".format(
            expected, axis.binCenters()))

    return passed
コード例 #4
0
def test_0(**kwds):

    from histogram.Axis import Axis

    name = 'test'
    unit = '1'
    attributes = {
        'plottable': True,
        'nifty': False,
        'pi': 3.14159,
        3.14159: 'pi'
    }
    length = 23
    dtype = 6  # double

    storage = ndArray(dtype, length + 1, 1.0)

    axis = Axis(name, unit, attributes, length, storage)

    passed = True
    if axis._shape != [length + 1]:
        passed = False
        log("shape was {0!s} instead of {1!s}".format(axis._shape,
                                                      [length + 1]))
    # everything else tested in histogramTest_StdvectorDataset.py

    return passed
コード例 #5
0
    def testDiscreteMapper(self):
        "Axis: DiscreteMapper"
        from histogram.DiscreteAxisMapper import DiscreteAxisMapper as AxisMapper
        items = [10,100,2999]
        itemDict = {}
        for i, value in enumerate(items): itemDict[value] = i
        axisMapper = AxisMapper( itemDict )

        from histogram import ndArray
        storage = ndArray( 'int', items + [-1] ) # -1 is a patch
        from histogram.Axis import Axis
        axis = Axis( name = "category", storage = storage, mapper = axisMapper )
        
        self.assertEqual( axis.cellIndexFromValue( 10 ), 0 )
        self.assertEqual( axis.cellIndexFromValue( 100 ), 1 )
        self.assertEqual( axis.cellIndexFromValue( 2999 ), 2 )
        self.assertRaises( IndexError, axis.cellIndexFromValue, -1 )
        self.assertVectorEqual( axis.binCenters(), [10,100,2999])
        return
コード例 #6
0
    def testDiscreteMapper(self):
        "Axis: DiscreteMapper"
        from histogram.DiscreteAxisMapper import DiscreteAxisMapper as AxisMapper
        items = [10, 100, 2999]
        itemDict = {}
        for i, value in enumerate(items):
            itemDict[value] = i
        axisMapper = AxisMapper(itemDict)

        from histogram import ndArray
        storage = ndArray('int', items + [-1])  # -1 is a patch
        from histogram.Axis import Axis
        axis = Axis(name="category", storage=storage, mapper=axisMapper)

        self.assertEqual(axis.cellIndexFromValue(10), 0)
        self.assertEqual(axis.cellIndexFromValue(100), 1)
        self.assertEqual(axis.cellIndexFromValue(2999), 2)
        self.assertRaises(IndexError, axis.cellIndexFromValue, -1)
        self.assertVectorEqual(axis.binCenters(), [10, 100, 2999])
        return
コード例 #7
0
def test_3(**kwds):

    from histogram.Axis import Axis

    name = "test"
    unit = "1"
    attributes = {"plottable": True, "nifty": False, "pi": 3.14159, 3.14159: "pi"}
    length = 23
    dtype = 6  # double

    binBounds = [i + 1.0 for i in range(length + 1)]
    storage = ndArray(dtype, binBounds)

    axis = Axis(name, unit, attributes, length, storage)

    passed = storage.asList() == axis.binBoundariesAsList()
    if not passed:
        log("binBoundariesAsList(): expected %s, got %s" % (storage.asList(), axis.binBoundariesAsList()))

    return passed
コード例 #8
0
def test_0(**kwds):

    from histogram.Axis import Axis

    name = "test"
    unit = "1"
    attributes = {"plottable": True, "nifty": False, "pi": 3.14159, 3.14159: "pi"}
    length = 23
    dtype = 6  # double

    storage = ndArray(dtype, length + 1, 1.0)

    axis = Axis(name, unit, attributes, length, storage)

    passed = True
    if axis._shape != [length + 1]:
        passed = False
        log("shape was %s instead of %s" % (axis._shape, [length + 1]))
    # everything else tested in histogramTest_StdvectorDataset.py

    return passed
コード例 #9
0
def test_1(**kwds):

    from histogram.Axis import Axis

    name = "test"
    unit = "1"
    attributes = {"plottable": True, "nifty": False, "pi": 3.14159, 3.14159: "pi"}
    length = 23
    dtype = 6  # double

    binBounds = [i + 1.0 for i in range(length + 1)]
    storage = ndArray(dtype, binBounds)

    axis = Axis(name, unit, attributes, length, storage)

    expected = [i + 1.5 for i in range(23)]
    passed = utilities.compareFPLists(expected, axis.binCenters(), 1e-15, log)
    if not passed:
        log("binCenters(): expected %s, got %s" % (expected, axis.binCenters()))

    return passed
コード例 #10
0
 def testContinuousMapper(self):
     "Axis: ContinuousMapper"
     from histogram.EvenlyContinuousAxisMapper import EvenlyContinuousAxisMapper as AxisMapper
     min = 0.5; delta = 1.0; nBins = 3
     binBoundaries = calcBinBoundaries( min, delta, nBins )
     storage = ndArray( "double", binBoundaries )
     
     self.assertVectorEqual( binBoundaries, [0.0, 1.0, 2.0, 3.0] )
     axisMapper = AxisMapper( binBoundaries = binBoundaries )
     
     axis = Axis(
         'x', unit='1', attributes = {},
         length = nBins, storage = storage, mapper = axisMapper)
         
     self.assertEqual( axis.cellIndexFromValue( 0.5 ), 0 )
     self.assertEqual( axis.cellIndexFromValue( 0. ), 0 )
     self.assertEqual( axis.cellIndexFromValue( 1. ), 1 )
     self.assertEqual( axis.cellIndexFromValue( 2. ), 2 )
     self.assertEqual( axis.cellIndexFromValue( 0.9 ), 0 )
     self.assertEqual( axis.cellIndexFromValue( 1.9 ), 1 )
     self.assertRaises( IndexError, axis.cellIndexFromValue, -0.5 )
     self.assertRaises( IndexError, axis.cellIndexFromValue, 3.5 )
     self.assertVectorEqual( axis.binCenters(), [0.5,1.5,2.5] )
     return