[Scipy-svn] r6404 - trunk/scipy/misc

scipy-svn at scipy.org scipy-svn at scipy.org
Mon May 24 09:10:27 EDT 2010


Author: rgommers
Date: 2010-05-24 08:10:27 -0500 (Mon, 24 May 2010)
New Revision: 6404

Modified:
   trunk/scipy/misc/common.py
   trunk/scipy/misc/pilutil.py
Log:
DOC: merge wiki edits - misc module.

Modified: trunk/scipy/misc/common.py
===================================================================
--- trunk/scipy/misc/common.py	2010-05-24 13:10:10 UTC (rev 6403)
+++ trunk/scipy/misc/common.py	2010-05-24 13:10:27 UTC (rev 6404)
@@ -93,9 +93,31 @@
         return vals
 
 def factorialk(n,k,exact=1):
-    """n(!!...!)  = multifactorial of order k
-        k times
     """
+    n(!!...!)  = multifactorial of order k
+    k times
+
+
+    Parameters
+    ----------
+    n : int, array-like
+        Calculate multifactorial. Arrays are only supported with exact
+        set to False. If n < 0, the return value is 0.
+    exact : bool, optional
+        If exact is set to True, calculate the answer exactly using
+        integer arithmetic.
+
+    Returns
+    -------
+    val : int
+        Multi factorial of n.
+
+    Raises
+    ------
+    NotImplementedError
+        Raises when exact is False
+
+    """
     if exact:
         if n < 1-k:
             return 0L
@@ -110,14 +132,29 @@
 
 
 def comb(N,k,exact=0):
-    """Combinations of N things taken k at a time.
+    """
+    Combinations of N things taken k at a time.
 
-    If exact==0, then floating point precision is used, otherwise
-    exact long integer is computed.
+    Parameters
+    ----------
+    N : int, array
+        Nunmber of things.
+    k : int, array
+        Numner of elements taken.
+    exact : int, optional
+        If exact is 0, then floating point precision is used, otherwise
+        exact long integer is computed.
 
-    Notes:
-      - Array arguments accepted only for exact=0 case.
-      - If k > N, N < 0, or k < 0, then a 0 is returned.
+    Returns
+    -------
+    val : int, array
+        The total number of combinations.
+
+    Notes
+    -----
+    - Array arguments accepted only for exact=0 case.
+    - If k > N, N < 0, or k < 0, then a 0 is returned.
+
     """
     if exact:
         if (k > N) or (N < 0) or (k < 0):
@@ -137,13 +174,17 @@
         return where(cond, vals, 0.0)
 
 def central_diff_weights(Np,ndiv=1):
-    """Return weights for an Np-point central derivative of order ndiv
-       assuming equally-spaced function points.
+    """
+    Return weights for an Np-point central derivative of order ndiv
+    assuming equally-spaced function points.
 
-       If weights are in the vector w, then
-       derivative is w[0] * f(x-ho*dx) + ... + w[-1] * f(x+h0*dx)
+    If weights are in the vector w, then
+    derivative is w[0] * f(x-ho*dx) + ... + w[-1] * f(x+h0*dx)
 
-       Can be inaccurate for large number of points.
+    Notes
+    -----
+    Can be inaccurate for large number of points.
+
     """
     assert (Np >= ndiv+1), "Number of points must be at least the derivative order + 1."
     assert (Np % 2 == 1), "Odd-number of points only."
@@ -158,13 +199,31 @@
     return w
 
 def derivative(func,x0,dx=1.0,n=1,args=(),order=3):
-    """Given a function, use a central difference formula with spacing dx to
-       compute the nth derivative at x0.
+    """
+    Find the n-th derivative of a function at point x0.
 
-       order is the number of points to use and must be odd.
+    Given a function, use a central difference formula with spacing `dx` to
+    compute the n-th derivative at `x0`.
 
-       Warning: Decreasing the step size too small can result in
-       round-off error.
+    Parameters
+    ----------
+    func : function
+        Input function.
+    x0 : float
+        The point at which nth derivative is found.
+    dx : int, optional
+        Spacing.
+    n : int, optional
+        Order of the derivative. Default is 1.
+    args : tuple, optional
+        Arguments
+    order : int, optional
+        Number of points to use, must be odd.
+
+    Notes
+    -----
+    Decreasing the step size too small can result in round-off error.
+
     """
     assert (order >= n+1), "Number of points must be at least the derivative order + 1."
     assert (order % 2 == 1), "Odd number of points only."

Modified: trunk/scipy/misc/pilutil.py
===================================================================
--- trunk/scipy/misc/pilutil.py	2010-05-24 13:10:10 UTC (rev 6403)
+++ trunk/scipy/misc/pilutil.py	2010-05-24 13:10:27 UTC (rev 6404)
@@ -15,6 +15,22 @@
 
 # Returns a byte-scaled image
 def bytescale(data, cmin=None, cmax=None, high=255, low=0):
+    """
+    Parameters
+    ----------
+    im : PIL image
+         Input image.
+    flatten : bool
+              If true, convert the output to grey-scale
+
+    Returns
+    -------
+    img_array : ndarray
+                The different colour bands/channels are stored in the
+                third dimension, such that a grey-image is MxN, an
+                RGB-image MxNx3 and an RGBA-image MxNx4.
+
+    """
     if data.dtype == uint8:
         return data
     high = high - low
@@ -25,39 +41,72 @@
     return bytedata + cast[uint8](low)
 
 def imread(name,flatten=0):
-    """Read an image file from a filename.
+    """
+    Read an image file from a filename.
 
-    Optional arguments:
+    Parameters
+    ----------
+    name : str
+        The file name to be read.
+    flatten : bool, optional
+        If True, flattens the color layers into a single gray-scale layer.
 
-     - flatten (0): if true, the image is flattened by calling convert('F') on
-     the resulting image object.  This flattens the color layers into a single
-     grayscale layer.
+    Returns
+    -------
+     : nd_array
+        The array obtained by reading image.
+
+    Notes
+    -----
+    The image is flattened by calling convert('F') on
+    the resulting image object.
+
     """
 
     im = Image.open(name)
     return fromimage(im,flatten=flatten)
 
 def imsave(name, arr):
-    """Save an array to an image file.
     """
+    Save an array to an image file.
+
+    Parameters
+    ----------
+    im : PIL image
+         Input image.
+
+    flatten : bool
+         If true, convert the output to grey-scale.
+
+    Returns
+    -------
+    img_array : ndarray
+                The different colour bands/channels are stored in the
+                third dimension, such that a grey-image is MxN, an
+                RGB-image MxNx3 and an RGBA-image MxNx4.
+
+    """
     im = toimage(arr)
     im.save(name)
     return
 
 def fromimage(im, flatten=0):
-    """Return a copy of a PIL image as a numpy array.
+    """
+    Return a copy of a PIL image as a numpy array.
 
-    :Parameters:
-        im : PIL image
-            Input image.
-        flatten : bool
-            If true, convert the output to grey-scale.
+    Parameters
+    ----------
+    im : PIL image
+        Input image.
+    flatten : bool
+        If true, convert the output to grey-scale.
 
-    :Returns:
-        img_array : ndarray
-            The different colour bands/channels are stored in the
-            third dimension, such that a grey-image is MxN, an
-            RGB-image MxNx3 and an RGBA-image MxNx4.
+    Returns
+    -------
+    img_array : ndarray
+        The different colour bands/channels are stored in the
+        third dimension, such that a grey-image is MxN, an
+        RGB-image MxNx3 and an RGBA-image MxNx4.
 
     """
     if not Image.isImageType(im):
@@ -171,12 +220,33 @@
     return image
 
 def imrotate(arr,angle,interp='bilinear'):
-    """Rotate an image counter-clockwise by angle degrees.
+    """
+    Rotate an image counter-clockwise by angle degrees.
 
+    Parameters
+    ----------
+    arr : nd_array
+        Input array of image to be rotated.
+    angle : float
+        The angle of rotation.
+    interp : str, optional
+        Interpolation
+
+
+    Returns
+    -------
+     : nd_array
+        The rotated array of image.
+
+    Notes
+    -----
+
     Interpolation methods can be:
-        'nearest' :  for nearest neighbor
-        'bilinear' : for bilinear
-        'cubic' or 'bicubic' : for bicubic
+    * 'nearest' :  for nearest neighbor
+    * 'bilinear' : for bilinear
+    * 'cubic' : cubic
+    * 'bicubic' : for bicubic
+
     """
     arr = asarray(arr)
     func = {'nearest':0,'bilinear':2,'bicubic':3,'cubic':3}
@@ -215,11 +285,25 @@
         raise RuntimeError('Could not execute image viewer.')
 
 def imresize(arr,size):
-    """Resize an image.
+    """
+    Resize an image.
 
-    If size is an integer it is a percentage of current size.
-    If size is a float it is a fraction of current size.
-    If size is a tuple it is the size of the output image.
+    Parameters
+    ----------
+    arr : nd_array
+        The array of image to be resized.
+
+    size : int, float or tuple
+        * int   - Percentage of current size.
+        * float - Fraction of current size.
+        * tuple - Size of the output image.
+
+    Returns
+    -------
+
+     : nd_array
+        The resized array of image.
+
     """
     im = toimage(arr)
     ts = type(size)
@@ -234,11 +318,29 @@
 
 
 def imfilter(arr,ftype):
-    """Simple filtering of an image.
+    """
+    Simple filtering of an image.
 
-    type can be:
-            'blur', 'contour', 'detail', 'edge_enhance', 'edge_enhance_more',
-            'emboss', 'find_edges', 'smooth', 'smooth_more', 'sharpen'
+    Parameters
+    ----------
+    arr : ndarray
+        The array of Image in which the filter is to be applied.
+    ftype : str
+        The filter that has to be applied. Legal values are:
+        'blur', 'contour', 'detail', 'edge_enhance', 'edge_enhance_more',
+        'emboss', 'find_edges', 'smooth', 'smooth_more', 'sharpen'.
+
+    Returns
+    -------
+    res : nd_array
+        The array with filter applied.
+
+    Raises
+    ------
+    ValueError
+        *Unknown filter type.* . If the filter you are trying
+        to apply is unsupported.
+
     """
     _tdict = {'blur':ImageFilter.BLUR,
               'contour':ImageFilter.CONTOUR,




More information about the Scipy-svn mailing list