B
    d%!                @   s  d Z ddlZddlZddlmZ ddlZddlZddlm	Z	m
Z
mZmZmZmZmZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZ ddl m!Z!m"Z"m#Z# ddl$m%Z%m&Z&m'Z'm(Z( ddddddgZ)dgZ*dZ+ej,ej-ej.ej/hZ0G dd dej1Z2e2 Z3G dd dZ4G dd deZ5G dd de5Z6G dd dej7Z8G dd de8Z9d&d!dZ:d'e;d"d#dZ<d$d% Z=dS )(z
This module defines the `Quantity` object, which represents a number with some
associated units. `Quantity` objects support operations like ordinary numbers,
but will deal with unit conversions internally.
    N)Fraction   )Unitdimensionless_unscaledget_current_unit_registryUnitBase
UnitsErrorUnitConversionErrorUnitTypeError)is_effectively_unity)Latex)override__dir__)AstropyDeprecationWarningAstropyWarning)
isiterable)ParentDtypeInfo)config)converters_and_unitcan_have_arbitrary_unitcheck_output)SUBCLASS_SAFE_FUNCTIONSFUNCTION_HELPERSDISPATCHED_FUNCTIONSUNSUPPORTED_FUNCTIONSQuantitySpecificTypeQuantityQuantityInfoBaseQuantityInfoallcloseisclosez
Quantity.*z(Unit not initialised)c               @   s   e Zd ZdZeddZdS )Confz/
    Configuration parameters for Quantity
    d   a&  The maximum size an array Quantity can be before its LaTeX representation for IPython gets "summarized" (meaning only the first and last few elements are shown with "..." between). Setting this to a negative number means that the value will instead be whatever numpy gets from get_printoptions.N)__name__
__module____qualname____doc___configZ
ConfigItemlatex_array_threshold r(   r(   c/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/astropy/units/quantity.pyr    .   s   r    c               @   s<   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZeZ	dS )QuantityIteratora  
    Flat iterator object to iterate over Quantities

    A `QuantityIterator` iterator is returned by ``q.flat`` for any Quantity
    ``q``.  It allows iterating over the array as if it were a 1-D array,
    either in a for-loop or by calling its `next` method.

    Iteration is done in C-contiguous style, with the last index varying the
    fastest. The iterator can also be indexed using basic slicing or
    advanced indexing.

    See Also
    --------
    Quantity.flatten : Returns a flattened copy of an array.

    Notes
    -----
    `QuantityIterator` is inspired by `~numpy.ma.core.MaskedIterator`.  It
    is not exported by the `~astropy.units` module.  Instead of
    instantiating a `QuantityIterator` directly, use `Quantity.flat`.
    c             C   s   || _ |tjj| _d S )N)	_quantityviewnpndarrayflat	_dataiter)selfqr(   r(   r)   __init__T   s    zQuantityIterator.__init__c             C   s   | S )Nr(   )r1   r(   r(   r)   __iter__X   s    zQuantityIterator.__iter__c             C   s0   | j |}t|t| jr |S | j|S d S )N)r0   __getitem__
isinstancetyper+   	_new_view)r1   Zindxoutr(   r(   r)   r5   [   s    zQuantityIterator.__getitem__c             C   s   | j || j|< d S )N)r+   _to_own_unitr0   )r1   indexvaluer(   r(   r)   __setitem__d   s    zQuantityIterator.__setitem__c             C   s   t | j}| j|S )z@
        Return the next value, or raise StopIteration.
        )nextr0   r+   r8   )r1   r9   r(   r(   r)   __next__g   s    
zQuantityIterator.__next__N)
r"   r#   r$   r%   r3   r4   r5   r=   r?   r>   r(   r(   r(   r)   r*   =   s   	r*   c               @   s0   e Zd ZddhZdZedd Zedd ZdS )	r   dtypeunitTc             C   s   | j  S )N)r<   )valr(   r(   r)   default_formaty   s    zQuantityInfoBase.default_formatc             c   s"   dd V  dd V  dd V  dS )ac  Iterate through possible string-derived format functions.

        A string can either be a format specifier for the format built-in,
        a new-style format string, or an old-style format string.

        This method is overridden in order to suppress printing the unit
        in each row since it is already at the top in the column header.
        c             S   s   t |j| S )N)formatr<   )format_rB   r(   r(   r)   <lambda>       zCQuantityInfoBase.possible_string_format_functions.<locals>.<lambda>c             S   s   |  |jS )N)rD   r<   )rE   rB   r(   r(   r)   rF      rG   c             S   s
   | |j  S )N)r<   )rE   rB   r(   r(   r)   rF      rG   Nr(   )rE   r(   r(   r)    possible_string_format_functions}   s    


z1QuantityInfoBase.possible_string_format_functionsN)r"   r#   r$   Zattrs_from_parentZ_supports_indexingstaticmethodrC   rH   r(   r(   r(   r)   r   r   s   c               @   s0   e Zd ZdZdZdgZdZd
ddZdd	 ZdS )r   z
    Container for meta information like name, description, format.  This is
    required when the object is used as a mixin column within a table, but can
    be used as a general way to store meta information.
    )r<   rA   r<   warnNc                s   |   ||d}|f|d }|d}tj||d fdd| jD }d|d< | |}	x"| D ]\}
}t|	j|
| qjW |	S )	a  
        Return a new Quantity instance which is consistent with the
        input ``cols`` and has ``length`` rows.

        This is intended for creating an empty column object whose elements can
        be set in-place for table operations like join or vstack.

        Parameters
        ----------
        cols : list
            List of input columns
        length : int
            Length of the output column object
        metadata_conflicts : str ('warn'|'error'|'silent')
            How to handle metadata conflicts
        name : str
            Output column name

        Returns
        -------
        col : `~astropy.units.Quantity` (or subclass)
            Empty instance of this class consistent with ``cols``

        )metarD   descriptionshaper@   )rM   r@   c                s(   i | ] }|d krnt  d ||qS )r<   )getattr).0key)colsdatar(   r)   
<dictcomp>   s   z)QuantityInfo.new_like.<locals>.<dictcomp>Fcopy)	Zmerge_cols_attributespopr-   Zzeros_represent_as_dict_attrsZ_construct_from_dictitemssetattrinfo)r1   rR   lengthZmetadata_conflictsnameattrsrM   r@   mapr9   attrr<   r(   )rR   rS   r)   new_like   s    



zQuantityInfo.new_likec             C   s   | j gS )z
        Return a list of arrays which can be lexically sorted to represent
        the order of the parent column.

        For Quantity this is just the quantity itself.


        Returns
        -------
        arrays : list of ndarray
        )_parent)r1   r(   r(   r)   get_sortable_arrays   s    z QuantityInfo.get_sortable_arrays)rJ   N)	r"   r#   r$   r%   rW   Z_construct_from_dict_argsZ_represent_as_dict_primary_datar`   rb   r(   r(   r(   r)   r      s   
0c                   s  e Zd ZdZg ZeZdZdZdddZ	 fd	d
Z
dddZ fddZdd Zdd ZdddZdd Zdd Z fddZ fddZe Zg fddZg dfdd Zdg fd!d"Zeed#d$Zed%d& Zed'd( Zed)d* Zed+d, Zed-d. ZdZ e!d/d0 Z"d1d2 Z# fd3d4Z$ fd5d6Z%d7d8 Z&d9d: Z'd;d< Z(d=d> Z)d?d@ Z*dAdB Z+ fdCdDZ, fdEdFZ-dGdH Z. fdIdJZ/ fdKdLZ0 fdMdNZ1dOdP Z2dQdR Z3dSdT Z4 fdUdVZ5dWdX Z6dYdZ Z7 fd[d\Z8d]d^ Z9d_d` Z:dadb Z;dcdd Z<dedf Z=dgdh Z>edidj Z?ddkdlZ@dmdn ZAdodp ZBdqdr ZCdsdt ZDg fdudvZEdg fdwdxZF fdydzZGd{d| ZHdd}d~ZIdd ZJdddZKdddZLdddZMdd ZNdd ZOdd ZPedd ZQeQjRdd ZQḋ fdd	ZSdddZTdddZUdddZVdd ZWdddZXdddZY fddZZdd Z[dddddZ\dddZ]dddZ^dddZ_dddZ`dddZadddZbdddZcdddZddddZedddZfdddZgdddÄZh  ZiS )r   aA  A `~astropy.units.Quantity` represents a number with some associated unit.

    See also: https://docs.astropy.org/en/stable/units/quantity.html

    Parameters
    ----------
    value : number, `~numpy.ndarray`, `~astropy.units.Quantity` (sequence), or str
        The numerical value of this quantity in the units given by unit.  If a
        `Quantity` or sequence of them (or any other valid object with a
        ``unit`` attribute), creates a new `Quantity` object, converting to
        `unit` units as needed.  If a string, it is converted to a number or
        `Quantity`, depending on whether a unit is present.

    unit : unit-like
        An object that represents the unit associated with the input value.
        Must be an `~astropy.units.UnitBase` object or a string parseable by
        the :mod:`~astropy.units` package.

    dtype : ~numpy.dtype, optional
        The dtype of the resulting Numpy array or scalar that will
        hold the value.  If not provided, it is determined from the input,
        except that any integer and (non-Quantity) object inputs are converted
        to float by default.

    copy : bool, optional
        If `True` (default), then the value is copied.  Otherwise, a copy will
        only be made if ``__array__`` returns a copy, if value is a nested
        sequence, or if a copy is needed to satisfy an explicitly given
        ``dtype``.  (The `False` option is intended mostly for internal use,
        to speed up initialization where a copy is known to have been made.
        Use with care.)

    order : {'C', 'F', 'A'}, optional
        Specify the order of the array.  As in `~numpy.array`.  This parameter
        is ignored if the input is a `Quantity` and ``copy=False``.

    subok : bool, optional
        If `False` (default), the returned array will be forced to be a
        `Quantity`.  Otherwise, `Quantity` subclasses will be passed through,
        or a subclass appropriate for the unit will be used (such as
        `~astropy.units.Dex` for ``u.dex(u.AA)``).

    ndmin : int, optional
        Specifies the minimum number of dimensions that the resulting array
        should have.  Ones will be pre-pended to the shape as needed to meet
        this requirement.  This parameter is ignored if the input is a
        `Quantity` and ``copy=False``.

    Raises
    ------
    TypeError
        If the value provided is not a Python numeric type.
    TypeError
        If the unit provided is not either a :class:`~astropy.units.Unit`
        object or a parseable string unit.

    Notes
    -----
    Quantities can also be created by multiplying a number or array with a
    :class:`~astropy.units.Unit`. See https://docs.astropy.org/en/latest/units/

    Unless the ``dtype`` argument is explicitly specified, integer
    or (non-Quantity) object inputs are converted to `float` by default.
    Ni'  TFr   c          
      s   d k	rt   t|tr d k	r: |jk	r:| }d}t|| k	r^|rTt|| s^|| }|d krv|jjdkrvt	}t
j||||d|dS d }t|t
jst|tr*d}	t|	|}
d }yt	|
 }W n& tk
r   td|| jY nX |
j|
 d   }|rt |} d kr| nVt|rt|dkrtdd	 |D r d krj|d j  fd
d|D } }|d krt|dd }|d kr d kr| j  }nbyt |}W n6 tk
r } ztd|j|W d d }~X Y nX  d kr
| n |k	rd}t
j||||d|d}|jjdkrf|jjdkr^t|dtjsftd|d kr|jjdkr| t	}|rt d| }t!|| r|} || }|"|  |kr|S | S d S )NFiuT)r@   rU   ordersubokndminzk\s*[+-]?((\d+\.?\d*)|(\.\d+)|([nN][aA][nN])|([iI][nN][fF]([iI][nN][iI][tT][yY]){0,1}))([eE][+-]?\d+)?[.+-]?z;Cannot parse "{}" as a {}. It does not start with a number.r   c             s   s   | ]}t |tV  qd S )N)r6   r   )rP   vr(   r(   r)   	<genexpr>[  s    z#Quantity.__new__.<locals>.<genexpr>c                s   g | ]}|  qS r(   )to_value)rP   r2   )rA   r(   r)   
<listcomp>_  s    z$Quantity.__new__.<locals>.<listcomp>rA   zpThe unit attribute {!r} of the input could not be parsed as an astropy Unit, raising the following exception:
{}ZOSUOz7The value must be a valid Python or Numpy numeric type.ZiuO_quantity_class)#r   r6   r   rA   tor7   r,   r@   kindfloatr-   arrayr.   strrematchgroup	Exception	TypeErrorrD   r"   stringendstripr   lenallrO   _default_unititemnumbersNumberZastype
issubclass	_set_unit)clsr<   rA   r@   rU   rd   re   rf   Z
value_unitpatternrg   Zunit_stringexcZqclsr(   )rA   r)   __new__#  s    

















zQuantity.__new__c                sn   t  j}|d k	r|| |d ks,|jtjkr0d S | jd krXt|dd }|d k	rX| | d|jkrj|j	| _	d S )N_unitrZ   )
super__array_finalize__	__class__r-   r.   r   rO   r   __dict__rZ   )r1   objZsuper_array_finalizerA   )r   r(   r)   r     s    


zQuantity.__array_finalize__c             C   s   |d kr|  |S tdd S )Nz__array_wrap__ should not be used with a context any more since all use should go through array_function. Please raise an issue on https://github.com/astropy/astropy)r8   NotImplementedError)r1   r   contextr(   r(   r)   __array_wrap__  s    
zQuantity.__array_wrap__c                s   t ||f| \}}|dd}|dk	rb|jdkr:|d }t||||d}|jdkrZ|fn||d< g }	x8t||D ]*\}
}t|
d|
}
|	|r||
n|
 qrW t j||f|	|}|dks|dks|t	kr|S | 
|||S )a  Wrap numpy ufuncs, taking care of units.

        Parameters
        ----------
        function : callable
            ufunc to wrap.
        method : str
            Ufunc method: ``__call__``, ``at``, ``reduce``, etc.
        inputs : tuple
            Input arrays.
        kwargs : keyword arguments
            As passed on, with ``out`` containing possible quantity output.

        Returns
        -------
        result : `~astropy.units.Quantity`
            Results of the ufunc, with the unit set properly.
        r9   Nr   r   )functionr<   )r   getZnoutr   ziprO   appendr   __array_ufunc__NotImplemented_result_as_quantity)r1   r   methodinputskwargs
convertersrA   r9   	out_arrayarraysZinput_	converterresult)r   r(   r)   r     s    
zQuantity.__array_ufunc__c                sp   t |ttfrB|dkr"dt| }| fddt|||D S |dkrb|dkrV|S  ||S || |S )ab  Turn result into a quantity with the given unit.

        If no output is given, it will take a view of the array as a quantity,
        and set the unit.  If output is given, those should be quantity views
        of the result arrays, and the function will just set the unit.

        Parameters
        ----------
        result : ndarray or tuple thereof
            Array(s) which need to be turned into quantity.
        unit : `~astropy.units.Unit`
            Unit for the quantities to be returned (or `None` if the result
            should not be a quantity).  Should be tuple if result is a tuple.
        out : `~astropy.units.Quantity` or None
            Possible output quantity. Should be `None` or a tuple if result
            is a tuple.

        Returns
        -------
        out : `~astropy.units.Quantity`
           With units set.
        N)Nc             3   s"   | ]\}}}  |||V  qd S )N)r   )rP   Zresult_Zunit_Zout_)r1   r(   r)   rh     s   z/Quantity._result_as_quantity.<locals>.<genexpr>)r6   tuplelistrz   r   r   r8   r   )r1   r   rA   r9   r(   )r1   r)   r     s    

zQuantity._result_as_quantityc             C   s   t dfS )a  
        Overridden by subclasses to change what kind of view is
        created based on the output unit of an operation.

        Parameters
        ----------
        unit : UnitBase
            The unit for which the appropriate class should be returned

        Returns
        -------
        tuple :
            - `~astropy.units.Quantity` subclass
            - bool: True if subclasses of the given class are ok
        T)r   )r1   rA   r(   r(   r)   __quantity_subclass__  s    zQuantity.__quantity_subclass__c             C   s   |dkr| j }| j}nP|| j kr0| jtkr0t}n6t|}t|dt}t| |rf| |\}}|rf| j}|dkr|| tj	}ntj
|ddd}||}|| ||  |S )a]  
        Create a Quantity view of some array-like input, and set the unit

        By default, return a view of ``obj`` of the same class as ``self`` and
        with the same unit.  Subclasses can override the type of class for a
        given unit using ``__quantity_subclass__``, and can ensure properties
        other than the unit are copied using ``__array_finalize__``.

        If the given unit defines a ``_quantity_class`` of which ``self``
        is not an instance, a view using this class is taken.

        Parameters
        ----------
        obj : ndarray or scalar, optional
            The array to create a view of.  If obj is a numpy or python scalar,
            it will be converted to an array scalar.  By default, ``self``
            is converted.

        unit : unit-like, optional
            The unit of the resulting object.  It is used to select a
            subclass, and explicitly assigned to the view if given.
            If not given, the subclass and unit will be that of ``self``.

        Returns
        -------
        view : `~astropy.units.Quantity` subclass
        Nrl   FT)rU   re   )rA   r   r   r   rO   r6   r   r,   r-   r.   rp   r   r   )r1   r   rA   Zquantity_subclassre   r,   r(   r(   r)   r8   ,  s$    
	


zQuantity._new_viewc             C   sJ   t |ts@tt|dd}t |ts@tdt| jtt||| _dS )a  Set the unit.

        This is used anywhere the unit is set or modified, i.e., in the
        initilizer, in ``__imul__`` and ``__itruediv__`` for in-place
        multiplication and division by another unit, as well as in
        ``__array_finalize__`` for wrapping up views.  For Quantity, it just
        sets the unit, but subclasses can override it to check that, e.g.,
        a unit is consistent.
        silent)parse_strictz0{} instances require {} units, not {} instances.N)	r6   r   r   rq   r
   rD   r7   r"   r   )r1   rA   r(   r(   r)   r   m  s    


zQuantity._set_unitc             C   s   |   S )N)rU   )r1   memor(   r(   r)   __deepcopy__  s    zQuantity.__deepcopy__c                s(   t t  }|d | jf|d< t|S )N   )r   r   
__reduce__r   r   )r1   Zobject_state)r   r(   r)   r     s    zQuantity.__reduce__c                s$   |\}}t  | | j| d S )N)r   __setstate__r   update)r1   stateZnd_stateZ	own_state)r   r(   r)   r     s    zQuantity.__setstate__c             C   s(   |g kr| j }| jj|| tj|dS )z"Helper method for to and to_value.)equivalencies)_equivalenciesrA   rm   r,   r-   r.   )r1   rA   r   r(   r(   r)   	_to_value  s    zQuantity._to_valuec             C   s2   t |}|r| ||}n| ||}| ||S )a  
        Return a new `~astropy.units.Quantity` object with the specified unit.

        Parameters
        ----------
        unit : unit-like
            An object that represents the unit to convert to. Must be
            an `~astropy.units.UnitBase` object or a string parseable
            by the `~astropy.units` package.

        equivalencies : list of tuple
            A list of equivalence pairs to try if the units are not
            directly convertible.  See :ref:`unit_equivalencies`.
            If not provided or ``[]``, class default equivalencies will be used
            (none for `~astropy.units.Quantity`, but may be set for subclasses)
            If `None`, no equivalencies will be applied at all, not even any
            set globally or within a context.

        copy : bool, optional
            If `True` (default), then the value is copied.  Otherwise, a copy
            will only be made if necessary.

        See also
        --------
        to_value : get the numerical value in a given unit.
        )r   r   ri   r8   )r1   rA   r   rU   r<   r(   r(   r)   rm     s
    zQuantity.toc             C   s~   |dks|| j kr | tj}nVt|}y| j |}W n  tk
rX   | ||}Y nX | tj}t|sv|| }|d S )a  
        The numerical value, possibly in a different unit.

        Parameters
        ----------
        unit : unit-like, optional
            The unit in which the value should be given. If not given or `None`,
            use the current unit.

        equivalencies : list of tuple, optional
            A list of equivalence pairs to try if the units are not directly
            convertible (see :ref:`unit_equivalencies`). If not provided or
            ``[]``, class default equivalencies will be used (none for
            `~astropy.units.Quantity`, but may be set for subclasses).
            If `None`, no equivalencies will be applied at all, not even any
            set globally or within a context.

        Returns
        -------
        value : ndarray or scalar
            The value in the units specified. For arrays, this will be a view
            of the data if no unit conversion was necessary.

        See also
        --------
        to : Get a new instance in a different unit.
        Nr(   )	rA   r,   r-   r.   r   _toru   r   r   )r1   rA   r   r<   scaler(   r(   r)   ri     s    zQuantity.to_valuez}The numerical value of this instance.

    See also
    --------
    to_value : Get the numerical value in a given unit.
    )docc             C   s   | j S )zd
        A `~astropy.units.UnitBase` object representing the unit of this
        quantity.
        )r   )r1   r(   r(   r)   rA      s    zQuantity.unitc             C   s   | j S )zj
        A list of equivalencies that will be applied by default during
        unit conversions.
        )r   )r1   r(   r(   r)   r   	  s    zQuantity.equivalenciesc             C   s"   | j j}| | j|j ||j S )z
        Returns a copy of the current `Quantity` instance with SI units. The
        value of the resulting object will be scaled.
        )rA   sir8   r<   r   )r1   Zsi_unitr(   r(   r)   r     s    zQuantity.sic             C   s"   | j j}| | j|j ||j S )z
        Returns a copy of the current `Quantity` instance with CGS units. The
        value of the resulting object will be scaled.
        )rA   cgsr8   r<   r   )r1   Zcgs_unitr(   r(   r)   r     s    zQuantity.cgsc             C   s   | j  S )a  
        True if the `value` of this quantity is a scalar, or False if it
        is an array-like object.

        .. note::
            This is subtly different from `numpy.isscalar` in that
            `numpy.isscalar` returns False for a zero-dimensional array
            (e.g. ``np.array(1)``), while this is True for quantities,
            since quantities cannot represent true numpy scalars.
        )rM   )r1   r(   r(   r)   isscalar&  s    zQuantity.isscalarc             C   sB   | j s
g S t }t| j}x | j|D ]}||j q*W |S )z
        Quantities are able to directly convert to other units that
        have the same physical type.  This function is implemented in
        order to make autocompletion still work correctly in IPython.
        )	 _include_easy_conversion_memberssetr   Z_normalize_equivalenciesr   rA   Z"_get_units_with_same_physical_typer   names)r1   Zextra_membersr   Z
equivalentr(   r(   r)   __dir__:  s    
zQuantity.__dir__c                s^   j s tdjj d  d fdd}| }|dkrVtjj d  dn|S dS )zr
        Quantities are able to directly convert to other units that
        have the same physical type.
        'z' object has no 'z' memberc                 sP   t  j} |  d }|d kr d S yjj|jjdS  tk
rJ   d S X d S )N)r   )r   registryr   rA   rm   r<   r   r   )r   Zto_unit)r_   r1   r(   r)   get_virtual_unit_attributeS  s    z8Quantity.__getattr__.<locals>.get_virtual_unit_attributeNz instance has no attribute ')r   AttributeErrorr   r"   )r1   r_   r   r<   r(   )r_   r1   r)   __getattr__J  s    zQuantity.__getattr__c                sT   y(| j jdkrt |S t| |S W n& tk
r<   dS  tk
rN   tS X d S )NVF)	r@   rn   r   __eq__r-   equalr   rv   r   )r1   other)r   r(   r)   r   k  s    zQuantity.__eq__c                sT   y(| j jdkrt |S t| |S W n& tk
r<   dS  tk
rN   tS X d S )Nr   T)	r@   rn   r   __ne__r-   	not_equalr   rv   r   )r1   r   )r   r(   r)   r   v  s    zQuantity.__ne__c             C   s8   yt |dd}W n tk
r$   tS X | j| |dddS )Nr   )r   FT)rU   re   )r   r
   r   r   )r1   r   r(   r(   r)   
__lshift__  s
    zQuantity.__lshift__c             C   s   yt |dd}W n tk
r$   tS X y| j|}W nH tk
r~   y| |}W n tk
rh   tS X || tj	d< Y nX | tj	d  |9  < | 
| | S )Nr   )r   .)r   r
   r   rA   r   r	   r   r,   r-   r.   r   )r1   r   factorr<   r(   r(   r)   __ilshift__  s    
zQuantity.__ilshift__c             C   s   | j s
tS t| |S )N)r   r   r   __rlshift__)r1   r   r(   r(   r)   r     s    zQuantity.__rlshift__c             C   s   t dt tS )Nz_>> is not implemented. Did you mean to convert something to this quantity as a unit using '<<'?)warningsrJ   r   r   )r1   r   r(   r(   r)   __rrshift__  s    zQuantity.__rrshift__c             C   s   t S )N)r   )r1   r   r(   r(   r)   
__rshift__  s    zQuantity.__rshift__c             C   s   t S )N)r   )r1   r   r(   r(   r)   __irshift__  s    zQuantity.__irshift__c                sF   t |ttfr:y| |  || j S  tk
r8   tS X t 	|S )z= Multiplication between `Quantity` objects and other objects.)
r6   r   rq   r8   rU   rA   r   r   r   __mul__)r1   r   )r   r(   r)   r     s    zQuantity.__mul__c                s.   t |ttfr"| || j  | S t |S )z>In-place multiplication between `Quantity` objects and others.)r6   r   rq   r   rA   r   __imul__)r1   r   )r   r(   r)   r     s    zQuantity.__imul__c             C   s
   |  |S )zT Right Multiplication between `Quantity` objects and other
        objects.
        )r   )r1   r   r(   r(   r)   __rmul__  s    zQuantity.__rmul__c                sF   t |ttfr:y| |  | j| S  tk
r8   tS X t 	|S )z7 Division between `Quantity` objects and other objects.)
r6   r   rq   r8   rU   rA   r   r   r   __truediv__)r1   r   )r   r(   r)   r     s    zQuantity.__truediv__c                s.   t |ttfr"| | j|  | S t |S )z>Inplace division between `Quantity` objects and other objects.)r6   r   rq   r   rA   r   __itruediv__)r1   r   )r   r(   r)   r     s    zQuantity.__itruediv__c                s2   t |ttfr&| d| j || j S t |S )z= Right Division between `Quantity` objects and other objects.g      ?)r6   r   rq   r8   r<   rA   r   __rtruediv__)r1   r   )r   r(   r)   r     s    zQuantity.__rtruediv__c             C   s
   |  |S )z& Division between `Quantity` objects. )r   )r1   r   r(   r(   r)   __div__  s    zQuantity.__div__c             C   s
   |  |S )z& Division between `Quantity` objects. )r   )r1   r   r(   r(   r)   __idiv__  s    zQuantity.__idiv__c             C   s
   |  |S )z& Division between `Quantity` objects. )r   )r1   r   r(   r(   r)   __rdiv__  s    zQuantity.__rdiv__c                s2   t |tr&| | jt| | j| S t |S )N)r6   r   r8   r<   ro   rA   r   __pow__)r1   r   )r   r(   r)   r     s    
zQuantity.__pow__c             C   s   t | jt | jA S )N)hashr<   rA   )r1   r(   r(   r)   __hash__  s    zQuantity.__hash__c                s,    j rtdj jjd fdd}| S )Nz2'{cls}' object with a scalar value is not iterable)r   c              3   s    x j D ]}  | V  qW d S )N)r<   r8   )rB   )r1   r(   r)   quantity_iter  s    z(Quantity.__iter__.<locals>.quantity_iter)r   rv   rD   r   r"   )r1   r   r(   )r1   r)   r4     s    zQuantity.__iter__c                s^   yt  |}W n2 tk
rB   | jr<tdj| jjdn Y nX t|t	j
sZ| |}|S )Nz<'{cls}' object with a scalar value does not support indexing)r   )r   r5   
IndexErrorr   rv   rD   r   r"   r6   r-   r.   r8   )r1   rQ   r9   )r   r(   r)   r5     s    
zQuantity.__getitem__c             C   sB   | j s$d| jkr$| j||t|  | tj|| 	| d S )NrZ   )
r   r   rZ   Zadjust_indicesrz   r,   r-   r.   r=   r:   )r1   ir<   r(   r(   r)   r=   %  s    zQuantity.__setitem__c             C   s   t dt dS )zwQuantities should always be treated as non-False; there is too much
        potential for ambiguity otherwise.
        zWThe truth value of a Quantity is ambiguous. In the future this will raise a ValueError.T)r   rJ   r   )r1   r(   r(   r)   __bool__/  s    zQuantity.__bool__c             C   s*   | j rtdj| jjdn
t| jS d S )Nz/'{cls}' object with a scalar value has no len())r   )r   rv   rD   r   r"   rz   r<   )r1   r(   r(   r)   __len__8  s    zQuantity.__len__c          	   C   s4   yt | tS  ttfk
r.   tdY nX d S )NzGonly dimensionless scalar quantities can be converted to Python scalars)ro   ri   r   r   rv   )r1   r(   r(   r)   	__float__@  s    zQuantity.__float__c          	   C   s4   yt | tS  ttfk
r.   tdY nX d S )NzGonly dimensionless scalar quantities can be converted to Python scalars)intri   r   r   rv   )r1   r(   r(   r)   __int__G  s    zQuantity.__int__c             C   s:   y| j  st| j S  tk
r4   tdY nX d S )NzOonly integer dimensionless scalar quantities can be converted to a Python index)rA   Zis_unityAssertionErrorr<   	__index__ru   rv   )r1   r(   r(   r)   r   N  s
    
zQuantity.__index__c             C   s*   | j d krt}n
t| j }|r&d| }|S )N )rA   _UNIT_NOT_INITIALISEDrq   )r1   Zunitstrr(   r(   r)   _unitstrY  s    

zQuantity._unitstrc          	      sn  |dk	r*|| j kr*| |jd|||dS dddddd}||krVtd| dn:|dkr|dkrx| j | jd	S tj| j|d
d| j S t }d|dk	r|n|d  d  fdd} fdd}zN||d}	t	j
dkrtjt	j
|	d tj| tjtjdd}
|
dd}
W dtjf | X | j dk	rH| j  dd nt}|| | \}}dj|
|||dS )a  
        Generate a string representation of the quantity and its unit.

        The behavior of this function can be altered via the
        `numpy.set_printoptions` function and its various keywords.  The
        exception to this is the ``threshold`` keyword, which is controlled via
        the ``[units.quantity]`` configuration item ``latex_array_threshold``.
        This is treated separately because the numpy default of 1000 is too big
        for most browsers to handle.

        Parameters
        ----------
        unit : unit-like, optional
            Specifies the unit.  If not provided,
            the unit used to initialize the quantity will be used.

        precision : number, optional
            The level of decimal precision. If `None`, or not provided,
            it will be determined from NumPy print options.

        format : str, optional
            The format of the result. If not provided, an unadorned
            string is returned. Supported values are:

            - 'latex': Return a LaTeX-formatted string

        subfmt : str, optional
            Subformat of the result. For the moment,
            only used for format="latex". Supported values are:

            - 'inline': Use ``$ ... $`` as delimiters.

            - 'display': Use ``$\displaystyle ... $`` as delimiters.

        Returns
        -------
        str
            A string with the contents of this Quantity
        N)rA   	precisionrD   subfmt)$r   )z$\displaystyle r   )Ninlinedisplay)NlatexzUnknown format 'r   sZfixed)r   Z	floatmode.r   gc                s   t j|  dS )N)format_spec)r   format_exponential_notation)r<   )r   r(   r)   float_formatter  s    z+Quantity.to_string.<locals>.float_formatterc                s(   d tj| j dtj| jd  dS )Nz({}{}i))r   +)rD   r   r   realimag)r<   )r   r(   r)   complex_formatter  s
    z-Quantity.to_string.<locals>.complex_formatter)Z
float_kindZcomplex_kindrN   )	threshold	formatterz,~)Zmax_line_width	separatorz...z\dotsr   z{left}{0} \; {1}{right})leftright)rA   rm   	to_string
ValueErrorr<   r   r-   array2stringZget_printoptionsconfr'   Zset_printoptionsr,   r.   infreplace_repr_latex_r   rD   )r1   rA   r   rD   r   formatsZpopsr   r   r   Zlatex_valueZ
latex_unitZdelimiter_leftZdelimiter_rightr(   )r   r)   r   e  sD    (


zQuantity.to_stringc             C   s   |   S )N)r   )r1   r(   r(   r)   __str__  s    zQuantity.__str__c             C   s>   d| j j d }tj| tjd|d}| | | jddS )N<r   z, )r   prefixr   >)r   r"   r-   r   r,   r.   r   )r1   Z	prefixstrZarrstrr(   r(   r)   __repr__  s    zQuantity.__repr__c             C   s   | j dddS )z
        Generate a latex representation of the quantity and its unit.

        Returns
        -------
        lstr
            A LaTeX string with the contents of this Quantity
        r   r   )rD   r   )r   )r1   r(   r(   r)   r     s    
zQuantity._repr_latex_c             C   sJ   yt | j|}d}W n tk
r2   | j}|}Y nX t | | jd|S )aF  
        Format quantities using the new-style python formatting codes
        as specifiers for the number.

        If the format specifier correctly applies itself to the value,
        then it is used to format only the value. If it cannot be
        applied to the value, then it is applied to the whole string.

        r   )rD   r<   r   r   )r1   r   r<   Zfull_format_specr(   r(   r)   
__format__  s    

zQuantity.__format__c             C   s   | j d|dS )a  
        Generates a new `Quantity` with the units
        decomposed. Decomposed units have only irreducible units in
        them (see `astropy.units.UnitBase.decompose`).

        Parameters
        ----------
        bases : sequence of `~astropy.units.UnitBase`, optional
            The bases to decompose into.  When not provided,
            decomposes down to any irreducible units.  When provided,
            the decomposed result will only contain the given units.
            This will raises a `~astropy.units.UnitsError` if it's not possible
            to do so.

        Returns
        -------
        newq : `~astropy.units.Quantity`
            A new object equal to this quantity with units decomposed.
        F)bases)
_decompose)r1   r  r(   r(   r)   	decompose  s    zQuantity.decomposec             C   sR   | j j|d}|s>t|dr>| j|j }||j }| ||S | |  |S dS )a  
        Generates a new `Quantity` with the units decomposed. Decomposed
        units have only irreducible units in them (see
        `astropy.units.UnitBase.decompose`).

        Parameters
        ----------
        allowscaledunits : bool
            If True, the resulting `Quantity` may have a scale factor
            associated with it.  If False, any scaling in the unit will
            be subsumed into the value of the resulting `Quantity`

        bases : sequence of UnitBase, optional
            The bases to decompose into.  When not provided,
            decomposes down to any irreducible units.  When provided,
            the decomposed result will only contain the given units.
            This will raises a `~astropy.units.UnitsError` if it's not possible
            to do so.

        Returns
        -------
        newq : `~astropy.units.Quantity`
            A new object equal to this quantity with units decomposed.

        )r  r   N)rA   r  hasattrr<   r   r8   rU   )r1   Zallowscaledunitsr  Znew_unit	new_valuer(   r(   r)   r    s    
zQuantity._decomposec                s   |  t j| S )zCopy an element of an array to a scalar Quantity and return it.

        Like :meth:`~numpy.ndarray.item` except that it always
        returns a `Quantity`, not a Python scalar.

        )r8   r   r}   )r1   args)r   r(   r)   r}   =  s    zQuantity.itemc             C   s   t dd S )NzKcannot make a list of Quantities.  Get list of values with q.value.tolist())r   )r1   r(   r(   r)   tolistF  s    zQuantity.tolistc             C   s  y| | j}W n tk
r   |tjjksD|tjjkrH| jjdkrH|S yt	|}| | j}W n2 t
k
r   t|dst|jr|j}n Y nX Y nX | jjdkr|rtj|ddd}t|j| jstj|| jdd}tt||kt|std|S )	Nrk   rA   r   FT)rU   re   )re   z>cannot convert value type to array type without precision loss)ri   rA   r   r-   maZmaskedZmasked_print_optionr@   rn   r   r   r	  r   r<   rp   Zcan_castr{   
logical_orisnanrv   )r1   r<   check_precision_valueZas_quantityZself_dtype_arrayr(   r(   r)   r:   J  s.    

zQuantity._to_own_unitc             G   sB   t |dkrtd| tjj|d d | |d f   d S )Nr   z'itemset must have at least one argumentrN   )rz   r   r,   r-   r.   itemsetr:   )r1   r  r(   r(   r)   r  r  s    zQuantity.itemsetCc             C   s   t dd S )NzKcannot write Quantities to string.  Write array with q.value.tostring(...).)r   )r1   rd   r(   r(   r)   tostringy  s    zQuantity.tostringc             C   s   t dd S )NzJcannot write Quantities to string.  Write array with q.value.tobytes(...).)r   )r1   rd   r(   r(   r)   tobytes}  s    zQuantity.tobytes %sc             C   s   t dd S )NzFcannot write Quantities to file.  Write array with q.value.tofile(...))r   )r1   fidseprD   r(   r(   r)   tofile  s    zQuantity.tofilec             C   s   t dd S )Nz@cannot dump Quantities to file.  Write array with q.value.dump())r   )r1   filer(   r(   r)   dump  s    zQuantity.dumpc             C   s   t dd S )NzCcannot dump Quantities to string.  Write array with q.value.dumps())r   )r1   r(   r(   r)   dumps  s    zQuantity.dumpsc             C   s   |  tj| | d S )N)r,   r-   r.   fillr:   )r1   r<   r(   r(   r)   r    s    zQuantity.fillc             C   s   t | S )a(  A 1-D iterator over the Quantity array.

        This returns a ``QuantityIterator`` instance, which behaves the same
        as the `~numpy.flatiter` instance returned by `~numpy.ndarray.flat`,
        and is similar to, but not a subclass of, Python's built-in iterator
        object.
        )r*   )r1   r(   r(   r)   r/     s    	zQuantity.flatc             C   s   |   }||d d < d S )N)Zravel)r1   r<   yr(   r(   r)   r/     s    raisec                s2   t  j||||d}t|t| k	r.| |}|S )N)axisr9   mode)r   taker7   r8   )r1   indicesr!  r9   r"  )r   r(   r)   r#    s    
zQuantity.takec             C   s    |  tj|| || d S )N)r,   r-   r.   putr:   )r1   r$  valuesr"  r(   r(   r)   r%    s    zQuantity.putc             C   s   t dd S )NzMcannot choose based on quantity.  Choose using array with q.value.choose(...))r   )r1   choicesr9   r"  r(   r(   r)   choose  s    zQuantity.chooserN   	quicksortc             C   s   |  tjj|||dS )N)r!  rn   rd   )r,   r-   r.   argsort)r1   r!  rn   rd   r(   r(   r)   r*    s    zQuantity.argsortc             O   s$   t jt | | j|ddf||S )NF)r  )r-   searchsortedrp   r:   )r1   rg   r  r   r(   r(   r)   r+    s    zQuantity.searchsortedc             C   s   |  tjj||dS )N)r9   )r,   r-   r.   argmax)r1   r!  r9   r(   r(   r)   r,    s    zQuantity.argmaxc             C   s   |  tjj||dS )N)r9   )r,   r-   r.   argmin)r1   r!  r9   r(   r(   r)   r-    s    zQuantity.argminc       
         s  |t krt ||||S |tkrrt| }y|||\}}}}W n tk
r\   | ||S X t ||||}nv|tkrt| }	y|	||\}}}W q tk
r   | ||S X n2|tkrtS t	
d|jt t ||||S |dk s|tkr |S | j|||dS )a  Wrap numpy functions, taking care of units.

        Parameters
        ----------
        function : callable
            Numpy function to wrap
        types : iterable of classes
            Classes that provide an ``__array_function__`` override. Can
            in principle be used to interact with other classes. Below,
            mostly passed on to `~numpy.ndarray`, which can only interact
            with subclasses.
        args : tuple
            Positional arguments provided in the function call.
        kwargs : dict
            Keyword arguments provided in the function call.

        Returns
        -------
        result: `~astropy.units.Quantity`, `~numpy.ndarray`
            As appropriate for the function.  If the function is not
            supported, `NotImplemented` is returned, which will lead to
            a `TypeError` unless another argument overrode the function.

        Raises
        ------
        ~astropy.units.UnitsError
            If operands have incompatible units.
        zfunction '{}' is not known to astropy's Quantity. Will run it anyway, hoping it will treat ndarray subclasses correctly. Please raise an issue at https://github.com/astropy/astropy/issues. N)r9   )r   r   __array_function__r   r   _not_implemented_or_raiser   r   r   r   rJ   rD   r"   r   r   )
r1   r   typesr  r   Zfunction_helperrA   r9   r   Zdispatched_function)r   r(   r)   r.    s.    )zQuantity.__array_function__c             C   s,   t dd |D r$td|d ntS d S )Nc             s   s&   | ]}t |tjot |t V  qd S )N)r   r-   r.   r   )rP   tr(   r(   r)   rh   !  s   z5Quantity._not_implemented_or_raise.<locals>.<genexpr>zFthe Quantity implementation cannot handle {} with the given arguments.)anyrv   rD   r   )r1   r   r0  r(   r(   r)   r/    s
    
z"Quantity._not_implemented_or_raise)rA   r9   c            O   sn   |dkr| j }| jftdd |D  }|dk	rVtdd |D }t||||d|d< |||}| |||S )a  Wrap a numpy function that processes self, returning a Quantity.

        Parameters
        ----------
        function : callable
            Numpy function to wrap.
        args : positional arguments
            Any positional arguments to the function beyond the first argument
            (which will be set to ``self``).
        kwargs : keyword arguments
            Keyword arguments to the function.

        If present, the following arguments are treated specially:

        unit : `~astropy.units.Unit`
            Unit of the output result.  If not given, the unit of ``self``.
        out : `~astropy.units.Quantity`
            A Quantity instance in which to store the output.

        Notes
        -----
        Output should always be assigned via a keyword argument, otherwise
        no proper account of the unit is taken.

        Returns
        -------
        out : `~astropy.units.Quantity`
            Result of the function call, with the unit set properly.
        Nc             s   s"   | ]}t |tr|jn|V  qd S )N)r6   r   r<   )rP   argr(   r(   r)   rh   O  s   z*Quantity._wrap_function.<locals>.<genexpr>c             s   s   | ]}t |tjr|V  qd S )N)r6   r-   r.   )rP   r3  r(   r(   r)   rh   T  s    )r   r9   )rA   r<   r   r   r   )r1   r   rA   r9   r  r   r   r   r(   r(   r)   _wrap_function.  s    
zQuantity._wrap_functionr   c             C   s   | j tj|||||dS )N)r9   )r4  r-   trace)r1   offsetZaxis1Zaxis2r@   r9   r(   r(   r)   r5  Z  s    zQuantity.tracec          	   C   s    | j tj|||||| jd dS )Nr   )r9   ddofkeepdimsrA   )r4  r-   varrA   )r1   r!  r@   r9   r7  r8  r(   r(   r)   r9  ^  s    zQuantity.varc             C   s   | j tj|||||dS )N)r9   r7  r8  )r4  r-   std)r1   r!  r@   r9   r7  r8  r(   r(   r)   r:  c  s    zQuantity.stdc             C   s   | j tj||||dS )N)r9   r8  )r4  r-   mean)r1   r!  r@   r9   r8  r(   r(   r)   r;  g  s    zQuantity.meanc             C   s   | j tj||dS )N)r9   )r4  r-   round)r1   Zdecimalsr9   r(   r(   r)   r<  k  s    zQuantity.roundc             C   s&   | j t|dt }| jtj|||dS )NrA   )r9   rA   )rA   rO   r   r4  r-   dot)r1   br9   Zresult_unitr(   r(   r)   r=  n  s    zQuantity.dotc             C   s   t dd S )NzOcannot evaluate truth value of quantities. Evaluate array with q.value.all(...))rv   )r1   r!  r9   r(   r(   r)   r{   t  s    zQuantity.allc             C   s   t dd S )NzOcannot evaluate truth value of quantities. Evaluate array with q.value.any(...))rv   )r1   r!  r9   r(   r(   r)   r2  x  s    zQuantity.anyc             C   s   |  tj||S )N)r4  r-   diff)r1   nr!  r(   r(   r)   r?  ~  s    zQuantity.diffc             C   s   |  tj||S )N)r4  r-   ediff1d)r1   Zto_endZto_beginr(   r(   r)   rA    s    zQuantity.ediff1dc             C   s   | j tj|||dS )N)r9   r8  )r4  r-   nansum)r1   r!  r9   r8  r(   r(   r)   rB    s    
zQuantity.nansumc             C   s"   t | j|| ||}| |S )aA  
        Insert values along the given axis before the given indices and return
        a new `~astropy.units.Quantity` object.

        This is a thin wrapper around the `numpy.insert` function.

        Parameters
        ----------
        obj : int, slice or sequence of int
            Object that defines the index or indices before which ``values`` is
            inserted.
        values : array-like
            Values to insert.  If the type of ``values`` is different
            from that of quantity, ``values`` is converted to the matching type.
            ``values`` should be shaped so that it can be broadcast appropriately
            The unit of ``values`` must be consistent with this quantity.
        axis : int, optional
            Axis along which to insert ``values``.  If ``axis`` is None then
            the quantity array is flattened before insertion.

        Returns
        -------
        out : `~astropy.units.Quantity`
            A copy of quantity with ``values`` inserted.  Note that the
            insertion does not occur in-place: a new quantity array is returned.

        Examples
        --------
        >>> import astropy.units as u
        >>> q = [1, 2] * u.m
        >>> q.insert(0, 50 * u.cm)
        <Quantity [ 0.5,  1.,  2.] m>

        >>> q = [[1, 2], [3, 4]] * u.m
        >>> q.insert(1, [10, 20] * u.m, axis=0)
        <Quantity [[  1.,  2.],
                   [ 10., 20.],
                   [  3.,  4.]] m>

        >>> q.insert(1, 10 * u.m, axis=1)
        <Quantity [[  1., 10.,  2.],
                   [  3., 10.,  4.]] m>

        )r-   insertr<   r:   r8   )r1   r   r&  r!  r   r(   r(   r)   rC    s    -zQuantity.insert)NNTNFr   )N)NN)NNNN)T)r  )r  )r  r  )NNr   )r   )Nr   )rN   r)  N)NN)NN)r   r   r   NN)NNNr   F)NNNr   F)NNNF)r   N)N)NN)NN)r   rN   )NN)NNF)N)jr"   r#   r$   r%   r   r   r|   r   __array_priority__r   r   r   r   r   r   r8   r   r   r   r   r   rZ   r   rm   ri   propertyr<   rA   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r4   r5   r=   r   r   r   r   r   r   r   r   r  r   r  r  r  r}   r  r:   r  r  r  r  r  r  r  r/   setterr#  r%  r(  r*  r+  r,  r-  r.  r/  r4  r5  r9  r:  r;  r<  r=  r{   r2  r?  rA  rB  rC  __classcell__r(   r(   )r   r)   r      s   @ 
r
6)
A'1		

!				
	
o*	
(







U,










c                   sB   e Zd ZdZdZdZdZejd Z fddZ	 fddZ
  ZS )r   a  Superclass for Quantities of specific physical type.

    Subclasses of these work just like :class:`~astropy.units.Quantity`, except
    that they are for specific physical types (and may have methods that are
    only appropriate for that type).  Astropy examples are
    :class:`~astropy.coordinates.Angle` and
    :class:`~astropy.coordinates.Distance`

    At a minimum, subclasses should set ``_equivalent_unit`` to the unit
    associated with the physical type.
    N
   c                s0   | | jrt| dfS t |d dfS d S )NTr   F)is_equivalent_equivalent_unitr7   r   r   )r1   rA   )r   r(   r)   r     s    z*SpecificTypeQuantity.__quantity_subclass__c                sT   |d ks| | jsDtdt| j| j|d kr4dn
d| d t | d S )Nz-{} instances require units equivalent to '{}'z, but no unit was given.z, so cannot set it to 'z'.)rI  rJ  r
   rD   r7   r"   r   r   )r1   rA   )r   r(   r)   r     s    zSpecificTypeQuantity._set_unit)r"   r#   r$   r%   rJ  r   r|   r   rD  r   r   rG  r(   r(   )r   r)   r     s   
h㈵>Fc             K   s"   t | |||}tj|d|i|S )u  
    Return a boolean array where two arrays are element-wise equal
    within a tolerance.

    Parameters
    ----------
    a, b : array-like or `~astropy.units.Quantity`
        Input values or arrays to compare
    rtol : array-like or `~astropy.units.Quantity`
        The relative tolerance for the comparison, which defaults to
        ``1e-5``.  If ``rtol`` is a :class:`~astropy.units.Quantity`,
        then it must be dimensionless.
    atol : number or `~astropy.units.Quantity`
        The absolute tolerance for the comparison.  The units (or lack
        thereof) of ``a``, ``b``, and ``atol`` must be consistent with
        each other.  If `None`, ``atol`` defaults to zero in the
        appropriate units.
    equal_nan : `bool`
        Whether to compare NaN’s as equal. If `True`, NaNs in ``a`` will
        be considered equal to NaN’s in ``b``.

    Notes
    -----
    This is a :class:`~astropy.units.Quantity`-aware version of
    :func:`numpy.isclose`. However, this differs from the `numpy` function in
    that the default for the absolute tolerance here is zero instead of
    ``atol=1e-8`` in `numpy`, as there is no natural way to set a default
    *absolute* tolerance given two inputs that may have differently scaled
    units.

    Raises
    ------
    `~astropy.units.UnitsError`
        If the dimensions of ``a``, ``b``, or ``atol`` are incompatible,
        or if ``rtol`` is not dimensionless.

    See also
    --------
    allclose
    	equal_nan)_unquantify_allclose_argumentsr-   r   )ar>  rtolatolrL  r   unquantified_argsr(   r(   r)   r     s    ))returnc             K   s"   t | |||}tj|d|i|S )u  
    Whether two arrays are element-wise equal within a tolerance.

    Parameters
    ----------
    a, b : array-like or `~astropy.units.Quantity`
        Input values or arrays to compare
    rtol : array-like or `~astropy.units.Quantity`
        The relative tolerance for the comparison, which defaults to
        ``1e-5``.  If ``rtol`` is a :class:`~astropy.units.Quantity`,
        then it must be dimensionless.
    atol : number or `~astropy.units.Quantity`
        The absolute tolerance for the comparison.  The units (or lack
        thereof) of ``a``, ``b``, and ``atol`` must be consistent with
        each other.  If `None`, ``atol`` defaults to zero in the
        appropriate units.
    equal_nan : `bool`
        Whether to compare NaN’s as equal. If `True`, NaNs in ``a`` will
        be considered equal to NaN’s in ``b``.

    Notes
    -----
    This is a :class:`~astropy.units.Quantity`-aware version of
    :func:`numpy.allclose`. However, this differs from the `numpy` function in
    that the default for the absolute tolerance here is zero instead of
    ``atol=1e-8`` in `numpy`, as there is no natural way to set a default
    *absolute* tolerance given two inputs that may have differently scaled
    units.

    Raises
    ------
    `~astropy.units.UnitsError`
        If the dimensions of ``a``, ``b``, or ``atol`` are incompatible,
        or if ``rtol`` is not dimensionless.

    See also
    --------
    isclose
    rL  )rM  r-   r   )rN  r>  rO  rP  rL  r   rQ  r(   r(   r)   r     s    (c          	   C   s
  t | ddd} t |ddd}y|| j}W n. tk
rZ   td|j d| j dY nX |d krnt d}nNt |ddd}y|| j}W n. tk
r   td|j d| j dY nX t |ddd}y|t}W n tk
r   td	Y nX | j|j|j|jfS )
NTF)re   rU   zUnits for 'desired' (z) and 'actual' (z) are not convertibler   zUnits for 'atol' (z'rtol' should be dimensionless)r   rm   rA   r   r   ru   r<   )actualZdesiredrO  rP  r(   r(   r)   rM  =  s*    
rM  )rK  NF)rK  NF)>r%   rr   r~   	fractionsr   r   numpyr-   corer   r   r   r   r   r	   r
   utilsr   Zformat.latexr   Zastropy.utils.compat.miscr   Zastropy.utils.exceptionsr   r   Zastropy.utils.miscr   Zastropy.utils.data_infor   Zastropyr   r&   Zquantity_helperr   r   r   Z quantity_helper.function_helpersr   r   r   r   __all__Z__doctest_skip__r   ZarcsinZarccosZarccoshZarctanhZ_UFUNCS_FILTER_WARNINGSZConfigNamespacer    r   r*   r   r   r.   r   r   r   boolr   rM  r(   r(   r(   r)   <module>   sR   $5I           o+
-,