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 ddlmZmZ dd	d
ddddddddddœZd 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)Ú	Parameter)ÚQTableé   )Ú
from_tableÚto_tablez	$$H_{0}$$z$$\Omega_{m,0}$$z$$\Omega_{\Lambda,0}$$z	$$T_{0}$$z$$N_{eff}$$z
$$m_{nu}$$z$$\Omega_{b,0}$$z	$$w_{0}$$z	$$w_{a}$$z	$$w_{z}$$z	$$w_{p}$$z	$$z_{p}$$)ZH0ZOm0ZOde0ZTcmb0ZNeffZm_nuZOb0Zw0ÚwaZwzZwpZzpFT)Úmove_to_metaÚ	cosmologyÚlatex_namesc             	   K   s’   |  dd¡}|dkr"td|› �ƒ‚t t¡� tj| fddi|—Ž}W 5 Q R X |r‚t|jƒ}t	 
¡ D ]\}	}
|
|krd| |
|	¡ qdt||||d�S )aL  Read a |Cosmology| from an HTML file.

    Parameters
    ----------
    filename : path-like or file-like
        From where to read the Cosmology.
    index : int or 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 or |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'.
    latex_names : bool, optional keyword-only
        Whether the |Table| (might) have latex column names for the parameters
        that need to be mapped to the correct parameter name -- e.g. $$H_{0}$$
        to 'H0'. This is `True` by default, but can be turned off (set to
        `False`) if there is a known name conflict (e.g. both an 'H0' and
        '$$H_{0}$$' column) as this will raise an error. In this case, the
        correct name ('H0') is preferred.
    **kwargs : Any
        Passed to :attr:`astropy.table.QTable.read`. ``format`` is set to
        'ascii.html', regardless of input.

    Returns
    -------
    |Cosmology| subclass instance

    Raises
    ------
    ValueError
        If the keyword argument 'format' is given and is not "ascii.html".
    Úformatú
ascii.htmlú!format must be 'ascii.html', not )Úindexr
   r   )ÚpopÚ
ValueErrorÚuZadd_enabled_unitsÚcur   ÚreadÚsetZcolnamesÚ_FORMAT_TABLEÚitemsZrename_columnr   )Úfilenamer   r
   r   r   Úkwargsr   ÚtableÚtable_columnsÚnameÚlatex© r   úX/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/cosmology/io/html.pyÚread_html_table   s     6 
   ÿr!   )Ú	overwriteÚclsr   c                K   sÊ   |  dd¡}|dkr"td|› �ƒ‚t| |dd�}t| ƒ}|j ¡ D ]H\}	}
t||	dƒ}t|tƒrB|j	dt
jfkrrqB|j|	|
|j	> jdd� qB|r®dd	„ | jD ƒ}| | j|¡ |j|f|dd
œ|—Ž dS )a	  Serialize the |Cosmology| into a HTML table.

    Parameters
    ----------
    cosmology : |Cosmology| subclass instance file : path-like or file-like
        Location to save the serialized cosmology.
    file : path-like or file-like
        Where to write the html table.

    overwrite : bool, optional keyword-only
        Whether to overwrite the file, if it exists.
    cls : |Table| class, optional keyword-only
        Astropy |Table| (sub)class to use when writing. Default is |QTable|
        class.
    latex_names : bool, optional keyword-only
        Whether to format the parameters (column) names to latex -- e.g. 'H0' to
        $$H_{0}$$.
    **kwargs : Any
        Passed to ``cls.write``.

    Raises
    ------
    TypeError
        If the optional keyword-argument 'cls' is not a subclass of |Table|.
    ValueError
        If the keyword argument 'format' is given and is not "ascii.html".

    Notes
    -----
    A HTML file containing a Cosmology HTML table should have scripts enabling
    MathJax.

    ::
        <script
        src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
        <script type="text/javascript" id="MathJax-script" async
            src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js">
        </script>
    r   r   r   F)r#   Zcosmology_in_metaN)Úcopyc                 S   s   g | ]}t  ||¡‘qS r   )r   Úget)Ú.0Úkr   r   r    Ú
<listcomp>¥   s     z$write_html_table.<locals>.<listcomp>)r"   r   )r   r   r   ÚtypeÚcolumnsr   ÚgetattrÚ
isinstancer   Úunitr   ÚoneZreplace_columnÚvalueÚ__parameters__Zrename_columnsÚwrite)r   Úfiler"   r#   r   r   r   r   Z	cosmo_clsr   ÚcolÚparamZ	new_namesr   r   r    Úwrite_html_tablei   s    +r5   c                 O   s   t |tƒo| d¡S )a‚  Identify if an object uses the HTML Table format.

    Parameters
    ----------
    origin : Any
        Not used.
    filepath : str or Any
        From where to read the Cosmology.
    fileobj : Any
        Not used.
    *args : Any
        Not used.
    **kwargs : Any
        Not used.

    Returns
    -------
    bool
        If the filepath is a string ending with '.html'.
    z.html)r,   ÚstrÚendswith)ÚoriginÚfilepathÚfileobjÚargsr   r   r   r    Úhtml_identify¬   s    r<   r   )N)Zastropy.cosmology.unitsr   Zunitsr   Zastropy.unitsr   Zastropy.cosmology.connectr   Zastropy.cosmology.corer   Zastropy.cosmology.parameterr   Zastropy.tabler   r   r   r   r   r!   r5   r<   Zregister_readerZregister_writerZregister_identifierr   r   r   r    Ú<module>   sB   ô þúN  ÿC