コード例 #1
0
def TwoDimensionallyHistogram(xnum, xlow, xhigh, xquantity,
                              ynum, ylow, yhigh, yquantity,
                              selection=unweighted):
    """Convenience function for creating a conventional, two-dimensional histogram."""
    return Select.ing(selection,
        Bin.ing(xnum, xlow, xhigh, xquantity,
            Bin.ing(ynum, ylow, yhigh, yquantity)))
コード例 #2
0
 def testUntypedLabelBin(self):
     with Numpy() as numpy:
         if numpy is None:
             return
         sys.stderr.write("\n")
         self.compare("UntypedLabelBin no data", UntypedLabel(
             x=Bin(100, -3.0, 3.0, lambda x: x["empty"])), self.data, UntypedLabel(x=Bin(100, -3.0, 3.0, lambda x: x)), self.empty)
         self.compare("UntypedLabelBin noholes", UntypedLabel(
             x=Bin(100, -3.0, 3.0, lambda x: x["noholes"])), self.data, UntypedLabel(x=Bin(100, -3.0, 3.0, lambda x: x)), self.noholes)
         self.compare("UntypedLabelBin holes", UntypedLabel(x=Bin(
             100, -3.0, 3.0, lambda x: x["withholes"])), self.data, UntypedLabel(x=Bin(100, -3.0, 3.0, lambda x: x)), self.withholes)
コード例 #3
0
 def testSelectBin(self):
     with Numpy() as numpy:
         if numpy is None:
             return
         sys.stderr.write("\n")
         self.compare("SelectBin no data", Select(lambda x: x["empty"], Bin(
             100, -3.0, 3.0, lambda x: x["empty"])), self.data, Select(lambda x: x, Bin(100, -3.0, 3.0, lambda x: x)), self.empty)
         self.compare("SelectBin noholes", Select(lambda x: x["noholes"], Bin(
             100, -3.0, 3.0, lambda x: x["noholes"])), self.data, Select(lambda x: x, Bin(100, -3.0, 3.0, lambda x: x)), self.noholes)
         self.compare("SelectBin holes", Select(lambda x: x["withholes"], Bin(
             100, -3.0, 3.0, lambda x: x["withholes"])), self.data, Select(lambda x: x, Bin(100, -3.0, 3.0, lambda x: x)), self.withholes)
コード例 #4
0
 def testStackBin(self):
     with Numpy() as numpy:
         if numpy is None:
             return
         sys.stderr.write("\n")
         cuts = [-3.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 3.0]
         self.compare("StackBin no data", Stack(cuts, lambda x: x["empty"], Bin(
             100, -3.0, 3.0, lambda x: x["empty"])), self.data, Stack(cuts, lambda x: x, Bin(100, -3.0, 3.0, lambda x: x)), self.empty)
         self.compare("StackBin noholes", Stack(cuts, lambda x: x["noholes"], Bin(
             100, -3.0, 3.0, lambda x: x["noholes"])), self.data, Stack(cuts, lambda x: x, Bin(100, -3.0, 3.0, lambda x: x)), self.noholes)
         self.compare("StackBin holes", Stack(cuts, lambda x: x["withholes"], Bin(
             100, -3.0, 3.0, lambda x: x["withholes"])), self.data, Stack(cuts, lambda x: x, Bin(100, -3.0, 3.0, lambda x: x)), self.withholes)
コード例 #5
0
 def testBin(self):
     with Numpy() as numpy:
         if numpy is None:
             return
         sys.stderr.write("\n")
         for bins in [10, 100]:
             self.compare("Bin ({0} bins) no data".format(bins), Bin(bins, -3.0, 3.0,
                                                                     lambda x: x["empty"]), self.data, Bin(bins, -3.0, 3.0, lambda x: x), self.empty)
             self.compare("Bin ({0} bins) noholes".format(bins), Bin(bins, -3.0, 3.0,
                                                                     lambda x: x["noholes"]), self.data, Bin(bins, -3.0, 3.0, lambda x: x), self.noholes)
             self.compare("Bin ({0} bins) holes".format(bins), Bin(
                 bins, -3.0, 3.0, lambda x: x["withholes"]), self.data, Bin(bins, -3.0, 3.0, lambda x: x), self.withholes)
コード例 #6
0
def ProfileErr(num,
               low,
               high,
               binnedQuantity,
               averagedQuantity,
               selection=unweighted):
    """Convenience function for creating a physicist's "profile plot," which is a Profile with variances."""
    return Select.ing(
        selection,
        Bin.ing(num, low, high, binnedQuantity, Deviate.ing(averagedQuantity)))
コード例 #7
0
def Profile(num,
            low,
            high,
            binnedQuantity,
            averagedQuantity,
            selection=unweighted):
    """Convenience function for creating binwise averages."""
    return Select.ing(
        selection,
        Bin.ing(num, low, high, binnedQuantity, Average.ing(averagedQuantity)))
コード例 #8
0
def Histogram(num, low, high, quantity=identity):
    """Create a conventional histogram that is capable of being filled and added.

    Parameters:
        num (int): the number of bins; must be at least one.
        low (float): the minimum-value edge of the first bin.
        high (float): the maximum-value edge of the last bin; must be strictly greater than `low`.
        quantity (function returning float or string): function that computes the quantity of interest from
            the data. pass on all values by default. If a string is given, quantity is set to identity(string),
            in which case that column is picked up from a pandas df.
    """
    return Bin.ing(num, low, high, quantity, Count.ing(), Count.ing(), Count.ing(), Count.ing())
コード例 #9
0
    def testBinWithSum(self):
        one = Bin(5, -3.0, 7.0, named("xaxis", lambda x: x),
                  Sum(named("yaxis", lambda x: 10.0)), Sum(lambda x: 10.0),
                  Sum(lambda x: 10.0), Sum(lambda x: 10.0))
        for _ in self.simple:
            one.fill(_)
        self.assertEqual(list(map(lambda _: _.sum, one.values)),
                         [30.0, 20.0, 20.0, 10.0, 0.0])
        self.assertEqual(one.underflow.sum, 10.0)
        self.assertEqual(one.overflow.sum, 10.0)
        self.assertEqual(one.nanflow.sum, 0.0)

        two = Select(
            lambda x: x.bool,
            Bin(5, -3.0, 7.0, lambda x: x.double, Sum(lambda x: 10.0),
                Sum(lambda x: 10.0), Sum(lambda x: 10.0), Sum(lambda x: 10.0)))
        for _ in self.struct:
            two.fill(_)

        self.assertEqual(list(map(lambda _: _.sum, two.cut.values)),
                         [20.0, 10.0, 10.0, 10.0, 0.0])
        self.assertEqual(two.cut.underflow.sum, 0.0)
        self.assertEqual(two.cut.overflow.sum, 0.0)
        self.assertEqual(two.cut.nanflow.sum, 0.0)

        self.checkScaling(one)
        self.checkScaling(one.toImmutable())
        self.checkJson(one)
        self.checkPickle(one)
        self.checkName(one)
        self.checkScaling(two)
        self.checkScaling(two.toImmutable())
        self.checkJson(two)
        self.checkPickle(two)
        self.checkName(two)
コード例 #10
0
    def testBin(self):
        one = Bin(5, -3.0, 7.0, named("xaxis", lambda x: x))
        for _ in self.simple:
            one.fill(_)
        self.assertEqual(list(map(lambda _: _.entries, one.values)),
                         [3.0, 2.0, 2.0, 1.0, 0.0])
        self.assertEqual(one.underflow.entries, 1.0)
        self.assertEqual(one.overflow.entries, 1.0)
        self.assertEqual(one.nanflow.entries, 0.0)

        two = Select(lambda x: x.bool, Bin(5, -3.0, 7.0, lambda x: x.double))
        for _ in self.struct:
            two.fill(_)

        self.assertEqual(list(map(lambda _: _.entries, two.cut.values)),
                         [2.0, 1.0, 1.0, 1.0, 0.0])
        self.assertEqual(two.cut.underflow.entries, 0.0)
        self.assertEqual(two.cut.overflow.entries, 0.0)
        self.assertEqual(two.cut.nanflow.entries, 0.0)

        self.checkScaling(one)
        self.checkScaling(one.toImmutable())
        self.checkJson(one)
        self.checkPickle(one)
        self.checkName(one)
        self.checkScaling(two)
        self.checkScaling(two.toImmutable())
        self.checkJson(two)
        self.checkPickle(two)
        self.checkName(two)
コード例 #11
0
def HistogramCut(num, low, high, quantity=identity, selection=unweighted):
    """Create a conventional histogram that is capable of being filled and added, with a selection cut.

    Parameters:
        num (int): the number of bins; must be at least one.
        low (float): the minimum-value edge of the first bin.
        high (float): the maximum-value edge of the last bin; must be strictly greater than `low`.
        quantity (function returning float or string): function that computes the quantity of interest from
            the data. pass on all values by default. If a string is given, quantity is set to identity(string),
            in which case that column is picked up from a pandas df.
        selection (function returning boolean): function that computes if data point is accepted or not.
            default is: lamba x: True
    """
    return Select.ing(selection, Bin.ing(num, low, high, quantity, Count.ing(), Count.ing(), Count.ing(), Count.ing()))
コード例 #12
0
def ProfileErr(num, low, high, binnedQuantity, averagedQuantity, selection=unweighted):
    """Convenience function for creating a physicist's "profile plot," which is a Profile with variances."""
    return Select.ing(selection,
        Bin.ing(num, low, high, binnedQuantity,
            Deviate.ing(averagedQuantity)))
コード例 #13
0
def Profile(num, low, high, binnedQuantity, averagedQuantity, selection=unweighted):
    """Convenience function for creating binwise averages."""
    return Select.ing(selection,
        Bin.ing(num, low, high, binnedQuantity,
            Average.ing(averagedQuantity)))
コード例 #14
0
def Histogram(num, low, high, quantity, selection=unweighted):
    """Convenience function for creating a conventional histogram."""
    return Select.ing(selection, Bin.ing(num, low, high, quantity,
        Count.ing(), Count.ing(), Count.ing(), Count.ing()))
コード例 #15
0
def Profile(num, low, high, binnedQuantity, averagedQuantity):
    """Convenience function for creating binwise averages."""
    return Bin.ing(num, low, high, binnedQuantity, Average.ing(averagedQuantity))
コード例 #16
0
def ProfileErr(num, low, high, binnedQuantity, averagedQuantity):
    """Convenience function for creating a profile plot

    This is a Profile with variances.
    """
    return Bin.ing(num, low, high, binnedQuantity, Deviate.ing(averagedQuantity))
コード例 #17
0
def Histogram(num, low, high, quantity, selection=unweighted):
    """Convenience function for creating a conventional histogram."""
    return Select.ing(
        selection,
        Bin.ing(num, low, high, quantity, Count.ing(), Count.ing(),
                Count.ing(), Count.ing()))