
    HR-e$                        d Z ddlZddlZddlZddl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 g Z G d	 d
e          Zd Zd Zd Z ej        de	e            ej        de	e            ej        de	e           dS )a-  
The following are private functions, included here **FOR REFERENCE ONLY** since
the io registry cannot be displayed. These functions are registered into
:meth:`~astropy.cosmology.Cosmology.to_format` and
:meth:`~astropy.cosmology.Cosmology.from_format` and should only be accessed
via these methods.
    N)convert_registry)	Cosmology)FittableModelModel)classproperty   )$convert_parameter_to_model_parameterc                       e Zd ZdZej        d             Zej        d             Zed             Z	e
d             Zed             Zd ZdS )	_CosmologyModela  Base class for Cosmology redshift-method Models.

    .. note::

        This class is not publicly scoped so should not be used directly.
        Instead, from a Cosmology instance use ``.to_format("astropy.model")``
        to create an instance of a subclass of this class.

    `_CosmologyModel` (subclasses) wrap a redshift-method of a
    :class:`~astropy.cosmology.Cosmology` class, converting each non-`None`
    |Cosmology| :class:`~astropy.cosmology.Parameter` to a
    :class:`astropy.modeling.Model` :class:`~astropy.modeling.Parameter`
    and the redshift-method to the model's ``__call__ / evaluate``.

    See Also
    --------
    astropy.cosmology.Cosmology.to_format
    c                     dS )z:Cosmology class as a private attribute. Set in subclasses.N selfs    :lib/python3.11/site-packages/astropy/cosmology/io/model.py_cosmology_classz _CosmologyModel._cosmology_class/             c                     dS )z@Cosmology method name as a private attribute. Set in subclasses.Nr   r   s    r   _method_namez_CosmologyModel._method_name3   r   r   c                     | j         S )z|Cosmology| class.)r   )clss    r   cosmology_classz_CosmologyModel.cosmology_class7   s     ##r   c                 V       j         dd j        i fd j        D             }|S )z>Return |Cosmology| using `~astropy.modeling.Parameter` values.namec                 \    i | ](}|t          |          xj        sj        nj        )S r   )getattrunitvaluequantity).0kr   vs     r   
<dictcomp>z-_CosmologyModel.cosmology.<locals>.<dictcomp>A   sJ        q)9)9$9A#?OAGGQZ  r   r   )r   r   param_names)r   cosmor"   s   ` @r   	cosmologyz_CosmologyModel.cosmology<   sc     &% 
 

    )  
 
 r   c                     | j         S )z-Redshift-method name on |Cosmology| instance.)r   r   s    r   method_namez_CosmologyModel.method_nameH   s       r   c                     | j         j        j        || j        d         i |}| j        D ]}||j        vr-t          | |          }|j        s|j        n|j	        |j        |<   t          j        |j        |                   rE|dk    r$t          |j        |         j                  dk    r|j        |         d         |j        |<    | j        di |j        } t          || j                  |d| j                  }|S )a  Evaluate method {method!r} of {cosmo_cls!r} Cosmology.

        The Model wraps the :class:`~astropy.cosmology.Cosmology` method,
        converting each |Cosmology| :class:`~astropy.cosmology.Parameter` to a
        :class:`astropy.modeling.Model` :class:`~astropy.modeling.Parameter`
        (unless the Parameter is None, in which case it is skipped).
        Here an instance of the cosmology is created using the current
        Parameter values and the method is evaluated given the input.

        Parameters
        ----------
        *args, **kwargs
            The first ``n_inputs`` of ``*args`` are for evaluating the method
            of the cosmology. The remaining args and kwargs are passed to the
            cosmology class constructor.
            Any unspecified Cosmology Parameter use the current value of the
            corresponding Model Parameter.

        Returns
        -------
        Any
            Results of evaluating the Cosmology method.
        Nm_nur   r   r   )r   _init_signaturebind_partialn_inputsr$   	argumentsr   r   r   r   npshapelenr   r   )r   argskwargsbar!   r"   r%   results           r   evaluatez_CosmologyModel.evaluateO   s   4 ?T!1>$-//"
&,
 

 ! 	5 	5A$$D!$$12"G!''QZQ xQ(( 5;;3r|A'<#=#=#B#B"$,q/!"4Q &%55552 122D4=4IJr   N)__name__
__module____qualname____doc__abcabstractmethodr   r   r   r   propertyr&   r(   r6   r   r   r   r   r      s         & 	I I I 	O O O $ $ ]$ 	 	 X	 ! ! ]!1 1 1 1 1r   r   c                 Z   | j         }t          j        | j                  }i }| j        D ]R}t          | |          j        rj        nj        |j	        <   fdt                    D             |j	        <   S |j        j        dd| j	        i|d|i} ||j        i |j        S )a|  Load |Cosmology| from `~astropy.modeling.Model` object.

    Parameters
    ----------
    model : `_CosmologyModel` subclass instance
        See ``Cosmology.to_format.help("astropy.model") for details.

    Returns
    -------
    `~astropy.cosmology.Cosmology` subclass instance

    Examples
    --------
    >>> from astropy.cosmology import Cosmology, Planck18
    >>> model = Planck18.to_format("astropy.model", method="lookback_time")
    >>> Cosmology.from_format(model)
    FlatLambdaCDM(name="Planck18", H0=67.66 km / (Mpc s), Om0=0.30966,
                  Tcmb0=2.7255 K, Neff=3.046, m_nu=[0. 0. 0.06] eV, Ob0=0.04897)
    c                     i | ]E}|                     d           t          t          |                    4|t          |          FS )_)
startswithcallabler   )r    nps     r   r#   zfrom_model.<locals>.<dictcomp>   s_     
 
 
LL%%
 *2'!Q--)@)@
wq!}}
 
 
r   r   metar   )r   copydeepcopyrE   r$   r   r   r   r   r   dirr+   bindr2   r3   )modelr&   rE   paramsrC   r4   rD   s         @r   
from_modelrL      s    ( %I=$$D F 
 
E1'(v:17qv
 
 
 
VV
 
 
QV 
(	"	'	M	MUZ	M6	M	M	M	M	MB9bg++++r   c                X     j         }t           |          st          | d j          d          t           |          }t	          |          st           j          d| d          t          j        |          }t          d t          |j
                                                  D                       }i }||d<   ||d<   ||d<   d|d	<   i } j        D ]O}	t           |	          }
|
t          t          ||	          |
 j                            |	                    ||	<   P|j                            dd          dz   |                    dd                                                              dd          z   dz   }t'          |t(          fi ||          }||j        _        |j        j                            |j        |          |j        _         fd|                                D             } |di | j        t7          j         j                  d}|S )a  Convert a `~astropy.cosmology.Cosmology` to a `~astropy.modeling.Model`.

    Parameters
    ----------
    cosmology : `~astropy.cosmology.Cosmology` subclass instance
    method : str, keyword-only
        The name of the method on the ``cosmology``.

    Returns
    -------
    `_CosmologyModel` subclass instance
        The Model wraps the |Cosmology| method, converting each non-`None`
        :class:`~astropy.cosmology.Parameter` to a
        :class:`astropy.modeling.Model` :class:`~astropy.modeling.Parameter`
        and the method to the model's ``__call__ / evaluate``.

    Examples
    --------
    >>> from astropy.cosmology import Planck18
    >>> model = Planck18.to_format("astropy.model", method="lookback_time")
    >>> model
    <FlatLambdaCDMCosmologyLookbackTimeModel(H0=67.66 km / (Mpc s), Om0=0.30966,
        Tcmb0=2.7255 K, Neff=3.046, m_nu=[0.  , 0.  , 0.06] eV, Ob0=0.04897,
        name='Planck18')>
    z is not a method on .z is not callable.c                 $    g | ]}|j         d v |S ))r   r   )kind)r    rD   s     r   
<listcomp>zto_model.<locals>.<listcomp>   s$    UUU!16VCSCSACSCSCSr   r   r   r-   r   	n_outputsNr@   r     r   )	cosmo_clsmethodc                 2    i | ]}|t          |          S r   )r   )r    rC   r&   s     r   r#   zto_model.<locals>.<dictcomp>   s%    	:	:	:q!WY""	:	:	:r   )r   rE   r   )	__class__hasattrAttributeErrorr   rB   
ValueErrorinspect	signaturer1   tuple
parametersvalues__parameters__r	   rE   getr9   replacetitletyper   r6   __signature__r:   formatkeysr   rF   rG   )r&   rV   r@   rU   funcmsigr-   attrsrK   rC   r"   clsname
CosmoModelpsrJ   s   `              r   to_modelro      sp   4 #I 9f%% TRRI<ORRRSSS9f%%DD>> MI/KK&KKKLLLT""D UUuT_%;%;%=%=>>UUUVVHE )E
"E. E*E+F% 	
 	
Iq!!9 9Iq!!1in&8&8&;&;
 
q		 	&&sC00
	
..c
"
"
(
(
*
*
2
23
;
;	< 	  g13Fe3Fv3FGGJ(,J%","5"="D"D( #E # #J
 
;	:	:	:FKKMM	:	:	:BJUUU).t}Y^7T7TUUUUELr   c                 T    d}| dk    rt          |d         t                    o|dv }|S )zkIdentify if object uses the :class:`~astropy.modeling.Model` format.

    Returns
    -------
    bool
    Freadr   )Nastropy.model)
isinstancer   )originrg   r2   r3   itiss        r   model_identifyrv      s7     D$q'5))Qv9P/PKr   rr   )r:   r;   rF   r\   numpyr/   astropy.cosmology.connectr   astropy.cosmology.corer   astropy.modelingr   r   astropy.utils.decoratorsr   utilsr	   __all__r   rL   ro   rv   register_readerregister_writerregister_identifierr   r   r   <module>r      sR    


       6 6 6 6 6 6 , , , , , , 1 1 1 1 1 1 1 1 2 2 2 2 2 2 7 7 7 7 7 7
e e e e em e e eV$, $, $,NM M M`  " !   )Z H H H     )X F F F $  $_i P P P P Pr   