예제 #1
0
    def project(self, parent, key, axes):
        """
        TH{2/3}/!project/axes
        Project axes out of 2D and 3D histograms
        """

        if "," in axes:
            projections = axes.split(",")

            new_contexts = [((p, ), self["!project"][p]) for p in projections]

            return MultipleTraverser.from_parent(
                parent,
                key,
                new_contexts,
                slot_filler=self.multiproject_slot_filler)

        if "".join(sorted(axes)) not in ("x", "y", "z", "xy", "xz", "yz"):
            # raise HTTPMethodNotAllowed("Bad parameter '{0}', expected axes".format(axes))
            return

        if self.obj.GetDimension() == 1:
            if axes == "x":
                # Only x projection is valid for 1D histogram
                return Histogram.from_parent(parent, key, self.o)
            return

        if self.obj.GetDimension() == 2 and len(axes) == 1:

            def project(hist):
                return get_xyz_func(hist, "Projection{ax}", axes)()

            return Histogram.from_parent(parent, key,
                                         self.o.transform(project))

        def project(hist):
            # Thread safety, histograms are named by anything which remains in the
            # option string, and they clobber each other, yay ROOT!
            from random import randint
            random_name = str(randint(0, 2**32 - 1))
            optstring = "{0}{1}".format(axes, random_name)
            h = hist.Project3D(optstring)
            h.SetName(h.GetName()[:-len(random_name)])
            return h

        return Histogram.from_parent(parent, key, self.o.transform(project))
예제 #2
0
파일: histogram.py 프로젝트: rootpy/WebOOT
    def project(self, parent, key, axes):
        """
        TH{2/3}/!project/axes
        Project axes out of 2D and 3D histograms
        """

        if "," in axes:
            projections = axes.split(",")

            new_contexts = [((p,), self["!project"][p]) for p in projections]

            return MultipleTraverser.from_parent(parent, key, new_contexts, slot_filler=self.multiproject_slot_filler)

        if "".join(sorted(axes)) not in ("x", "y", "z", "xy", "xz", "yz"):
            # raise HTTPMethodNotAllowed("Bad parameter '{0}', expected axes".format(axes))
            return

        if self.obj.GetDimension() == 1:
            if axes == "x":
                # Only x projection is valid for 1D histogram
                return Histogram.from_parent(parent, key, self.o)
            return

        if self.obj.GetDimension() == 2 and len(axes) == 1:

            def project(hist):
                return get_xyz_func(hist, "Projection{ax}", axes)()

            return Histogram.from_parent(parent, key, self.o.transform(project))

        def project(hist):
            # Thread safety, histograms are named by anything which remains in the
            # option string, and they clobber each other, yay ROOT!
            from random import randint

            random_name = str(randint(0, 2 ** 32 - 1))
            optstring = "{0}{1}".format(axes, random_name)
            h = hist.Project3D(optstring)
            h.SetName(h.GetName()[: -len(random_name)])
            return h

        return Histogram.from_parent(parent, key, self.o.transform(project))
예제 #3
0
파일: histogram.py 프로젝트: rootpy/WebOOT
    def explode(self, parent, key, ax):
        """
        TH{2,3}/!explode/axis
        Returns many histograms, one per bin in axis `ax`, with the range configured.
        """
        assert ax in "xyz"

        axis = get_haxis(self.obj, ax)

        def build_bin(i):
            r = self["!binrange"][ax][i][i]
            s = "bin {0:03d}: [{1}, {2}) {3}"
            lo = axis.GetBinLowEdge(i) if i else "-inf"
            up = axis.GetBinUpEdge(i) if i != axis.GetNbins() + 1 else "+inf"
            s = s.format(i, lo, up, axis.GetTitle())
            return ((self.ExplodeSlotKey(ax, i, s),), r)

        new_contexts = [build_bin(i) for i in xrange(1, axis.GetNbins() + 1)]

        return MultipleTraverser.from_parent(parent, ax, new_contexts, slot_filler=self.explode_slot_filler)
예제 #4
0
    def explode(self, parent, key, ax):
        """
        TH{2,3}/!explode/axis
        Returns many histograms, one per bin in axis `ax`, with the range configured.
        """
        assert ax in "xyz"

        axis = get_haxis(self.obj, ax)

        def build_bin(i):
            r = self["!binrange"][ax][i][i]
            s = "bin {0:03d}: [{1}, {2}) {3}"
            lo = axis.GetBinLowEdge(i) if i else "-inf"
            up = axis.GetBinUpEdge(i) if i != axis.GetNbins() + 1 else "+inf"
            s = s.format(i, lo, up, axis.GetTitle())
            return ((self.ExplodeSlotKey(ax, i, s), ), r)

        new_contexts = [build_bin(i) for i in xrange(1, axis.GetNbins() + 1)]

        return MultipleTraverser.from_parent(
            parent, ax, new_contexts, slot_filler=self.explode_slot_filler)