From 59ca4d08a09f83489c9a6c5afbc76120bfabc9f1 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Mon, 24 Dec 2018 08:52:21 -0600 Subject: [PATCH 1/3] fixed #27 --- uproot_methods/classes/TVector3.py | 6 +++--- uproot_methods/version.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/uproot_methods/classes/TVector3.py b/uproot_methods/classes/TVector3.py index 4406f5b..9b4dd27 100644 --- a/uproot_methods/classes/TVector3.py +++ b/uproot_methods/classes/TVector3.py @@ -97,13 +97,13 @@ def _rotate_euler(self, phi, theta, psi): return x, y, z def rotatex(self, angle): - return self.rotate_axis(Methods(1.0, 0.0, 0.0), angle) + return self.rotate_axis(TVector3(1.0, 0.0, 0.0), angle) def rotatey(self, angle): - return self.rotate_axis(Methods(0.0, 1.0, 0.0), angle) + return self.rotate_axis(TVector3(0.0, 1.0, 0.0), angle) def rotatez(self, angle): - return self.rotate_axis(Methods(0.0, 0.0, 1.0), angle) + return self.rotate_axis(TVector3(0.0, 0.0, 1.0), angle) class ArrayMethods(Common, uproot_methods.common.TVector.ArrayMethods, uproot_methods.base.ROOTMethods): def _initObjectArray(self, table): diff --git a/uproot_methods/version.py b/uproot_methods/version.py index bb5a20e..b5a2709 100644 --- a/uproot_methods/version.py +++ b/uproot_methods/version.py @@ -30,7 +30,7 @@ import re -__version__ = "0.3.1" +__version__ = "0.3.2" version = __version__ version_info = tuple(re.split(r"[-\.]", __version__)) From 97a19574a5ec440f6fafeef35723ca98311bdb88 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Mon, 24 Dec 2018 09:41:20 -0600 Subject: [PATCH 2/3] quell a false sense of hope --- uproot_methods/classes/TLorentzVector.py | 3 +++ uproot_methods/classes/TVector2.py | 3 +++ uproot_methods/classes/TVector3.py | 3 +++ 3 files changed, 9 insertions(+) diff --git a/uproot_methods/classes/TLorentzVector.py b/uproot_methods/classes/TLorentzVector.py index ace6c37..6b7e22a 100644 --- a/uproot_methods/classes/TLorentzVector.py +++ b/uproot_methods/classes/TLorentzVector.py @@ -287,6 +287,9 @@ def sum(self): return TLorentzVector(self.x.sum(), self.y.sum(), self.z.sum(), self.t.sum()) def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): + if "out" in kwargs: + raise NotImplementedError("in-place operations not supported") + if method != "__call__": return NotImplemented diff --git a/uproot_methods/classes/TVector2.py b/uproot_methods/classes/TVector2.py index efa7e45..54fbcd1 100644 --- a/uproot_methods/classes/TVector2.py +++ b/uproot_methods/classes/TVector2.py @@ -66,6 +66,9 @@ def sum(self): return TVector2(self.x.sum(), self.y.sum()) def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): + if "out" in kwargs: + raise NotImplementedError("in-place operations not supported") + if method != "__call__": return NotImplemented diff --git a/uproot_methods/classes/TVector3.py b/uproot_methods/classes/TVector3.py index 9b4dd27..ed172e4 100644 --- a/uproot_methods/classes/TVector3.py +++ b/uproot_methods/classes/TVector3.py @@ -157,6 +157,9 @@ def sum(self): return TVector3(self.x.sum(), self.y.sum(), self.z.sum()) def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): + if "out" in kwargs: + raise NotImplementedError("in-place operations not supported") + if method != "__call__": return NotImplemented From 0e19d23af455e33c54fe142e77cfffd9d260e23b Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Fri, 4 Jan 2019 16:26:53 -0600 Subject: [PATCH 3/3] fixed #30: TH2 methods are up-to-date with TH1 --- uproot_methods/classes/TH1.py | 29 +++++------ uproot_methods/classes/TH2.py | 93 +++++++++++++++++++++++++---------- 2 files changed, 83 insertions(+), 39 deletions(-) diff --git a/uproot_methods/classes/TH1.py b/uproot_methods/classes/TH1.py index 9685ca5..8c666c0 100644 --- a/uproot_methods/classes/TH1.py +++ b/uproot_methods/classes/TH1.py @@ -107,19 +107,28 @@ def allbins(self): @property def values(self): - return numpy.array(self[1:-1]) + return self.allvalues[1:-1] @property def allvalues(self): - return numpy.array(self) + return numpy.array(self, dtype=getattr(self, "_dtype", numpy.dtype(numpy.float64)).newbyteorder("=")) @property def variances(self): - return numpy.array(self._fSumw2[1:-1]) + return self.allvariances[1:-1] @property def allvariances(self): - return numpy.array(self._fSumw2) + if len(getattr(self, "_fSumw2", [])) != len(self): + return numpy.array(self, dtype=numpy.float64) + else: + return numpy.array(self._fSumw2, dtype=numpy.float64) + + def numpy(self): + return self.values, self.edges + + def allnumpy(self): + return self.allvalues, self.alledges def interval(self, index): if index < 0: @@ -221,17 +230,9 @@ def show(self, width=80, minimum=None, maximum=None, stream=sys.stdout): stream.write(out) stream.write("\n") - def numpy(self): - freq = numpy.array(self.values, dtype=self._dtype.newbyteorder("=")) - if getattr(self._fXaxis, "_fXbins", None): - edges = numpy.array(self._fXaxis._fXbins) - else: - edges = numpy.linspace(self._fXaxis._fXmin, self._fXaxis._fXmax, self._fXaxis._fNbins + 1) - return freq, edges - def pandas(self, underflow=True, overflow=True, variance=True): import pandas - freq = numpy.array(self.allvalues, dtype=self._dtype.newbyteorder("=")) + freq = numpy.array(self.allvalues, dtype=getattr(self, "_dtype", numpy.dtype(numpy.float64)).newbyteorder("=")) if not underflow and not overflow: freq = freq[1:-1] @@ -288,7 +289,7 @@ def pandas(self, underflow=True, overflow=True, variance=True): def physt(self): import physt.binnings import physt.histogram1d - freq = numpy.array(self.allvalues, dtype=self._dtype.newbyteorder("=")) + freq = numpy.array(self.allvalues, dtype=getattr(self, "_dtype", numpy.dtype(numpy.float64)).newbyteorder("=")) if getattr(self._fXaxis, "_fXbins", None): binning = physt.binnings.NumpyBinning(numpy.array(self._fXaxis._fXbins)) else: diff --git a/uproot_methods/classes/TH2.py b/uproot_methods/classes/TH2.py index 2c503b5..ac0e61a 100644 --- a/uproot_methods/classes/TH2.py +++ b/uproot_methods/classes/TH2.py @@ -103,40 +103,83 @@ def xoverflows(self): def yoverflows(self): return self.overflows[1] + @property + def edges(self): + xaxis = self._fXaxis + yaxis = self._fYaxis + if len(getattr(xaxis, "_fXbins", [])) > 0: + xedges = numpy.array(xaxis._fXbins) + else: + xedges = numpy.linspace(xaxis._fXmin, xaxis._fXmax, xaxis._fNbins + 1) + if len(getattr(yaxis, "_fYbins", [])) > 0: + yedges = numpy.array(yaxis._fXbins) + else: + yedges = numpy.linspace(yaxis._fXmin, yaxis._fXmax, yaxis._fNbins + 1) + return xedges, yedges + + @property + def alledges(self): + xedges, yedges = self.edges + vx = numpy.empty(len(xedges) + 2) + vy = numpy.empty(len(yedges) + 2) + vx[0] = -numpy.inf + vx[-1] = numpy.inf + vx[1:-1] = xedges + vy[0] = -numpy.inf + vy[-1] = numpy.inf + vy[1:-1] = yedges + return vx, vy + + @property + def bins(self): + xedges, yedges = self.edges + vx = numpy.empty((len(xedges) - 1, 2)) + vy = numpy.empty((len(yedges) - 1, 2)) + vx[:, 0] = xedges[:-1] + vx[:, 1] = xedges[1:] + vy[:, 0] = yedges[:-1] + vy[:, 1] = yedges[1:] + return vx, vy + + @property + def allbins(self): + xedges, yedges = self.alledges + vx = numpy.empty((len(xedges) - 1, 2)) + vy = numpy.empty((len(yedges) - 1, 2)) + vx[:, 0] = xedges[:-1] + vx[:, 1] = xedges[1:] + vy[:, 0] = yedges[:-1] + vy[:, 1] = yedges[1:] + return vx, vy + @property def values(self): - va = numpy.array(self.allvalues) - va = va[1:self.ynumbins+1, 1:self.xnumbins+1] - return va.tolist() + va = self.allvalues + return va[1:self.ynumbins+1, 1:self.xnumbins+1] @property def allvalues(self): - v = numpy.array(self[:]) - v = v.reshape(self.ynumbins + 2, self.xnumbins + 2) - return v.tolist() + v = numpy.array(self[:], dtype=getattr(self, "_dtype", numpy.dtype(numpy.float64)).newbyteorder("=")) + return v.reshape(self.ynumbins + 2, self.xnumbins + 2) - def numpy(self): - xlow = self.xlow - xhigh = self.xhigh - xbins = self._fXaxis._fXbins - if not xbins: - norm = float(xhigh - xlow) / self.xnumbins - xedges = numpy.array([i*norm + xlow for i in range(self.xnumbins + 1)]) - else: - xedges = numpy.array(xbins) - - ylow = self.ylow - yhigh = self.yhigh - ybins = self._fYaxis._fXbins - if not ybins: - norm = (yhigh - ylow) / self.ynumbins - yedges = numpy.array([i*norm + ylow for i in range(self.ynumbins + 1)]) + @property + def variances(self): + va = self.allvariances + return va[1:self.ynumbins+1, 1:self.xnumbins+1] + + @property + def allvariances(self): + if len(getattr(self, "_fSumw2", [])) != len(self): + v = numpy.array(self, dtype=numpy.float64) else: - yedges = numpy.array(ybins) + v = numpy.array(self._fSumw2, dtype=numpy.float64) + return v.reshape(self.ynumbins + 2, self.xnumbins + 2) - freq = numpy.array(self.values, dtype=self._dtype.newbyteorder("=")) + def numpy(self): + return (self.values,) + self.edges - return freq, (xedges, yedges) + def numpy(self): + return (self.allvalues,) + self.alledges def interval(self, index, axis): if axis == "x":