[yoda-svn] r518 - in trunk/pyext/yoda: . include

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Fri Aug 3 12:20:02 BST 2012


Author: davemallows
Date: Fri Aug  3 12:20:01 2012
New Revision: 518

Log:
Tidying up of Cython -- reintroducing docstrings, improving naming consistency.

Deleted:
   trunk/pyext/yoda/include/Annotations.pyx
Modified:
   trunk/pyext/yoda/core.pyx
   trunk/pyext/yoda/declarations.pxd
   trunk/pyext/yoda/include/AnalysisObject.pyx
   trunk/pyext/yoda/include/Axis1D_BIN1D_DBN.pyx
   trunk/pyext/yoda/include/Axis2D_BIN2D_DBN.pyx
   trunk/pyext/yoda/include/Bin2D_DBN.pyx
   trunk/pyext/yoda/include/Dbn1D.pyx
   trunk/pyext/yoda/include/Dbn2D.pyx
   trunk/pyext/yoda/include/Dbn3D.pyx
   trunk/pyext/yoda/include/Histo2D.pyx
   trunk/pyext/yoda/include/HistoBin1D.pyx
   trunk/pyext/yoda/include/HistoBin2D.pyx
   trunk/pyext/yoda/include/IO.pyx
   trunk/pyext/yoda/include/Point2D.pyx
   trunk/pyext/yoda/include/Point3D.pyx
   trunk/pyext/yoda/include/Profile1D.pyx
   trunk/pyext/yoda/include/Profile2D.pyx
   trunk/pyext/yoda/include/ProfileBin1D.pyx
   trunk/pyext/yoda/include/ProfileBin2D.pyx
   trunk/pyext/yoda/include/Scatter2D.pyx

Modified: trunk/pyext/yoda/core.pyx
==============================================================================
--- trunk/pyext/yoda/core.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/core.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -28,8 +28,6 @@
 
 include "include/ProfileBin1D.pyx"
 
-include "include/Annotations.pyx"
-
 include "include/AnalysisObject.pyx"
 
 include "include/Histo1D.pyx"

Modified: trunk/pyext/yoda/declarations.pxd
==============================================================================
--- trunk/pyext/yoda/declarations.pxd	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/declarations.pxd	Fri Aug  3 12:20:01 2012	(r518)
@@ -186,6 +186,8 @@
         void setYErr(pair[double, double]) except+ err
         double xMin() except+ err
         double xMax() except+ err
+        double yMin() except+ err
+        double yMax() except+ err
         void scale(double x, double y) except+ err
         bool operator == (Point2D) except+ err
         bool operator != (Point2D b) except+ err

Modified: trunk/pyext/yoda/include/AnalysisObject.pyx
==============================================================================
--- trunk/pyext/yoda/include/AnalysisObject.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/AnalysisObject.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -1,7 +1,8 @@
 from cython.operator cimport dereference as deref, preincrement as preinc
 from cStringIO import StringIO
 
-cdef void set_ann(c.AnalysisObject *ana, char *k, char *v):
+# Useful helper function to avoid hoops in Cython's type system
+cdef void set_annotation(c.AnalysisObject *ana, char *k, char *v):
     ana.setAnnotation(string(k), string(v))
 
 # AnalysisObject is the base class of most of the user facing objects
@@ -13,13 +14,13 @@
 
     # Deallocator (only needed as a base class)
     def __dealloc__(self):
-        cdef c.AnalysisObject *p = self._AnalysisObject()
+        p = self._AnalysisObject()
         if self._deallocate:
             del p
 
     def annotations(self):
         """
-        Key value pairs of metadata, returned as a dictionary.
+        Key value pairs of metadata, returned as a Python dictionary.
         
         """
         ana = self._AnalysisObject().annotations()
@@ -45,7 +46,8 @@
     def updateAnnotations(self, E=None, **F):
         """
         AO.update([E, ]**F) -> None.  Update annotations of AO from
-        dict/iterable E and F.
+        dict/iterable E and F. Has the same semantics as Python's
+        dict.update(...).
 
         If E present and has a .keys() method:
             for k in E: AO[k] = E[k]
@@ -59,13 +61,13 @@
         if E is not None:
             if hasattr(E, 'keys'):
                 for k in E:
-                    set_ann(AO, k, E[k])
+                    set_annotation(AO, k, E[k])
             else:
                 for k, v in E:
-                    set_ann(AO, k, v)
+                    set_annotation(AO, k, v)
 
         for k in F:
-            set_ann(AO, k, F[k])
+            set_annotation(AO, k, F[k])
 
     property path:
         """

Modified: trunk/pyext/yoda/include/Axis1D_BIN1D_DBN.pyx
==============================================================================
--- trunk/pyext/yoda/include/Axis1D_BIN1D_DBN.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/Axis1D_BIN1D_DBN.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -1,3 +1,5 @@
+# TODO (when there is absolutely nothing else to do) docstrings (but never will
+# it be a user facing class... it's merely there for tests)
 cdef class Axis1D_${BIN1D}_${DBN}(util.Base):
 
     def __init__(self, size_t nbins, double lower, double upper):
@@ -34,7 +36,7 @@
     def reset(self):
         self._Axis1D().reset()
 
-    def bin_at(self, x):
+    def binByCoord(self, x):
         return self[self._Axis1D().getBinIndex(x)]
 
     # BOILERPLATE STUFF

Modified: trunk/pyext/yoda/include/Axis2D_BIN2D_DBN.pyx
==============================================================================
--- trunk/pyext/yoda/include/Axis2D_BIN2D_DBN.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/Axis2D_BIN2D_DBN.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -1,3 +1,5 @@
+# TODO (when there is absolutely nothing else to do) docstrings (but never will
+# it be a user facing class... it's merely there for tests)
 cdef class Axis2D_${BIN2D}_${DBN}(util.Base):
 
     def __init__(self, nx, xl, xu, ny, yl, yu):

Modified: trunk/pyext/yoda/include/Bin2D_DBN.pyx
==============================================================================
--- trunk/pyext/yoda/include/Bin2D_DBN.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/Bin2D_DBN.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -1,4 +1,5 @@
 
+#TODO docstrings
 cdef class Bin2D_${DBN}(Bin):
     """1D Bin class templated on a ${DBN}"""
 

Modified: trunk/pyext/yoda/include/Dbn1D.pyx
==============================================================================
--- trunk/pyext/yoda/include/Dbn1D.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/Dbn1D.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -50,12 +50,12 @@
         return (self._Dbn1D().xVariance())
 
     @property
-    def std_dev(self):
+    def stdDev(self):
         """Weighted standard deviation of x"""
         return (self._Dbn1D().xStdDev())
 
     @property
-    def std_err(self):
+    def stdErr(self):
         """Weighted standard error on <x>"""
         return (self._Dbn1D().xStdErr())
 
@@ -65,33 +65,33 @@
         return (self._Dbn1D().xRMS())
 
     @property
-    def count(self):
+    def numEntries(self):
         """The number of entries"""
         return self._Dbn1D().numEntries()
 
     @property
-    def effective_count(self):
+    def effNumEntries(self):
         """Effective number of entries (for weighted events)"""
-        return self._Dbn1D().numEntries()
+        return self._Dbn1D().effNumEntries()
 
     @property
-    def sum_w(self):
+    def sumW(self):
         """sum(weights)"""
         return self._Dbn1D().sumW()
 
     @property
-    def sum_w2(self):
-        """sum(weights**2)"""
+    def sumW2(self):
+        """sum(weights * weights)"""
         return self._Dbn1D().sumW2()
 
     @property
-    def sum_wx(self):
+    def sumWX(self):
         """sum(weights * xs)"""
         return self._Dbn1D().sumWX()
 
     @property
-    def sum_wx2(self):
-        """sum(weights * xs**2)"""
+    def sumWX2(self):
+        """sum(weights * xs * xs)"""
         return self._Dbn1D().sumWX2()
 
     def __add__(Dbn1D self, Dbn1D other):
@@ -103,7 +103,7 @@
             deref(self._Dbn1D()) - deref(other._Dbn1D())))
 
     def __repr__(self):
-        return 'Dbn1D(mean=%g, stdDev=%g)' % (self.mean, self.stdDev)
+        return '<Dbn1D(mean=%g, stdDev=%g)>' % (self.mean, self.stdDev)
 
     # Magic stuff
     cdef c.Dbn1D *_Dbn1D(self) except NULL:

Modified: trunk/pyext/yoda/include/Dbn2D.pyx
==============================================================================
--- trunk/pyext/yoda/include/Dbn2D.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/Dbn2D.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -21,25 +21,6 @@
         """
         self._Dbn2D().fill(x, y, weight)
 
-    def fill_many(self, xs, ys, ws=repeat(1)):
-        """
-        (xs, ys, ws=repeat(1.0)) -> None
-
-        Fills the distribution from iterables xs, ys and ws.
-
-        """
-        cdef c.Dbn2D *ptr = self._Dbn2D()
-        itx = iter(xs)
-        ity = iter(ys)
-        itw = iter(ws)
-        while True:
-            x = next(xs, None)
-            y = next(ys, None)
-            w = next(ws, None)
-            if x is None or y is None or w is None:
-                break
-            ptr.fill(x, y, w)
-
     def reset(self):
         """
         () -> None
@@ -74,12 +55,12 @@
         return util.XY(self._Dbn2D().xVariance(), self._Dbn2D().yVariance())
 
     @property
-    def std_dev(self):
+    def stdDev(self):
         """Weighted standard deviation of x"""
         return util.XY(self._Dbn2D().xStdDev(), self._Dbn2D().yStdDev())
 
     @property
-    def std_err(self):
+    def stdErr(self):
         """Weighted standard error on <x>"""
         return util.XY(self._Dbn2D().xStdErr(), self._Dbn2D().yStdErr())
 
@@ -89,47 +70,47 @@
         return util.XY(self._Dbn2D().xRMS(), self._Dbn2D().yRMS())
 
     @property
-    def count(self):
+    def numEntries(self):
         """The number of entries"""
         return self._Dbn2D().numEntries()
 
     @property
-    def effective_count(self):
+    def effNumEntries(self):
         """Effective number of entries (for weighted events)"""
         return self._Dbn2D().effNumEntries()
 
     @property
-    def sum_w(self):
+    def sumW(self):
         """sum(weights)"""
         return self._Dbn2D().sumW()
 
     @property
-    def sum_w2(self):
-        """sum(weights**2)"""
+    def sumW2(self):
+        """sum(weights * weights)"""
         return self._Dbn2D().sumW2()
 
     @property
-    def sum_wx(self):
+    def sumWX(self):
         """sum(weights * xs)"""
         return self._Dbn2D().sumWX()
 
     @property
-    def sum_wy(self):
+    def sumWY(self):
         """sum(weights * ys)"""
         return self._Dbn2D().sumWY()
 
     @property
-    def sum_wx2(self):
-        """sum(weights * xs**2)"""
+    def sumWX2(self):
+        """sum(weights * xs * xs)"""
         return self._Dbn2D().sumWX2()
 
     @property
-    def sum_wy2(self):
-        """sum(weights * ys**2)"""
+    def sumWY2(self):
+        """sum(weights * ys * ys)"""
         return self._Dbn2D().sumWY2()
 
     @property
-    def sum_wxy(self):
+    def sumWXY(self):
         """sum(weights xs * ys)"""
         return self._Dbn2D().sumWXY()
 
@@ -142,7 +123,7 @@
             deref(self._Dbn2D()) - deref(other._Dbn2D())))
 
     def __repr__(self):
-        return 'Dbn2D(mean=(%g, %g), stdDev=(%g, %g))' % (self.mean + self.std_dev)
+        return '<Dbn2D(mean=(%g, %g), stdDev=(%g, %g))>' % (self.mean + self.std_dev)
 
     # Magic stuff
     cdef c.Dbn2D *_Dbn2D(self) except NULL:

Modified: trunk/pyext/yoda/include/Dbn3D.pyx
==============================================================================
--- trunk/pyext/yoda/include/Dbn3D.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/Dbn3D.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -22,28 +22,6 @@
         """
         self._Dbn3D().fill(x, y, z, weight)
 
-    def fill_many(self, xs, ys, zs, ws=repeat(1)):
-        """
-        (xs, ys, ws=repeat(1.0)) -> None
-
-        Fills the distribution from iterables xs, ys and ws.
-
-        """
-        cdef c.Dbn3D *ptr = self._Dbn3D()
-        itx = iter(xs)
-        ity = iter(ys)
-        itz = iter(zs)
-        itw = iter(ws)
-        while True:
-            x = next(xs, None)
-            y = next(ys, None)
-            z = next(zs, None)
-            w = next(ws, None)
-            if x is None or y is None or w is None:
-                break
-            ptr.fill(x, y, z, w)
-
-
     def reset(self):
         """
         () -> None
@@ -53,9 +31,9 @@
 
     def scale(self, x=1.0, y=1.0, z=1.0, w=1.0):
         """
-        (x=1.0, y=1.0, w=1.0) -> None
+        (x=1.0, y=1.0, z=1.0, w=1.0) -> None
 
-        Scale Dbn3D's parameters
+        Scale Dbn3D's x, y, z and/or weight parameters.
 
         """
         if x != 1.0 and y != 1.0 and z != 1.0:
@@ -86,14 +64,14 @@
                         self._Dbn3D().zVariance())
 
     @property
-    def std_dev(self):
+    def stdDev(self):
         """Weighted standard deviation of x"""
         return util.XYZ(self._Dbn3D().xStdDev(),
                         self._Dbn3D().yStdDev(),
                         self._Dbn3D().zStdDev())
 
     @property
-    def std_err(self):
+    def stdErr(self):
         """Weighted standard error on <x>"""
         return util.XYZ(self._Dbn3D().xStdErr(),
                         self._Dbn3D().yStdErr(),
@@ -107,75 +85,70 @@
                        self._Dbn3D().zRMS())
 
     @property
-    def count(self):
+    def numEntries(self):
         """The number of entries"""
         return self._Dbn3D().numEntries()
 
     @property
-    def effective_count(self):
+    def effNumEntries(self):
         """Effective number of entries (for weighted events)"""
         return self._Dbn3D().effNumEntries()
 
     @property
-    def sum_w(self):
+    def sumW(self):
         """sum(weights)"""
         return self._Dbn3D().sumW()
 
     @property
-    def sum_w2(self):
-        """sum(weights**2)"""
+    def sumW2(self):
+        """sum(weights * weights)"""
         return self._Dbn3D().sumW2()
 
     @property
-    def sum_wx(self):
+    def sumWX(self):
         """sum(weights * xs)"""
         return self._Dbn3D().sumWX()
 
     @property
-    def sum_wy(self):
+    def sumWY(self):
         """sum(weights * ys)"""
         return self._Dbn3D().sumWY()
 
     @property
-    def sum_wz(self):
-        """sum(weights * ys)"""
+    def sumWZ(self):
+        """sum(weights * zs)"""
         return self._Dbn3D().sumWZ()
 
     @property
-    def sum_wx2(self):
-        """sum(weights * xs**2)"""
+    def sumWX2(self):
+        """sum(weights * xs * xs)"""
         return self._Dbn3D().sumWX2()
 
     @property
-    def sum_wy2(self):
-        """sum(weights * ys**2)"""
+    def sumWY2(self):
+        """sum(weights * ys * ys)"""
         return self._Dbn3D().sumWY2()
 
     @property
-    def sum_wz2(self):
-        """sum(weights * ys)"""
+    def sumWZ2(self):
+        """sum(weights * zs * zs")"""
         return self._Dbn3D().sumWZ2()
 
     @property
-    def sum_wxy(self):
-        """sum(weights xs * ys)"""
+    def sumWXY(self):
+        """sum(weights * xs * ys)"""
         return self._Dbn3D().sumWXY()
 
     @property
-    def sum_wxz(self):
-        """sum(weights xs * ys)"""
+    def sumWXZ(self):
+        """sum(weights * xs * zs)"""
         return self._Dbn3D().sumWXZ()
 
     @property
-    def sum_wyz(self):
-        """sum(weights xs * ys)"""
+    def sumWYZ(self):
+        """sum(weights * ys * zs)"""
         return self._Dbn3D().sumWYZ()
 
-    @property
-    def sum_wxyz(self):
-        """sum(weights xs * ys)"""
-        return self._Dbn3D().sumWXYZ()
-
     def __add__(Dbn3D self, Dbn3D other):
         return util.new_owned_cls(Dbn3D, new c.Dbn3D(
             deref(self._Dbn3D()) + deref(other._Dbn3D())))

Modified: trunk/pyext/yoda/include/Histo2D.pyx
==============================================================================
--- trunk/pyext/yoda/include/Histo2D.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/Histo2D.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -1,3 +1,5 @@
+#TODO tidy up when Axis2D is fixed
+
 cdef class Histo2D(AnalysisObject):
 
     cdef inline c.Histo2D *_Histo2D(self) except NULL:

Modified: trunk/pyext/yoda/include/HistoBin1D.pyx
==============================================================================
--- trunk/pyext/yoda/include/HistoBin1D.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/HistoBin1D.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -7,23 +7,56 @@
         util.set_owned_ptr(
             self, new c.HistoBin1D(a, b))
         
-    def fill(self, double value, double weight=1.0):
-        self._HistoBin1D().fill(value, weight)
+    def fill(self, value=None, double weight=1.0):
+        """
+        (value=None, weight=1.0)
+
+        Fill this bin with the given value and given weight. If value is None,
+        fill at the midpoint of the bin.
+        """
+        try:
+            self._HistoBin1D().fill(value, weight)
+        except TypeError:
+            self._HistoBin1D().fillBin(weight)
 
     @property
     def area(self):
+        """
+        b.area <==> b.sumW
+
+        The area of the bin is the sum of weights of the bin; it is
+        independent of width.
+
+        """
         return self._HistoBin1D().area()
 
     @property
     def height(self):
+        """
+        b.height <==> b.area / b.width
+
+        The height of the bin is defined as the area divided by the
+        width.
+
+        """
         return self._HistoBin1D().height()
 
     @property
     def areaErr(self):
+        """
+        Error computed using binomial statistics on squared sum of bin
+        weights, i.e. s.areaErr = sqrt(s.sumW2)
+
+        """
         return self._HistoBin1D().areaErr()
 
     @property
     def heightErr(self):
+        """
+        Height error - scales the s.areaError by the reciprocal of the
+        bin width.
+
+        """
         return self._HistoBin1D().heightErr()
 
     def __add__(HistoBin1D a, HistoBin1D b):

Modified: trunk/pyext/yoda/include/HistoBin2D.pyx
==============================================================================
--- trunk/pyext/yoda/include/HistoBin2D.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/HistoBin2D.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -1,3 +1,4 @@
+# TODO: tidy once we have a working Histo2D
 cdef class HistoBin2D(Bin2D_Dbn2D):
 
     cdef inline c.HistoBin2D *_HistoBin2D(self) except NULL:

Modified: trunk/pyext/yoda/include/IO.pyx
==============================================================================
--- trunk/pyext/yoda/include/IO.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/IO.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -1,4 +1,11 @@
 # Readers and writers
+# TODO: (low priority) refactor to improve readability.
+
+# The basic idea here is to provide Python IO semantics by using Python to do
+# the IO. Otherwise we get C++ IO semantics in Python. It also means we can use
+# dummy files, e.g. anything with read/write attirbutes. Generally a much better
+# idea than just "give this a filename", and well worth the inefficiencies and
+# potential memory limits.
 
 cdef list aobjects_to_list(vector[c.AnalysisObject*] *aobjects):
     cdef list out = []

Modified: trunk/pyext/yoda/include/Point2D.pyx
==============================================================================
--- trunk/pyext/yoda/include/Point2D.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/Point2D.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -28,6 +28,7 @@
         return util.new_owned_cls(Point2D,
                                   new c.Point2D(deref(self._Point2D())))
 
+
     property x:
         """x coordinate"""
         def __get__(self):
@@ -35,6 +36,7 @@
 
         def __set__(self, x):
             self._Point2D().setX(x)
+            
 
     property y:
         """y coordinate"""
@@ -44,6 +46,7 @@
         def __set__(self, y):
             self._Point2D().setY(y)
 
+
     property coords:
         """x and y coordinates as a tuple"""
         def __get__(self):
@@ -52,12 +55,25 @@
         def __set__(self, val):
             self.x, self.y = val
 
+
     property xRange:
-        """The minimum and maximum points within the error"""
+        """The minimum and maximum points within the x errors"""
         def __get__(self):
             return util.Edges(self._Point2D().xMin(),
                               self._Point2D().xMax())
 
+    property yRange:
+        """The minimum and maximum points within the y errors"""
+        def __get__(self):
+            return util.Edges(self._Point2D().yMin(),
+                              self._Point2D().yMax())
+
+    property ranges:
+        """The x- and y-ranges"""
+        def __get__(self):
+            return util.XY(self.xRange, self.yRange)
+
+
     property xErrs:
         """The x errors"""
         def __get__(self):
@@ -66,6 +82,7 @@
         def __set__(self, val):
             self._Point2D().setXErr(read_symmetric(val))
 
+
     property yErrs:
         """The y errors"""
         def __get__(self):
@@ -74,6 +91,7 @@
         def __set__(self, val):
             self._Point2D().setYErr(read_symmetric(val))
 
+
     property errs:
         """The x and y errors as a tuple"""
         def __get__(self):
@@ -95,7 +113,7 @@
         """
         (x=1.0, y=1.0) -> None
 
-        Scale the Dbn's variables by the given factors
+        Scale the Point's variables by the given factors.
 
         """
         self._Point2D().scale(x, y)

Modified: trunk/pyext/yoda/include/Point3D.pyx
==============================================================================
--- trunk/pyext/yoda/include/Point3D.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/Point3D.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -1,6 +1,8 @@
 from collections import namedtuple
 from libcpp cimport bool
 
+# TODO: make more consistent with Point2D
+
 cdef class Point3D(util.Base):
     """
     A 1D distribution 'counter', used and exposed by 1D histograms and their bins.

Modified: trunk/pyext/yoda/include/Profile1D.pyx
==============================================================================
--- trunk/pyext/yoda/include/Profile1D.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/Profile1D.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -1,4 +1,5 @@
 #TODO: docstrings!!!
+#TODO: introduce better constructors
 
 cdef class Profile1D(AnalysisObject):
     cdef inline c.Profile1D *_Profile1D(self) except NULL:
@@ -32,36 +33,9 @@
     def __repr__(self):
         return "<Profile1D at %x>" % id(self)
 
-    def fill(self, double x, double y, double weight=1.0):
+    def fill(self, x, y, weight=1.0):
         self._Profile1D().fill(x, y, weight)
 
-    def fillMany(self, xs, ys, ws=None):
-        cdef double x, y, w
-        cdef c.Profile1D *p = self._Profile1D()
-
-        itx = iter(xs)
-        ity = iter(ys)
-        if ws:
-            itw = iter(ws)
-            while True:
-                try:
-                    x = next(itx, None)
-                    y = next(ity, None)
-                    w = next(itw, None)
-                except TypeError:
-                    break
-                else:
-                    p.fill(x, y, w)
-        else:
-            while True:
-                try:
-                    x = next(itx, None)
-                    y = next(ity, None)
-                except TypeError:
-                    break
-                else:
-                    p.fill(x, y, 1.0)
-
     def copy(self, char *path=""):
         return util.new_owned_cls(Profile1D,
             new c.Profile1D(deref(self._Profile1D()), string(path)))
@@ -98,7 +72,7 @@
     def rebin(self, int n):
         self._Profile1D().rebin(n)
 
-    def addBin(self, double low, double high):
+    def addBin(self, low, high):
         """Add a bin to the Profile1D"""
         self._Profile1D().addBin(low, high)
         return self

Modified: trunk/pyext/yoda/include/Profile2D.pyx
==============================================================================
--- trunk/pyext/yoda/include/Profile2D.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/Profile2D.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -1,3 +1,4 @@
+#TODO rewrite when we have a Profile2D
 cdef class Profile2D(AnalysisObject):
     cdef inline c.Profile2D *_Profile2D(self) except NULL:
         return <c.Profile2D*> self.ptr()

Modified: trunk/pyext/yoda/include/ProfileBin1D.pyx
==============================================================================
--- trunk/pyext/yoda/include/ProfileBin1D.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/ProfileBin1D.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -1,44 +1,74 @@
 cdef class ProfileBin1D(Bin1D_Dbn2D):
+    """
+    A 1D profile bin, as stored inside Profile1D.
 
-    cdef inline c.ProfileBin1D *_ProfileBin1D(self) except NULL:
-        return <c.ProfileBin1D *> self.ptr()
+    Only one constructor:
+
+    * ProfileBin1D(xlow, xhigh)
+    """
 
     def __init__(self, double a, double b):
         util.set_owned_ptr(
             self, new c.ProfileBin1D(a, b))
 
-    def fill(self, double x, double y, double weight=1.0):
+    def fill(self, x, y, weight=1.0):
+        """
+        (x, y, weight=1.0) -> None. Fill this bin with given values and weight.
+
+        """
         self._ProfileBin1D().fill(x, y, weight)
 
-    def fill_bin(self, double y, double weight=1.0):
+    def fillBin(self, y, weight=1.0):
+        """
+        (y, weight=1.0) -> None. Fill this bin with given y-value and weight.
+
+        """
         self._ProfileBin1D().fillBin(y, weight)
 
+    def scale(self, x=1.0, w=1.0):
+        """
+        (x=1.0, w=1.0) -> None
+        
+        Scale values by given coefficients.
+        """
+        if x != 1.0:
+            self._ProfileBin1D().scaleX(x)
+        if w != 1.0:
+            self._ProfileBin1D().scaleW(w)
+
     @property
     def mean(self):
+        """The mean of the y-values that have filled the bin."""
         return self._ProfileBin1D().mean()
 
     @property
-    def stdDev(self):
-        return self._ProfileBin1D().stdDev()
-
-    @property
     def variance(self):
+        """The variance of the y-values that have filled the bin."""
         return self._ProfileBin1D().variance()
 
     @property
+    def stdDev(self):
+        """The standard deviation of the y-values that have filled the bin."""
+        return self._ProfileBin1D().stdDev()
+
+    @property
     def stdErr(self):
+        """The standard error of the y-values that have filled the bin."""
         return self._ProfileBin1D().stdErr()
 
     @property
     def rms(self):
+        """The RMS of the y-values that have filled the bin."""
         return self._ProfileBin1D().rms()
 
     @property
     def sumWY(self):
+        """sum(weights * ys)"""
         return self._ProfileBin1D().sumWY()
 
     @property
     def sumWY2(self):
+        """sum(weights * ys * ys)"""
         return self._ProfileBin1D().sumWY2()
 
     def __add__(ProfileBin1D a, ProfileBin1D b):
@@ -54,3 +84,7 @@
             new c.ProfileBin1D(
                 deref(a._ProfileBin1D()) -
                 deref(b._ProfileBin1D())))
+
+    cdef inline c.ProfileBin1D *_ProfileBin1D(self) except NULL:
+        return <c.ProfileBin1D *> self.ptr()
+

Modified: trunk/pyext/yoda/include/ProfileBin2D.pyx
==============================================================================
--- trunk/pyext/yoda/include/ProfileBin2D.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/ProfileBin2D.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -1,3 +1,4 @@
+#TODO improve this once we have a working Profile2D
 cdef class ProfileBin2D(Bin2D_Dbn3D):
 
     cdef inline c.ProfileBin2D *_ProfileBin2D(self) except NULL:

Modified: trunk/pyext/yoda/include/Scatter2D.pyx
==============================================================================
--- trunk/pyext/yoda/include/Scatter2D.pyx	Fri Aug  3 10:18:51 2012	(r517)
+++ trunk/pyext/yoda/include/Scatter2D.pyx	Fri Aug  3 12:20:01 2012	(r518)
@@ -1,37 +1,11 @@
+#TODO: Tidy up + docstrings etc.
 
 cdef class Scatter2D(AnalysisObject):
     """
-    1D histogram. Complete histogramming is supported, including
-    uniform/regular binning, variable wideth bininng, unbinned gaps in
-    the covered range, and under/overflows. Rebinning by integer
-    factors, or by explicit merging of contiguous bins is also
-    supported.
-
-    Rescaling of weights and/or the x axis is permitted in-place: the
-    result is still a valid Scatter2D. Binning-compatible 1D histograms
-    may be divided, resulting in a Scatter2D since further fulls would
-    not be meaningful.
-
-    Several sets of arguments are tried by the constructor in the
-    following order.
-
-    Scatter2D(path="", title=""). Construct a histogram with optional path
-    and title but no bins.
+    2D Scatter plot.
 
-    Scatter2D(B, path="", title=""). Construct a histogram from an
-    iterator of bins, B.
-
-    Scatter2D(E, path="", title=""). Construct a histogram from an
-    iterator of edges, E.
-
-    Should this constructor fail, then 
-    Scatter2D(nbins, low, high, path="", title="")
     """
 
-    # Is there a reason why this sounds like an advert? I'M ALREADY SOLD
-    # DAMMIT!
-
-
     cdef inline c.Scatter2D *_Scatter2D(self) except NULL:
         return <c.Scatter2D*> self.ptr()
 
@@ -41,7 +15,6 @@
     # ([bins], **kwargs)
 
     def __init__(self, *args, **kwargs):
-        #try_loop([self.__init2, self.__init5, self.__init3], *args, **kwargs)
         util.try_loop([self.__init_2, self.__init_3], *args, **kwargs)
 
     def __init_2(self, char* path="", char* title=""):


More information about the yoda-svn mailing list