
    HR-e'                         d Z ddlZddlmZ ddlmZ ddlmZmZ g Z	ddddZ
eddd	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)Mapping)convert_registry)_COSMOLOGY_CLASSES	CosmologyF)move_to_meta	cosmologyc                   t          |           }||                    d          }n|                    dd           t          |t                    rt          |         }|j                                        }|                                 |j        j        	                                D ]#}||v r|                    |          |j
        |<   $t          |j        j                                                  d         }|j        dk    r||j
        |j        <   n5|r|j
        d         pi }i |||j
        d<   n|rt          d| d           ||j        i |j        S )a
  Load `~astropy.cosmology.Cosmology` from mapping object.

    Parameters
    ----------
    map : mapping
        Arguments into the class -- like "name" or "meta".
        If 'cosmology' is None, must have field "cosmology" which can be either
        the string name of the cosmology class (e.g. "FlatLambdaCDM") or the
        class itself.

    move_to_meta : bool (optional, keyword-only)
        Whether to move keyword arguments that are not in the Cosmology class'
        signature to the Cosmology's metadata. This will only be applied if the
        Cosmology does NOT have a keyword-only argument (e.g. ``**kwargs``).
        Arguments moved to the metadata will be merged with existing metadata,
        preferring specified metadata in the case of a merge conflict
        (e.g. for ``Cosmology(meta={'key':10}, key=42)``, the ``Cosmology.meta``
        will be ``{'key': 10}``).

    cosmology : str, `~astropy.cosmology.Cosmology` class, or None (optional, keyword-only)
        The cosmology class (or string name thereof) to use when constructing
        the cosmology instance. The class also provides default parameter values,
        filling in any non-mandatory arguments missing in 'map'.

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

    Examples
    --------
    To see loading a `~astropy.cosmology.Cosmology` from a dictionary with
    ``from_mapping``, we will first make a mapping using
    :meth:`~astropy.cosmology.Cosmology.to_format`.

        >>> from astropy.cosmology import Cosmology, Planck18
        >>> cm = Planck18.to_format('mapping')
        >>> cm
        {'cosmology': <class 'astropy.cosmology.flrw.lambdacdm.FlatLambdaCDM'>,
         'name': 'Planck18', 'H0': <Quantity 67.66 km / (Mpc s)>, 'Om0': 0.30966,
         'Tcmb0': <Quantity 2.7255 K>, 'Neff': 3.046,
         'm_nu': <Quantity [0. , 0. , 0.06] eV>, 'Ob0': 0.04897,
         'meta': ...

    Now this dict can be used to load a new cosmological instance identical
    to the ``Planck18`` cosmology from which it was generated.

        >>> cosmo = Cosmology.from_format(cm, format="mapping")
        >>> cosmo
        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)

    Specific cosmology classes can be used to parse the data. The class'
    default parameter values are used to fill in any information missing in the
    data.

        >>> from astropy.cosmology import FlatLambdaCDM
        >>> del cm["Tcmb0"]  # show FlatLambdaCDM provides default
        >>> FlatLambdaCDM.from_format(cm)
        FlatLambdaCDM(name="Planck18", H0=67.66 km / (Mpc s), Om0=0.30966,
                      Tcmb0=0.0 K, Neff=3.046, m_nu=None, Ob0=0.04897)
    Nr      metazthere are unused parameters .)dictpop
isinstancestrr   _init_signaturebind_partialapply_defaults
parameterskeys	argumentstuplevalueskindname	TypeErrorargskwargs)mapr   r   paramsbaklastpr   s           <lib/python3.11/site-packages/astropy/cosmology/io/mapping.pyfrom_mappingr%      sv   | #YYF
 JJ{++		

;%%%)S!! 2&y1	 
	"	/	/	1	1B&16688 , ,;;$jjmmBLO )+6==??@@DEzQ#)UZ  	 B|F#)r1&1D1V	 B@v@@@AAA 9bg++++    )clscosmology_as_strmove_from_metac                   t          |t          t          f          st          d|            |            }|r| j        j        n| j        |d<   | j        |d<   t          j        | j	                  }|rA|
                    dd           |
                    dd           |                    |           |                    d | j                                        D                        |s||d<   |S )a  Return the cosmology class, parameters, and metadata as a `dict`.

    Parameters
    ----------
    cosmology : `~astropy.cosmology.Cosmology` subclass instance
    *args
        Not used. Needed for compatibility with
        `~astropy.io.registry.UnifiedReadWriteMethod`
    cls : type (optional, keyword-only)
        `dict` or `collections.Mapping` subclass.
        The mapping type to return. Default is `dict`.
    cosmology_as_str : bool (optional, keyword-only)
        Whether the cosmology value is the class (if `False`, default) or
        the semi-qualified name (if `True`).
    move_from_meta : bool (optional, keyword-only)
        Whether to add the Cosmology's metadata as an item to the mapping (if
        `False`, default) or to merge with the rest of the mapping, preferring
        the original values (if `True`)

    Returns
    -------
    dict
        with key-values for the cosmology parameters and also:
        - 'cosmology' : the class
        - 'meta' : the contents of the cosmology's metadata attribute.
                   If ``move_from_meta`` is `True`, this key is missing and the
                   contained metadata are added to the main `dict`.

    Examples
    --------
    A Cosmology as a mapping will have the cosmology's name and
    parameters as items, and the metadata as a nested dictionary.

        >>> from astropy.cosmology import Planck18
        >>> Planck18.to_format('mapping')
        {'cosmology': <class 'astropy.cosmology.flrw.lambdacdm.FlatLambdaCDM'>,
         'name': 'Planck18', 'H0': <Quantity 67.66 km / (Mpc s)>, 'Om0': 0.30966,
         'Tcmb0': <Quantity 2.7255 K>, 'Neff': 3.046,
         'm_nu': <Quantity [0.  , 0.  , 0.06] eV>, 'Ob0': 0.04897,
         'meta': ...

    The dictionary type may be changed with the ``cls`` keyword argument:

        >>> from collections import OrderedDict
        >>> Planck18.to_format('mapping', cls=OrderedDict)
        OrderedDict([('cosmology', <class 'astropy.cosmology.flrw.lambdacdm.FlatLambdaCDM'>),
          ('name', 'Planck18'), ('H0', <Quantity 67.66 km / (Mpc s)>),
          ('Om0', 0.30966), ('Tcmb0', <Quantity 2.7255 K>), ('Neff', 3.046),
          ('m_nu', <Quantity [0.  , 0.  , 0.06] eV>), ('Ob0', 0.04897),
          ('meta', ...

    Sometimes it is more useful to have the name of the cosmology class, not
    the object itself. The keyword argument ``cosmology_as_str`` may be used:

        >>> Planck18.to_format('mapping', cosmology_as_str=True)
        {'cosmology': 'FlatLambdaCDM', ...

    The metadata is normally included as a nested mapping. To move the metadata
    into the main mapping, use the keyword argument ``move_from_meta``. This
    kwarg inverts ``move_to_meta`` in
    ``Cosmology.to_format("mapping", move_to_meta=...)`` where extra items
    are moved to the metadata (if the cosmology constructor does not have a
    variable keyword-only argument -- ``**kwargs``).

        >>> from astropy.cosmology import Planck18
        >>> Planck18.to_format('mapping', move_from_meta=True)
        {'cosmology': <class 'astropy.cosmology.flrw.lambdacdm.FlatLambdaCDM'>,
         'name': 'Planck18', 'Oc0': 0.2607, 'n': 0.9665, 'sigma8': 0.8102, ...
    z3'cls' must be a (sub)class of dict or Mapping, not r   r   Nc                 "    i | ]\  }}|d v	||S ))r   r    ).0r"   vs      r$   
<dictcomp>zto_mapping.<locals>.<dictcomp>   s4     	
 	
 	
1((( q(((r&   r   )
issubclassr   r   r   	__class____qualname__r   copydeepcopyr   r   update_init_argumentsitems)r   r'   r(   r)   r   mr   s          r$   
to_mappingr9   u   s   P cD'?++ UScSSTTTA -=U	(()BU kN AfI=((D  	d###	 HH	
 	
!17799	
 	
 	
    &	Hr&   c                 T    d}| dk    rt          |d         t                    o|dv }|S )zRIdentify if object uses the mapping format.

    Returns
    -------
    bool
    Fread   )Nmapping)r   r   )originformatr   r   itiss        r$   mapping_identifyrA      s7     D$q'7++M;L1LKr&   r=   )__doc__r3   collections.abcr   astropy.cosmology.connectr   astropy.cosmology.corer   r   __all__r%   r   r9   rA   register_readerregister_writerregister_identifierr,   r&   r$   <module>rJ      s	     # # # # # # 6 6 6 6 6 6 @ @ @ @ @ @ @ @
 ',t ^, ^, ^, ^, ^,D ug g g g gT
 
 
  !   I| D D D     Iz B B B $  $Y	;K L L L L Lr&   