ó
 ‰\c           @   s  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 Z d d l m	 Z	 d d l
 m Z m Z d d d d	 d
 d g Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d d „ Z d d „ Z d d „ Z d „  Z d „  Z d S(   iÿÿÿÿNi   (   t   img_as_floati   (   t   all_warningst   warnt
   deprecatedt   get_bound_method_classR   t   safe_as_intt	   assert_nDR   t   skimage_deprecationc           B   s   e  Z d  Z RS(   sa   Create our own deprecation class, since Python >= 2.7
    silences deprecations by default.

    (   t   __name__t
   __module__t   __doc__(    (    (    s4   lib/python2.7/site-packages/skimage/_shared/utils.pyR      s   c           B   s)   e  Z d  Z d d d d „ Z d „  Z RS(   sú  Decorator to mark deprecated functions with warning.

    Adapted from <http://wiki.python.org/moin/PythonDecoratorLibrary>.

    Parameters
    ----------
    alt_func : str
        If given, tell user what function to use instead.
    behavior : {'warn', 'raise'}
        Behavior during call to deprecated function: 'warn' = warn user that
        function is deprecated; 'raise' = raise error.
    removed_version : str
        The package version in which the deprecated function will be removed.
    R   c         C   s   | |  _  | |  _ | |  _ d  S(   N(   t   alt_funct   behaviort   removed_version(   t   selfR   R   R   (    (    s4   lib/python2.7/site-packages/skimage/_shared/utils.pyt   __init__)   s    		c            sÄ   d } ˆ j  d  k	 r% d ˆ j  } n  d } ˆ j d  k	 rJ d ˆ j } n  d ˆ  j | d | ‰ t j ˆ  ƒ ‡  ‡ ‡ f d †  ƒ } d | } | j d  k r¬ | | _ n | d | j | _ | S(	   Nt    s    Use ``%s`` instead.s"    and will be removed in version %ss   Function ``%s`` is deprecatedt   .c       	      s…   ˆ j  d k rZ t j ˆ  ƒ } t j d t ƒ t j ˆ d t d | j d | j d ƒn ˆ j  d k rx t ˆ ƒ ‚ n  ˆ  |  | Ž  S(   NR   t   alwayst   categoryt   filenamet   linenoi   t   raise(	   R   t   sixt   get_function_codet   warningst   simplefilterR   t   warn_explicitt   co_filenamet   co_firstlineno(   t   argst   kwargst	   func_code(   t   funct   msgR   (    s4   lib/python2.7/site-packages/skimage/_shared/utils.pyt   wrapped;   s    	s   **Deprecated function**.s   

    (   R   t   NoneR   R   t	   functoolst   wrapsR
   (   R   R!   t   alt_msgt   rmv_msgR#   t   doc(    (   R!   R"   R   s4   lib/python2.7/site-packages/skimage/_shared/utils.pyt   __call__.   s    $
N(   R   R	   R
   R$   R   R*   (    (    (    s4   lib/python2.7/site-packages/skimage/_shared/utils.pyR      s   c         C   s    t  j d k  r |  j S|  j j S(   s*   Return the class for a bound method.

    t   3(   t   syst   versiont   im_classt   __self__t	   __class__(   t   m(    (    s4   lib/python2.7/site-packages/skimage/_shared/utils.pyR   R   s    gü©ñÒMbP?c         C   s»   t  j |  ƒ d } | j d k r> | d k r\ d | } q\ n d | | d k | | d k <y t  j j | d d | ƒWn& t k
 r¡ t d j |  ƒ ƒ ‚ n Xt  j |  ƒ j	 t  j
 ƒ S(   sÇ  
    Attempt to safely cast values to integer format.

    Parameters
    ----------
    val : scalar or iterable of scalars
        Number or container of numbers which are intended to be interpreted as
        integers, e.g., for indexing purposes, but which may not carry integer
        type.
    atol : float
        Absolute tolerance away from nearest integer to consider values in
        ``val`` functionally integers.

    Returns
    -------
    val_int : NumPy scalar or ndarray of dtype `np.int64`
        Returns the input value(s) coerced to dtype `np.int64` assuming all
        were within ``atol`` of the nearest integer.

    Notes
    -----
    This operation calculates ``val`` modulo 1, which returns the mantissa of
    all values. Then all mantissas greater than 0.5 are subtracted from one.
    Finally, the absolute tolerance from zero is calculated. If it is less
    than ``atol`` for all value(s) in ``val``, they are rounded and returned
    in an integer array. Or, if ``val`` was a scalar, a NumPy scalar type is
    returned.

    If any value(s) are outside the specified tolerance, an informative error
    is raised.

    Examples
    --------
    >>> safe_as_int(7.0)
    7

    >>> safe_as_int([9, 4, 2.9999999999])
    array([9, 4, 3])

    >>> safe_as_int(53.1)
    Traceback (most recent call last):
        ...
    ValueError: Integer argument required but received 53.1, check inputs.

    >>> safe_as_int(53.01, atol=0.01)
    53

    i   i    g      à?t   atols9   Integer argument required but received {0}, check inputs.(   t   npt   asarrayt   ndimt   testingt   assert_allcloset   AssertionErrort
   ValueErrort   formatt   roundt   astypet   int64(   t   valR2   t   mod(    (    s4   lib/python2.7/site-packages/skimage/_shared/utils.pyR   Y   s    1	t   imagec         C   s¦   t  j |  ƒ }  d } d } t | t ƒ r6 | g } n  |  j d k rX t | | ƒ ‚ n  |  j | k r¢ t | | d j g  | D] } t | ƒ ^ q} ƒ f ƒ ‚ n  d S(   sJ  
    Verify an array meets the desired ndims and array isn't empty.

    Parameters
    ----------
    array : array-like
        Input array to be validated
    ndim : int or iterable of ints
        Allowable ndim or ndims for the array.
    arg_name : str, optional
        The name of the array in the original function.

    s1   The parameter `%s` must be a %s-dimensional arrays+   The parameter `%s` cannot be an empty arrayi    s   -or-N(	   R3   t
   asanyarrayt
   isinstancet   intt   sizeR9   R5   t   joint   str(   t   arrayR5   t   arg_namet   msg_incorrect_dimt   msg_empty_arrayt   n(    (    s4   lib/python2.7/site-packages/skimage/_shared/utils.pyR   œ   s    c         C   sF   t  j t j |  ƒ t j |  ƒ | p* |  j t j |  ƒ t j |  ƒ ƒ S(   s£   Create a copy of a function.

    Parameters
    ----------
    f : function
        Function to copy.
    name : str, optional
        Name of new function.

    (   t   typest   FunctionTypeR   R   t   get_function_globalsR   t   get_function_defaultst   get_function_closure(   t   ft   name(    (    s4   lib/python2.7/site-packages/skimage/_shared/utils.pyt	   copy_funcµ   s    c         C   s€   |  d k s |  t j k r( t j j j St |  t j t j f ƒ rS t j j	 |  ƒ St |  t j j	 ƒ rl |  St
 d |  ƒ ‚ d S(   sÀ  Turn seed into a `np.random.RandomState` instance.

    Parameters
    ----------
    seed : None, int or np.random.RandomState
           If `seed` is None, return the RandomState singleton used by `np.random`.
           If `seed` is an int, return a new RandomState instance seeded with `seed`.
           If `seed` is already a RandomState instance, return it.

    Raises
    ------
    ValueError
        If `seed` is of the wrong type.

    s=   %r cannot be used to seed a numpy.random.RandomState instanceN(   R$   R3   t   randomt   mtrandt   _randRB   t   numberst   Integralt   integert   RandomStateR9   (   t   seed(    (    s4   lib/python2.7/site-packages/skimage/_shared/utils.pyt   check_random_stateÅ   s    c         C   s+   | r |  j  t j ƒ }  n t |  ƒ }  |  S(   sd  Convert input image to double image with the appropriate range.

    Parameters
    ----------
    image : ndarray
        Input image.
    preserve_range : bool
        Determines if the range of the image should be kept or transformed
        using img_as_float.

    Returns
    -------
    image : ndarray
        Transformed version of the input.
    (   R<   R3   t   doubleR    (   R@   t   preserve_range(    (    s4   lib/python2.7/site-packages/skimage/_shared/utils.pyt   convert_to_floatà   s    (   R   R%   R,   t   numpyR3   RL   RW   R   t   utilR    t	   _warningsR   R   t   __all__t   WarningR   t   objectR   R   R   R   R$   RS   R\   R_   (    (    (    s4   lib/python2.7/site-packages/skimage/_shared/utils.pyt   <module>   s$   	9	C	