ó
šßÈ[c           @   sÛ  d  d l  m Z d  d l Z d d l m Z m Z m Z m Z m	 Z	 d „  Z
 d „  Z i  Z e e j e j e j e j e j e j e j e j e j e j g
 ƒ Z xB d/ D]: Z e e e d ƒ Z e e e j ƒ r« e e h OZ q« q« Wd
 „  Z e e e j <e e e j  <e e e j! <e e e j" <e e e j# <d „  Z$ e$ e e j% <e$ e e j& <e$ e e j' <e$ e e j( <e$ e e j) <e$ e e j* <e$ e e j+ <e$ e e j, <e$ e e j- <e$ e e j. <e e e d d ƒ e j ƒ rìe$ e e j/ <n  d „  e e j0 <d „  e e j1 <d „  e e j2 <e e e d d ƒ e j ƒ rMd „  e e j3 <n  d „  e e j j4 j5 <d „  Z6 e6 e e j7 <e6 e e j8 <e6 e e j9 <e6 e e j: <e6 e e j; <e6 e e j< <e6 e e j= <e e e j j4 d d ƒ e j ƒ re6 e e j j4 j> <n  d „  Z? e? e e j@ <d „  ZA eA e e jB <eA e e jC <eA e e jD <eA e e jE <eA e e jF <eA e e jG <d „  ZH eH e e jI <eH e e jJ <d „  ZK eK e e jL <eK e e jM <d „  ZN eN e e jO <eN e e jP <eN e e jQ <eN e e jR <eN e e jS <eN e e jT <d „  ZU eU e e jV <d „  ZW eW e e jX <d „  ZY eY e e jZ <eY e e j[ <d „  Z\ e\ e e j] <e e e d d ƒ e j ƒ rže\ e e j^ <n  d „  Z_ e_ e e j` <d  „  Za ea e e jb <e e e d! d ƒ e j ƒ rd" „  Zc ec e e jd <n  d# „  Ze ee e e jf <ee e e jg <d$ „  Zh d% „  Zi ei e e jj <ei e e jk <ei e e jl <ei e e jm <ei e e jn <ei e e jo <ei e e jp <ei e e jq <ei e e jr <ei e e js <ei e e jt <d& „  Zu eu e e jv <eu e e jw <eu e e jx <eu e e jy <eu e e jz <eu e e j{ <d' „  Z| e| e e j} <e e e j j4 d( d ƒ e j ƒ rle| e e j j4 j~ <n  d) „  Z e e e j€ <e e e d* d ƒ e j ƒ r¹d+ „  Z e e e j‚ <n  d, „  Zƒ d- „  Z„ d d. „ Z… d S(0   iÿÿÿÿ(   t   FractionNi   (   t
   UnitsErrort   UnitConversionErrort   UnitTypeErrort   dimensionless_unscaledt   get_current_unit_registryc         C   s   |  d  k r t S|  Sd  S(   N(   t   NoneR   (   t   unit(    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   _d   s    c            s†   y |  j  | ƒ ‰  WnO t k
 r< |  j |  | t ƒ  j ƒ St k
 rd t d j |  | ƒ ƒ ‚ n Xˆ  d k ru d S‡  f d †  Sd S(   sp   Like Unit._get_converter, except returns None if no scaling is needed,
    i.e., if the inferred scale is unity.s'   Unit '{0}' cannot be converted to '{1}'g      ð?c            s   ˆ  |  S(   N(    (   t   val(   t   scale(    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   <lambda>    s    N(	   t   _toR   t   _apply_equivalenciesR   t   equivalenciest   AttributeErrorR   t   formatR   (   t	   from_unitt   to_unit(    (   R
   s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   get_converter   s    	t   isnatt   gcdt   lcmc         C   s   d  g d  f S(   N(   R   (   t   fR   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyR   =   s    c         C   s   d  g t | ƒ f S(   N(   R   R   (   R   R   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyR   G   s    t   positivec         C   s#   d  g | d  k	 r | d n t f S(   Ng      à?(   R   R   (   R   R   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyR   Y   s    c         C   s#   d  g | d  k	 r | d n t f S(   Ni   (   R   R   (   R   R   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyR   [   s    c         C   s#   d  g | d  k	 r | d n t f S(   Niÿÿÿÿ(   R   R   (   R   R   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyR   ]   s    t   cbrtc         C   s,   d  g | d  k	 r% | t d d ƒ n t f S(   Ni   i   (   R   R    R   (   R   R   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyR   a   s    %c         C   s   d  g t f S(   N(   R   R   (   R   R   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyR   d   s    c         C   sc   | d  k r d  g t f Sy t | t ƒ g t f SWn) t k
 r^ t d j |  j ƒ ƒ ‚ n Xd  S(   Ns9   Can only apply '{0}' function to dimensionless quantities(   R   R   R   R   R   R   t   __name__(   R   R   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt%   helper_dimensionless_to_dimensionlessj   s    	t   erfc         C   so   | d  k r d  g t t f f Sy  t | t ƒ g t t f f SWn) t k
 rj t d j |  j ƒ ƒ ‚ n Xd  S(   Ns9   Can only apply '{0}' function to dimensionless quantities(   R   R   R   R   R   R   R   (   R   R   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_modf…   s    	c         C   ss   d d l  m } | d  k r) d  g | f Sy t | t ƒ g | f SWn) t k
 rn t d j |  j ƒ ƒ ‚ n Xd  S(   Ni   (   t   radians9   Can only apply '{0}' function to dimensionless quantities(	   t   siR   R   R   R   R   R   R   R   (   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_dimensionless_to_radian–   s    	c         C   s`   d d l  m } m } y t | | ƒ g | f SWn) t k
 r[ t d j |  j ƒ ƒ ‚ n Xd  S(   Ni   (   t   degreeR   s<   Can only apply '{0}' function to quantities with angle units(   R   R!   R   R   R   R   R   R   (   R   R   R!   R   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_degree_to_radian¬   s    	c         C   s`   d d l  m } m } y t | | ƒ g | f SWn) t k
 r[ t d j |  j ƒ ƒ ‚ n Xd  S(   Ni   (   R!   R   s<   Can only apply '{0}' function to quantities with angle units(   R   R!   R   R   R   R   R   R   (   R   R   R!   R   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_radian_to_degree»   s    	c         C   sZ   d d l  m } y t | | ƒ g t f SWn) t k
 rU t d j |  j ƒ ƒ ‚ n Xd  S(   Ni   (   R   s<   Can only apply '{0}' function to quantities with angle units(   R   R   R   R   R   R   R   R   (   R   R   R   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_radian_to_dimensionlessÊ   s    	c         C   s4   | j  ƒ  s' t d j |  j ƒ ƒ ‚ n  d  g d f S(   NsB   Can only apply '{0}' function to unscaled dimensionless quantities(   NN(   t   is_unityR   R   R   R   (   R   R   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_frexpÝ   s    	c         C   s    d  d  g t | ƒ t | ƒ f S(   N(   R   R   (   R   t   unit1t   unit2(    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_multiplicationé   s    c         C   s    d  d  g t | ƒ t | ƒ f S(   N(   R   R   (   R   R'   R(   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_divisionð   s    c         C   s]   | d  k r d  d  g t f Sy d  t | t ƒ g t f SWn t k
 rX t d ƒ ‚ n Xd  S(   Ns4   Can only raise something to a dimensionless quantity(   R   t   FalseR   R   R   R   (   R   R'   R(   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_powerø   s    t   float_powerc         C   s5   | d  k	 r t d ƒ ‚ n d  d  g t | ƒ f Sd  S(   Ns4   Cannot use ldexp with a quantity as second argument.(   R   t	   TypeErrorR   (   R   R'   R(   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_ldexp  s    c         C   s0   | d  k r d  d  g d  f Sd  d  g | f Sd  S(   N(   R   (   R   R'   R(   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_copysign  s    t	   heavisidec         C   sU   y% | d  k	 r t | t ƒ n d  } Wn t k
 rD t d ƒ ‚ n Xd  | g t f S(   NsI   Can only apply 'heaviside' function with a dimensionless second argument.(   R   R   R   R   R   (   R   R'   R(   t
   converter2(    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_heaviside"  s
    %c         C   s‚   yF | d  k	 r t | t ƒ n d  } | d  k	 r? t | t ƒ n d  } Wn) t k
 rq t d j |  j ƒ ƒ ‚ n X| | g t f S(   Ns9   Can only apply '{0}' function to dimensionless quantities(   R   R   R   R   R   R   R   (   R   R'   R(   t
   converter1R2   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_two_arg_dimensionless.  s    !%	c         G   s  d  d  g } t d „  | Dƒ ƒ r, | t f S| d d  k rB d n d \ } } | | d  k r¯ y t | | t ƒ | | <Wn& t k
 r¡ t | | <| | | f SX| t f SnY y t | | | | ƒ | | <Wn) t k
 rù t d j |  j ƒ ƒ ‚ n X| | | f Sd  S(   Nc         s   s   |  ] } | d  k Vq d  S(   N(   R   (   t   .0R   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pys	   <genexpr>C  s    i   i    sF   Can only apply '{0}' function to quantities with compatible dimensions(   i   i    (   i    i   (	   R   t   allR   R   R   R+   R   R   R   (   R   t   unitst
   converterst   fixedt
   changeable(    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   get_converters_and_unit?  s(    
"


c         C   s   t  |  | | ƒ S(   N(   R<   (   R   R'   R(   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_twoarg_invariant_  s    c         C   s"   t  |  | | ƒ \ } } | d  f S(   N(   R<   R   (   R   R'   R(   R9   t   _(    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_twoarg_comparisonp  s    c         C   s2   d d l  m } t |  | | ƒ \ } } | | f S(   Ni   (   R   (   R   R   R<   (   R   R'   R(   R   R9   R>   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_twoarg_invtrig}  s    t   _argc         C   s"   t  |  | | ƒ \ } } | t f S(   N(   R<   R   (   R   R'   R(   R9   R>   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_twoarg_floor_divide‰  s    t   divmodc         C   s(   t  |  | | ƒ \ } } | t | f f S(   N(   R<   R   (   R   R'   R(   R9   t   result_unit(    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   helper_divmod’  s    c         C   s/   t  j t  j t  j |  d ƒ t  j |  ƒ ƒ ƒ S(   sB  Test whether the items in value can have arbitrary units

    Numbers whose value does not change upon a unit change, i.e.,
    zero, infinity, or not-a-number

    Parameters
    ----------
    value : number or array

    Returns
    -------
    `True` if each member is either zero or not finite, `False` otherwise
    g        (   t   npR7   t
   logical_ort   equalt   isfinite(   t   value(    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   can_have_arbitrary_unit™  s    c         G   s  |  t  k r' t d j |  j ƒ ƒ ‚ n  | d k sN | d k r-|  j d k r-g  | D] } t | d d ƒ ^ qU } |  t k r› t |  |  | Œ \ } } n t d j |  j ƒ ƒ ‚ t d „  | Dƒ ƒ r\| | j	 t
 ƒ } y7 t | ƒ rú d d g } n t d j |  j ƒ ƒ ‚ Wq\t k
 rXt d	 j |  j | d
 j j | d j j ƒ ƒ ‚ q\Xn  | t
 k r| d
 d k sˆ| d
 t k r‘t } q*| d d k r®| d } n | d j t ƒ j } y | d
 | } Wq*t k
 r&}	 y | d
 j t ƒ | d
 <Wn t k
 r|	 ‚ q'Xt } q*XqnÙ| d k r³t | d
 d d ƒ }
 |
 g } |  j d k r‡| j t | d d d ƒ ƒ n  t |  |  | Œ \ } } | j d d ƒ n¾ | d k r)|  j d k r)t | d
 d d ƒ }
 t |  |  |
 |
 ƒ \ } } | d  } | d k rq| d g 7} qqnH | d k r\|  j d k r\t d j | ƒ ƒ ‚ n  t d j | ƒ ƒ ‚ |
 d k	 r§| d k r§t d j |  j | ƒ ƒ ‚ n  | d
 d k	 sè|
 d k	 r| j |
 ƒ sè| j |
 ƒ d k rt d j |  j | ƒ ƒ ‚ n  | | f S(   s2  Determine the required converters and the unit of the ufunc result.

    Converters are functions required to convert to a ufunc's expected unit,
    e.g., radian for np.sin; or to ensure units of two inputs are consistent,
    e.g., for np.add.  In these examples, the unit of the result would be
    dimensionless_unscaled for np.sin, and the same consistent unit for np.add.

    Parameters
    ----------
    function : `~numpy.ufunc`
        Numpy universal function
    method : str
        Method with which the function is evaluated, e.g.,
        '__call__', 'reduce', etc.
    *args : Quantity or other ndarray subclass
        Input arguments to the function

    Raises
    ------
    TypeError : when the specified function cannot be used with Quantities
        (e.g., np.logical_or), or when the routine does not know how to handle
        the specified function (in which case an issue should be raised on
        https://github.com/astropy/astropy).
    UnitTypeError : when the conversion to the required (or consistent) units
        is not possible.
    s)   Cannot use function '{0}' with quantitiest   __call__t   outeri   R   sL   Unknown ufunc {0}.  Please raise issue on https://github.com/astropy/astropyc         s   s   |  ] } | t  k Vq d  S(   N(   R+   (   R6   t	   converter(    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pys	   <genexpr>Û  s    sŒ   Can only apply '{0}' function to dimensionless quantities when other argument is not a quantity (unless the latter is all zero/infinity/nan)s:   Unsupported operand type(s) for ufunc {0}: '{1}' and '{2}'i    i   t   att   reducet
   accumulatet   reduceats'   {0} only supported for binary functionssm   Unexpected ufunc method {0}.  If this should work, please raise an issue onhttps://github.com/astropy/astropys^   Cannot use '{1}' method on ufunc {0} with a Quantity instance as the result is not a Quantity.g      ð?sZ   Cannot use '{1}' method on ufunc {0} with a Quantity instance as it would change the unit.N(   RP   RQ   RR   (   RP   RQ   RR   RM   (   t   UNSUPPORTED_UFUNCSR.   R   R   t   nint   getattrR   t   UFUNC_HELPERSt   anyt   indexR+   RK   R   t	   __class__R   t   toRJ   t
   ValueErrort   _get_converterR   t   appendt   insertt   is_equivalent(   t   functiont   methodt   argst   argR8   R9   RD   t   maybe_arbitrary_argt   pt   excR   (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   converters_and_unitª  s„    	'%			 	

	 

				c            s¶  t  |  t ƒ r5 t ‡  ‡ f d †  t |  | ƒ Dƒ ƒ S|  d k rE d St |  d ƒ r%| d k rŸ t d j ˆ  d k	 r‡ d j ˆ  j ƒ n d t |  ƒ ƒ ƒ ‚ n  |  j	 | ƒ d t |  ƒ k	 rt
 d j | ˆ  d k	 rè d j ˆ  j ƒ n d t |  ƒ |  j	 | ƒ d ƒ ƒ ‚ n  |  j t j ƒ }  nN | d k p:| t k sst
 d j ˆ  d k rXd n d	 j ˆ  j ƒ ƒ ƒ ‚ n  t j t j ˆ Œ  |  j d
 d ƒs²t d j |  j ƒ ƒ ‚ n  |  S(   s¢  Check that function output can be stored in the output array given.

    Parameters
    ----------
    output : array or `~astropy.units.Quantity` or tuple
        Array that should hold the function output (or tuple of such arrays).
    unit : `~astropy.units.Unit` or None, or tuple
        Unit that the output will have, or `None` for pure numbers (should be
        tuple of same if output is a tuple of outputs).
    inputs : tuple
        Any input arguments.  These should be castable to the output.
    function : callable
        The function that will be producing the output.  If given, used to
        give a more informative error message.

    Returns
    -------
    arrays : `~numpy.ndarray` view of ``output`` (or tuple of such views).

    Raises
    ------
    UnitTypeError : If ``unit`` is inconsistent with the class of ``output``

    TypeError : If the ``inputs`` cannot be cast safely to ``output``.
    c         3   s*   |  ]  \ } } t  | | ˆ ˆ  ƒ Vq d  S(   N(   t   check_output(   R6   t   output_t   unit_(   R`   t   inputs(    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pys	   <genexpr>[  s   t   __quantity_subclass__s3   Cannot store non-quantity output{0} in {1} instances    from {0} functiont    i    sR   Cannot store output with unit '{0}'{1} in {2} instance.  Use {3} instance instead.sC   Cannot store quantity with dimension {0}in a non-Quantity instance.s   resulting from {0} function t   castingt	   same_kinds@   Arguments cannot be cast safely to inplace output with dtype={0}N(   t
   isinstancet   tuplet   zipR   t   hasattrR.   R   R   t   typeRl   R   t   viewRF   t   ndarrayR   t   can_castt   result_typet   dtype(   t   outputR   Rk   R`   (    (   R`   Rk   s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyRh   @  s6    	!*			(   R   R   R   (†   t	   fractionsR    t   numpyRF   t   coreR   R   R   R   R   R   R   RV   t   sett   bitwise_andt
   bitwise_ort   bitwise_xort   invertt
   left_shiftt   right_shiftt   logical_andRG   t   logical_xort   logical_notRS   t   nameRU   R   t   ufuncRp   t   helper_onearg_testRI   t   isinft   isnant   signt   signbitt   helper_invariantt   absolutet   fabst   conjt	   conjugatet   negativet   spacingt   rintt   floort   ceilt   truncR   t   sqrtt   squaret
   reciprocalR   t   umatht
   _ones_likeR   t   expt   expm1t   exp2t   logt   log10t   log2t   log1pR   R   t   modfR    t   arccost   arcsint   arctant   arccosht   arcsinht   arctanhR"   t   radianst   deg2radR#   t   degreest   rad2degR$   t   cost   sint   tant   cosht   sinht   tanhR&   t   frexpR)   t   multiplyR*   t   dividet   true_divideR,   t   powerR-   R/   t   ldexpR0   t   copysignR3   R1   R5   t	   logaddexpt
   logaddexp2R<   R=   t   addt   subtractt   hypott   maximumt   minimumt   fmint   fmaxt	   nextaftert	   remaindert   modt   fmodR?   t   greatert   greater_equalt   lesst
   less_equalt	   not_equalRH   R@   t   arctan2RA   RB   t   floor_divideRE   RC   RK   Rg   Rh   (    (    (    s<   lib/python2.7/site-packages/astropy/units/quantity_helper.pyt   <module>   sö   (		
			$			
	
	
										 			$				–