
    HR-eA                        d dl mc 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ZdedddZd Z ej        de	e            ej        de	e            ej        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}$$)H0Om0Ode0Tcmb0Neffm_nuOb0w0wawzwpzpFT)move_to_meta	cosmologylatex_namesc                   |                     dd          }|dk    rt          d|           t          j        t                    5  t          j        | fddi|}ddd           n# 1 swxY w Y   |rMt          |j                  }t          
                                D ]\  }	}
|
|v r|                    |
|	            t          ||||          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 N)indexr   r   )pop
ValueErroruadd_enabled_unitscur   readsetcolnames_FORMAT_TABLEitemsrename_columnr   )filenamer   r   r   r   kwargsr   tabletable_columnsnamelatexs              9lib/python3.11/site-packages/astropy/cosmology/io/html.pyread_html_tabler0      sK   l ZZ,//FEVEEFFF 
	R	 	  E EHDD\DVDDE E E E E E E E E E E E E E E  1EN++(..00 	1 	1KD%%%##E4000 U   s   A))A-0A-)	overwriteclsr   c                "   |                     dd          }|dk    rt          d|           t          | |d          }t          |           }|j                                        D ]f\  }	}
t          ||	d          }t          |t                    r|j	        dt          j        fv rA|                    |	|
|j	        z  j        d           g|r,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)r2   cosmology_in_metaN)copyc                 D    g | ]}t                               ||          S  )r&   get).0ks     r/   
<listcomp>z$write_html_table.<locals>.<listcomp>   s(    OOO]&&q!,,OOO    )r1   r   )r   r   r	   typecolumnsr'   getattr
isinstancer   unitr    onereplace_columnvalue__parameters__rename_columnswrite)r   filer1   r2   r   r*   r   r+   	cosmo_clsr-   colparam	new_namess                r/   write_html_tablerM   i   sA   V ZZ,//FEVEEFFF YC5AAAEYI]((** J J	c	4..%++ 	uzdAE]/J/JTC5:$5#<5IIII  BOOi6NOOO	Y5yAAA EKI	,II&IIIIIr<   c                 V    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*   s        r/   html_identifyrU      s'    * h$$C):):7)C)CCr<   r   )N)astropy.cosmology.unitsr   unitsr"   astropy.unitsr    astropy.cosmology.connectr   astropy.cosmology.corer   astropy.cosmology.parameterr   astropy.tabler   r+   r   r	   r&   r0   rM   rU   register_readerregister_writerregister_identifierr7   r<   r/   <module>r`      s   $ $ $ $ $ $ $ $ $       8 8 8 8 8 8 , , , , , , 1 1 1 1 1 1             ' ' ' ' ' ' ' '
 &




 $ J J J J J J\ #(V@J @J @J @J @JFD D D6 #  "<O L L L "  "<<L M M M &  &|Y N N N N Nr<   