
    HR-e0                     :   d dl Z d dlmZ d dlmZmZ dgZ G d d          Ze	                    d          d             Z
e	                    d          d             Ze	                    d	          d
             Ze	                    d          d             ZdS )    N)deprecated_attributedeprecated_renamed_argument	Parameterc                   .   e Zd ZdZi Z eddd          ddg dddd	d
            Zd Zed             Z	ed             Z
ed             Z edd          Zed             ZddZd Zed             Zd Zd Zedd            ZddZd Zd Z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)sinceFdefault )derivedunitequivalencies	fvalidater   docc                   d x| _         | _        || _        t          |          | _        || _        |t          j        |          nd | _        || _	        || _
        t          |          rn~|| j        v r| j        |         }ngt          |t                    r)t          d| j                                                   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__uUnit_unit_equivalencies_fvalidate_incallable_registry_validators
isinstance
ValueErrorkeys	TypeError
_fvalidate)selfr   r   r   r   r   r   s          ;lib/python3.11/site-packages/astropy/cosmology/parameter.py__init__zParameter.__init__6   s    598$1HH &*%5QVD\\\4
+ 'I 	$3331)<II	3'' 	U43L3Q3Q3S3SUU   WT5N5S5S5U5UWW   $    c                 (    || _         d|z   | _        d S )N_)r   r   )r#   	cosmo_clsnames      r$   __set_name__zParameter.__set_name__^   s    "%*r&   c                     | j         S )zParameter name.)r   r#   s    r$   r*   zParameter.namec        r&   c                     | j         S )zParameter unit.)r   r-   s    r$   r   zParameter.unith   s     zr&   c                     | j         S )z/Equivalencies used when initializing Parameter.)r   r-   s    r$   r   zParameter.equivalenciesm   s     ""r&   format_specc                     | j         S )z:Whether the Parameter is derived; true parameters are not.)r   r-   s    r$   r   zParameter.derivedt   s     }r&   c                 4    || S t          || j                  S N)getattrr   )r#   	cosmologyr)   s      r$   __get__zParameter.__get__|   s     Ky$"9:::r&   c                 (   t          || j                  rt          d| j         d          |                     |t          j        |                    }t          |d          r|                    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deepcopyr9   setattrr#   r6   values      r$   __set__zParameter.__set__   s     9d566 	Q !O!O!O!OPPP iu)=)=>> 5*%% 	(NNN''' 		42E:::::r&   c                     | j         S )z9Function to validate a potential value of this Parameter.)r"   r-   s    r$   r   zParameter.fvalidate   r.   r&   c                 .    |                      |          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   s     r$   	validatorzParameter.validator   s     zzIz...r&   c                 0    |                      || |          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).
        rF   rA   s      r$   r=   zParameter.validate   s     ~~iu555r&   c                 j      j         v rt          dd          || j         <   |S  f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                     | j         <   | S )zRegister validator function.

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

            Returns
            -------
            ``validator``
            )r   )r   clskeys    r$   registerz.Parameter.register_validator.<locals>.register   s     -6C$S)r&   )r   KeyError)rL   rM   r   rN   s   ``  r$   register_validatorzParameter.register_validator   sn    " #***RRRRSSS  ,5C$S)	 	 	 	 	 	 r&   c                 |    | j         | j        | j        |r| j        n| j        | j        d}| j        r
| 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kws      r$   _get_init_argumentszParameter._get_init_arguments   sV      |I!/ ,5L$:L<
 
  	*)BuI	r&   c                     i |                                  |} t          |           di |}| 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)
         )rT   typer   r   )r#   rS   kwargscloneds       r$   rG   zParameter.clone  sV    * 6D,,..5"5d%%f%% !O$($;!r&   c                     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   NotImplementedrT   r*   )r#   others     r$   __eq__zParameter.__eq__&  sX    , %++ 	"!! ((..%2K2KD2Q2QQ 
I#	
r&   c                     d                     d                    d |                                                                 D                                 S )zString representation.

        ``eval(repr())`` should work, depending if contents like ``fvalidate``
        can be similarly round-tripped.
        zParameter({})z, c              3   *   K   | ]\  }}| d |V  dS )=NrV   ).0kvs      r$   	<genexpr>z%Parameter.__repr__.<locals>.<genexpr>L  s0      RRtq!llQllRRRRRRr&   )formatjoinrT   itemsr-   s    r$   __repr__zParameter.__repr__E  sR     %%IIRRt/G/G/I/I/O/O/Q/QRRRRR
 
 	
r&   r4   )F)__name__
__module____qualname__r   r   r   r%   r+   propertyr*   r   r   r   r1   r   r7   rC   r   rH   r=   classmethodrP   rT   rG   r]   rh   rV   r&   r$   r   r      s       & &P   E::: %$ %$ %$ %$ ;:%$N- - -
   X   X # # X# '&}EBBBK  X; ; ; ;; ; ;&   X/ / / 6 6 6" ( ( ( [(X   <  >
 
 
>
 
 
 
 
r&   r	   c                     |j         Kt          j        |j                  5  t          j        ||j                   }ddd           n# 1 swxY w Y   |S )z]
    Default Parameter value validator.
    Adds/converts units if Parameter has a unit.
    N)r   r   add_enabled_equivalenciesr   Quantityr6   paramrB   s      r$   _validate_with_unitrs   T  s     z()<== 	2 	2Juej11E	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2Ls   AAAfloatc                 B    t          | ||          }t          |          S )z=Parameter value validator with units, and converted to float.)rs   rt   rq   s      r$   _validate_to_floatrv   `  s!      	5%88E<<r&   scalarc                 d    t          | ||          }|j        st          |j         d          |S )r
   z is a non-scalar quantity)rs   isscalarr   r*   rq   s      r$   _validate_to_scalarrz   g  s>      	5%88E> CEJAAABBBLr&   znon-negativec                 b    t          | ||          }|dk     rt          |j         d          |S )z:Parameter value validator where value is a positive float.g        z cannot be negative.)rv   r   r*   rq   s      r$   _validate_non_negativer|   p  s<     y%77Es{{EJ<<<===Lr&   )r>   astropy.unitsunitsr   astropy.utils.decoratorsr   r   __all__r   rP   rs   rv   rz   r|   rV   r&   r$   <module>r      s$          V V V V V V V V-B
 B
 B
 B
 B
 B
 B
 B
R
 i((  )( g&&  '& h''  (' n--  .-  r&   