[Scipy-svn] r6403 - in trunk/scipy/io: . matlab

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


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

Modified:
   trunk/scipy/io/data_store.py
   trunk/scipy/io/matlab/byteordercodes.py
   trunk/scipy/io/matlab/miobase.py
   trunk/scipy/io/mmio.py
   trunk/scipy/io/wavfile.py
Log:
DOC: merge wiki edits - io module.

Modified: trunk/scipy/io/data_store.py
===================================================================
--- trunk/scipy/io/data_store.py	2010-05-24 13:09:52 UTC (rev 6402)
+++ trunk/scipy/io/data_store.py	2010-05-24 13:10:10 UTC (rev 6403)
@@ -86,9 +86,17 @@
 
 
 def save_as_module(file_name=None,data=None):
-    """ Save the dictionary "data" into
-        a module and shelf named save
     """
+    Save the dictionary "data" into a module and shelf named save.
+
+    Parameters
+    ----------
+    file_name : str, optional
+        File name of the module to save.
+    data : dict, optional
+        The dictionary to store in the module.
+
+    """
     _create_module(file_name)
     _create_shelf(file_name,data)
 

Modified: trunk/scipy/io/matlab/byteordercodes.py
===================================================================
--- trunk/scipy/io/matlab/byteordercodes.py	2010-05-24 13:09:52 UTC (rev 6402)
+++ trunk/scipy/io/matlab/byteordercodes.py	2010-05-24 13:10:10 UTC (rev 6403)
@@ -18,21 +18,23 @@
            'swapped': ('swapped', 'S')}
 
 def to_numpy_code(code):
-    ''' Convert various order codings to numpy format
+    """
+    Convert various order codings to numpy format.
+
     Parameters
     ----------
-    code : {'little','big','l','b','le','be','<','>',
-             'native','=',
-             'swapped', 's'} string
-          code is converted to lower case before parsing
+    code : str
+        The code to convert. It is converted to lower case before parsing.
+        Legal values are:
+        'little', 'big', 'l', 'b', 'le', 'be', '<', '>', 'native', '=',
+        'swapped', 's'.
 
     Returns
     -------
-    out_code : {'<','>'} string
-             where '<' is the numpy dtype code for little
-             endian, and '>' is the code for big endian
+    out_code : {'<', '>'}
+        Here '<' is the numpy dtype code for little endian,
+        and '>' is the code for big endian.
 
-
     Examples
     --------
     >>> import sys
@@ -48,7 +50,8 @@
     >>> sc = to_numpy_code('swapped')
     >>> sc == '>' if sys_is_le else sc == '<'
     True
-    '''
+
+    """
     code = code.lower()
     if code is None:
         return native_code

Modified: trunk/scipy/io/matlab/miobase.py
===================================================================
--- trunk/scipy/io/matlab/miobase.py	2010-05-24 13:09:52 UTC (rev 6402)
+++ trunk/scipy/io/matlab/miobase.py	2010-05-24 13:10:10 UTC (rev 6403)
@@ -148,11 +148,13 @@
 
 
 def read_dtype(mat_stream, a_dtype):
-    ''' Generic get of byte stream data of known type
+    """
+    Generic get of byte stream data of known type
 
     Parameters
     ----------
     mat_stream : file-like object
+        Matlam (TM) stream
     a_dtype : dtype
        dtype of array to read.  `a_dtype` is assumed to be correct
        endianness
@@ -160,7 +162,9 @@
     Returns
     -------
     arr : array
-    '''
+        Array of given datatype obtained from stream.
+
+    """
     num_bytes = a_dtype.itemsize
     arr = np.ndarray(shape=(),
                      dtype=a_dtype,
@@ -221,17 +225,32 @@
 
 
 def matdims(arr, oned_as='column'):
-    ''' Determine equivalent matlab dimensions for given array
+    """
+    Determine equivalent matlab dimensions for given array
 
     Parameters
     ----------
     arr : ndarray
-    oned_as : {'column', 'row'} string, optional
+        Input array.
+    oned_as : {'column', 'row'}, optional
+        Whether 1-D arrays are returned as Matlab row or column matrices.
+        Default is 'column'.
 
     Returns
     -------
-    dims : shape as matlab expects
+    dims : tuple
+        Shape tuple, in the form Matlab expects it.
 
+    Notes
+    -----
+    We had to decide what shape a 1 dimensional array would be by
+    default.  ``np.atleast_2d`` thinks it is a row vector.  The
+    default for a vector in matlab (e.g. ``>> 1:12``) is a row vector.
+
+    Versions of scipy up to and including 0.7 resulted (accidentally)
+    in 1-D arrays being read as column vectors.  For the moment, we
+    maintain the same tradition here.
+
     Examples
     --------
     >>> matdims(np.array(1)) # numpy scalar
@@ -253,7 +272,7 @@
     >>> matdims(np.array([[[]]])) # empty 3d
     (0, 0, 0)
 
-    Optional argument flips 1d shape behavior
+    Optional argument flips 1-D shape behavior.
 
     >>> matdims(np.array([1,2]), 'row') # 1d array, 2 elements
     (1, 2)
@@ -265,16 +284,7 @@
        ...
     ValueError: 1D option "bizarre" is strange
 
-    Notes
-    -----
-    We had to decide what shape a 1 dimensional array would be by
-    default.  ``np.atleast_2d`` thinks it is a row vector.  The
-    default for a vector in matlab (e.g. ``>> 1:12``) is a row vector.
-
-    Versions of scipy up to and including 0.7 resulted (accidentally)
-    in 1d arrays being read as column vectors.  For the moment, we
-    maintain the same tradition here.
-    '''
+    """
     if arr.size == 0: # empty
         return (0,) * np.max([arr.ndim, 2])
     shape = arr.shape

Modified: trunk/scipy/io/mmio.py
===================================================================
--- trunk/scipy/io/mmio.py	2010-05-24 13:09:52 UTC (rev 6402)
+++ trunk/scipy/io/mmio.py	2010-05-24 13:10:10 UTC (rev 6403)
@@ -18,50 +18,74 @@
 
 #-------------------------------------------------------------------------------
 def mminfo(source):
-    """ Queries the contents of the Matrix Market file 'filename' to
+    """
+    Queries the contents of the Matrix Market file 'filename' to
     extract size and storage information.
 
-    Inputs:
+    Parameters
+    ----------
 
-      source     - Matrix Market filename (extension .mtx) or open file object
+    source : file
+        Matrix Market filename (extension .mtx) or open file object
 
-    Outputs:
+    Returns
+    -------
 
-      rows,cols  - number of matrix rows and columns
-      entries    - number of non-zero entries of a sparse matrix
-                   or rows*cols for a dense matrix
-      format     - 'coordinate' | 'array'
-      field      - 'real' | 'complex' | 'pattern' | 'integer'
-      symm       - 'general' | 'symmetric' | 'skew-symmetric' | 'hermitian'
+    rows,cols : int
+       Number of matrix rows and columns
+    entries : int
+        Number of non-zero entries of a sparse matrix
+        or rows*cols for a dense matrix
+
+    format : {'coordinate', 'array'}
+
+    field : {'real', 'complex', 'pattern', 'integer'}
+
+    symm : {'general', 'symmetric', 'skew-symmetric', 'hermitian'}
+
     """
     return MMFile.info(source)
 
 #-------------------------------------------------------------------------------
 def mmread(source):
-    """ Reads the contents of a Matrix Market file 'filename' into a matrix.
+    """
+    Reads the contents of a Matrix Market file 'filename' into a matrix.
 
-    Inputs:
+    Parameters
+    ----------
 
-      source    - Matrix Market filename (extensions .mtx, .mtz.gz)
-                  or open file object.
+    source : file
+        Matrix Market filename (extensions .mtx, .mtz.gz)
+        or open file object.
 
-    Outputs:
+    Returns
+    -------
+    a:
+        Sparse or full matrix
 
-      a         - sparse or full matrix
     """
     return MMFile().read(source)
 
 #-------------------------------------------------------------------------------
 def mmwrite(target, a, comment='', field=None, precision=None):
-    """ Writes the sparse or dense matrix A to a Matrix Market formatted file.
+    """
+    Writes the sparse or dense matrix A to a Matrix Market formatted file.
 
-    Inputs:
+    Parameters
+    ----------
 
-      target    - Matrix Market filename (extension .mtx) or open file object
-      a         - sparse or full matrix
-      comment   - comments to be prepended to the Matrix Market file
-      field     - 'real' | 'complex' | 'pattern' | 'integer'
-      precision - Number of digits to display for real or complex values.
+    target : file
+        Matrix Market filename (extension .mtx) or open file object
+    a : array like
+        Sparse or full matrix
+    comment : str
+        comments to be prepended to the Matrix Market file
+
+    field : {'real', 'complex', 'pattern', 'integer'}, optional
+
+    precision :
+        Number of digits to display for real or complex values.
+
     """
     MMFile().write(target, a, comment, field, precision)
 

Modified: trunk/scipy/io/wavfile.py
===================================================================
--- trunk/scipy/io/wavfile.py	2010-05-24 13:09:52 UTC (rev 6402)
+++ trunk/scipy/io/wavfile.py	2010-05-24 13:10:10 UTC (rev 6403)
@@ -1,3 +1,13 @@
+"""
+Module to read / write wav files using numpy arrays
+
+Functions
+---------
+read: Return the sample rate (in samples/sec) and data from a WAV file.
+
+write: Write a numpy array as a WAV file.
+
+"""
 import numpy
 import struct
 import warnings
@@ -66,12 +76,30 @@
 
 # open a wave-file
 def read(file):
-    """Return the sample rate (in samples/sec) and data from a WAV file
+    """
+    Return the sample rate (in samples/sec) and data from a WAV file
 
-    The file can be an open file or a filename.
-    The returned sample rate is a Python integer
-    The data is returned as a numpy array with a
-        data-type determined from the file.
+    Parameters
+    ----------
+    file : file
+        Input wav file.
+
+    Returns
+    -------
+    rate : int
+        Sample rate of wav file
+    data : numpy array
+        Data read from wav file
+
+    Notes
+    -----
+
+    * The file can be an open file or a filename.
+
+    * The returned sample rate is a Python integer
+    * The data is returned as a numpy array with a
+      data-type determined from the file.
+
     """
     if hasattr(file,'read'):
         fid = file
@@ -98,16 +126,25 @@
 # Write a wave-file
 # sample rate, data
 def write(filename, rate, data):
-    """Write a numpy array as a WAV file
+    """
+    Write a numpy array as a WAV file
 
-    filename -- The name of the file to write (will be over-written)
-    rate -- The sample rate (in samples/sec).
-    data -- A 1-d or 2-d numpy array of integer data-type.
-            The bits-per-sample will be determined by the data-type
-            To write multiple-channels, use a 2-d array of shape
-            (Nsamples, Nchannels)
+    Parameters
+    ----------
+    filename : file
+        The name of the file to write (will be over-written).
+    rate : int
+        The sample rate (in samples/sec).
+    data : ndarray
+        A 1-D or 2-D numpy array of integer data-type.
 
-    Writes a simple uncompressed WAV file.
+    Notes
+    -----
+    * Writes a simple uncompressed WAV file.
+    * The bits-per-sample will be determined by the data-type.
+    * To write multiple-channels, use a 2-D array of shape
+      (Nsamples, Nchannels).
+
     """
     fid = open(filename, 'wb')
     fid.write('RIFF')




More information about the Scipy-svn mailing list