"""
##################
Local Data Storage
##################
A :class:`ATK.Models.DataSet` of any kind can be stored as a local FITS file. These files can then be read to recreate the original :class:`~ATK.Models.DataSet`.

|

Automatic Local Data Storage
============================
To store any returned data, :func:`~ATK.Tools.query` can be provided with a ``path``:
"""

# sphinx_gallery_start_ignore
# fmt: off
# isort: skip_file
# sphinx_gallery_end_ignore

from ATK import query

target = 2552928187080872832
galex_query = query("vizier", targets=target, survey="galex", path="example_data.fits.gz")
# sphinx_gallery_start_ignore
pass
# sphinx_gallery_end_ignore

# %%
# This will automatically save the returned :class:`~ATK.Models.DataSet` to ``path``, and **running the script again will read this local file instead of running** :func:`~ATK.Tools.query` **again.**
#
# |
# 
# .. note::
#
#    The following situations will automatically trigger the :func:`~ATK.Tools.query` to run again, overwriting the local file with the updated :class:`~ATK.Models.DataSet`:
# 
#    - Changes to query parameters
#    - Changes to the working version of ATK 
#    - If an exception was encountered during data retrieval prior to file creation (i.e. :attr:`~ATK.Models.DataSet.exception` is ``True``)
#
# |
# |
#
# Manual Local Data Storage
# =========================
# A :class:`~ATK.Models.DataSet` can also be stored manually by calling its :meth:`~ATK.Models.DataSet.store` method:

from ATK import query

target = 2552928187080872832
galex_query = query("vizier", targets=target, survey="galex")
galex_query.store("example_data.fits.gz")
# sphinx_gallery_start_ignore
pass
# sphinx_gallery_end_ignore

# %%
# |
#
# The original :class:`~ATK.Models.DataSet` can be read from the file and re-created with :func:`~ATK.Tools.read`:

from ATK import read

data = read("example_data.fits.gz")
data.show()
# sphinx_gallery_start_ignore
pass
# sphinx_gallery_end_ignore

# %%
# |
# |
#
# File Compression
# ================
# FITS files generated by any of the methods outlined above are **automatically compressed based on the provided extension.** For example, to compress with **gzip**:

galex_query = query("vizier", targets=target, survey="galex", path="example_data.fits.gz")

# %%
# Or:

galex_query.store("example_data.fits.gz")
# sphinx_gallery_start_ignore
pass
# sphinx_gallery_end_ignore

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