U
    d»{jË  ã                   @   s¬   d dl m  mZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ ddlmZmZ ddddœd	d
„Zdeddœdd„Zdd„ Ze de	e¡ e de	e¡ e de	e¡ dS )é    N)Úreadwrite_registry)Ú	Cosmology)ÚQTableé   )Ú
from_tableÚto_tableF)Úmove_to_metaÚ	cosmologyc             	   K   s<   d|d< t  t¡� tj| f|Ž}W 5 Q R X t||||d�S )aü  Read a `~astropy.cosmology.Cosmology` from an ECSV file.

    Parameters
    ----------
    filename : path-like or file-like
        From where to read the Cosmology.
    index : int, str, or None, optional
        Needed to select the row in tables with multiple rows. ``index`` can be
        an integer for the row number or, if the table is indexed by a column,
        the value of that column. If the table is not indexed and ``index``
        is a string, the "name" column is used as the indexing column.

    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 'table'.

    **kwargs
        Passed to :attr:`astropy.table.QTable.read`

    Returns
    -------
    `~astropy.cosmology.Cosmology` subclass instance
    ú
ascii.ecsvÚformat)Úindexr   r	   )ÚuZadd_enabled_unitsÚcur   Úreadr   )Úfilenamer   r   r	   ÚkwargsÚtable© r   úX/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/cosmology/io/ecsv.pyÚ	read_ecsv   s    "   ÿr   T)Ú	overwriteÚclsÚcosmology_in_metac                K   s0   t | ||d�}d|d< |j|fd|i|—Ž dS )a  Serialize the cosmology into a ECSV.

    Parameters
    ----------
    cosmology : `~astropy.cosmology.Cosmology` subclass instance
    file : path-like or file-like
        Location to save the serialized cosmology.

    overwrite : bool
        Whether to overwrite the file, if it exists.
    cls : type (optional, keyword-only)
        Astropy :class:`~astropy.table.Table` (sub)class to use when writing.
        Default is :class:`~astropy.table.QTable`.
    cosmology_in_meta : bool
        Whether to put the cosmology class in the Table metadata (if `True`,
        default) or as the first column (if `False`).
    **kwargs
        Passed to ``cls.write``

    Raises
    ------
    TypeError
        If kwarg (optional) 'cls' is not a subclass of `astropy.table.Table`
    )r   r   r
   r   r   N)r   Úwrite)r	   Úfiler   r   r   r   r   r   r   r   Ú
write_ecsv8   s    r   c                 O   s   |dk	o|  d¡S )zPIdentify if object uses the Table format.

    Returns
    -------
    bool
    Nz.ecsv)Úendswith)ÚoriginÚfilepathÚfileobjÚargsr   r   r   r   Úecsv_identifyY   s    r!   r
   )N)Zastropy.cosmology.unitsr	   Zunitsr   Zastropy.unitsr   Zastropy.cosmology.connectr   Zastropy.cosmology.corer   Zastropy.tabler   r   r   r   r   r   r!   Zregister_readerZregister_writerZregister_identifierr   r   r   r   Ú<module>   s   -  ÿ!