U
    d»{j'  ã                   @   s�   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d	„Z
eddd
œdd„Zdd„ Ze dee
¡ e dee¡ e 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                C   sæ   t | ƒ}|dkr| d¡}n| dd¡ t|tƒr:t| }|j ¡ }| ¡  |jj 	¡ D ]}||krX| |¡|j
|< qXt|jj ¡ ƒd }|jdkr¢||j
|j< n6|rÄ|j
d p²i }||–|j
d< n|rØtd|› d�ƒ‚||j|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   Z_init_signatureÚbind_partialÚapply_defaultsÚ
parametersÚkeysÚ	argumentsÚtupleÚvaluesÚkindÚnameÚ	TypeErrorÚargsÚkwargs)Úmapr   r   ÚparamsÚbaÚkZlastpr
   © r    ú[/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/cosmology/io/mapping.pyÚfrom_mapping   s(    >


r"   )ÚclsÚcosmology_as_strÚmove_from_metac                G   sž   t |ttfƒstd|› �ƒ‚|ƒ }|r.| jjn| j|d< | j|d< t | j	¡}|rt| 
d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                 S   s   i | ]\}}|d kr||“qS ))r
   r   r    )Ú.0r   Úvr    r    r!   Ú
<dictcomp>Ò   s   þ zto_mapping.<locals>.<dictcomp>r
   )Ú
issubclassr   r   r   Ú	__class__Ú__qualname__r   ÚcopyÚdeepcopyr
   r   ÚupdateZ_init_argumentsÚitems)r   r#   r$   r%   r   Úmr
   r    r    r!   Ú
to_mappingu   s&    Hÿ

þÿr1   c                 O   s&   d}| dkr"t |d tƒo |dk}|S )zRIdentify if object uses the mapping format.

    Returns
    -------
    bool
    FÚreadé   )NÚmapping)r   r   )ÚoriginÚformatr   r   Zitisr    r    r!   Úmapping_identifyß   s    r7   r4   )Ú__doc__r,   Úcollections.abcr   Zastropy.cosmology.connectr   Zastropy.cosmology.corer   r   Ú__all__r"   r   r1   r7   Zregister_readerZregister_writerZregister_identifierr    r    r    r!   Ú<module>   s   b  ÿj