a
    ߙfbO"                     @   s   d dl 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 g dZeZe ZG dd dejZG d	d
 d
ejZe ZG dd dejZG dd dejZdS )    N)unitsregistry)add_enabled_units)AstropyUserWarning)CosmologyReadCosmologyWriteCosmologyFromFormatCosmologyToFormatc                       s(   e Zd ZdZ fddZdd Z  ZS )r   a  Read and parse data to a `~astropy.cosmology.Cosmology`.

    This function provides the Cosmology interface to the Astropy unified I/O
    layer. This allows easily reading a file in supported data formats using
    syntax such as::

        >>> from astropy.cosmology import Cosmology
        >>> cosmo1 = Cosmology.read('<file name>')

    When the ``read`` method is called from a subclass the subclass will
    provide a keyword argument ``cosmology=<class>`` to the registered read
    method. The method uses this cosmology class, regardless of the class
    indicated in the file, and sets parameters' default values from the class'
    signature.

    Get help on the available readers using the ``help()`` method::

      >>> Cosmology.read.help()  # Get help reading and list supported formats
      >>> Cosmology.read.help(format='<format>')  # Get detailed help on a format
      >>> Cosmology.read.list_formats()  # Print list of available formats

    See also: https://docs.astropy.org/en/stable/io/unified.html

    Parameters
    ----------
    *args
        Positional arguments passed through to data reader. If supplied the
        first argument is typically the input filename.
    format : str (optional, keyword-only)
        File format specifier.
    **kwargs
        Keyword arguments passed through to data reader.

    Returns
    -------
    out : `~astropy.cosmology.Cosmology` subclass instance
        `~astropy.cosmology.Cosmology` corresponding to file contents.

    Notes
    -----
    c                    s   t  j||dtd d S Nreadr   super__init__readwrite_registryselfinstanceZ	cosmo_cls	__class__ 8lib/python3.9/site-packages/astropy/cosmology/connect.pyr   A   s    zCosmologyRead.__init__c                 O   s   ddl m} | j|ur\|d| j | j| jjf}|d |vr\td|d  d|d  dtt, | jj	| jg|R i |}W d    n1 s0    Y  |S Nr   )	CosmologyZ	cosmologyz6keyword argument `cosmology` must be either the class z or its qualified name '   ')
astropy.cosmology.corer   _cls
setdefault__qualname__
ValueErrorr   cur   r   )r   argskwargsr   validcosmor   r   r   __call__D   s    

:zCosmologyRead.__call____name__
__module__r   __doc__r   r&   __classcell__r   r   r   r   r      s   *r   c                       s(   e Zd ZdZ fddZdd Z  ZS )r   a  Write this Cosmology object out in the specified format.

    This function provides the Cosmology interface to the astropy unified I/O
    layer. This allows easily writing a file in supported data formats
    using syntax such as::

      >>> from astropy.cosmology import Planck18
      >>> Planck18.write('<file name>')

    Get help on the available writers for ``Cosmology`` using the ``help()``
    method::

      >>> Cosmology.write.help()  # Get help writing and list supported formats
      >>> Cosmology.write.help(format='<format>')  # Get detailed help on format
      >>> Cosmology.write.list_formats()  # Print list of available formats

    Parameters
    ----------
    *args
        Positional arguments passed through to data writer. If supplied the
        first argument is the output filename.
    format : str (optional, keyword-only)
        File format specifier.
    **kwargs
        Keyword arguments passed through to data writer.

    Notes
    -----
    c                    s   t  j||dtd d S Nwriter   r   r   r   clsr   r   r   r   y   s    zCosmologyWrite.__init__c                 O   s    | j j| jg|R i | d S )Nr   r-   Z	_instance)r   r"   r#   r   r   r   r&   |   s    zCosmologyWrite.__call__r'   r   r   r   r   r   Z   s   r   c                       s(   e Zd ZdZ fddZdd Z  ZS )r	   a  Transform object to a `~astropy.cosmology.Cosmology`.

    This function provides the Cosmology interface to the Astropy unified I/O
    layer. This allows easily parsing supported data formats using
    syntax such as::

      >>> from astropy.cosmology import Cosmology
      >>> cosmo1 = Cosmology.from_format(cosmo_mapping, format='mapping')

    When the ``from_format`` method is called from a subclass the subclass will
    provide a keyword argument ``cosmology=<class>`` to the registered parser.
    The method uses this cosmology class, regardless of the class indicated in
    the data, and sets parameters' default values from the class' signature.

    Get help on the available readers using the ``help()`` method::

      >>> Cosmology.from_format.help()  # Get help and list supported formats
      >>> Cosmology.from_format.help('<format>')  # Get detailed help on a format
      >>> Cosmology.from_format.list_formats()  # Print list of available formats

    See also: https://docs.astropy.org/en/stable/io/unified.html

    Parameters
    ----------
    obj : object
        The object to parse according to 'format'
    *args
        Positional arguments passed through to data parser.
    format : str (optional, keyword-only)
        Object format specifier.
    **kwargs
        Keyword arguments passed through to data parser.

    Returns
    -------
    out : `~astropy.cosmology.Cosmology` subclass instance
        `~astropy.cosmology.Cosmology` corresponding to ``obj`` contents.

    c                    s   t  j||dtd d S r   r   r   convert_registryr   r   r   r   r      s    zCosmologyFromFormat.__init__c                 O   s~   ddl m} | j|ur\|d| j | j| jjf}|d |vr\td|d  d|d  d| jj| j|g|R i |}|S r   )r   r   r   r   r   r    r   r   )r   objr"   r#   r   r$   r%   r   r   r   r&      s    
zCosmologyFromFormat.__call__r'   r   r   r   r   r	      s   (r	   c                       s(   e Zd ZdZ fddZdd Z  ZS )r
   a@  Transform this Cosmology to another format.

    This function provides the Cosmology interface to the astropy unified I/O
    layer. This allows easily transforming to supported data formats
    using syntax such as::

      >>> from astropy.cosmology import Planck18
      >>> Planck18.to_format("mapping")
      {'cosmology': astropy.cosmology.core.FlatLambdaCDM,
       'name': 'Planck18',
       'H0': <Quantity 67.66 km / (Mpc s)>,
       'Om0': 0.30966,
       ...

    Get help on the available representations for ``Cosmology`` using the
    ``help()`` method::

      >>> Cosmology.to_format.help()  # Get help and list supported formats
      >>> Cosmology.to_format.help('<format>')  # Get detailed help on format
      >>> Cosmology.to_format.list_formats()  # Print list of available formats

    Parameters
    ----------
    format : str
        Format specifier.
    *args
        Positional arguments passed through to data writer. If supplied the
        first argument is the output filename.
    **kwargs
        Keyword arguments passed through to data writer.

    c                    s   t  j||dtd d S r,   r1   r.   r   r   r   r      s    zCosmologyToFormat.__init__c                 O   s"   | j j| jd g|R d|i|S )Nformatr0   )r   r4   r"   r#   r   r   r   r&      s    zCosmologyToFormat.__call__r'   r   r   r   r   r
      s   !r
   )copywarningsZastropy.cosmologyr   r!   Z
astropy.ior   Zio_registryZastropy.unitsr   Zastropy.utils.exceptionsr   __all__Z__doctest_skip__ZUnifiedIORegistryr   ZUnifiedReadWriter   r   r2   r	   r
   r   r   r   r   <module>   s   D*@