
 m[c           @` s'  d  Z  d d l m Z m Z m Z m Z d d l Z d d l m Z m	 Z	 m
 Z
 d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l j Z d d l m Z d d l m Z d d l Z e j r e Z n  e j d d d	 d
    Z d   Z d   Z d e  d  Z! e  e  d  Z" d d  Z# e  d  Z$ e  d  Z% d   Z& e  d d  Z' d d  Z( e  e  e  e  e  e  e  e  e  e  d 
 Z) e  e  e  e  d  Z* e j+ j, d e j- d   e j+ j, d e j- d   e j+ j, d e j- d   e j. e  e  e  e  e  e  e  e  d   Z/ e j. e  e  e  e  e  e  e  e  d   Z0 e j. e  e  e  e  d   Z1 e j. e  e  e  e  d    Z2 e j. e  e  e  e  d!   Z3 e j. e  e  e  e  d"   Z4 e j. e  e  e  e  e  e  e  e  e  d# 	  Z5 d$ Z6 e j. d% d& e% e d e  d' e  d(   Z7 e j d  d)    Z8 e j d d*  d% d& e% e d e9 e8 e: d+   Z; e j d d,  d-    Z< e j d d.  d/    Z= e j d  d0    Z> e j d  d1    Z? e j d  d2    Z@ e j d  d3 eA f d4     Y ZB e j d d5  d6 d7 d8 d9 d: f d;   ZC e j d  d<    ZD e j d  d d=   ZE e j d d>  d?    ZF e j d  d@ d@ d6 d6 d6 dA   ZG e j d  dB    ZH e j d  dC dD   ZI e j d dE  dF    ZJ e j d  dG    ZK e j d  dH    ZL e j d  e% e dI   ZM e j d  dJ    ZN e jO dK  ZP dL ZQ e j d dM  dN    ZR e j d d dO dP    ZS e j d  dQ    ZT e j d d dR dS    ZU e j d d dT dU    ZV e j d d dV d& dW   ZW e j d dX  e  e  dY   ZX e j d dZ  d& d[ e  d\   ZY e j d  d& d d]   ZZ e j d  d^ d_   Z[ e j d d`  e jO da  db   Z\ e j d  dc    Z] e j d  dd    Z^ e j d de  df    Z_ e j d dg  dh    Z` e j d  e  di   Za e j d  dj    Zb e j d  dk    Zc e j d  dl    Zd e j d  dm    Ze e j d  dn e  do dp dq   Zf e j d  dr d6 e  ds   Zg e j d  dt d d du e  e  dv e  e: e: e: dw   Zh e j d  dx eA f dy     Y Zi e j d  dz ei f d{     Y Zj e j d  d| ei f d}     Y Zk e j d  d~ ek f d     Y Zl e j d  d ei f d     Y Zm e j d  d ei f d     Y Zn e j d  d el f d     Y Zo e j d  d el f d     Y Zp e j d  d el f d     Y Zq e j d d d d ei f d     Y Zr e j d d d d er f d     Y Zs e j d  e  d   Zt e j d  d    Zu e j d d d e  d d e  d   Zv e j d d d du e  dv e  e9 d   Zw e j d d d d d   Zx e j d d d e: d   Zy e j d  d    Zz e j d  e  d   Z{ d eA f d     YZ| e j d  d    Z} e j d  d    Z~ e j d  d    Z e j d  d    Z e j d d d d    Z e j d  d    Z e j d  d    Z e j d  da e  d   Z e j d  d    Z e j d  d    Z e j d  d    Z e j d  d    Z d S(   u  

Numerical python functions written for compatibility with MATLAB
commands with the same names.

MATLAB compatible functions
---------------------------

:func:`cohere`
    Coherence (normalized cross spectral density)

:func:`csd`
    Cross spectral density using Welch's average periodogram

:func:`detrend`
    Remove the mean or best fit line from an array

:func:`find`
    Return the indices where some condition is true;
    numpy.nonzero is similar but more general.

:func:`griddata`
    Interpolate irregularly distributed data to a
    regular grid.

:func:`prctile`
    Find the percentiles of a sequence

:func:`prepca`
    Principal Component Analysis

:func:`psd`
    Power spectral density using Welch's average periodogram

:func:`rk4`
    A 4th order runge kutta integrator for 1D or ND systems

:func:`specgram`
    Spectrogram (spectrum over segments of time)

Miscellaneous functions
-----------------------

Functions that don't exist in MATLAB, but are useful anyway:

:func:`cohere_pairs`
    Coherence over all pairs.  This is not a MATLAB function, but we
    compute coherence a lot in my lab, and we compute it for a lot of
    pairs.  This function is optimized to do this efficiently by
    caching the direct FFTs.

:func:`rk4`
    A 4th order Runge-Kutta ODE integrator in case you ever find
    yourself stranded without scipy (and the far superior
    scipy.integrate tools)

:func:`contiguous_regions`
    Return the indices of the regions spanned by some logical mask

:func:`cross_from_below`
    Return the indices where a 1D array crosses a threshold from below

:func:`cross_from_above`
    Return the indices where a 1D array crosses a threshold from above

:func:`complex_spectrum`
    Return the complex-valued frequency spectrum of a signal

:func:`magnitude_spectrum`
    Return the magnitude of the frequency spectrum of a signal

:func:`angle_spectrum`
    Return the angle (wrapped phase) of the frequency spectrum of a signal

:func:`phase_spectrum`
    Return the phase (unwrapped angle) of the frequency spectrum of a signal

:func:`detrend_mean`
    Remove the mean from a line.

:func:`demean`
    Remove the mean from a line. This function is the same as
    :func:`detrend_mean` except for the default *axis*.

:func:`detrend_linear`
    Remove the best fit line from a line.

:func:`detrend_none`
    Return the original line.

:func:`stride_windows`
    Get all windows in an array in a memory-efficient manner

:func:`stride_repeat`
    Repeat an array in a memory-efficient manner

:func:`apply_window`
    Apply a window along a given axis


record array helper functions
-----------------------------

A collection of helper methods for numpyrecord arrays

.. _htmlonly:

    See :ref:`misc-examples-index`

:func:`rec2txt`
    Pretty print a record array

:func:`rec2csv`
    Store record array in CSV file

:func:`csv2rec`
    Import record array from CSV file with type inspection

:func:`rec_append_fields`
    Adds  field(s)/array(s) to record array

:func:`rec_drop_fields`
    Drop fields from record array

:func:`rec_join`
    Join two record arrays on sequence of fields

:func:`recs_join`
    A simple join of multiple recarrays using a single column as a key

:func:`rec_groupby`
    Summarize data by groups (similar to SQL GROUP BY)

:func:`rec_summarize`
    Helper code to filter rec array fields into new fields

For the rec viewer functions(e rec2csv), there are a bunch of Format
objects you can pass into the functions that will do things like color
negative values red, set percent formatting and scaling, etc.

Example usage::

    r = csv2rec('somefile.csv', checkrows=0)

    formatd = dict(
        weight = FormatFloat(2),
        change = FormatPercent(2),
        cost   = FormatThousands(2),
        )


    rec2excel(r, 'test.xls', formatd=formatd)
    rec2csv(r, 'test.csv', formatd=formatd)
    scroll = rec2gtk(r, formatd=formatd)

    win = gtk.Window()
    win.set_size_request(600,800)
    win.add(scroll)
    win.show_all()
    gtk.main()


i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   mapt   xranget   zip(   t	   docstring(   t   Pathu   2.2t   alternativeu!   numpy.logspace or numpy.geomspacec         C` s.   t  j t  j t  j |   t  j |  |   S(   uH   
    Return N values logarithmically spaced between xmin and xmax.

    (   t   npt   expt   linspacet   log(   t   xmint   xmaxt   N(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   logspace   s    c         C` s   t  j t |    |  S(   u   
    Return x times the hanning window of len(x).

    See Also
    --------
    :func:`window_none`
        :func:`window_none` is another window algorithm.
    (   R
   t   hanningt   len(   t   x(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   window_hanning   s    	c         C` s   |  S(   u   
    No window function; simply return x.

    See Also
    --------
    :func:`window_hanning`
        :func:`window_hanning` is another window algorithm.
    (    (   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   window_none   s    	c   
      C` sT  t  j |   }  |  j d k  s- |  j d k r< t d   n  | d |  j k rb t d |   n  t |  j  } | j |  } t j |  r t	 |  | k r t d   n  | } n | t  j
 | d |  j  } |  j d k r| r | |  | f S| |  Sn  | j   } | d d } t | | d | }	 | rH|	 |  | f S|	 |  Sd S(	   u  
    Apply the given window to the given 1D or 2D array along the given axis.

    Parameters
    ----------
    x : 1D or 2D array or sequence
        Array or sequence containing the data.

    window : function or array.
        Either a function to generate a window or an array with length
        *x*.shape[*axis*]

    axis : integer
        The axis over which to do the repetition.
        Must be 0 or 1.  The default is 0

    return_window : bool
        If true, also return the 1D values of the window that was applied
    i   i   u    only 1D or 2D arrays can be usedu   axis(=%s) out of boundsuF   The len(window) must be the same as the shape of x for the chosen axist   dtypet   axisN(   R
   t   asarrayt   ndimt
   ValueErrort   listt   shapet   popt   cbookt   iterableR   t   onesR   t   stride_repeat(
   R   t   windowR   t   return_windowt   xshapet
   xshapetargt
   windowValst   xshapeothert	   otheraxist   windowValsRep(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   apply_window   s,    	c         C` st  | d k s | d k r. t |  d t d | S| d k rP t |  d t d | S| d k rr t |  d t d | St | t j  r t d |   n  t	 |  s t d |   n  t
 j |   }  | d k	 r | d	 |  j k r t d
 |   n  | d k r|  j d k s(| r2|  j d	 k r2| |   Sy | |  d | SWn' t k
 rot
 j | d | d |  SXd S(   u  
    Return x with its trend removed.

    Parameters
    ----------
    x : array or sequence
        Array or sequence containing the data.

    key : [ 'default' | 'constant' | 'mean' | 'linear' | 'none'] or function
        Specifies the detrend algorithm to use. 'default' is 'mean', which is
        the same as :func:`detrend_mean`. 'constant' is the same. 'linear' is
        the same as :func:`detrend_linear`. 'none' is the same as
        :func:`detrend_none`. The default is 'mean'. See the corresponding
        functions for more details regarding the algorithms. Can also be a
        function that carries out the detrend operation.

    axis : integer
        The axis along which to do the detrending.

    See Also
    --------
    :func:`detrend_mean`
        :func:`detrend_mean` implements the 'mean' algorithm.

    :func:`detrend_linear`
        :func:`detrend_linear` implements the 'linear' algorithm.

    :func:`detrend_none`
        :func:`detrend_none` implements the 'none' algorithm.
    u   constantu   meanu   defaultt   keyR   u   linearu   noneu`   Unknown value for key %s, must be one of: 'default', 'constant', 'mean', 'linear', or a functioni   u   axis(=%s) out of boundsi    t   arrN(   u   constantu   meanu   default(   t   Nonet   detrendt   detrend_meant   detrend_lineart   detrend_nonet
   isinstancet   sixt   string_typesR   t   callableR
   R   R   t	   TypeErrort   apply_along_axis(   R   R,   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR/     s*    1
c         C` s   t  |  d | S(   uN  
    Return x minus its mean along the specified axis.

    Parameters
    ----------
    x : array or sequence
        Array or sequence containing the data
        Can have any dimensionality

    axis : integer
        The axis along which to take the mean.  See numpy.mean for a
        description of this argument.

    See Also
    --------
    :func:`delinear`

    :func:`denone`
        :func:`delinear` and :func:`denone` are other detrend algorithms.

    :func:`detrend_mean`
        This function is the same as :func:`detrend_mean` except for the
        default *axis*.
    R   (   R0   (   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   demeanU  s    c         C` s   t  j |   }  | d k	 rA | d |  j k rA t d |   n  |  j s` t  j d d |  j S| d k s | d k s |  j d k r |  |  j |  St d  g |  j } t  j	 | | <|  |  j |  | S(   u  
    Return x minus the mean(x).

    Parameters
    ----------
    x : array or sequence
        Array or sequence containing the data
        Can have any dimensionality

    axis : integer
        The axis along which to take the mean.  See numpy.mean for a
        description of this argument.

    See Also
    --------
    :func:`demean`
        This function is the same as :func:`demean` except for the default
        *axis*.

    :func:`detrend_linear`

    :func:`detrend_none`
        :func:`detrend_linear` and :func:`detrend_none` are other detrend
        algorithms.

    :func:`detrend`
        :func:`detrend` is a wrapper around all the detrend algorithms.
    i   u   axis(=%s) out of boundsg        R   i    N(
   R
   R   R.   R   R   t   arrayR   t   meant   slicet   newaxis(   R   R   t   ind(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR0   q  s    	'c         C` s   |  S(   u{  
    Return x: no detrending.

    Parameters
    ----------
    x : any object
        An object containing the data

    axis : integer
        This parameter is ignored.
        It is included for compatibility with detrend_mean

    See Also
    --------
    :func:`denone`
        This function is the same as :func:`denone` except for the default
        *axis*, which has no effect.

    :func:`detrend_mean`

    :func:`detrend_linear`
        :func:`detrend_mean` and :func:`detrend_linear` are other detrend
        algorithms.

    :func:`detrend`
        :func:`detrend` is a wrapper around all the detrend algorithms.
    (    (   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR2     s    c         C` s   t  j |   }  |  j d k r- t d   n  |  j sL t  j d d |  j St  j |  j d t } t  j	 | |  d d } | d | d } |  j
   | | j
   } |  | | | S(	   u  
    Return x minus best fit line; 'linear' detrending.

    Parameters
    ----------
    y : 0-D or 1-D array or sequence
        Array or sequence containing the data

    axis : integer
        The axis along which to take the mean.  See numpy.mean for a
        description of this argument.

    See Also
    --------
    :func:`delinear`
        This function is the same as :func:`delinear` except for the default
        *axis*.

    :func:`detrend_mean`

    :func:`detrend_none`
        :func:`detrend_mean` and :func:`detrend_none` are other detrend
        algorithms.

    :func:`detrend`
        :func:`detrend` is a wrapper around all the detrend algorithms.
    i   u   y cannot have ndim > 1g        R   t   biasi    (   i    i   (   i    i    (   R
   R   R   R   R:   R   t   aranget   sizet   floatt   covR;   (   t   yR   t   Ct   bt   a(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR1     s    	c         C` s  | d
 k r d } n  | | k r0 t d   n  | d k  rK t d   n  t j |   }  |  j d k rx t d   n  | d k r | d k r | d k r |  t j S|  t j j   Sn  | |  j k r t d   n  t |  } t |  } | | } | d k rC| |  j	 d | | f } |  j
 d | |  j
 d f } n9 |  j	 d | | | f } | |  j
 d |  j
 d f } t j j j |  d | d	 | S(   u~  
    Get all windows of x with length n as a single array,
    using strides to avoid data duplication.

    .. warning::

        It is not safe to write to the output array.  Multiple
        elements may point to the same piece of memory,
        so modifying one value may change others.

    Parameters
    ----------
    x : 1D array or sequence
        Array or sequence containing the data.

    n : integer
        The number of data points in each window.

    noverlap : integer
        The overlap between adjacent windows.
        Default is 0 (no overlap)

    axis : integer
        The axis along which the windows will run.

    References
    ----------
    `stackoverflow: Rolling window for 1D arrays in Numpy?
    <http://stackoverflow.com/a/6811241>`_
    `stackoverflow: Using strides for an efficient moving average filter
    <http://stackoverflow.com/a/4947453>`_
    i    u   noverlap must be less than ni   u   n cannot be less than 1u%   only 1-dimensional arrays can be usedu(   n cannot be greater than the length of xiR   t   stridesN(   R.   R   R
   R   R   R=   t	   transposeRA   t   intR   RH   t   libt   stride_trickst
   as_strided(   R   t   nt   noverlapR   t   stepR   RH   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   stride_windows  s0    !	
!c         C` s  | d k r t  d   n  t j |   }  |  j d k rH t  d   n  | d k r | d k rm t j |   St j |   j Sn  | d k  r t  d   n  t |  } | d k r | |  j f } d |  j d f } n" |  j | f } |  j d d f } t j	 j
 j |  d | d | S(	   u  
    Repeat the values in an array in a memory-efficient manner.  Array x is
    stacked vertically n times.

    .. warning::

        It is not safe to write to the output array.  Multiple
        elements may point to the same piece of memory, so
        modifying one value may change others.

    Parameters
    ----------
    x : 1D array or sequence
        Array or sequence containing the data.

    n : integer
        The number of time to repeat the array.

    axis : integer
        The axis along which the data will run.

    References
    ----------
    `stackoverflow: Repeat NumPy array without replicating data?
    <http://stackoverflow.com/a/5568169>`_
    i    i   u   axis must be 0 or 1u%   only 1-dimensional arrays can be usedu   n cannot be less than 1R   RH   (   i    i   (   R   R
   R   R   t
   atleast_2dt   TRJ   RA   RH   RK   RL   RM   (   R   RN   R   R   RH   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR"   2  s$    c         C` s  | d k r t } n | |  k } | d k r6 d } n  | d k rK d } n  | d k r` t } n  | d k ru t } n  | d k r d } n  |
 d k s |
 d k r d }
 n |
 d k r t d
 |
   n  | r |
 d k r t d   n  t j |   }  | st j |  } n  | d k s+| d k rLt j |   rCd } qkd } n | d k rkt d |   n  t |   | k  rt |   } t j	 |  | f  }  d |  | )n  | rt |  | k  rt |  } t j	 | | f  } d | | )n  | d k r| } n  |
 d k rt
 }	 n |	 d k r1t }	 n  | d k ru| } | d rb| d d d } n
 | d } d } n> | d k r| d r| d d } n | d d } d } n  t |  | | d d } t | | d d } t | | d d d t \ } } t j j | d | d d d |  d d  f } t j j | d |  |  } | st | | |  } t | | d d } t | | d d } t j j | d | d d d |  d d  f } t j |  | } n |
 d k r t j |  | } n |
 d k r1t j |  t j |  j   } nR |
 d k sI|
 d	 k r[t j |  } n( |
 d k r| t j |  j   } n  |
 d k r | d st d d d  } n t d d d  } | | c | 9<|	 r | | } | t j |  d j   } q | t j |  j   d } n  t j | d t |   | d d | |  | } | d k rt j | | | |  f  } t j | | d  d d  f | d |  d d  f f d  } n | d s| d c d 9<n  |
 d	 k rt j | d d } n  | | | f S(   u   
    This is a helper function that implements the commonality between the
    psd, csd, spectrogram and complex, magnitude, angle, and phase spectrums.
    It is *NOT* meant to be used outside of mlab and may change at any time.
    i   i    i   u   defaultu   psdu   complexu	   magnitudeu   angleu   phaseue   Unknown value for mode %s, must be one of: 'default', 'psd', 'complex', 'magnitude', 'angle', 'phase'u*   x and y must be equal if mode is not 'psd'u   twosidedu   onesideduP   Unknown value for sides %s, must be one of: 'default', 'onesided', or 'twosided'i   g      ?g       @R   R$   RN   Ni(   u   psdu   complexu	   magnitudeu   angleu   phase(   u   onesidedu   twosided(   R.   t   TrueR2   R   R   R
   R   t   iscomplexobjR   t   resizet   FalseRQ   R/   R+   t   fftt   fftfreqt   conjt   abst   sumt   angleR<   R@   t   concatenatet   unwrap(   R   RD   t   NFFTt   Fst   detrend_funcR#   RO   t   pad_tot   sidest   scale_by_freqt   modet	   same_dataRN   t   numFreqst
   freqcentert   scaling_factort   resultR'   t   freqst   resultYt   slct   t(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   _spectral_helperi  s    												

	
	44%

  3(
c   	      C` s	  | d k s$ | d k s$ | d k r7 t d |   n  | d k rR t |   } n  t d |  d d d t |   d | d t d	 | d
 d d | d | d t d |  \ } } } | d k r | j } n  | j d k r | j d d k r | d d  d f } n  | | f S(   u   
    This is a helper function that implements the commonality between the
    complex, magnitude, angle, and phase spectrums.
    It is *NOT* meant to be used outside of mlab and may change at any time.
    u   psdu   defaultu2   _single_spectrum_helper does not work with %s modeR   RD   R`   Ra   Rb   R#   RO   i    Rc   Rd   Re   Rf   u   complexi   i   N(	   R.   R   R   Rp   R2   RW   t   realR   R   (	   R   Rf   Ra   R#   Rc   Rd   t   specRl   t   _(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   _single_spectrum_helper  s     $$"t   Spectralu  
    Fs : scalar
        The sampling frequency (samples per time unit).  It is used
        to calculate the Fourier frequencies, freqs, in cycles per time
        unit. The default value is 2.

    window : callable or ndarray
        A function or a vector of length *NFFT*. To create window
        vectors see :func:`window_hanning`, :func:`window_none`,
        :func:`numpy.blackman`, :func:`numpy.hamming`,
        :func:`numpy.bartlett`, :func:`scipy.signal`,
        :func:`scipy.signal.get_window`, etc. The default is
        :func:`window_hanning`.  If a function is passed as the
        argument, it must take a data segment as an argument and
        return the windowed version of the segment.

    sides : [ 'default' | 'onesided' | 'twosided' ]
        Specifies which sides of the spectrum to return.  Default gives the
        default behavior, which returns one-sided for real data and both
        for complex data.  'onesided' forces the return of a one-sided
        spectrum, while 'twosided' forces two-sided.
t   Single_Spectrumu  
    pad_to : integer
        The number of points to which the data segment is padded when
        performing the FFT.  While not increasing the actual resolution of
        the spectrum (the minimum distance between resolvable peaks),
        this can give more points in the plot, allowing for more
        detail. This corresponds to the *n* parameter in the call to fft().
        The default is None, which sets *pad_to* equal to the length of the
        input signal (i.e. no padding).
t   PSDu  
    pad_to : integer
        The number of points to which the data segment is padded when
        performing the FFT.  This can be different from *NFFT*, which
        specifies the number of data points used.  While not increasing
        the actual resolution of the spectrum (the minimum distance between
        resolvable peaks), this can give more points in the plot,
        allowing for more detail. This corresponds to the *n* parameter
        in the call to fft(). The default is None, which sets *pad_to*
        equal to *NFFT*

    NFFT : integer
        The number of data points used in each block for the FFT.
        A power 2 is most efficient.  The default value is 256.
        This should *NOT* be used to get zero padding, or the scaling of the
        result will be incorrect. Use *pad_to* for this instead.

    detrend : {'default', 'constant', 'mean', 'linear', 'none'} or callable
        The function applied to each segment before fft-ing,
        designed to remove the mean or linear trend.  Unlike in
        MATLAB, where the *detrend* parameter is a vector, in
        matplotlib is it a function.  The :mod:`~matplotlib.pylab`
        module defines :func:`~matplotlib.pylab.detrend_none`,
        :func:`~matplotlib.pylab.detrend_mean`, and
        :func:`~matplotlib.pylab.detrend_linear`, but you can use
        a custom function as well.  You can also use a string to choose
        one of the functions.  'default', 'constant', and 'mean' call
        :func:`~matplotlib.pylab.detrend_mean`.  'linear' calls
        :func:`~matplotlib.pylab.detrend_linear`.  'none' calls
        :func:`~matplotlib.pylab.detrend_none`.

    scale_by_freq : boolean, optional
        Specifies whether the resulting density values should be scaled
        by the scaling frequency, which gives density in units of Hz^-1.
        This allows for integration over the returned frequency values.
        The default is True for MATLAB compatibility.
c	         C` sX   t  d |  d d d | d | d | d | d | d | d	 | d
 |  
\ }	 }
 |	 j |
 f S(   u  
    Compute the power spectral density.

    Call signature::

        psd(x, NFFT=256, Fs=2, detrend=mlab.detrend_none,
            window=mlab.window_hanning, noverlap=0, pad_to=None,
            sides='default', scale_by_freq=None)

    The power spectral density :math:`P_{xx}` by Welch's average
    periodogram method.  The vector *x* is divided into *NFFT* length
    segments.  Each segment is detrended by function *detrend* and
    windowed by function *window*.  *noverlap* gives the length of
    the overlap between segments.  The :math:`|\mathrm{fft}(i)|^2`
    of each segment :math:`i` are averaged to compute :math:`P_{xx}`.

    If len(*x*) < *NFFT*, it will be zero padded to *NFFT*.

    Parameters
    ----------
    x : 1-D array or sequence
        Array or sequence containing the data

    %(Spectral)s

    %(PSD)s

    noverlap : integer
        The number of points of overlap between segments.
        The default value is 0 (no overlap).

    Returns
    -------
    Pxx : 1-D array
        The values for the power spectrum `P_{xx}` (real valued)

    freqs : 1-D array
        The frequencies corresponding to the elements in *Pxx*

    References
    ----------
    Bendat & Piersol -- Random Data: Analysis and Measurement Procedures, John
    Wiley & Sons (1986)

    See Also
    --------
    :func:`specgram`
        :func:`specgram` differs in the default overlap; in not returning the
        mean of the segment periodograms; and in returning the times of the
        segments.

    :func:`magnitude_spectrum`
        :func:`magnitude_spectrum` returns the magnitude spectrum.

    :func:`csd`
        :func:`csd` returns the spectral density between two signals.
    R   RD   R`   Ra   R/   R#   RO   Rc   Rd   Re   N(   t   csdR.   Rq   (   R   R`   Ra   R/   R#   RO   Rc   Rd   Re   t   PxxRl   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   psdp  s    <$c
         C` s   | d k r d } n  t d |  d | d | d | d | d | d | d	 | d
 | d |	 d d  \ }
 } } |
 j d k r |
 j d d k r |
 j d d  }
 q |
 d d  d f }
 n  |
 | f S(   u  
    Compute the cross-spectral density.

    Call signature::

        csd(x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
            window=mlab.window_hanning, noverlap=0, pad_to=None,
            sides='default', scale_by_freq=None)

    The cross spectral density :math:`P_{xy}` by Welch's average
    periodogram method.  The vectors *x* and *y* are divided into
    *NFFT* length segments.  Each segment is detrended by function
    *detrend* and windowed by function *window*.  *noverlap* gives
    the length of the overlap between segments.  The product of
    the direct FFTs of *x* and *y* are averaged over each segment
    to compute :math:`P_{xy}`, with a scaling to correct for power
    loss due to windowing.

    If len(*x*) < *NFFT* or len(*y*) < *NFFT*, they will be zero
    padded to *NFFT*.

    Parameters
    ----------
    x, y : 1-D arrays or sequences
        Arrays or sequences containing the data

    %(Spectral)s

    %(PSD)s

    noverlap : integer
        The number of points of overlap between segments.
        The default value is 0 (no overlap).

    Returns
    -------
    Pxy : 1-D array
        The values for the cross spectrum `P_{xy}` before scaling (real valued)

    freqs : 1-D array
        The frequencies corresponding to the elements in *Pxy*

    References
    ----------
    Bendat & Piersol -- Random Data: Analysis and Measurement Procedures, John
    Wiley & Sons (1986)

    See Also
    --------
    :func:`psd`
        :func:`psd` is the equivalent to setting y=x.
    i   R   RD   R`   Ra   Rb   R#   RO   Rc   Rd   Re   Rf   u   psdi   i   R   Ni    (   R.   Rp   R   R   R;   (   R   RD   R`   Ra   R/   R#   RO   Rc   Rd   Re   t   PxyRl   Rs   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyRx     s    7	c         C` s+   t  d |  d | d | d | d | d d  S(   u  
    Compute the complex-valued frequency spectrum of *x*.  Data is padded to a
    length of *pad_to* and the windowing function *window* is applied to the
    signal.

    Parameters
    ----------
    x : 1-D array or sequence
        Array or sequence containing the data

    %(Spectral)s

    %(Single_Spectrum)s

    Returns
    -------
    spectrum : 1-D array
        The values for the complex spectrum (complex valued)

    freqs : 1-D array
        The frequencies corresponding to the elements in *spectrum*

    See Also
    --------
    :func:`magnitude_spectrum`
        :func:`magnitude_spectrum` returns the absolute value of this function.

    :func:`angle_spectrum`
        :func:`angle_spectrum` returns the angle of this function.

    :func:`phase_spectrum`
        :func:`phase_spectrum` returns the phase (unwrapped angle) of this
        function.

    :func:`specgram`
        :func:`specgram` can return the complex spectrum of segments within the
        signal.
    R   Ra   R#   Rc   Rd   Rf   u   complex(   Rt   (   R   Ra   R#   Rc   Rd   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   complex_spectrum  s    )c         C` s+   t  d |  d | d | d | d | d d  S(   ug  
    Compute the magnitude (absolute value) of the frequency spectrum of
    *x*.  Data is padded to a length of *pad_to* and the windowing function
    *window* is applied to the signal.

    Parameters
    ----------
    x : 1-D array or sequence
        Array or sequence containing the data

    %(Spectral)s

    %(Single_Spectrum)s

    Returns
    -------
    spectrum : 1-D array
        The values for the magnitude spectrum (real valued)

    freqs : 1-D array
        The frequencies corresponding to the elements in *spectrum*

    See Also
    --------
    :func:`psd`
        :func:`psd` returns the power spectral density.

    :func:`complex_spectrum`
        This function returns the absolute value of :func:`complex_spectrum`.

    :func:`angle_spectrum`
        :func:`angle_spectrum` returns the angles of the corresponding
        frequencies.

    :func:`phase_spectrum`
        :func:`phase_spectrum` returns the phase (unwrapped angle) of the
        corresponding frequencies.

    :func:`specgram`
        :func:`specgram` can return the magnitude spectrum of segments within
        the signal.
    R   Ra   R#   Rc   Rd   Rf   u	   magnitude(   Rt   (   R   Ra   R#   Rc   Rd   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   magnitude_spectrum&  s    -c         C` s+   t  d |  d | d | d | d | d d  S(   u  
    Compute the angle of the frequency spectrum (wrapped phase spectrum) of
    *x*.  Data is padded to a length of *pad_to* and the windowing function
    *window* is applied to the signal.

    Parameters
    ----------
    x : 1-D array or sequence
        Array or sequence containing the data

    %(Spectral)s

    %(Single_Spectrum)s

    Returns
    -------
    spectrum : 1-D array
        The values for the angle spectrum in radians (real valued)

    freqs : 1-D array
        The frequencies corresponding to the elements in *spectrum*

    See Also
    --------
    :func:`complex_spectrum`
        This function returns the angle value of :func:`complex_spectrum`.

    :func:`magnitude_spectrum`
        :func:`angle_spectrum` returns the magnitudes of the corresponding
        frequencies.

    :func:`phase_spectrum`
        :func:`phase_spectrum` returns the unwrapped version of this function.

    :func:`specgram`
        :func:`specgram` can return the angle spectrum of segments within the
        signal.
    R   Ra   R#   Rc   Rd   Rf   u   angle(   Rt   (   R   Ra   R#   Rc   Rd   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   angle_spectrumW  s    )c         C` s+   t  d |  d | d | d | d | d d  S(   u  
    Compute the phase of the frequency spectrum (unwrapped angle spectrum) of
    *x*.  Data is padded to a length of *pad_to* and the windowing function
    *window* is applied to the signal.

    Parameters
    ----------
    x : 1-D array or sequence
        Array or sequence containing the data

    %(Spectral)s

    %(Single_Spectrum)s

    Returns
    -------
    spectrum : 1-D array
        The values for the phase spectrum in radians (real valued)

    freqs : 1-D array
        The frequencies corresponding to the elements in *spectrum*

    See Also
    --------
    :func:`complex_spectrum`
        This function returns the angle value of :func:`complex_spectrum`.

    :func:`magnitude_spectrum`
        :func:`magnitude_spectrum` returns the magnitudes of the corresponding
        frequencies.

    :func:`angle_spectrum`
        :func:`angle_spectrum` returns the wrapped version of this function.

    :func:`specgram`
        :func:`specgram` can return the phase spectrum of segments within the
        signal.
    R   Ra   R#   Rc   Rd   Rf   u   phase(   Rt   (   R   Ra   R#   Rc   Rd   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   phase_spectrum  s    )c
         C` s   | d k r d } n  | d k r* d } n  t |   | k r` t j d d | t |   f  n  t d |  d d d | d | d	 | d
 | d | d | d | d | d |	  \ }
 } } |	 d k r |
 j }
 n  |
 | | f S(   u&  
    Compute a spectrogram.

    Compute and plot a spectrogram of data in x.  Data are split into
    NFFT length segments and the spectrum of each section is
    computed.  The windowing function window is applied to each
    segment, and the amount of overlap of each segment is
    specified with noverlap.

    Parameters
    ----------
    x : array_like
        1-D array or sequence.

    %(Spectral)s

    %(PSD)s

    noverlap : int, optional
        The number of points of overlap between blocks.  The default
        value is 128.
    mode : str, optional
        What sort of spectrum to use, default is 'psd'.
            'psd'
                Returns the power spectral density.

            'complex'
                Returns the complex-valued frequency spectrum.

            'magnitude'
                Returns the magnitude spectrum.

            'angle'
                Returns the phase spectrum without unwrapping.

            'phase'
                Returns the phase spectrum with unwrapping.

    Returns
    -------
    spectrum : array_like
        2-D array, columns are the periodograms of successive segments.

    freqs : array_like
        1-D array, frequencies corresponding to the rows in *spectrum*.

    t : array_like
        1-D array, the times corresponding to midpoints of segments
        (i.e the columns in *spectrum*).

    See Also
    --------
    psd : differs in the overlap and in the return values.
    complex_spectrum : similar, but with complex valued frequencies.
    magnitude_spectrum : similar single segment when mode is 'magnitude'.
    angle_spectrum : similar to single segment when mode is 'angle'.
    phase_spectrum : similar to single segment when mode is 'phase'.

    Notes
    -----
    detrend and scale_by_freq only apply when *mode* is set to 'psd'.

    i   i   u4   Only one segment is calculated since parameter NFFT u   (=%d) >= signal length (=%d).R   RD   R`   Ra   Rb   R#   RO   Rc   Rd   Re   Rf   u   complexN(   R.   R   t   warningst   warnRp   Rq   (   R   R`   Ra   R/   R#   RO   Rc   Rd   Re   Rf   Rr   Rl   Ro   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   specgram  s     C			uw   Coherence is calculated by averaging over *NFFT*
length segments.  Your signal is too short for your choice of *NFFT*.
i   i   u   defaultc
         C` s   t  |   d | k  r% t t   n  t |  | | | | | | | |	 	 \ }
 } t | | | | | | | | |	 	 \ } } t |  | | | | | | | | |	 
 \ } } t j |  d |
 | } | | f S(   uH  
    The coherence between *x* and *y*.  Coherence is the normalized
    cross spectral density:

    .. math::

        C_{xy} = \frac{|P_{xy}|^2}{P_{xx}P_{yy}}

    Parameters
    ----------
    x, y
        Array or sequence containing the data

    %(Spectral)s

    %(PSD)s

    noverlap : integer
        The number of points of overlap between blocks.  The default value
        is 0 (no overlap).

    Returns
    -------
    The return value is the tuple (*Cxy*, *f*), where *f* are the
    frequencies of the coherence vector. For cohere, scaling the
    individual densities by the sampling frequency has no effect,
    since the factors cancel out.

    See Also
    --------
    :func:`psd`, :func:`csd` :
        For information about the methods used to compute :math:`P_{xy}`,
        :math:`P_{xx}` and :math:`P_{yy}`.
    i   (   R   R   t
   _coh_errorRz   Rx   R
   R[   (   R   RD   R`   Ra   R/   R#   RO   Rc   Rd   Re   Ry   t   ft   PyyR{   t   Cxy(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   cohere  s    &c          G` s   d  S(   N(    (   t   args(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   donothing_callback@  s    u   scipy.signal.coherencec
   $      C` s  |  j  \ }
 } |
 | k  r^ |  } t j | | f |  j  }  | |  d |
  d d  f <~ n  |  j  \ }
 } t   } x. | D]& \ } } | j |  | j |  q} Wt |  } t j |   r | } n | d d } t j	 |  rt |  | k r	t
 d   n  | } n | t j | |  j   } t t d |
 | d | |   } t |  } i  } i  } i  } t |  } t j j |  d } x | D] } | | | d  t j | | f d t j } xf | D]^ } |  | | | | |  | f } | | |  } t j j |  |  | | d d  f <qW| | | <| r\t j |  | | <n  t j t j t |  d d d |  | | <qW~ ~ ~ i  } i  } d }  t |  }! x | D] \ } } |  d 7}  |  d	 d k r| |  |! d
  n  | r| | | | }" n | | t j | |  }" | d k rQt j |" d d }" n  |" | }" t |"  d | | | | | | | f <t j |" j |" j  | | | f <qW| | t j |  }# |	 r| | |# | f S| | |# f Sd S(   u
  
    Compute the coherence and phase for all pairs *ij*, in *X*.

    *X* is a *numSamples* * *numCols* array

    *ij* is a list of tuples.  Each tuple is a pair of indexes into
    the columns of X for which you want to compute coherence.  For
    example, if *X* has 64 columns, and you want to compute all
    nonredundant pairs, define *ij* as::

      ij = []
      for i in range(64):
          for j in range(i+1,64):
              ij.append( (i,j) )

    *preferSpeedOverMemory* is an optional bool. Defaults to true. If
    False, limits the caching by only making one, rather than two,
    complex cache arrays. This is useful if memory becomes critical.
    Even when *preferSpeedOverMemory* is False, :func:`cohere_pairs`
    will still give significant performance gains over calling
    :func:`cohere` for each pair, and will use subtantially less
    memory than if *preferSpeedOverMemory* is True.  In my tests with
    a 43000,64 array over all nonredundant pairs,
    *preferSpeedOverMemory* = True delivered a 33% performance boost
    on a 1.7GHZ Athlon with 512MB RAM compared with
    *preferSpeedOverMemory* = False.  But both solutions were more
    than 10x faster than naively crunching all possible pairs through
    :func:`cohere`.

    Returns
    -------
    Cxy : dictionary of (*i*, *j*) tuples -> coherence vector for
        that pair.  i.e., ``Cxy[(i,j) = cohere(X[:,i], X[:,j])``.
        Number of dictionary keys is ``len(ij)``.

    Phase : dictionary of phases of the cross spectral density at
        each frequency for each pair.  Keys are (*i*, *j*).

    freqs : vector of frequencies, equal in length to either the
         coherence or phase vectors for any (*i*, *j*) key.

    e.g., to make a coherence Bode plot::

          subplot(211)
          plot( freqs, Cxy[(12,19)])
          subplot(212)
          plot( freqs, Phase[(12,19)])

    For a large number of pairs, :func:`cohere_pairs` can be much more
    efficient than just calling :func:`cohere` for each pair, because
    it caches most of the intensive computations.  If :math:`N` is the
    number of pairs, this function is :math:`O(N)` for most of the
    heavy lifting, whereas calling cohere for each pair is
    :math:`O(N^2)`.  However, because of the caching, it is also more
    memory intensive, making 2 additional complex arrays with
    approximately the same number of elements as *X*.

    See :file:`test/cohere_pairs_test.py` in the src tree for an
    example script that shows that this :func:`cohere_pairs` and
    :func:`cohere` give the same results for a given pair.

    See Also
    --------
    :func:`psd`
        For information about the methods used to compute :math:`P_{xy}`,
        :math:`P_{xx}` and :math:`P_{yy}`.
    Ni   i   u.   The length of the window must be equal to NFFTi    u   Cacheing FFTsR   R   i
   u   Computing coherences(   R   R
   t   zerosR   t   sett   addR   RU   R   R    R   R!   R   R   t   ranget   linalgt   normt   complex_RX   RZ   t   divideR;   R[   t   arctan2t   imagRq   R@   ($   t   Xt   ijR`   Ra   R/   R#   RO   t   preferSpeedOverMemoryt   progressCallbackt	   returnPxxt   numRowst   numColst   tmpt
   allColumnst   it   jt   NcolsRh   R'   R>   t	   numSlicest	   FFTSlicest   FFTConjSlicesRy   t   slicest   normValt   iColt   Slicest   iSlicet	   thisSliceR   t   Phaset   countR   R{   Rl   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   cohere_pairsE  sv    J			$"*
3	

*&u   scipy.stats.entropyc         C` s   t  j |  |  \ } } | j t  } t  j | t  j |  d  } t  j | t |    } | d | d } d t  j | t  j	 |   t  j	 |  } | S(   u  
    Return the entropy of the data in *y* in units of nat.

    .. math::

      -\sum p_i \ln(p_i)

    where :math:`p_i` is the probability of observing *y* in the
    :math:`i^{th}` bin of *bins*.  *bins* can be a number of bins or a
    range of bins; see :func:`numpy.histogram`.

    Compare *S* with analytic calculation for a Gaussian::

      x = mu + sigma * randn(200000)
      Sanalytic = 0.5 * ( 1.0 + log(2*pi*sigma**2.0) )
    i    i   g      (
   R
   t	   histogramt   astypeRB   t   taket   nonzeroR   R   R\   R   (   RD   t   binsRN   t   pt   deltat   S(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   entropy  s    -u   scipy.stats.norm.pdfc         G` sI   | \ } } d t  j d t  j  | t  j d d | |  | d  S(   uC   Return the normal pdf evaluated at *x*; args provides *mu*, *sigma*g      ?i   g      (   R
   t   sqrtt   piR   (   R   R   t   mut   sigma(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   normpdf  s    c         C` s   t  j t  j |    \ } | S(   u1   Return the indices where ravel(condition) is true(   R
   R   t   ravel(   t	   conditiont   res(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   find  s    c         C` s>  t  j |   }  t |   d k r. t  j g   S|  d k j   d } t |  d k ri t  j t |    St |  t |   k r t  j g   St  j t |   d f |  j  } |  | d d +t  j |  } | d k j   d } | d k j   d } | | t	 | |  k j   d d } t  j | | | |  } | S(   u   
    Return the indices of the longest stretch of contiguous ones in *x*,
    assuming *x* is a vector of zeros and ones.  If there are two
    equally long stretches, pick the first.
    i    i   i   i(
   R
   R   R   R:   R   R@   R   R   t   difft   max(   R   R>   RD   t   dift   upt   dnR   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   longest_contiguous_ones  s     "(c         C` s
   t  |   S(   u!   alias for longest_contiguous_ones(   R   (   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   longest_ones+  s    t   PCAc           B` s8   e  Z e d   Z d d  Z d   Z e d    Z RS(   c   
      C` s
  | j  \ } } | | k  r* t d   n  | | |  _ |  _ | j d d  |  _ | j d d  |  _ | |  _ |  j	 |  } | |  _
 t j j | d t \ } } } | |  _ t j | | j  j } | |  _ | d |  _ |  j t |  }	 |	 |	 j   |  _ d S(   u  
        compute the SVD of a and store data for PCA.  Use project to
        project the data onto a reduced set of dimensions

        Parameters
        ----------
        a : np.ndarray
            A numobservations x numdims array
        standardize : bool
            True if input data are to be standardized. If False, only centering
            will be carried out.

        Attributes
        ----------
        a
            A centered unit sigma version of input ``a``.

        numrows, numcols
            The dimensions of ``a``.

        mu
            A numdims array of means of ``a``. This is the vector that points
            to the origin of PCA space.

        sigma
            A numdims array of standard deviation of ``a``.

        fracs
            The proportion of variance of each of the principal components.

        s
            The actual eigenvalues of the decomposition.

        Wt
            The weight vector for projecting a numdims point or array into
            PCA space.

        Y
            A projected into PCA space.

        Notes
        -----
        The factor loadings are in the ``Wt`` factor, i.e., the factor loadings
        for the first principal component are given by ``Wt[0]``. This row is
        also the first eigenvector.

        u5   we assume data in a is organized with numrows>numcolsR   i    t   full_matricesi   N(   R   t   RuntimeErrort   numrowst   numcolsR;   R   t   stdR   t   standardizet   centerRG   R
   R   t   svdRW   t   Wtt   dotRS   t   Yt   sR   R\   t   fracs(
   t   selfRG   R   RN   t   mt   UR   t   VhR   t   vars(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   __init__3  s     0		!		g        c         C` s   t  j |  } | j d |  j k r; t d |  j   n  t  j |  j |  j |  j  j } |  j	 | k } | j
 d k r | d d  | f } n
 | | } | S(   uq   
        project x onto the principle axes, dropping any axes where fraction
        of variance<minfrac
        iu#   Expected an array with dims[-1]==%di   N(   R
   R   R   R   R   R   R   R   RS   R   R   (   R   R   t   minfracR   t   maskt   Yreduced(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   project  s    $
c         C` s*   |  j  r | |  j |  j S| |  j Sd S(   uq   
        center and optionally standardize the data using the mean and sigma
        from training set a
        N(   R   R   R   (   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR     s    	c          C` s   t  j d d d d d d d d d	 d
 d d d d d d d d d d g  }  t  j d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( g  } |  d) | } d* |  d+ | } t  j | |  | | g  j } | S(,   Nguy?g9?gK'zj?gypaz?g{b?gL?gҘ9z?gH;Ey?g8?gl|?g.Taw?g/`v?gVtn?g{-r?gp~;?g4H?g״ޱе?g^*1?g?g-F'?g)Ȯ8gAºqgѿg|G*u.?ge@t?gl#gbVD??g,#w?g_?g |?gq6>g	eD gTg2E5
?g"PYM?gzQݿg<?gG.Ҽ¿gdֿg?i   ii   (   R
   R:   RS   (   t   c0t   c1t   c2t   c3RG   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   _get_colinear  s    (   t   __name__t
   __module__RT   R   R   R   t   staticmethodR   (    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR   1  s   W	
u   numpy.percentileg        g      9@g      I@g     R@g      Y@c   
      C` s   d   } t  j |  } t  j |  d d } | d | j d d } | j t  } | d } | d } | t |  k }	 | j r | |	 c d 8<| |	 c d 8<| |	 c d 7<n' |	 r | d 8} | d 8} | d 7} n  | | | | | |  S(   uS  
    Return the percentiles of *x*.  *p* can either be a sequence of
    percentile values or a scalar.  If *p* is a sequence, the ith
    element of the return sequence is the *p*(i)-th percentile of *x*.
    If *p* is a scalar, the largest value of *x* less than or equal to
    the *p* percentage point in the sequence is returned.
    c         S` s   |  | |  | S(   us   Returns the point at the given fraction between a and b, where
        'fraction' must be between 0 and 1.
        (    (   RG   RF   t   fraction(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   _interpolate  s    R   id   i    i   N(	   R
   R:   t   sortR.   R   R   RJ   R   R   (
   R   R   R   t   pert   valuest   idxst   ait   bit   fract   cond(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   prctile  s"    	

	

c         C` s   t  j |  s/ t j d | d d |  } n t j |  } | j   d k st | j   d k  st | j   d k r t d   n  t |  |  } t j	 | |   S(   u  
    Return the rank for each element in *x*, return the rank
    0..len(*p*).  e.g., if *p* = (25, 50, 75), the return value will be a
    len(*x*) array with values in [0,1,2,3] where 0 indicates the
    value is less than the 25th percentile, 1 indicates the value is
    >= the 25th and < 50th percentile, ... and 3 indicates the value
    is above the 75th percentile cutoff.

    *p* is either an array of percentiles in [0..100] or a scalar which
    indicates how many quantiles of data you want ranked.
    g      Y@i   i    id   u/   percentiles should be in range 0..100, not 0..1(
   R   R    R
   R@   R   R   t   minR   R   t   searchsorted(   R   R   t   ptiles(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   prctile_rank  s     6c         C` s   t  j |  t  }  | rA |  |  j d d  |  j d d  }  nR |  |  j d d  d d  t  j f }  |  |  j d d  d d  t  j f }  |  S(   u   
    Return the matrix *M* with each row having zero mean and unit std.

    If *dim* = 1 operate on columns instead of rows.  (*dim* is
    opposite to the numpy axis kwarg.)
    R   i    i   N(   R
   R   RB   R;   R   R=   (   t   Mt   dim(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   center_matrix  s    )))u   scipy.integrate.odec         C` sw  y t  |  } Wn, t k
 r> t j t  |  f t  } n Xt j t  |  | f t  } | | d <d } xt j t  |  d  D] } | | } | | d | } | d } | | } t j |  | |   }	 t j |  | | |	 | |   }
 t j |  | | |
 | |   } t j |  | | | | |   } | | d |	 d |
 d | | | | d <q W| S(   u  
    Integrate 1D or ND system of ODEs using 4-th order Runge-Kutta.
    This is a toy implementation which may be useful if you find
    yourself stranded on a system w/o scipy.  Otherwise use
    :func:`scipy.integrate`.

    Parameters
    ----------
    y0
        initial state vector

    t
        sample times

    derivs
        returns the derivative of the system and has the
        signature ``dy = derivs(yi, ti)``

    Examples
    --------

    A 2D system::

        def derivs6(x,t):
            d1 =  x[0] + 2*x[1]
            d2 =  -3*x[0] + 4*x[1]
            return (d1, d2)
        dt = 0.0005
        t = arange(0.0, 2.0, dt)
        y0 = (1,2)
        yout = rk4(derivs6, y0, t)

    A 1D system::

        alpha = 2
        def derivs(x,t):
            return -alpha*x + exp(-t)

        y0 = 1
        yout = rk4(derivs, y0, t)

    If you have access to scipy, you should probably be using the
    scipy.integrate tools rather than this function.
    i    i   g       @g      @i   (   R   R7   R
   R   RB   R@   R   (   t   derivst   y0Ro   t   Nyt   youtR   t   thistt   dtt   dt2t   k1t   k2t   k3t   k4(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   rk4  s$    /
 


$$$2g      ?c         C` s   |  | } | | } | | | }	 | d | d | d | d d |	 | | | | }
 d t  j | | t  j d |	 d  } t  j |
 d d |	 d  | S(   u   
    Bivariate Gaussian distribution for equal shape *X*, *Y*.

    See `bivariate normal
    <http://mathworld.wolfram.com/BivariateNormalDistribution.html>`_
    at mathworld.
    i   i   (   R
   R   R   R   (   R   R   t   sigmaxt   sigmayt   muxt   muyt   sigmaxyt   Xmut   Ymut   rhot   zt   denom(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   bivariate_normalT  s    


:*c         C` s1   t  j |  j  \ } } | | | | |  | f S(   u.  
    *Z* and *Cond* are *M* x *N* matrices.  *Z* are data and *Cond* is
    a boolean matrix where some condition is satisfied.  Return value
    is (*x*, *y*, *z*) where *x* and *y* are the indices into *Z* and
    *z* are the values of *Z* at those indices.  *x*, *y*, and *z* are
    1D arrays.
    (   R
   t   indicesR   (   t   Zt   CondR   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   get_xyz_whereg  s    	g?c         C` s   t  j |  | f  d } xm t t |  | |   D]Q } t  j j d |  d  } t  j j d | d  } t  j j   | | | f <q4 W| S(   uT   
    Return a *M* x *N* sparse matrix with *frac* elements randomly
    filled.
    g        i    i   (   R
   R   R   RJ   t   randomt   randintt   rand(   R   R   R   t   dataR   R   RD   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   get_sparse_matrixt  s    !u   numpy.hypotc         C` s#   |  | } t  j t  j | |   S(   u1   
    Return the distance between two points.
    (   R
   R   R   (   R   RD   t   d(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   dist  s    
c   	      C` s   t  j |  t  }  t  j | t  } t  j | t  } | | } |  | } t  j | |  } | d k ru t |  |  St  j | |  } | | k r t |  |  S| | } | | | } t |  |  S(   u   
    Get the distance of a point to a segment.

      *p*, *s0*, *s1* are *xy* sequences

    This algorithm from
    http://geomalgorithms.com/a02-_lines.html
    i    (   R
   R   RB   R   R  (	   R   t   s0t   s1t   vt   wR   R   RF   t   pb(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   dist_point_to_segment  s    



c         C` s   |  \ \ } } \ } } | \ \ } } \ } }	 |	 | | | | | | | }
 | | | | |	 | | | } | | | | | | | | } |
 d k r t  S| |
 } | |
 } d | k o d k n o d | k o d k SS(   u   
    Return *True* if *s1* and *s2* intersect.
    *s1* and *s2* are defined as::

      s1: (x1, y1), (x2, y2)
      s2: (x3, y3), (x4, y4)
    i    g        g      ?(   RW   (   R  t   s2t   x1t   y1t   x2t   y2t   x3t   y3t   x4t   y4t   dent   n1t   n2t   u1t   u2(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   segments_intersect  s    	"""

c         C` s   t  j |  r" | | |   }  n | | |    }  t j j |   } d t j d } | t j j t |    } | t j |  } t j j	 |  j
 S(   u;   
    Compute an FFT phase randomized surrogate of *x*.
    g       @y              ?(   R   R    R
   RX   R   R  R  R   R   t   ifftRq   (   R   R/   R#   R  RG   t   phase(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   fftsurr  s    c         C` s9   t  j | f d t } d | | (t  j |  | d d S(   u5   
    Compute the len(*n*) moving average of *x*.
    R   g      ?Rf   u   valid(   R
   t   emptyRB   t   convolve(   R   RN   R  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   movavg  s    g       gu	   numpy.expc         C` sB   t  |   t j k r1 t j t j |  t t   St j |   Sd S(   u   
    Compute exponentials which safely underflow to zero.

    Slow, but convenient to use. Note that numpy provides proper
    floating point exception handling with access to the underlying
    hardware.
    N(   t   typeR
   t   ndarrayR   t   clipt   exp_safe_MINt   exp_safe_MAXt   math(   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   exp_safe  s    
u   numpy.array(list(map(...)))c         G` s   t  j t t |  |    S(   u   
    amap(function, sequence[, sequence, ...]) -> array.

    Works like :func:`map`, but it returns an array.  This is just a
    convenient shorthand for ``numpy.array(map(...))``.
    (   R
   R:   R   R   (   t   fnR   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   amap   s    c         C` s#   t  j t  j t  j |   d   S(   uP   
    Return the root mean square of all the elements of *a*, flattened out.
    i   (   R
   R   R;   R[   (   RG   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   rms_flat+  s    u   numpy.linalg.norm(a, ord=1)c         C` s   t  j t  j |    S(   u   
    Return the *l1* norm of *a*, flattened out.

    Implemented as a separate function (not a call to :func:`norm` for speed).
    (   R
   R\   R[   (   RG   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   l1norm3  s    u   numpy.linalg.norm(a, ord=2)c         C` s#   t  j t  j t  j |   d   S(   u   
    Return the *l2* norm of *a*, flattened out.

    Implemented as a separate function (not a call to :func:`norm` for speed).
    i   (   R
   R   R\   R[   (   RG   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   l2norm=  s    u    numpy.linalg.norm(a.flat, ord=p)c         C` sH   | d k r" t  j t  j |    St  j t  j |   |  d | Sd S(   u  
    norm(a,p=2) -> l-p norm of a.flat

    Return the l-p norm of *a*, considered as a flat array.  This is NOT a true
    matrix norm, since arrays of arbitrary rank are always flattened.

    *p* can be a number or the string 'Infinity' to get the L-infinity norm.
    u   Infinityi   N(   R
   R   R[   R\   (   RG   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt	   norm_flatG  s    u   numpy.arangec         K` s   | j  d d  | d d k } | d k r? |  d } d }  n  | d k rT d } n  y  | d } | |  | | } Wn2 t k
 r t t j | |  |   | } n Xt j |  | |  S(   u  
    frange([start,] stop[, step, keywords]) -> array of floats

    Return a numpy ndarray containing a progression of floats. Similar to
    :func:`numpy.arange`, but defaults to a closed interval.

    ``frange(x0, x1)`` returns ``[x0, x0+1, x0+2, ..., x1]``; *start*
    defaults to 0, and the endpoint *is included*. This behavior is
    different from that of :func:`range` and
    :func:`numpy.arange`. This is deliberate, since :func:`frange`
    will probably be more useful for generating lists of points for
    function evaluation, and endpoints are often desired in this
    use. The usual behavior of :func:`range` can be obtained by
    setting the keyword *closed* = 0, in this case, :func:`frange`
    basically becomes :func:numpy.arange`.

    When *step* is given, it specifies the increment (or
    decrement). All arguments can be floating point numbers.

    ``frange(x0,x1,d)`` returns ``[x0,x0+d,x0+2d,...,xfin]`` where
    *xfin* <= *x1*.

    :func:`frange` can also be called with the keyword *npts*. This
    sets the number of points the list should contain (and overrides
    the value *step* might have been given). :func:`numpy.arange`
    doesn't offer this option.

    Examples::

      >>> frange(3)
      array([ 0.,  1.,  2.,  3.])
      >>> frange(3,closed=0)
      array([ 0.,  1.,  2.])
      >>> frange(1,6,2)
      array([1, 3, 5])   or 1,3,5,7, depending on floating point vagueries
      >>> frange(1,6.5,npts=5)
      array([ 1.   ,  2.375,  3.75 ,  5.125,  6.5  ])
    u   closedi   i    g        g      ?u   nptsN(   t
   setdefaultR.   t   KeyErrorRJ   R
   t   roundR@   (   t   xinit   xfinR   t   kwt   endpointt   npts(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   frangeY  s    *
		
%u   numpy.identityu   lc         C` s`   | d k	 r | } n  t j |  f | |  } x+ t |   D] } | f | } d | | <q; W| S(   u  
    Returns the identity matrix of shape (*n*, *n*, ..., *n*) (rank *r*).

    For ranks higher than 2, this object is simply a multi-index Kronecker
    delta::

                            /  1  if i0=i1=...=iR,
        id[i0,i1,...,iR] = -|
                            \  0  otherwise.

    Optionally a *dtype* (or typecode) may be given (it defaults to 'l').

    Since rank defaults to 2, this function behaves in the default case (when
    only *n* is given) like ``numpy.identity(n)`` -- but surprisingly, it is
    much faster.
    i   N(   R.   R
   R   R   (   RN   t   rankR   t   typecodet   idenR   t   idx(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   identity  s    	c         C` s   d } |  | k  r0 | d | d | t  |   St  t j |   t j |   } t |  | } t  |  |  } | | t |  | | | t | d |   S(   uF   
    Return the representation of a *number* in any given *base*.
    u$   0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZi   i    (   RJ   R9  R   t   longt	   base_reprR   (   t   numbert   baset   paddingt   charst   max_exponentt	   max_powert
   lead_digit(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyRP    s    "i  c         C` s   t  t j | |  g t | d d d   } t t  t j | | d g   } | j d  sa d S| | j d  } d j t  t	 |   j
 d d  S(   uO  
    Return the binary representation of the input *number* as a
    string.

    This is more efficient than using :func:`base_repr` with base 2.

    Increase the value of max_length for very large numbers. Note that
    on 32-bit machines, 2**1023 is the largest integer power of 2
    which can be converted to a Python float.
    i   ii   i    u    u   L(   R   t   operatort   rshiftR   R   t   modR   t   indext   joint   reprt   replace(   RQ  t
   max_lengtht   shiftst   digits(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   binary_repr  s    "u
   numpy.log2g       @c         C` sg   y t  |   d } Wn% t t f k
 r; t j |   | SXd | k rY t j |   | St |  Sd S(   u   
    Return the log(*x*) in base 2.

    This is a _slow_ function but which is guaranteed to return the correct
    integer value if the input is an integer exact power of 2.
    i   u   1N(   Rb  t   AssertionErrorR7   R9  R   R   (   R   t   ln2t   bin_n(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   log2  s    c         C` s.   t  |   d } d | k r  d St |  Sd S(   u   
    Returns the log base 2 of *n* if *n* is a power of 2, zero otherwise.

    Note the potential ambiguity if *n* == 1: 2**0 == 1, interpret accordingly.
    i   u   1i    N(   Rb  R   (   RN   Re  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   ispower2  s    c         C` s"   t  j |  j  t  j |  j  k S(   uZ  
    Like the MATLAB function with the same name, returns *True*
    if the supplied numpy array or matrix *X* looks like a vector,
    meaning it has a one non-singleton axis (i.e., it can have
    multiple axes, but all must have length 1, except for one of
    them).

    If you just want to see if the array has 1 axis, use X.ndim == 1.
    (   R
   t   prodR   R   (   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   isvector	  s    u   numpy.isnanc         C` sW   t  |  t j  r t Sy t j |   } Wn# t k
 r= t St k
 rN t SX| Sd S(   u'   :func:`numpy.isnan` for arbitrary typesN(   R3   R4   R5   RW   R
   t   isnant   NotImplementedErrorR7   (   R   RF   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt
   safe_isnan	  s    u   numpy.isinfc         C` sW   t  |  t j  r t Sy t j |   } Wn# t k
 r= t St k
 rN t SX| Sd S(   u'   :func:`numpy.isinf` for arbitrary typesN(   R3   R4   R5   RW   R
   t   isinfRk  R7   (   R   RF   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt
   safe_isinf!	  s    c         C` s  t  | t j  rn t j |  rn t |  rn t  | d t j  rn t |  t |  k r t d   q n | g } | g } t t t	 j
 |   } | d k r g  | D] } | j ^ q } n t j |  s | g } n  t |  t |  k r*t |  d k r| t |  } q*t d   n  |  j j } t j rpg  | D]! \ } } | j d  | f ^ qF} n  t	 j | t t | |    } t	 j |  j d | }	 x" |  j j D] }
 |  |
 |	 |
 <qWx' t | |  D] \ } } | |	 | <qW|	 S(   u   
    Return a new record array with field names populated with data
    from arrays in *arrs*.  If appending a single field, then *names*,
    *arrs* and *dtypes* do not have to be lists. They can just be the
    values themselves.
    i    u-   number of arrays do not match number of namesi   u-   dtypes must be None, a single dtype or a listu   utf-8R   N(   R3   R4   R5   R   R    R   R   R   R   R
   R   R.   R   t   descrt   PY2t   encodeR   t   recarrayR   t   fields(   t   rect   namest   arrst   dtypesRG   t
   old_dtypest   nameR   t   newdtypet   newrect   fieldR-   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   rec_append_fields0	  s2    ""			1"c         C` s   t  |  } t j g  |  j j D]% } | | k r | |  j | f ^ q  } t j |  j d | } x | j D] } |  | | | <qo W| S(   uI   
    Return a new numpy record array with fields in *names* dropped.
    R   (   R   R
   R   Ru  Rr  R   (   Rt  Ru  Ry  Rz  R{  R|  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   rec_drop_fieldsU	  s    (c         C` sb   t  | t j  r$ | j d  } n  g  } x | D] } | j |  |  q1 Wt j j | d | S(   uJ   
    Return a new numpy record array with only fields listed in names
    u   ,Ru  (   R3   R4   R5   t   splitt   appendR
   Rt  t
   fromarrays(   Rt  Ru  t   arraysRy  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   rec_keep_fieldsg	  s    c         C` s&  i  } xV t  |   D]H \ } } t g  | D] } | | ^ q)  } | j | g   j |  q Wg  } xt t |  D]f } t |  } | | }	 |  |	 }
 | j g  | D] \ } } } | |
 |  ^ q  | j |  qr Wt t |    \ } } } t |  } | j |  t j	 j
 | d | S(   u  
    *r* is a numpy record array

    *groupby* is a sequence of record array attribute names that
    together form the grouping key.  e.g., ('date', 'productcode')

    *stats* is a sequence of (*attr*, *func*, *outname*) tuples which
    will call ``x = func(attr)`` and assign *x* to the record array
    output with attribute *outname*.  For example::

      stats = ( ('sales', len, 'numsales'), ('sales', np.mean, 'avgsale') )

    Return record array has *dtype* names for each attribute name in
    the *groupby* argument, with the associated group values, and
    for each outname name in the *stats* argument, with the associated
    stat summary output.
    Ru  (   t	   enumeratet   tupleRA  R  t   sortedR   t   extendR   R
   Rt  t   fromrecords(   t   rt   groupbyt   statst   rowdR   t   rowt   attrR,   t   rowsR>   t   thisrt   funct   outnamet   attrst   funcst   outnamesRu  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   rec_groupbyw	  s    #

3c         C` s   t  |  j j  } g  | D] } |  | ^ q } xD | D]< \ } } } | j |  | j t j | |  |    q6 Wt j j | d | S(   uH  
    *r* is a numpy record array

    *summaryfuncs* is a list of (*attr*, *func*, *outname*) tuples
    which will apply *func* to the array *r*[attr] and assign the
    output to a new attribute name *outname*.  The returned record
    array is identical to *r*, with extra arrays for each element in
    *summaryfuncs*.

    Ru  (   R   R   Ru  R  R
   R   Rt  R  (   R  t   summaryfuncsRu  Ry  R  R  R  R  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   rec_summarize	  s    $u   inneru   1u   2c   '      ` sB  t    t j  r   f   n  xX   D]P } |  j j k rP t d |   n  |  j j k r% t d |   q% q% W  f d     f d   t   D }  f d   t   D }	 t |  }
 t |	  } |
 | @} t j	 g  | D] } | | ^ q  } t j	 g  | D] } |	 | ^ q } t
 |  } d } } | d k s\| d k r|
 j |  } t j	 g  | D] } | | ^ qx } t
 |  } n  | d k r| j |
  } t j	 g  | D] } |	 | ^ q } t
 |  } n    f d	   } g    D] } | |  ^ q	}     f d
   }     f d   } g   j j D]0 } | d   k rX| | d  | d f ^ qX} g   j j D]0 } | d   k r| | d  | d f ^ q} | | | } t j rg  | D]! \ } } | j d  | f ^ q} n  t j |  }  t j | | | f d |  }! | d k	 rx= | D]2 }" |" |  j k r[t j d |" |  j f  q[q[Wn  x7 |  j D], } |  | } | j d k rd |! | <qqW| d k r4| d k	 r4t |! j j  }# x9 t j |  D]% \ } }$ | |# k r|$ |! | <qqWn  x}  j j D]o }% | |%  }& | rr |% | |! |& | *n  | d k s| d k rA| rA |% | |! |& | | | +qAqAWxw  j j D]i }% | |%  }& |%   k r| r |% | |! |& | *n  | d k r| r |% | |! |& | )qqW|! j d    |! S(   u  
    Join record arrays *r1* and *r2* on *key*; *key* is a tuple of
    field names -- if *key* is a string it is assumed to be a single
    attribute name. If *r1* and *r2* have equal values on all the keys
    in the *key* tuple, then their fields will be merged into a new
    record array containing the intersection of the fields of *r1* and
    *r2*.

    *r1* (also *r2*) must not have any duplicate keys.

    The *jointype* keyword can be 'inner', 'outer', 'leftouter'.  To
    do a rightouter join just reverse *r1* and *r2*.

    The *defaults* keyword is a dictionary filled with
    ``{column_name:default_value}`` pairs.

    The keywords *r1postfix* and *r2postfix* are postfixed to column names
    (other than keys) that are both in *r1* and *r2*.
    u   r1 does not have key field %su   r2 does not have key field %sc         ` s!   t  g    D] } |  | ^ q
  S(   N(   R  (   R  Ry  (   R,   (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   makekey	  s    c         ` s%   i  |  ] \ } } |   |   q S(    (    (   t   .0R   R  (   R  (    s.   lib/python2.7/site-packages/matplotlib/mlab.pys
   <dictcomp>	  s   	 c         ` s%   i  |  ] \ } } |   |   q S(    (    (   R  R   R  (   R  (    s.   lib/python2.7/site-packages/matplotlib/mlab.pys
   <dictcomp>	  s   	 i    u   outeru	   leftouterc         ` s     j  |  } | j t j k r4 |  | j d d f S j  |  } | | k re t d j |     n  | j | j k r |  | j d d f S|  | j d d f Sd S(   ua   
        if name is a string key, use the larger size of r1 or r2 before
        merging
        i    i   u@   The '{}' fields in arrays 'r1' and 'r2' must have the same dtypeN(   R   R4  R
   t   string_Ro  R   t   formatt   num(   Ry  t   dt1R   (   t   r1t   r2(    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   key_desc	  s    	c         ` s.   |    k s |   j  j k r" |  S|   Sd S(   uU   
        The column name in *newrec* that corresponds to the column in *r1*.
        N(   R   Ru  (   Ry  (   R,   t	   r1postfixR  (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   mapped_r1field
  s    c         ` s.   |    k s |   j  j k r" |  S|   Sd S(   uU   
        The column name in *newrec* that corresponds to the column in *r2*.
        N(   R   Ru  (   Ry  (   R,   R  t	   r2postfix(    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   mapped_r2field
  s    i   u   utf-8R   u6   rec_join defaults key="%s" not in new dtype names "%s"u   fu   iu   innert   orderN(   u   fu   i(   R3   R4   R5   R   Ru  R   R  R   R
   R:   R   t
   differenceRo  Rp  Rq  Rr  R.   R   R   t   kindR   Rs  t	   iteritemsR   ('   R,   R  R  t   jointypet   defaultsR  R  Ry  t   r1dt   r2dt   r1keyst   r2keyst   common_keyst   kt   r1indt   r2indt
   common_lent   left_lent	   right_lent	   left_keyst   left_indt
   right_keyst	   right_indR  t   keydescR  R  t   desct   r1desct   r2desct
   all_dtypesR   Rz  R{  t   thiskeyt   newrec_fieldsR  R|  t   newfield(    (   R,   R  R  R  R  R  s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   rec_join	  s    
&&
&&		00	1 	
$u   outerc         ` sn  g  } t  j t j |   g  | D] } t |  ^ q  }    f d   }	 | d k r x | D]/ \ }
 } | j |
 g t t |	 |    q_ WnX | d k r xI | D]> \ }
 } d | k r | j |
 g t t |	 |    q q Wn  | d k r%g  t	 t
 |   D] } d | ^ q} n  d j |  g g  | D] } d  | f ^ q8 } t j j | d | S(	   u  
    Join a sequence of record arrays on single column key.

    This function only joins a single column of the multiple record arrays

    *key*
      is the column name that acts as a key

    *name*
      is the name of the column that we want to join

    *recs*
      is a list of record arrays to join

    *jointype*
      is a string 'inner' or 'outer'

    *missing*
      is what any missing field is replaced by

    *postfixes*
      if not None, a len recs sequence of postfixes

    returns a record array with columns [rowkey, name0, name1, ... namen-1].
    or if postfixes [PF0, PF1, ..., PFN-1] are supplied,
    [rowkey, namePF0, namePF1, ... namePFN-1].

    Example::

      r = recs_join("date", "close", recs=[r0, r1], missing=0.)

    c         ` s   |  d  k r   S|   Sd  S(   N(   R.   (   R  (   t   missingRy  (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   extractp
  s    u   outeru   inneru   %du   ,u   %s%sRu  N(   R   t   align_iteratorsRX  t
   attrgettert   iterR  R   R   R.   R   R   R\  R
   Rt  R  (   R,   Ry  t   recsR  R  t	   postfixest   resultsR  t   aligned_itersR  t   rowkeyR  R   t   postfixRu  (    (   R  Ry  s.   lib/python2.7/site-packages/matplotlib/mlab.pyt	   recs_joinJ
  s     ""*-,$u   #u   ,u    c   $      ` s   d k r t    n   d k r- i   n  d d l } d d l } t j |    t |  } d d! d     Y} | d k r |    n  t j  d | }   f d   } | |    f d     f d	    d
   	 | j	 j
     f d      | j d d d     t t j    t d    t d    	 d  	    f d   
  
 | j d d d   
 	 
     f d    i d d 6d d 6d d 6}     	   f d   }  d k } | r\xF | D]> } t |  rA| d k	 rA| d j |  rAq
n  | } Pq
Wt d  } | j d  g   t   } x"t |  D] \ } } | j   j   j d d  } d j g  | D] } | | k r| ^ q } t |  sd | } n  | j | |  } | j | d  } | d k r: j | d |  n  j |  | d | | <qWn= t  t j  rg   j d  D] } | j   ^ q~ n  | | |  } | d k rt d   n   j  d  t j  d | } | |  | rCxK t! r?t" |  } t |  r;| d k	 r;| d j |  r;qn  PqWn  g  } g  } x t |  D] \ } } t |  szq\n  | d k	 r| d j |  rq\n  | j# d g t |  t |   | j g  t$ |  |  D] \ }  }! }" |  |! |"  ^ q | j g  t$  |  D] \ }! }"  |! |"  ^ q q\W j%   t |  sWd S|	 rt j& |  rt j' j( j) | d  d  | }# n t j* j) | d  }# |# S("   u.  
    Load data from comma/space/tab delimited file in *fname* into a
    numpy record array and return the record array.

    If *names* is *None*, a header row is required to automatically
    assign the recarray names.  The headers will be lower cased,
    spaces will be converted to underscores, and illegal attribute
    name characters removed.  If *names* is not *None*, it is a
    sequence of names to use for the column names.  In this case, it
    is assumed there is no header row.


    - *fname*: can be a filename or a file handle.  Support for gzipped
      files is automatic, if the filename ends in '.gz'

    - *comments*: the character used to indicate the start of a comment
      in the file, or *None* to switch off the removal of comments

    - *skiprows*: is the number of rows from the top to skip

    - *checkrows*: is the number of rows to check to validate the column
      data type.  When set to zero all rows are validated.

    - *converterd*: if not *None*, is a dictionary mapping column number or
      munged column name to a converter function.

    - *names*: if not None, is a list of header names.  In this case, no
      header will be read from the file

    - *missingd* is a dictionary mapping munged column names to field values
      which signify that the field does not contain actual data and should
      be masked, e.g., '0000-00-00' or 'unused'

    - *missing*: a string whose value signals a missing field regardless of
      the column it appears in

    - *use_mrecords*: if True, return an mrecords.fromrecords record array if
      any of the data are missing

    - *dayfirst*: default is False so that MM-DD-YY has precedence over
      DD-MM-YY.  See
      http://labix.org/python-dateutil#head-b95ce2094d189a89f80f5ae52a05b4ab7b41af47
      for further information.

    - *yearfirst*: default is False so that MM-DD-YY has precedence over
      YY-MM-DD. See
      http://labix.org/python-dateutil#head-b95ce2094d189a89f80f5ae52a05b4ab7b41af47
      for further information.

      If no rows are found, *None* is returned
    i    Nt   FHc           B` sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   uC  
        For space-delimited files, we want different behavior than
        comma or tab.  Generally, we want multiple spaces to be
        treated as a single separator, whereas with comma and tab we
        want multiple commas to return multiple (empty) fields.  The
        join/strip trick below effects this.
        c         S` s   | |  _  d  S(   N(   t   fh(   R   R  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR   
  s    c         S` s   |  j  j   d  S(   N(   R  t   close(   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR  
  s    c         S` s   |  j  j |  d  S(   N(   R  t   seek(   R   t   arg(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR  
  s    c         S` s   d j  | j    S(   Nu    (   R\  R  (   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   fix
  s    c         S` s   |  j  t |  j   S(   N(   R  t   nextR  (   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   __next__
  s    c         s` s&   x |  j  D] } |  j |  Vq
 Wd  S(   N(   R  R  (   R   t   line(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   __iter__
  s    (	   R   R   t   __doc__R   R  R  R  R  R  (    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR  
  s   					u    t	   delimiterc         ` sD    r: x1 t  |   D]  \ } } |  d k r Pq q Wn    |  f S(   Ni   (   R  (   t   readerR   R  (   R  t   skiprows(    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   process_skiprows
  s
    c         ` s+   |   k p* |  j  |   k p* | d k S(   u.   Should the value val in column name be masked?u    (   t   get(   Ry  t   val(   R  t   missingd(    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt	   ismissing
  s    c         ` s       f d   } | S(   Nc         ` s!    |  |  r   S |  Sd  S(   N(    (   Ry  R  (   t   defaultR  R  (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   newfunc
  s    (    (   R  R  R  (   R  (   R  R  s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   with_default_value
  s    c         S` s0   |  d k r t  S|  d k r  t St d   d  S(   Nu   Trueu   Falseu   invalid bool(   RT   RW   R   (   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   mybool   s
    c         ` s     |  d  d  } | S(   Nt   dayfirstt	   yearfirst(    (   R   R  (   t
   dateparserR  R  (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   mydateparser
  s    i   iu    c         ` s^     |  d  d  } | j  d k sE | j d k sE | j d k rT t d   n  | j   S(   NR  R  i    u
   not a date(   t   hourt   minutet   secondR   t   date(   R   R  (   R  R  R  (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   mydate  s    -c         ` so          g } xD | | j  |  D]/ } y | |  |  Wn t k
 rY q, n X| SWt d   d  S(   Nu,   Could not find a working conversion function(   R[  t	   ExceptionR   (   Ry  t   itemR  R  (   R  R  R  t   myfloatt   myintt   mystr(    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   get_func  s    u   return_u   returnu   file_u   fileu   print_u   printc   	      ` sF  d  } d } x3|  D]+} t |  rJ | d  k	 rJ | d j |  rJ q n  | d k rl  g t |  } n    r |   k r Pn  | d 7} x t t  |   D] \ } \ } }  j |  } | d  k r  j |  } n  | d  k r!| | } t | j    r0 | | |  } q0n  | d   } | | | <q Wq W| S(   Ni    i   (   R.   R   t
   startswithR  R   R  t   strip(	   R  t   commentst
   convertersR   R  R   Ry  R  R  (   t	   checkrowst
   converterdR  R  Ru  R  (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   get_converters1  s,    
(
u   ~!@#$%^&*()-=+~\|}[]{';: /?.>,<u   "u   _u   column%du   _%du   ,u)   Could not find any valid data in CSV fileRu  R   (    (+   R.   t   dictt   dateutil.parsert   datetimeR   t   to_filehandlet   strt   csvR  t   parsert   parseRB   R
   t   nanRJ   R  R   R  R   R   R  R  t   lowerR^  R\  R  R  R3   R4   R5   R  R   R  RT   R  R  R   R  t   anyt   mat   mrecordsR  Rt  ($   t   fnameR  R  R  R  R  Ru  R  R  t   use_mrecordsR  R  t   dateutilR  R  R  R  t   itemdR  t
   needheaderR  t   headerst   deletet   seenR   R  t   ct   cntRN   R  R  t   rowmasksR  Ry  R  R  (    (   R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  Ru  R  R  R  s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   csv2rec
  s    8	
	
	.+
	$	5	3
$t	   FormatObjc           B` s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C` s   |  j  |  S(   N(   t   toval(   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   tostr  s    c         C` s
   t  |  S(   N(   R  (   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    c         C` s   | S(   N(    (   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   fromstr  s    c         C` s   t  |  j  S(   u   
        override the hash function of any of the formatters, so that we don't
        create duplicate excel format styles
        (   t   hasht	   __class__(   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   __hash__  s    (   R   R   R  R  R  R  (    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s   			t   FormatStringc           B` s   e  Z d    Z RS(   c         C` s   t  |  } | d d !S(   Ni   i(   R]  (   R   R   R  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    (   R   R   R  (    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s   t   FormatFormatStrc           B` s   e  Z d    Z d   Z RS(   c         C` s   | |  _  d  S(   N(   t   fmt(   R   R  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR     s    c         C` s$   | d  k r d S|  j |  j |  S(   Nu   None(   R.   R  R  (   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    (   R   R   R   R  (    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s   	t   FormatFloatc           B` s2   e  Z d  d d  Z d   Z d   Z d   Z RS(   i   g      ?c         C` s*   t  j |  d |  | |  _ | |  _ d  S(   Nu   %%1.%df(   R  R   t	   precisiont   scale(   R   R!  R"  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR     s    	c         C` s   t  |  j |  j |  j f  S(   N(   R  R  R!  R"  (   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    c         C` s    | d  k	 r | |  j } n  | S(   N(   R.   R"  (   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    c         C` s   t  |  |  j S(   N(   RB   R"  (   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    (   R   R   R   R  R  R  (    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR     s   		t	   FormatIntc           B` s#   e  Z d    Z d   Z d   Z RS(   c         C` s   d t  |  S(   Nu   %d(   RJ   (   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    c         C` s
   t  |  S(   N(   RJ   (   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    c         C` s
   t  |  S(   N(   RJ   (   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    (   R   R   R  R  R  (    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR#    s   		t
   FormatBoolc           B` s   e  Z d    Z d   Z RS(   c         C` s
   t  |  S(   N(   R  (   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    c         C` s
   t  |  S(   N(   t   bool(   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    (   R   R   R  R  (    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR$    s   	t   FormatPercentc           B` s   e  Z d  d  Z RS(   i   c         C` s   t  j |  | d d d  S(   NR"  g      Y@(   R   R   (   R   R!  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR     s    (   R   R   R   (    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR&    s   t   FormatThousandsc           B` s   e  Z d  d  Z RS(   i   c         C` s   t  j |  | d d d  S(   NR"  gMbP?(   R   R   (   R   R!  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR     s    (   R   R   R   (    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR'    s   t   FormatMillionsc           B` s   e  Z d  d  Z RS(   i   c         C` s   t  j |  | d d d  S(   NR"  gư>(   R   R   (   R   R!  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR     s    (   R   R   R   (    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR(    s   u   date.strftimet
   FormatDatec           B` s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C` s   | |  _  d  S(   N(   R  (   R   R  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR     s    c         C` s   t  |  j |  j f  S(   N(   R  R  R  (   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    c         C` s    | d  k r d S| j |  j  S(   Nu   None(   R.   t   strftimeR  (   R   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    c         C` s"   d d  l  } | j j |  j   S(   Ni    (   R  R  R  R  (   R   R   R  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    (   R   R   R   R  R  R  (    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR)    s   			u   datetime.strftimet   FormatDatetimec           B` s   e  Z d  d  Z d   Z RS(   u   %Y-%m-%d %H:%M:%Sc         C` s   t  j |  |  d  S(   N(   R)  R   (   R   R  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR     s    c         C` s   d d  l  } | j j |  S(   Ni    (   R  R  R  (   R   R   R  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    (   R   R   R   R  (    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR+    s   c         C` s   i t    t j 6t   t j 6t   t j 6t   t j 6t   t j 6t   t j	 6t
   t j 6t   t j 6} | d k r t   } n  xm t |  j j  D]Y \ } } |  j | } | j |  } | d k r | j | j t
    } n  | | | <q W| S(   u=   build a formatd guaranteed to have a key for every dtype nameN(   R$  R
   t   bool_R#  t   int16t   int32t   int64R   t   float32t   float64R  t   object_R  R  R.   R  R  R   Ru  R  R4  (   R  t   formatdt   defaultformatdR   Ry  R   R  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   get_formatd  s$    c         C` s7   t  j |   }  t |  t  r3 d |  _ d |  _ n  |  S(   Ng      ?u   %r(   t   copyt   deepcopyR3   R   R"  R  (   R  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   csvformat_factory4  s
    	u   numpy.recarray.tofilei   c      	   ` s  | d k	 r t |  |  }  n  t j |  rF | g t |  j  } n  t   f d     f d   } | d k r |  j j } n  g  t |  j j  D]/ \ } } | | | |  j	 |  | |  ^ q } g  }	 x t
 t |   D] } | | \ }
 } } | d k r$|	 j |
 | | d f  q | | d \ } } } | d k rs|
 d k rs|	 j |
 |  | d f  q | d k r|
 d k r|	 j |
 | |  f  q |	 j |
 | | d f  q W  f d   } g  } | j d j g  t |  D] \ } } | | |	 |  ^ q  x t |   D]q \ } } | j d j g  t |  D] \ } } | | |	 |  ^ qM  | d k r(| d j   | d <q(q(Wt j j |  } | S(   u  
    Returns a textual representation of a record array.

    Parameters
    ----------
    r: numpy recarray

    header: list
        column headers

    padding:
        space between each column

    precision: number of decimal places to use for floats.
        Set to an integer to apply to all floats.  Set to a
        list of integers to apply precision individually.
        Precision for non-floats is simply ignored.

    fields : list
        If not None, a list of field names to print.  fields
        can be a list of strings like ['field1', 'field2'] or a single
        comma separated string like 'field1,field2'

    Examples
    --------

    For ``precision=[0,2,3]``, the output is ::

      ID    Price   Return
      ABC   12.54    0.234
      XYZ    6.32   -0.076
    c         ` sK   i t  d  6t t  6t t 6} y | t |    Wn   |  | |  SX| S(   N(   RJ   R.   RB   R  (   R  t   atypet   tdict(   t   get_type(    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR;  f  s    c         ` s  | j  } t j | t j  rW t | j d  } t t |   |  } d |  d f St j | t j  r t t |   t j t	 t
 t t	 t
 t |       } d |  d f St j | t j  r8d t |  d   t t |   t j t	 t
 t t	 t
   f d   |       } d |    f Sd t t |   t j t	 t
 t t	 t
 t |        d f S(	   Ni   i    u   %si   u   %du   %.u   fc         ` s     |  S(   N(    (   R   (   R  (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   <lambda>  s    (   R   R
   t
   issubdtypet	   characterRJ   R  R   R   t   integerR   R   t   floating(   t   colnamet   columnR!  t   ntypet   fixed_widtht   length(   RS  (   R  s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   get_justifyn  s&    	0	91i    i   c         ` s   | \ } } } } | d k r9 | d t  |   j |  S  |   t k r^ | t |   }  n%   |   t k r | t |   }  n  |  j |  Sd  S(   Ni    u    (   R  t   ljustRB   RJ   t   rjust(   R  t   just_pad_prec_spacert   justt   padt   prect   spacer(   R;  (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    u    N(   R.   R  R   t
   is_numlikeR   R   RJ   Ru  R  t   __getitem__R   R  R\  t   rstript   ost   linesep(   R  t   headerRS  R!  Rs  RF  R   RA  t   justify_pad_prect   justify_pad_prec_spacerRJ  RK  RL  t   pjustt   ppadt   pprecR  t   textlR   t   colitemR  t   text(    (   R;  RS  s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   rec2txt=  s@    #E 33c         C` s  t  |  } | d	 k r$ t   } n  d   } |  j d k rK t d   n  t |  |  } g  } x@ t |  j j  D], \ }	 }
 | j	 | t
 | |
  j   qs Wt j | d d t \ } } t j | d | } |  j j } | r | j |  n  g  } x' | D] }
 | j	 | j |
 |   qWt } t |   rV|  d } t | d  } n  x |  D] } | r| j   | j j   } } n t g t |  } | j g  t | | | |  D]$ \ } } } } | | | |  ^ q q]W| r| j   n  d	 S(
   u  
    Save the data from numpy recarray *r* into a
    comma-/space-/tab-delimited file.  The record array dtype names
    will be used for column headers.

    *fname*: can be a filename or a file handle.  Support for gzipped
      files is automatic, if the filename ends in '.gz'

    *withheader*: if withheader is False, do not write the attribute
      names in the first row

    for formatd type FormatFloat, we override the precision to store
    full precision floats in the CSV file

    See Also
    --------
    :func:`csv2rec`
        For information about *missing* and *missingd*, which can be used to
        fill in masked values into your CSV file.
    c         ` s     f d   } | S(   Nc         ` s   | r
 | S  |   Sd  S(   N(    (   R  R   t   mval(   R  (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    (    (   R  R  (    (   R  s.   lib/python2.7/site-packages/matplotlib/mlab.pyt	   with_mask  s    i   u0   rec2csv only operates on 1 dimensional recarraysu   wbt   return_openedR  i    u
   _fieldmaskN(   R  R.   R  R   R   R5  R  R   Ru  R  R8  R  R   R   RT   R  t   writert   writerowR  RW   R   t   hasattrR  t
   _fieldmaskR   R  (   R  R
  R  R3  R  R  t
   withheaderR^  R  R   Ry  R  t   openedR`  RS  t   mvalst   ismaskedR  t   rowmaskR  R  R   R]  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   rec2csv  s<    	$
	Bu   scipy.interpolate.griddatau   nnc         C` s  t  j |  d t  j }  t  j | d t  j } t  j | d t  j } |  j | j k s{ |  j | j k s{ |  j d k r t d   n  t  j | d t  j } t  j | d t  j } | j | j k r t d   n  | j d k r| j | j k rt d   n  | j d k r5t  j | |  \ } } n  | d k rJt } n! | d k r_t } n t d	   t  j	 j
 |  } | t  j	 j k	 r|  j |  }  | j |  } | j   } n  | ry d
 d l m } Wn t k
 rt d   n X| j d k r6| d
 d d  f } | d d  d
 f } n  | j d d
  | j d t  j  t  j t  j |   d
 k  st  j t  j |   d
 k  rt d   n  t  j | j d
 | j d
 f t  j  }	 t  j |  d d g }  t  j | d d g } t  j | d d g } t  j | d d g } t  j | d d g } | j |  | | | | |	  t  j t  j |	   rt  j	 j t  j |	  |	  }	 n  |	 Sd d l m }
 m } |
 |  |  } | | |  } | | |  Sd S(   u  
    Interpolates from a nonuniformly spaced grid to some other grid.

    Fits a surface of the form z = f(`x`, `y`) to the data in the
    (usually) nonuniformly spaced vectors (`x`, `y`, `z`), then
    interpolates this surface at the points specified by
    (`xi`, `yi`) to produce `zi`.

    Parameters
    ----------
    x, y, z : 1d array_like
        Coordinates of grid points to interpolate from.
    xi, yi : 1d or 2d array_like
        Coordinates of grid points to interpolate to.
    interp : string key from {'nn', 'linear'}
        Interpolation algorithm, either 'nn' for natural neighbor, or
        'linear' for linear interpolation.

    Returns
    -------
    2d float array
        Array of values interpolated at (`xi`, `yi`) points.  Array
        will be masked is any of (`xi`, `yi`) are outside the convex
        hull of (`x`, `y`).

    Notes
    -----
    If `interp` is 'nn' (the default), uses natural neighbor
    interpolation based on Delaunay triangulation.  This option is
    only available if the mpl_toolkits.natgrid module is installed.
    This can be downloaded from https://github.com/matplotlib/natgrid.
    The (`xi`, `yi`) grid must be regular and monotonically increasing
    in this case.

    If `interp` is 'linear', linear interpolation is used via
    matplotlib.tri.LinearTriInterpolator.

    Instead of using `griddata`, more flexible functionality and other
    interpolation options are available using a
    matplotlib.tri.Triangulation and a matplotlib.tri.TriInterpolator.
    R   i   u*   x, y and z must be equal-length 1-D arraysuD   xi and yi must be arrays with the same number of dimensions (1 or 2)i   u9   if xi and yi are 2D arrays, they must have the same shapeu   nnu   linearu   interp keyword must be one of 'linear' (for linear interpolation) or 'nn' (for natural neighbor interpolation).  Default is 'nn'.i    (   t   _natgridu   To use interp='nn' (Natural Neighbor interpolation) in griddata, natgrid must be installed. Either install it from http://github.com/matplotlib/natgrid or use interp='linear' instead.Nt   extt   nulu8   Output grid defined by xi,yi must be monotone increasingt   requirementsu   C(   t   Triangulationt   LinearTriInterpolator(    R
   t
   asanyarrayR1  R   R   R   t   meshgridRT   RW   R  t   getmaskt   nomaskt   compresst
   compressedt   mpl_toolkits.natgridRj  t   ImportErrorR   t   setit   setrR  R   R   R1  t   requiret   natgriddR  Rj  t   masked_wheret   triRn  Ro  (   R   RD   R  t   xit   yit   interpt   use_nn_interpolationR   Rj  t   ziRn  Ro  t   triangt   interpolator(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   griddata  sd    ,3!		<)!u   numpy.interpc   
      C` s~  t  j |   }  t  j |  } t  j |  } t | j  } t |  | d <t  j t  j |  } xt |  D]\ } } |  | k } t  j	 |  r t  j
 |  \ }	 | |	 d | | <qn | |  d k  r | rv| d | | <qvqn | |  d k r| rv| d | | <qvqn t  j
 |  | k   \ }	 t |	  }	 | |	 | |  |	 |  |	 d |  |	 | |	 d | |	 | | <qn W| S(   u  
    This function provides simple (but somewhat less so than
    :func:`cbook.simple_linear_interpolation`) linear interpolation.
    :func:`simple_linear_interpolation` will give a list of point
    between a start and an end, while this does true linear
    interpolation at an arbitrary set of points.

    This is very inefficient linear interpolation meant to be used
    only for a small number of points in relatively non-intensive use
    cases.  For real linear interpolation, use scipy.
    i    ii   (   R
   R   t
   atleast_1dR   R   R   t   tileR  R  R  R   R   (
   R   RD   R~  t   extrapR   R  t   iit   xxt   bbt   jj(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt    less_simple_linear_interpolation  s*    Fc         C` s   t  j |  t  }  t  j | t  } t  j | j t  } |  d |  d  } | d | d  } | | } | d  | d | d | d  | d | d  | d d +d | d | d | d | d <d | d | d | d | d <| S(   u  
    :func:`slopes` calculates the slope *y*'(*x*)

    The slope is estimated using the slope obtained from that of a
    parabola through any three consecutive points.

    This method should be superior to that described in the appendix
    of A CONSISTENTLY WELL BEHAVED METHOD OF INTERPOLATION by Russel
    W. Stineman (Creative Computing July 1980) in at least one aspect:

      Circles for interpolation demand a known aspect ratio between
      *x*- and *y*-values.  For many functions, however, the abscissa
      are given in different dimensions, so an aspect ratio is
      completely arbitrary.

    The parabola method gives very similar results to the circle
    method for most regular cases but behaves much better in special
    cases.

    Norbert Nemec, Institute of Theoretical Physics, University or
    Regensburg, April 2006 Norbert.Nemec at physik.uni-regensburg.de

    (inspired by a original implementation by Halldor Bjornsson,
    Icelandic Meteorological Office, March 2006 halldor at vedur.is)
    i   ig       @i    i(   R
   R   RB   R   R   (   R   RD   t   ypt   dxt   dyt   dydx(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   slopes  s    
9""c      	   C` s  t  j | t  } t  j | t  } | j | j k rE t d   n  | d k rc t | |  } n t  j | t  } t  j |  t  }  t  j |  j t  } | d | d  } | d | d  } | | } t  j | d d !|   } | j	 |  }	 | j	 |  }
 | j	 |  } | j	 | d  } | |	 |  |
 } | j	 |  |	 |  |
 } | j	 | d  |	 |  | } | | } | | t  j
 t  j t  j |  t  j  d d |  |
 | | | | |
 d d | | f  } | S(   u,  
    Given data vectors *x* and *y*, the slope vector *yp* and a new
    abscissa vector *xi*, the function :func:`stineman_interp` uses
    Stineman interpolation to calculate a vector *yi* corresponding to
    *xi*.

    Here's an example that generates a coarse sine curve, then
    interpolates over a finer abscissa::

      x = linspace(0,2*pi,20);  y = sin(x); yp = cos(x)
      xi = linspace(0,2*pi,40);
      yi = stineman_interp(xi,x,y,yp);
      plot(x,y,'o',xi,yi)

    The interpolation method is described in the article A
    CONSISTENTLY WELL BEHAVED METHOD OF INTERPOLATION by Russell
    W. Stineman. The article appeared in the July 1980 issue of
    Creative Computing with a note from the editor stating that while
    they were:

      not an academic journal but once in a while something serious
      and original comes in adding that this was
      "apparently a real solution" to a well known problem.

    For *yp* = *None*, the routine automatically determines the slopes
    using the :func:`slopes` routine.

    *x* is assumed to be sorted in increasing order.

    For values ``xi[j] < x[0]`` or ``xi[j] > x[-1]``, the routine
    tries an extrapolation.  The relevance of the data obtained from
    this, of course, is questionable...

    Original implementation by Halldor Bjornsson, Icelandic
    Meteorolocial Office, March 2006 halldor at vedur.is

    Completely reworked and optimized for Python by Norbert Nemec,
    Institute of Theoretical Physics, University or Regensburg, April
    2006 Norbert.Nemec at physik.uni-regensburg.de
    u!   'x' and 'y' must be of same shapei   ii   g        N(   R
   R   RB   R   R   R.   R  R   R   R   t   chooseR:   t   signR.  (   R~  R   RD   R  R  R  R  R   RM  t   sidxt   xidxt   yidxt   xidxp1t   yot   dy1t   dy2t   dy1dy2(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   stineman_interp  s4    ,

+t   GaussianKDEc           B` sA   e  Z d  Z d d  Z d   Z d   Z e Z d   Z e Z	 RS(   u  
    Representation of a kernel-density estimate using Gaussian kernels.

    Parameters
    ----------
    dataset : array_like
        Datapoints to estimate from. In case of univariate data this is a 1-D
        array, otherwise a 2-D array with shape (# of dims, # of data).

    bw_method : str, scalar or callable, optional
        The method used to calculate the estimator bandwidth.  This can be
        'scott', 'silverman', a scalar constant or a callable.  If a
        scalar, this will be used directly as `kde.factor`.  If a
        callable, it should take a `GaussianKDE` instance as only
        parameter and return a scalar. If None (default), 'scott' is used.

    Attributes
    ----------
    dataset : ndarray
        The dataset with which `gaussian_kde` was initialized.

    dim : int
        Number of dimensions.

    num_dp : int
        Number of datapoints.

    factor : float
        The bandwidth factor, obtained from `kde.covariance_factor`, with which
        the covariance matrix is multiplied.

    covariance : ndarray
        The covariance matrix of `dataset`, scaled by the calculated bandwidth
        (`kde.factor`).

    inv_cov : ndarray
        The inverse of `covariance`.

    Methods
    -------
    kde.evaluate(points) : ndarray
        Evaluate the estimated pdf on a provided set of points.

    kde(points) : ndarray
        Same as kde.evaluate(points)

    c         ` s  t  j |   _ t  j  j  j d k s< t d   n  t  j  j  j \  _  _ t	   t
 j  }   d  k r~ n | r   d k r  j  _ n | r   d k r  j  _ nj t  j    r | r d  _   f d    _ n6 t    r   _  f d    _ n t d    j    _ t  d	  st  j t  j  j d
 d d t   _ t  j j  j   _ n   j  j d  _  j  j d  _ t  j t  j j d t  j  j    j  _  d  S(   Ni   u.   `dataset` input should have multiple elements.u   scottu	   silvermanu   use constantc           ` s     S(   N(    (    (   t	   bw_method(    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR<  u  s    c           ` s     j     S(   N(   t
   _bw_method(    (   R   (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR<  x  s    uB   `bw_method` should be 'scott', 'silverman', a scalar or a callableu   _data_inv_covt   rowvarR?   i   (!   R
   RR   t   datasetR:   RA   R   R   R   t   num_dpR3   R4   R5   R.   t   scotts_factort   covariance_factort   silverman_factort   isscalarR  R6   t   factorRb  RC   RW   t   data_covarianceR   t   invt   data_inv_covt
   covariancet   inv_covR   t   detR   t   norm_factor(   R   R  R  t   isString(    (   R  R   s.   lib/python2.7/site-packages/matplotlib/mlab.pyR   e  s>    !				c         C` s   t  j |  j d |  j d  S(   Ng      i   (   R
   t   powerR  R   (   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    c         C` s-   t  j |  j |  j d d d |  j d  S(   Ng       @g      @g      i   (   R
   R  R  R   (   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR    s    c   	      C` s  t  j |  } t  j |  j \ } } | |  j k rT t d j | |  j    n  t  j | f d t } | |  j	 k rxt
 |  j	  D]o } |  j d d  | t  j f | } t  j |  j |  } t  j | | d d d } | t  j |  } q Wn x t
 |  D]~ } |  j | d d  | t  j f } t  j |  j |  } t  j | | d d d } t  j t  j |  d d | | <qW| |  j } | S(   u  Evaluate the estimated pdf on a set of points.

        Parameters
        ----------
        points : (# of dimensions, # of points)-array
            Alternatively, a (# of dimensions,) vector can be passed in and
            treated as a single point.

        Returns
        -------
        values : (# of points,)-array
            The values at each point.

        Raises
        ------
        ValueError : if the dimensionality of the input points is different
                     than the dimensionality of the KDE.

        u2   points have dimension {}, dataset has dimension {}R   NR   i    g       @(   R
   RR   R:   R   R   R   R  R   RB   R  R   R  R=   R   R  R\   R   R  (	   R   t   pointsR   t   num_mRk   R   R   t   tdifft   energy(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   evaluate  s&    	##'N(
   R   R   R  R.   R   R  R  R  R  t   __call__(    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR  1  s   /+			0c         C` s>   t  |  } g  t |   D]! \ } } | j |  r | ^ q S(   u   
    *points* is a sequence of *x*, *y* points.
    *verts* is a sequence of *x*, *y* vertices of a polygon.

    Return value is a sequence of indices into points for the points
    that are inside the polygon.
    (   R   R  t   contains_point(   R  t   vertst   polyRM  R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   inside_poly  s    
c         C` s   t  d   | | g D  r( t j } n t } | j |  } | j |  } t |  } t |  } | | k r t d   n  |  | j d |  } | j d |  } | | | *| | | *| d d d  | | )| | f S(   u/  
    Given a sequence of *xs* and *ys*, return the vertices of a
    polygon that has a horizontal base at *xmin* and an upper bound at
    the *ys*.  *xmin* is a scalar.

    Intended for use with :meth:`matplotlib.axes.Axes.fill`, e.g.,::

      xv, yv = poly_below(0, x, y)
      ax.fill(xv, yv)
    c         s` s$   |  ] } t  | t j j  Vq d  S(   N(   R3   R
   R  t   MaskedArray(   R  t   var(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pys	   <genexpr>  s    u'   'xs' and 'ys' must have the same lengthi   Ni(   R  R
   R  R   R   R   R!   (   R   t   xst   yst   numpyt   NxR   R   RD   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt
   poly_below  s    

c         C` s   t  d   | | |  g D  r+ t j } n t } t |   } t j |  sb | | j |  } n  t j |  s | | j |  } n  | j |  |  d d d  f  }  | j | | d d d  f  } |  | f S(   uC  
    Given a sequence of *x*, *ylower* and *yupper*, return the polygon
    that fills the regions between them.  *ylower* or *yupper* can be
    scalar or iterable.  If they are iterable, they must be equal in
    length to *x*.

    Return value is *x*, *y* arrays for use with
    :meth:`matplotlib.axes.Axes.fill`.
    c         s` s$   |  ] } t  | t j j  Vq d  S(   N(   R3   R
   R  R  (   R  R  (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pys	   <genexpr>
  s    Ni(   R  R
   R  R   R   R    R!   R^   (   R   t   ylowert   yupperR  R  RD   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   poly_between  s    ""c         C` s   t  j |  d |  d k  S(   u   
    Tests whether first and last object in a sequence are the same.  These are
    presumably coordinates on a polygonal curve, in which case this function
    tests if that curve is closed.
    i    i(   R
   t   all(   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   is_closed_polygon  s    t   messageu   Moved to matplotlib.cbookc         C` s   t  j |   S(   uq   
    return a list of (ind0, ind1) such that mask[ind0:ind1].all() is
    True and we cover all such regions
    (   R   t   contiguous_regions(   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyR  %  s    c         C` sV   t  j |   }  t  j |  d  | k  |  d | k @ d } t |  rN | d S| Sd S(   u  
    return the indices into *x* where *x* crosses some threshold from
    below, e.g., the i's where::

      x[i-1]<threshold and x[i]>=threshold

    Example code::

        import matplotlib.pyplot as plt

        t = np.arange(0.0, 2.0, 0.1)
        s = np.sin(2*np.pi*t)

        fig, ax = plt.subplots()
        ax.plot(t, s, '-o')
        ax.axhline(0.5)
        ax.axhline(-0.5)

        ind = cross_from_below(s, 0.5)
        ax.vlines(t[ind], -1, 1)

        ind = cross_from_above(s, -0.5)
        ax.vlines(t[ind], -1, 1)

        plt.show()

    See Also
    --------
    :func:`cross_from_above` and :func:`contiguous_regions`

    ii   i    N(   R
   R   R   R   (   R   t	   thresholdR>   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   cross_from_below.  s
    !+c         C` sV   t  j |   }  t  j |  d  | k |  d | k  @ d } t |  rN | d S| Sd S(   u   
    return the indices into *x* where *x* crosses some threshold from
    below, e.g., the i's where::

      x[i-1]>threshold and x[i]<=threshold

    See Also
    --------
    :func:`cross_from_below` and :func:`contiguous_regions`

    ii   i    N(   R
   R   R   R   (   R   R  R>   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   cross_from_aboveW  s
    +c         C` s.   t  j |   }  t  j |  | d | d | S(   u  
    Finds the length of a set of vectors in *n* dimensions.  This is
    like the :func:`numpy.norm` function for vectors, but has the ability to
    work over a particular axis of the supplied array or matrix.

    Computes ``(sum((x_i)^P))^(1/P)`` for each ``{x_i}`` being the
    elements of *X* along the given axis.  If *axis* is *None*,
    compute over all elements of *X*.
    R   g      ?(   R
   R   R\   (   R   t   PR   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   vector_lengthso  s    c         C` s%   t  j |  d d }  t |  d d S(   u   
    Computes the distance between a set of successive points in *N* dimensions.

    Where *X* is an *M* x *N* array or matrix.  The distances between
    successive rows is computed.  Distance is the standard Euclidean
    distance.
    R   i    i   (   R
   R   R  (   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   distances_along_curve~  s    	c         C` s1   t  |   }  t j t j d  t j |   f  S(   u   
    Computes the distance travelled along a polygonal curve in *N* dimensions.

    Where *X* is an *M* x *N* array or matrix.  Returns an array of
    length *M* consisting of the distance along the curve at each point
    (i.e., the rows of *X*).
    i   (   R  R
   R^   R   t   cumsum(   R   (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   path_length  s    	c   
      C` sf   |  d | |  | d | | } } | d | |  | d | | } }	 |  | | | | |	 | | f S(   u  
    Converts a quadratic Bezier curve to a cubic approximation.

    The inputs are the *x* and *y* coordinates of the three control
    points of a quadratic curve, and the output is a tuple of *x* and
    *y* coordinates of the four control points of the cubic curve.
    g       @g      @g      ?gUUUUUU?gUUUUUU?gUUUUUU?gUUUUUU?(    (
   t   q0xt   q0yt   q1xt   q1yt   q2xt   q2yt   c1xt   c1yt   c2xt   c2y(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt
   quad2cubic  s    %%c         C` s   t  j |  s6 t  j |  rM t |  t |   k rM |  | } |  | } n> t |  d k r |  | d |  | d } } n t d   | | f S(   uu  
    Offsets an array *y* by +/- an error and returns a tuple
    (y - err, y + err).

    The error term can be:

    * A scalar. In this case, the returned tuple is obvious.
    * A vector of the same length as *y*. The quantities y +/- err are computed
      component-wise.
    * A tuple of length 2. In this case, yerr[0] is the error below *y* and
      yerr[1] is error above *y*. For example::

        from pylab import *
        x = linspace(0, 2*pi, num=100, endpoint=True)
        y = sin(x)
        y_minus, y_plus = mlab.offset_line(y, 0.1)
        plot(x, y)
        fill_between(x, ym, y2=yp)
        show()

    i   i    i   u   yerr must be scalar, 1xN or 2xN(   R   RN  R    R   R   (   RD   t   yerrt   ymint   ymax(    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   offset_line  s    
 (   R  t
   __future__R    R   R   R   R4   t	   six.movesR   R   R   R6  R  RX  RQ  R   R  R
   t   matplotlib.cbookR   t
   matplotlibR   t   matplotlib.pathR   R9  t   PY3RJ   RO  t
   deprecatedR   R   R   R.   R+   R/   R9   R0   R2   R1   RQ   R"   Rp   Rt   t   interpdt   updatet   dedentt   dedent_interpdRz   Rx   R|   R}   R~   R   R   R   R   R   RT   RW   R   R   R   R   R   R   t   objectR   R   R   R   R  R  R  R  R  R  R-  R0  R3  R   R7  R8  R:  R<  R=  R>  R?  R@  RI  RN  RP  Rb  Rf  Rg  Ri  Rl  Rn  R}  R~  R  R  R  R  R  R  R  R  R  R   R#  R$  R&  R'  R(  R)  R+  R5  R8  R\  Ri  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  (    (    (    s.   lib/python2.7/site-packages/matplotlib/mlab.pyt   <module>   sr  "					8?/	/D7		
	
$
@E	+	/	+	+W0	'H	9

C$,	: 
		x	F(*^
	)