コード例 #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 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
コード例 #3
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
コード例 #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 test_1(**kwds):

    from histogram.Axis import Axis
    from histogram.NdArrayDataset import Dataset
    name = 'test'
    unit = '1'
    attributes = {
        'plottable': True,
        'nifty': False,
        'pi': 3.14159,
        3.14159: 'pi'
    }
    lengths = [2, 3, 4]
    dtype = 6  # double

    stor1 = NdArray(dtype, lengths[0] + 1, 1.0)
    ax1 = Axis(name + 'ax1', unit, attributes, lengths[0], stor1)

    stor2 = NdArray(dtype, lengths[1] + 1, 1.0)
    ax2 = Axis(name + 'ax2', unit, attributes, lengths[1], stor2)

    stor3 = NdArray(dtype, lengths[2] + 1, 1.0)
    ax3 = Axis(name + 'ax3', unit, attributes, lengths[2], stor3)

    size = lengths[0] * lengths[1] * lengths[2]

    dataStore = NdArray(dtype, size, 1.0)
    dataStore.setShape((2, 3, 4))
    data = Dataset(name + 'data', unit, attributes, lengths, dataStore)

    errorStore = NdArray(dtype, size, 1.0)
    errorStore.setShape((2, 3, 4))
    error = Dataset(name + 'error', unit, attributes, lengths, errorStore)

    from histogram.Histogram import Histogram

    hist = Histogram('testHist', data, error, [ax1, ax2, ax3], attributes)

    passed = True
    hax1 = hist.axisFromId(1)
    if hax1 is not ax1:
        passed = False
        log("hax1 was %s instead of %s" % (hax1, ax1))
    return passed
コード例 #6
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
コード例 #7
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
コード例 #8
0
def test_0(**kwds):

    from histogram.Axis import Axis
    from histogram.NdArrayDataset import Dataset
    name = 'test'
    unit = '1'
    attributes = {
        'plottable': True,
        'nifty': False,
        'pi': 3.14159,
        3.14159: 'pi'
    }
    lengths = [2, 3, 4]
    dtype = 6  # double

    stor1 = NdArray(dtype, lengths[0] + 1, 1.0)
    ax1 = Axis(name + 'ax1', unit, attributes, lengths[0], stor1)

    stor2 = NdArray(dtype, lengths[1] + 1, 1.0)
    ax2 = Axis(name + 'ax2', unit, attributes, lengths[1], stor2)

    stor3 = NdArray(dtype, lengths[2] + 1, 1.0)
    ax3 = Axis(name + 'ax3', unit, attributes, lengths[2], stor3)

    size = lengths[0] * lengths[1] * lengths[2]

    dataStore = NdArray(dtype, size, 1.0)
    dataStore.setShape((2, 3, 4))
    data = Dataset(name + 'data', unit, attributes, lengths, dataStore)

    errorStore = NdArray(dtype, size, 1.0)
    errorStore.setShape((2, 3, 4))
    error = Dataset(name + 'error', unit, attributes, lengths, errorStore)

    from histogram.Histogram import Histogram

    histogram = Histogram('testHist', data, error, [ax1, ax2, ax3], attributes)

    return True
コード例 #9
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