
    HR-eV                    h   d dl mZ d dlZd dlZd dlmZmZmZ d dl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mZ dd	lmZ erd d
lmZ d dlmZ g dZi Z e            Z edd          Z edd          Z  G d de!          Z" G d dej#                  Z$ G d dej#                  Z%d Z&dS )    )annotationsN)TYPE_CHECKINGAnyTypeVar)UnifiedReadWriteMethod)classproperty)MetaData   )CosmologyFromFormatCosmologyReadCosmologyToFormatCosmologyWrite)	Parameter)Mapping)_FormatType)	CosmologyCosmologyErrorFlatCosmologyMixin_CosmoTr   )bound_FlatCosmoTr   c                      e Zd ZdS )r   N)__name__
__module____qualname__     6lib/python3.11/site-packages/astropy/cosmology/core.pyr   r   5   s        Dr   r   c                  p    e Zd ZU dZ e            Z ee          Z ee	          Z
 ee          Z ee          ZdZded<   dZded<    fdZ ed          d	             ZddZed             Zeej        d                         Zd
ddZed             ZddddZd dZd dZd Z d Z! xZ"S )!r   a  Base-class for all Cosmologies.

    Parameters
    ----------
    *args
        Arguments into the cosmology; used by subclasses, not this base class.
    name : str or None (optional, keyword-only)
        The name of the cosmology.
    meta : dict or None (optional, keyword-only)
        Metadata for the cosmology, e.g., a reference.
    **kwargs
        Arguments into the cosmology; used by subclasses, not this base class.

    Notes
    -----
    Class instances are static -- you cannot (and should not) change the values
    of the parameters.  That is, all of the above attributes (except meta) are
    read only.

    For details on how to create performant custom subclasses, see the
    documentation on :ref:`astropy-cosmology-fast-integrals`.
    r   tuple[str, ...]__parameters____all_parameters__c                   t                                                       g g }| j        D ]X}t          | |          }t	          |t
                    r1|j        r|                    |          n                    |           Y| j        	                                D ]e\  }}|v s*|
                    d          st	          |t
                    s4|j        r|                    |          n                    |           ffd| j        j                                        D             }|z   t                    | _        | j        t          |          z   | _        | t           | j        <   d S )N_c                h    g | ].}|v                                          |                    /S r   )popindex).0n
parameterss     r   
<listcomp>z/Cosmology.__init_subclass__.<locals>.<listcomp>v   sD     
 
 
J NN:++A..//r   )super__init_subclass__r!   getattr
isinstancer   derivedappend__dict__items
startswith_init_signaturer*   keystupler"   _COSMOLOGY_CLASSESr   )clsderived_parametersr)   pvorderedr*   	__class__s         @r   r-   zCosmology.__init_subclass__a   s   !!### 
# 	T 	TAQA!Y'' T01	S"))!,,,z?P?PQR?S?S L&&(( 	P 	PDAqJ!,,s"3"3:a;S;S,-IO%%a(((:;L;LQ;O;O
 
 
 
(388::
 
 

 z)
":..!$!3e<N6O6O!O 033+,,,r   T)lazyc                    t          j        | j                  }|                    t	          |j                                                  dd                   }|S )z*Initialization signature (without 'self').r
   N)r*   )inspect	signature__init__replacelistr*   values)r9   sigs     r   r5   zCosmology._init_signature   sM     --kkT#.*?*?*A*A%B%B122%FkGG
r   Nc                n    |t          |          n|| _        | j                            |pi            d S N)str_namemetaupdate)selfnamerL   s      r   rC   zCosmology.__init__   s8    "&"2SYYY
	$$$$$r   c                    | j         S )z#The name of the Cosmology instance.)rK   rN   s    r   rO   zCosmology.name   s     zr   c                     t          d          )z{
        Return bool; `True` if the cosmology is flat.
        This is abstract and must be defined in subclasses.
        zis_flat is not implemented)NotImplementedErrorrQ   s    r   is_flatzCosmology.is_flat   s     "">???r   )rL   c               b   ||s| S | j         dz   }|                    d| j         |nd           ||ni }i | j        |}i | j        d|i|} | j        j        di |} t          |           |j        i |j        }|j         |k    r#|s!|	                    |           r| j         |_
        |S )a  Returns a copy of this object with updated parameters, as specified.

        This cannot be used to change the type of the cosmology, so ``clone()``
        cannot be used to change between flat and non-flat cosmologies.

        Parameters
        ----------
        meta : mapping or None (optional, keyword-only)
            Metadata that will update the current metadata.
        **kwargs
            Cosmology parameter (and name) modifications. If any parameter is
            changed and a new name is not given, the name will be set to "[old
            name] (modified)".

        Returns
        -------
        newcosmo : `~astropy.cosmology.Cosmology` subclass instance
            A new instance of this class with updated parameters as specified.
            If no arguments are given, then a reference to this object is
            returned instead of copy.

        Examples
        --------
        To make a copy of the ``Planck13`` cosmology with a different matter
        density (``Om0``), and a new name:

            >>> from astropy.cosmology import Planck13
            >>> Planck13.clone(name="Modified Planck 2013", Om0=0.35)
            FlatLambdaCDM(name="Modified Planck 2013", H0=67.77 km / (Mpc s),
                          Om0=0.35, ...

        If no name is specified, the new name will note the modification.

            >>> Planck13.clone(Om0=0.35).name
            'Planck13 (modified)'
        Nz (modified)rO   rL   r   )rO   
setdefaultrL   _init_argumentsr5   bind_partialtypeargskwargsis_equivalentrK   )rN   rL   r[   _modnamenew_metanew_initbacloneds           r   clonezCosmology.clone   s    L <<K 9},&ty/D88$PPP 'ttR(di(4(Gd*GFHGGG /T!.::::dRW2	22 K8##T#f6J6J46P6P#9FLr   c                V      fd j         D             } j        |d<    j        |d<   |S )Nc                2    i | ]}|t          |          S r   r.   )r(   r)   rN   s     r   
<dictcomp>z-Cosmology._init_arguments.<locals>.<dictcomp>   s%    ???aaq!!???r   rO   rL   )r!   rO   rL   )rN   kws   ` r   rW   zCosmology._init_arguments   s?     @???4+>??? Y6
Y6
	r   F)formatotherr   rh   r   returnboolc              T    ddl m} 	  || |d|fd          S # t          $ r Y dS w xY w)a=  Check equivalence between Cosmologies.

        Two cosmologies may be equivalent even if not the same class.
        For example, an instance of ``LambdaCDM`` might have :math:`\Omega_0=1`
        and :math:`\Omega_k=0` and therefore be flat, like ``FlatLambdaCDM``.

        Parameters
        ----------
        other : `~astropy.cosmology.Cosmology` subclass instance, positional-only
            The object to which to compare.
        format : bool or None or str, optional keyword-only
            Whether to allow, before equivalence is checked, the object to be
            converted to a |Cosmology|. This allows, e.g. a |Table| to be
            equivalent to a Cosmology.
            `False` (default) will not allow conversion. `True` or `None` will,
            and will use the auto-identification to try to infer the correct
            format. A `str` is assumed to be the correct format to use when
            converting.
            ``format`` is broadcast to match the shape of ``other``.
            Note that the cosmology arguments are not broadcast against
            ``format``, so it cannot determine the output shape.

        Returns
        -------
        bool
            True if cosmologies are equivalent, False otherwise.

        Examples
        --------
        Two cosmologies may be equivalent even if not of the same class.
        In this examples the ``LambdaCDM`` has ``Ode0`` set to the same value
        calculated in ``FlatLambdaCDM``.

            >>> import astropy.units as u
            >>> from astropy.cosmology import LambdaCDM, FlatLambdaCDM
            >>> cosmo1 = LambdaCDM(70 * (u.km/u.s/u.Mpc), 0.3, 0.7)
            >>> cosmo2 = FlatLambdaCDM(70 * (u.km/u.s/u.Mpc), 0.3)
            >>> cosmo1.is_equivalent(cosmo2)
            True

        While in this example, the cosmologies are not equivalent.

            >>> cosmo3 = FlatLambdaCDM(70 * (u.km/u.s/u.Mpc), 0.3, Tcmb0=3 * u.K)
            >>> cosmo3.is_equivalent(cosmo2)
            False

        Also, using the keyword argument, the notion of equivalence is extended
        to any Python object that can be converted to a |Cosmology|.

            >>> from astropy.cosmology import Planck18
            >>> tbl = Planck18.to_format("astropy.table")
            >>> Planck18.is_equivalent(tbl, format=True)
            True

        The list of valid formats, e.g. the |Table| in this example, may be
        checked with ``Cosmology.from_format.list_formats()``.

        As can be seen in the list of formats, not all formats can be
        auto-identified by ``Cosmology.from_format.registry``. Objects of
        these kinds can still be checked for equivalence, but the correct
        format string must be used.

            >>> tbl = Planck18.to_format("yaml")
            >>> Planck18.is_equivalent(tbl, format="yaml")
            True
        r
   )cosmology_equalNT)rh   allow_equivalentF)funcsrm   	Exception)rN   ri   rh   rm   s       r   r\   zCosmology.is_equivalent   sh    F 	+*****	"?eT6NT     	 	 	 55		s    
''c                    j          j         urt          S t           j                  t          j                  k    o t	           fd j        D                       S )a  Cosmology equivalence. Use ``.is_equivalent()`` for actual check!

        Parameters
        ----------
        other : `~astropy.cosmology.Cosmology` subclass instance, positional-only
            The object in which to compare.

        Returns
        -------
        bool or `NotImplemented`
            `NotImplemented` if ``other`` is from a different class.
            `True` if ``other`` is of the same class and has matching parameters
            and parameter values.
            `False` otherwise.
        c              3     K   | ]8}t          j        t          |          t          |          k              V  9d S rI   npallr.   r(   kri   rN   s     r   	<genexpr>z&Cosmology.__equiv__.<locals>.<genexpr>Q  sb       U
 U
 F74##wua'8'8899U
 U
 U
 U
 U
 U
r   )r>   NotImplementedsetr"   ru   )rN   ri   s   ``r   	__equiv__zCosmology.__equiv__<  s      ?$.00!! 4*++s53K/L/LL 
QT U
 U
 U
 U
 U
,U
 U
 U
 R
 R
 	
r   c                    j          j         urt          S  j        j        k    oJt           j                  t          j                  k    o t           fd j        D                       }|S )a  Check equality between Cosmologies.

        Checks the Parameters and immutable fields (i.e. not "meta").

        Parameters
        ----------
        other : `~astropy.cosmology.Cosmology` subclass instance, positional-only
            The object in which to compare.

        Returns
        -------
        bool
            `True` if Parameters and names are the same, `False` otherwise.
        c              3     K   | ]8}t          j        t          |          t          |          k              V  9d S rI   rs   rv   s     r   rx   z#Cosmology.__eq__.<locals>.<genexpr>o  Z         wtQ''75!+<+<<==     r   )r>   ry   rO   rz   r"   ru   )rN   ri   eqs   `` r   __eq__zCosmology.__eq__V  s     ?$.00!! I#  D+,,E4L0M0MM	
      0     	 	r   c                      j         j         d} j        |d j         dz  } fd j        D             }|d                    |          z   dz   S )N(zname="z", c              3  B   K   | ]}| d t          |           V  dS )=Nre   )r(   rw   rN   s     r   rx   z%Cosmology.__repr__.<locals>.<genexpr>~  s;      HHqA**a((**HHHHHHr   z, ))r>   r   rO   r!   join)rN   nameleadfmtpss   `  r   __repr__zCosmology.__repr__y  sn    n14449 /////HHHHHD4GHHH$))E***S00r   c                      | j         dd|i|S )a  Return a `~astropy.table.Table` of type ``cls``.

        Parameters
        ----------
        cls : type
            Astropy ``Table`` class or subclass.
        copy : bool
            Ignored.
        **kwargs : dict, optional
            Additional keyword arguments. Passed to ``self.to_format()``.
            See ``Cosmology.to_format.help("astropy.table")`` for allowed kwargs.

        Returns
        -------
        `astropy.table.Table` or subclass instance
            Instance of type ``cls``.
        astropy.tabler9   )r   )	to_format)rN   r9   copyr[   s       r   __astropy_table__zCosmology.__astropy_table__  s!    $ t~AA3A&AAAr   )NN)ri   r   rh   r   rj   rk   )ri   r   rj   rk   )#r   r   r   __doc__r	   rL   r   r   from_formatr   r   r   readr   writer!   __annotations__r"   r-   r   r5   rC   propertyrO   abcabstractmethodrT   rb   rW   r\   r{   r   r   r   __classcell__r>   s   @r   r   r   9   s         . 8::D )()<==K&&'899I "!-00D"">22E ')N((((*,,,,, 3  3  3  3  3D ]  % % % %   X @ @  X@ ! > > > > >@   X EJ M M M M M M^
 
 
 
4   F1 1 1B B B B B B Br   )	metaclassc                       e Zd ZU dZded<   ded<   d fd	Ze	 d d!d            Z eedd          Z	e
d             Zej        d"d            Zd
ddd# fdZ fdZ xZS )$r   aZ  
    Mixin class for flat cosmologies. Do NOT instantiate directly.
    Note that all instances of ``FlatCosmologyMixin`` are flat, but not all
    flat cosmologies are instances of ``FlatCosmologyMixin``. As example,
    ``LambdaCDM`` **may** be flat (for the a specific set of parameter values),
    but ``FlatLambdaCDM`` **will** be flat.
    r    r"   r!   r9   type[_FlatCosmoT]rj   Nonec                V    t                                                       | j         d S rI   )r,   r-   __nonflatclass__)r9   r>   s    r   r-   z$FlatCosmologyMixin.__init_subclass__  s*    !!### 	r   Nklstype[_CosmoT] | Nonetype[Cosmology] | Nonec                     | n|}d |j         D             }|s fd|j         D             }t          |          dk    rt          d| d| d          |sdS |                                S )a  Find the corresponding non-flat class.

        The class' bases are searched recursively.

        Parameters
        ----------
        kls : :class:`astropy.cosmology.Cosmology` class or None, optional
            If `None` (default) this class is searched instead of `kls`.

        Raises
        ------
        TypeError
            If more than one non-flat class is found at the same level of the
            inheritance. This is similar to the error normally raised by Python
            for an inconsistent method resolution order.

        Returns
        -------
        type
            A :class:`Cosmology` subclass this class inherits from that is not a
            :class:`FlatCosmologyMixin` subclass.
        Nc                f    h | ].}t          |t                    t          |t                    ,|/S r   )
issubclassr   r   )r(   bs     r   	<setcomp>z6FlatCosmologyMixin._get_nonflat_cls.<locals>.<setcomp>  sM     
 
 
!Y''
 1;1>P0Q0Q

 
 
r   c                B    h | ]}                     |          xS rI   )_get_nonflat_cls)r(   r   r9   rw   s     r   r   z6FlatCosmologyMixin._get_nonflat_cls.<locals>.<setcomp>  s8       33G3G3J3J.Ja-W-W-W-Wr   r
   z?cannot create a consistent non-flat class resolution order for z with bases z at the same inheritance level.)	__bases__len	TypeErrorr&   )r9   r   _klsnonflatrw   s   `   @r   r   z#FlatCosmologyMixin._get_nonflat_cls  s    4 ksss
 
^
 
 
  	    >  G w<<!RR R)0R R R    	4{{}}r   Tz(Return the corresponding non-flat class.)r?   docc                    dS )z%Return `True`, the cosmology is flat.Tr   rQ   s    r   rT   zFlatCosmologyMixin.is_flat  s	     tr   rN   r   r   c                    dS )z@Return the equivalent non-flat-class instance of this cosmology.Nr   rQ   s    r   r   zFlatCosmologyMixin.nonflat  s      r   F)rL   
to_nonflatrL   Mapping | Noner   rk   c               f    |r | j         j        dd|i|S  t                      j        dd|i|S )aL  Returns a copy of this object with updated parameters, as specified.

        This cannot be used to change the type of the cosmology, except for
        changing to the non-flat version of this cosmology.

        Parameters
        ----------
        meta : mapping or None (optional, keyword-only)
            Metadata that will update the current metadata.
        to_nonflat : bool, optional keyword-only
            Whether to change to the non-flat version of this cosmology.
        **kwargs
            Cosmology parameter (and name) modifications. If any parameter is
            changed and a new name is not given, the name will be set to "[old
            name] (modified)".

        Returns
        -------
        newcosmo : `~astropy.cosmology.Cosmology` subclass instance
            A new instance of this class with updated parameters as specified.
            If no arguments are given, then a reference to this object is
            returned instead of copy.

        Examples
        --------
        To make a copy of the ``Planck13`` cosmology with a different matter
        density (``Om0``), and a new name:

            >>> from astropy.cosmology import Planck13
            >>> Planck13.clone(name="Modified Planck 2013", Om0=0.35)
            FlatLambdaCDM(name="Modified Planck 2013", H0=67.77 km / (Mpc s),
                          Om0=0.35, ...

        If no name is specified, the new name will note the modification.

            >>> Planck13.clone(Om0=0.35).name
            'Planck13 (modified)'

        The keyword 'to_nonflat' can be used to clone on the non-flat equivalent
        cosmology.

            >>> Planck13.clone(to_nonflat=True)
            LambdaCDM(name="Planck13", ...

            >>> Planck13.clone(H0=70, to_nonflat=True)
            LambdaCDM(name="Planck13 (modified)", H0=70.0 km / (Mpc s), ...
        rL   r   )r   rb   r,   )rN   rL   r   r[   r>   s       r   rb   zFlatCosmologyMixin.clone  sO    `  	;%4<%::4:6:::uww}11$1&111r   c                ^    t          t                    r!t                                                    S t	          j         j                  st          S t           j	                  t          j	                  k    o't           fd j        D                       oj        }|S )a  flat-|Cosmology| equivalence.

        Use `astropy.cosmology.funcs.cosmology_equal` with
        ``allow_equivalent=True`` for actual checks!

        Parameters
        ----------
        other : `~astropy.cosmology.Cosmology` subclass instance
            The object to which to compare for equivalence.

        Returns
        -------
        bool or `NotImplemented`
            `True` if ``other`` is of the same class / non-flat class (e.g.
            |FlatLambdaCDM| and |LambdaCDM|) has matching parameters and
            parameter values.
            `False` if ``other`` is of the same class but has different
            parameters.
            `NotImplemented` otherwise.
        c              3     K   | ]8}t          j        t          |          t          |          k              V  9d S rI   rs   rv   s     r   rx   z/FlatCosmologyMixin.__equiv__.<locals>.<genexpr>G  r~   r   )r/   r   r,   r{   r   r>   r   ry   rz   r"   ru   r!   rT   )rN   ri   	params_eqr>   s   `` r   r{   zFlatCosmologyMixin.__equiv__$  s    * e/00 	,77$$U+++
 %/4+@AA 	"!!
 '((C0H,I,II      ,      	 r   )r9   r   rj   r   rI   )r   r   rj   r   )rN   r   rj   r   )rL   r   r   rk   )r   r   r   r   r   r-   classmethodr   r   r   r   rT   r   r   r   rb   r{   r   r   s   @r   r   r     s9          ('''####      )-0 0 0 0 [0d %}t)S     X 	O O O O /3u 22 22 22 22 22 22 22 22l+ + + + + + + + +r   c                    ddl m} t          ||           r;| dvr7dd l}ddlm} |                    d|  d|  d|           t          ||           S t          d	t          d
| d          )Nr
   )flrw)__path__r   )AstropyDeprecationWarningz`astropy.cosmology.core.zX` has been moved (since v5.0) and should be imported as ``from astropy.cosmology import z+``. In future this will raise an exception.zmodule z has no attribute .)
 r   hasattrwarningsastropy.utils.exceptionsr   warnr.   AttributeErrorr   )attrr   r   r   s       r   __getattr__r   U  s    tT #t=88FFFFFF7t 7 7EI7 7 7 &		
 	
 	
 tT"""
J8JJJJJ
K
KKr   )'
__future__r   r   rA   typingr   r   r   numpyrt   astropy.io.registryr   astropy.utils.decoratorsr   astropy.utils.metadatar	   connectr   r   r   r   	parameterr   collections.abcr   "astropy.cosmology.funcs.comparisonr   __all____doctest_requires__dictr8   r   r   rp   r   ABCMetar   r   r   r   r   r   <module>r      s   # " " " " " 



  . . . . . . . . . .     6 6 6 6 6 6 2 2 2 2 2 2 + + + + + +            !           ?''''''>>>>>> @
?
?  TVV  ');
/
/
/gm+?@@@
	 	 	 	 	Y 	 	 	[B [B [B [B [B#+ [B [B [B [B|
x x x x x3; x x x x|L L L L Lr   