U
    d»{jç0  ã                   @   s„   d dl Z d dlmZ d dlmZmZ dgZG dd„ dƒZe 	d¡dd„ ƒZ
e 	d¡d	d
„ ƒZe 	d¡dd„ ƒZe 	d¡dd„ ƒZdS )é    N)Údeprecated_attributeÚdeprecated_renamed_argumentÚ	Parameterc                   @   sÜ   e Zd ZdZi Zedddd�ddg dddd	œd
d„ƒZdd„ Zedd„ ƒZ	edd„ ƒZ
edd„ ƒZeddd�Zedd„ ƒZd+dd„Zdd„ Zedd„ ƒZdd„ Zdd „ Zed,d!d"„ƒZd-d#d$„Zd%d&„ Zd'd(„ Zd)d*„ ZdS ).r   a  Cosmological parameter (descriptor).

    Should only be used with a :class:`~astropy.cosmology.Cosmology` subclass.

    Parameters
    ----------
    derived : bool (optional, keyword-only)
        Whether the Parameter is 'derived', default `False`.
        Derived parameters behave similarly to normal parameters, but are not
        sorted by the |Cosmology| signature (probably not there) and are not
        included in all methods. For reference, see ``Ode0`` in
        ``FlatFLRWMixin``, which removes :math:`\Omega_{de,0}`` as an
        independent parameter (:math:`\Omega_{de,0} \equiv 1 - \Omega_{tot}`).
    unit : unit-like or None (optional, keyword-only)
        The `~astropy.units.Unit` for the Parameter. If None (default) no
        unit as assumed.
    equivalencies : `~astropy.units.Equivalency` or sequence thereof
        Unit equivalencies for this Parameter.
    fvalidate : callable[[object, object, Any], Any] or str (optional, keyword-only)
        Function to validate the Parameter value from instances of the
        cosmology class. If "default", uses default validator to assign units
        (with equivalencies), if Parameter has units.
        For other valid string options, see ``Parameter._registry_validators``.
        'fvalidate' can also be set through a decorator with
        :meth:`~astropy.cosmology.Parameter.validator`.
    fmt : str (optional, keyword-only)
        `format` specification, used when making string representation
        of the containing Cosmology.
        See https://docs.python.org/3/library/string.html#formatspec

        .. deprecated::  5.1

    doc : str or None (optional, keyword-only)
        Parameter description.

    Examples
    --------
    For worked examples see :class:`~astropy.cosmology.FLRW`.
    ÚfmtNz5.1)ZsinceFÚdefaultÚ )ÚderivedÚunitÚequivalenciesÚ	fvalidater   Údocc                C   s¤   d  | _ | _|| _t|ƒ| _|| _|d k	r4t |¡nd | _|| _	|| _
t|ƒrPnJ|| jkrf| j| }n4t|tƒr†td| j ¡ › �ƒ‚ntd| j ¡ › �ƒ‚|| _d S )Nz `fvalidate`, if str, must be in z"`fvalidate` must be a function or )Ú
_attr_nameÚ_attr_name_privateÚ_derivedÚstrÚ_format_specÚ__doc__ÚuZUnitÚ_unitÚ_equivalenciesÚ_fvalidate_inÚcallableÚ_registry_validatorsÚ
isinstanceÚ
ValueErrorÚkeysÚ	TypeErrorÚ
_fvalidate)Úselfr   r	   r
   r   r   r   © r   úZ/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/cosmology/parameter.pyÚ__init__6   s&    


ÿÿzParameter.__init__c                 C   s   || _ d| | _d S )NÚ_)r   r   )r   Ú	cosmo_clsÚnamer   r   r    Ú__set_name__^   s    zParameter.__set_name__c                 C   s   | j S )zParameter name.)r   ©r   r   r   r    r$   c   s    zParameter.namec                 C   s   | j S )zParameter unit.)r   r&   r   r   r    r	   h   s    zParameter.unitc                 C   s   | j S )z/Equivalencies used when initializing Parameter.)r   r&   r   r   r    r
   m   s    zParameter.equivalenciesÚformat_specc                 C   s   | j S )z:Whether the Parameter is derived; true parameters are not.)r   r&   r   r   r    r   t   s    zParameter.derivedc                 C   s   |d kr| S t || jƒS )N)Úgetattrr   )r   Ú	cosmologyr#   r   r   r    Ú__get__|   s    zParameter.__get__c                 C   sX   t || jƒrtd| j› d�ƒ‚|  |t |¡¡}t |dƒrF|jdd� t|| j|ƒ dS )zBAllows attribute setting once. Raises AttributeError subsequently.zcan't set attribute z againÚsetflagsF)ÚwriteN)	Úhasattrr   ÚAttributeErrorr   ÚvalidateÚcopyÚdeepcopyr+   Úsetattr©r   r)   Úvaluer   r   r    Ú__set__ƒ   s    
zParameter.__set__c                 C   s   | j S )z9Function to validate a potential value of this Parameter.)r   r&   r   r   r    r   –   s    zParameter.fvalidatec                 C   s   | j |d�S )ao  Make new Parameter with custom ``fvalidate``.

        Note: ``Parameter.fvalidator`` must be the top-most descriptor decorator.

        Parameters
        ----------
        fvalidate : callable[[type, type, Any], Any]

        Returns
        -------
        `~astropy.cosmology.Parameter`
            Copy of this Parameter but with custom ``fvalidate``.
        ©r   )Úclone)r   r   r   r   r    Ú	validator›   s    zParameter.validatorc                 C   s   |   || |¡S )af  Run the validator on this Parameter.

        Parameters
        ----------
        cosmology : `~astropy.cosmology.Cosmology` instance
        value : Any
            The object to validate.

        Returns
        -------
        Any
            The output of calling ``fvalidate(cosmology, self, value)``
            (yes, that parameter order).
        r6   r3   r   r   r    r/   «   s    zParameter.validatec                    sB   ˆˆ j krtdˆ›d�ƒ‚|dk	r0|ˆ j ˆ< |S ‡ ‡fdd„}|S )aí  Decorator to register a new kind of validator function.

        Parameters
        ----------
        key : str
        fvalidate : callable[[object, object, Any], Any] or None, optional
            Value validation function.

        Returns
        -------
        ``validator`` or callable[``validator``]
            if validator is None returns a function that takes and registers a
            validator. This allows ``register_validator`` to be used as a
            decorator.
        z
validator z# already registered with Parameter.Nc                    s   | ˆ j ˆ< | S )zýRegister validator function.

            Parameters
            ----------
            fvalidate : callable[[object, object, Any], Any]
                Validation function.

            Returns
            -------
            ``validator``
            )r   r6   ©ÚclsÚkeyr   r    ÚregisterÖ   s    
z.Parameter.register_validator.<locals>.register)r   ÚKeyError)r:   r;   r   r<   r   r9   r    Úregister_validator¼   s    

zParameter.register_validatorc                 C   s8   | j | j| j|r| jn| j| jdœ}| jr4| j|d< |S )a†  Initialization arguments.

        Parameters
        ----------
        processed : bool
            Whether to more closely reproduce the input arguments (`False`,
            default) or the processed arguments (`True`). The former is better
            for string representations and round-tripping with ``eval(repr())``.

        Returns
        -------
        dict[str, Any]
        )r   r	   r
   r   r   r   )r   r	   r
   r   r   r   r   )r   Ú	processedÚkwr   r   r    Ú_get_init_argumentsé   s    ù
zParameter._get_init_argumentsc                 K   s.   |   ¡ |–}t| ƒf |Ž}| j|_| j|_|S )ad  Clone this `Parameter`, changing any constructor argument.

        Parameters
        ----------
        **kw
            Passed to constructor. The current values, eg. ``fvalidate`` are
            used as the default values, so an empty ``**kw`` is an exact copy.

        Examples
        --------
        >>> p = Parameter()
        >>> p
        Parameter(derived=False, unit=None, equivalencies=[],
                  fvalidate='default', doc=None)

        >>> p.clone(unit="km")
        Parameter(derived=False, unit=Unit("km"), equivalencies=[],
                  fvalidate='default', doc=None)
        )rA   Útyper   r   )r   r@   ÚkwargsZclonedr   r   r    r7     s
    zParameter.clonec                 C   s.   t |tƒstS |  d¡| d¡ko,| j|jkS )a  Check Parameter equality. Only equal to other Parameter objects.

        Returns
        -------
        NotImplemented or True
            `True` if equal, `NotImplemented` otherwise. This allows `other` to
            be check for equality with ``other.__eq__``.

        Examples
        --------
        >>> p1, p2 = Parameter(unit="km"), Parameter(unit="km")
        >>> p1 == p2
        True

        >>> p3 = Parameter(unit="km / s")
        >>> p3 == p1
        False

        >>> p1 != 2
        True
        T)r   r   ÚNotImplementedrA   r$   )r   Úotherr   r   r    Ú__eq__&  s
    

ÿzParameter.__eq__c                 C   s"   d  d dd„ |  ¡  ¡ D ƒ¡¡S )z—String representation.

        ``eval(repr())`` should work, depending if contents like ``fvalidate``
        can be similarly round-tripped.
        zParameter({})z, c                 s   s    | ]\}}|› d |›�V  qdS )ú=Nr   )Ú.0ÚkÚvr   r   r    Ú	<genexpr>L  s     z%Parameter.__repr__.<locals>.<genexpr>)ÚformatÚjoinrA   Úitemsr&   r   r   r    Ú__repr__E  s    ÿzParameter.__repr__)N)N)F)Ú__name__Ú
__module__Ú__qualname__r   r   r   r!   r%   Úpropertyr$   r	   r
   r   r'   r   r*   r5   r   r8   r/   Úclassmethodr>   rA   r7   rF   rO   r   r   r   r    r      s@   (ø'





,
r   c              	   C   s4   |j dk	r0t |j¡� t ||j ¡}W 5 Q R X |S )z]
    Default Parameter value validator.
    Adds/converts units if Parameter has a unit.
    N)r	   r   Zadd_enabled_equivalenciesr
   ZQuantity©r)   Úparamr4   r   r   r    Ú_validate_with_unitT  s    
rW   Úfloatc                 C   s   t | ||ƒ}t|ƒS )z=Parameter value validator with units, and converted to float.)rW   rX   rU   r   r   r    Ú_validate_to_float`  s    rY   Zscalarc                 C   s&   t | ||ƒ}|js"t|j› d�ƒ‚|S )r   z is a non-scalar quantity)rW   Zisscalarr   r$   rU   r   r   r    Ú_validate_to_scalarg  s    rZ   znon-negativec                 C   s(   t | ||ƒ}|dk r$t|j› d�ƒ‚|S )z:Parameter value validator where value is a positive float.g        z cannot be negative.)rY   r   r$   rU   r   r   r    Ú_validate_non_negativep  s    r[   )r0   Zastropy.unitsZunitsr   Zastropy.utils.decoratorsr   r   Ú__all__r   r>   rW   rY   rZ   r[   r   r   r   r    Ú<module>   s     K


