Exemplo n.º 1
0
    def testSparselyBin(self):
        one = SparselyBin(1.0, named("something", lambda x: x))
        for _ in self.simple:
            one.fill(_)
        self.assertEqual([(i, v.entries) for i, v in sorted(one.bins.items())],
                         [(-5, 1.0), (-3, 1.0), (-2, 2.0), (0, 2.0), (1, 1.0),
                          (2, 1.0), (3, 1.0), (7, 1.0)])

        self.assertEqual(one.numFilled, 8)
        self.assertEqual(one.num, 13)
        self.assertEqual(one.low, -5.0)
        self.assertEqual(one.high, 8.0)

        self.checkScaling(one)
        self.checkScaling(one.toImmutable())
        self.checkJson(one)
        self.checkPickle(one)
        self.checkName(one)

        two = SparselyBin(1.0, named("something", lambda x: x),
                          Sum(named("elsie", lambda x: x)))
        for _ in self.simple:
            two.fill(_)

        self.checkScaling(two)
        self.checkScaling(two.toImmutable())
        self.checkJson(two)
        self.checkPickle(two)
        self.checkName(two)
Exemplo n.º 2
0
def TwoDimensionallySparselyHistogram(xbinWidth, xquantity,
                                      ybinWidth, yquantity,
                                      selection=unweighted,
                                      xorigin=0.0, yorigin=0.0):
    """Convenience function for creating a sparsely binned, two-dimensional histogram."""
    return Select.ing(selection,
        SparselyBin.ing(xbinWidth, xquantity,
            SparselyBin.ing(ybinWidth, yquantity,
                Count.ing(), Count.ing(), yorigin), Count.ing(), xorigin))
Exemplo n.º 3
0
def SparselyProfileErr(binWidth,
                       binnedQuantity,
                       averagedQuantity,
                       selection=unweighted,
                       origin=0.0):
    """Convenience function for creating a physicist's sparsely binned "profile plot," which is a Profile with variances."""
    return Select.ing(
        selection,
        SparselyBin.ing(binWidth, binnedQuantity,
                        Deviate.ing(averagedQuantity), Count.ing(), origin))
Exemplo n.º 4
0
def SparselyProfile(binWidth,
                    binnedQuantity,
                    averagedQuantity,
                    selection=unweighted,
                    origin=0.0):
    """Convenience function for creating sparsely binned binwise averages."""
    return Select.ing(
        selection,
        SparselyBin.ing(binWidth, binnedQuantity,
                        Average.ing(averagedQuantity), Count.ing(), origin))
Exemplo n.º 5
0
def SparselyHistogram(binWidth, quantity=identity, origin=0.0):
    """Create a sparsely binned histogram that is only capable of being added.

    Parameters:
        binWidth (float): the width of a bin.
        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.
        origin (float): the left edge of the bin whose index is zero.
    """
    return SparselyBin.ing(binWidth, quantity, Count.ing(), Count.ing(), origin)
Exemplo n.º 6
0
 def testSparselyBinDeviate(self):
     with Numpy() as numpy:
         if numpy is None:
             return
         sys.stderr.write("\n")
         self.compare("SparselyBinDeviate no data", SparselyBin(0.1, lambda x: x["empty"], Deviate(
             lambda x: x["empty"])), self.data, SparselyBin(0.1, lambda x: x, Deviate(lambda x: x)), self.empty)
         self.compare("SparselyBinDeviate noholes", SparselyBin(0.1, lambda x: x["noholes"], Deviate(
             lambda x: x["noholes"])), self.data, SparselyBin(0.1, lambda x: x, Deviate(lambda x: x)), self.noholes)
         self.compare("SparselyBinDeviate holes", SparselyBin(0.1, lambda x: x["withholes"], Deviate(
             lambda x: x["withholes"])), self.data, SparselyBin(0.1, lambda x: x, Deviate(lambda x: x)), self.withholes)
Exemplo n.º 7
0
 def testSparselyBinTrans(self):
     with Numpy() as numpy:
         if numpy is None:
             return
         sys.stderr.write("\n")
         self.compare("SparselyBinTrans no data", SparselyBin(0.1, lambda x: x["empty"], Count(
             lambda x: 0.5*x)), self.data, SparselyBin(0.1, lambda x: x, Count(lambda x: 0.5*x)), self.empty)
         self.compare("SparselyBinTrans noholes", SparselyBin(0.1, lambda x: x["noholes"], Count(
             lambda x: 0.5*x)), self.data, SparselyBin(0.1, lambda x: x, Count(lambda x: 0.5*x)), self.noholes)
         self.compare("SparselyBinTrans holes", SparselyBin(0.1, lambda x: x["withholes"], Count(
             lambda x: 0.5*x)), self.data, SparselyBin(0.1, lambda x: x, Count(lambda x: 0.5*x)), self.withholes)
Exemplo n.º 8
0
def SparselyProfileErr(binWidth, binnedQuantity, averagedQuantity, origin=0.0):
    """Convenience function for creating a sparsely binned profile plot

    This is a Profile with variances.
    """
    return SparselyBin.ing(binWidth, binnedQuantity, Deviate.ing(averagedQuantity), Count.ing(), origin)
Exemplo n.º 9
0
def SparselyHistogram(binWidth, quantity, selection=unweighted, origin=0.0):
    "Convenience function for creating a sparsely binned histogram."
    return Select.ing(
        selection,
        SparselyBin.ing(binWidth, quantity, Count.ing(), Count.ing(), origin))
Exemplo n.º 10
0
def SparselyProfileErr(binWidth, binnedQuantity, averagedQuantity, selection=unweighted, origin=0.0):
    """Convenience function for creating a physicist's sparsely binned "profile plot," which is a Profile with variances."""
    return Select.ing(selection,
        SparselyBin.ing(binWidth, binnedQuantity,
            Deviate.ing(averagedQuantity), Count.ing(), origin))
Exemplo n.º 11
0
def SparselyProfile(binWidth, binnedQuantity, averagedQuantity, selection=unweighted, origin=0.0):
    """Convenience function for creating sparsely binned binwise averages."""
    return Select.ing(selection,
        SparselyBin.ing(binWidth, binnedQuantity,
            Average.ing(averagedQuantity), Count.ing(), origin))
Exemplo n.º 12
0
def SparselyHistogram(binWidth, quantity, selection=unweighted, origin=0.0):
    """Convenience function for creating a sparsely binned histogram."""
    return Select.ing(selection,
        SparselyBin.ing(binWidth, quantity, Count.ing(), Count.ing(), origin))