"""
######################
Generating Data Tables
######################
:class:`~ATK.Models.DataTable` objects are a means of tabulating `Vizier <https://vizier.cds.unistra.fr/>`_ data, and are particularly useful in the generation of :class:`~ATK.Models.DataPages` (see the :doc:`next tutorial <../datapages/datapage_plotting>`). A :class:`~ATK.Models.DataTable` can be generated by specifying a ``dict`` of `Vizier <https://vizier.cds.unistra.fr/>`_ catalogues and corresponding column names inside a ``"datatable"`` :func:`~ATK.Tools.query`.

This tutorial will generate a table of photometric data from Gaia and GALEX:
"""

# sphinx_gallery_start_ignore
# fmt: off
# isort: skip_file
from bokeh.document import Document
# sphinx_gallery_end_ignore
from ATK import query

target = 587316166180416640

table = query("datatable", targets=target, columns={"gaia": ["Gmag", "BPmag", "RPmag"], "galex": ["NUVmag", "FUVmag"]}, path="example_table.fits.gz")
table.show(show_types=True)

# %%
# The returned :class:`~ATK.Models.DataSet`'s :attr:`~ATK.Models.DataSet.data` attribute is a list containing a single :class:`~ATK.Models.DataTable` object.pass
# 
# The :class:`~ATK.Models.DataTable` can be plotted like any other plottable container, by calling the :class:`~ATK.Models.DataSet`'s :meth:`~ATK.Models.DataSet.plot` or :meth:`~ATK.Models.DataSet.open` methods:

# sphinx_gallery_start_ignore
table.plot()
doc = Document()
doc.add_root(table.figure)
# sphinx_gallery_end_ignore
table.open()
# sphinx_gallery_start_ignore
table.figure
# sphinx_gallery_end_ignore

# %%
# .. note::
#
#    In this example, keys in ``rows`` are given as `Vizier <https://vizier.cds.unistra.fr/>`_ catalogue aliases. If a key is not found in the ATK Surveys file, it is instead interpreted as a `Vizier <https://vizier.cds.unistra.fr/>`_ catalogue ID.
#
#    For more information, see :doc:`here <../extension/vizier>`.

# %%
#
# |
# |
# |
#
# .. rubric:: Download this Tutorial
