# Path: astroNN/gaia/gaia_shared.py
# def gaia_env():
#     """
#     Get Gaia environment variable
# 
#     :return: Path to Gaia Data
#     :rtype: str
#     :History: 2017-Oct-26 - Written - Henry Leung (University of Toronto)
#     """
#     from astroNN.config import ENVVAR_WARN_FLAG
#     _GAIA = os.getenv('GAIA_TOOLS_DATA')
#     if _GAIA is None and ENVVAR_WARN_FLAG is True:
#         print("WARNING! Gaia environment variable GAIA_TOOLS_DATA not set")
#     return _GAIA
# 
# def gaia_default_dr(dr=None):
#     """
#     Check if dr argument is provided, if none then use default
# 
#     :param dr: Gaia DR
#     :type dr: Union[NoneType, int]
#     :return: Gaia DR
#     :rtype: int
#     :History: 2017-Oct-26 - Written - Henry Leung (University of Toronto)
#     """
#     if dr is None:
#         dr = 2
#         print(f'dr is not provided, using default dr={dr}')
#     else:
#         pass
#     return dr
# 
# Path: astroNN/shared/warnings.py
# def deprecated(func):
#     """
#     This is a decorator which can be used to mark functions
#     as deprecated. It will result in a warning being emitted
#     when the function is used.
#     """
# 
#     @functools.wraps(func)
#     def new_func(*args, **kwargs):
#         if inspect.isclass(func):
#             warnings.warn(f"The use of class {func.__name__}() is deprecated. It will be removed in future",
#                           category=DeprecationWarning, stacklevel=2)
#         else:
#             warnings.warn(f"Call to function {func.__name__}() is deprecated. It will be removed in future",
#                           category=DeprecationWarning, stacklevel=2)
#         return func(*args, **kwargs)
# 
#     return new_func
# 
# Path: astroNN/shared/downloader_tools.py
# class TqdmUpTo(tqdm):
#     """
#     NAME:
#         sha256_checksum
#     PURPOSE:
#         Provides `update_to(n)` which uses `tqdm.update(delta_n)`.
#     INPUT:
#     OUTPUT:
#     HISTORY:
#         2017-Oct-25 - Written - Henry Leung (University of Toronto)
#     """
# 
#     def update_to(self, b=1, bsize=1, tsize=None):
#         """
#         b  : int, optional
#             Number of blocks transferred so far [default: 1].
#         bsize  : int, optional
#             Size of each block (in tqdm units) [default: 1].
#         tsize  : int, optional
#             Total size (in tqdm units). If [default: None] remains unchanged.
#         """
#         if tsize is not None:
#             self.total = tsize
#         self.update(b * bsize - self.n)  # will also set self.n = b * bsize
# 
# def filehash(filename, block_size=65536, algorithm='sha256'):
#     """
#     Computes the hash value for a file by using a specified hash algorithm.
# 
#     :param filename: filename
#     :type filename: str
#     :param block_size: blocksize used to compute file hash
#     :type block_size: int
#     :param algorithm: hash algorithms like 'sha256' or 'md5' etc.
#     :type algorithm: str
#     :return: None
#     :History: 2019-Mar-12 - Written - Henry Leung (University of Toronto)
#     """
#     algorithm = algorithm.lower()
#     if algorithm not in hashlib.algorithms_guaranteed:
#         raise ValueError(f"{algorithm} is an unsupported hashing algorithm")
# 
#     func_algorithm = getattr(hashlib, algorithm)()
#     with open(filename, 'rb') as f:
#         for block in iter(lambda: f.read(block_size), b''):
#             func_algorithm.update(block)
#     return func_algorithm.hexdigest()


import os
import urllib.request
import numpy as np
import astroNN
import astroNN.data
from astropy.io import fits
from astroNN.gaia.gaia_shared import gaia_env, gaia_default_dr
from astroNN.shared.warnings import deprecated
from astroNN.shared.downloader_tools import TqdmUpTo, filehash
        parallax_gaia = parallax_gaia[filtered_index]
        parallax_error_gaia = parallax_error_gaia[filtered_index]
        g_band_gaia = g_band_gaia[filtered_index]

    return {'ra': ra, 'dec': dec, 'pmra': pmra_gaia, 'pmdec': pmdec_gaia, 'parallax': parallax_gaia,
            'parallax_err': parallax_error_gaia, 'gmag': g_band_gaia}


@deprecated
def gaia_source(dr=None, flag=None):
    """
    NAME:
        gaia_source
    PURPOSE:
        download the gaia_source files
    INPUT:
        dr (int): Gaia DR, example dr=1
        flag (int): 0: normal, 1: force to re-download
    OUTPUT:
        list of file path
    HISTORY:
        2017-Oct-13 - Written - Henry Leung (University of Toronto)
        2017-Nov-26 - Update - Henry Leung (University of Toronto)
    """
    dr = gaia_default_dr(dr=dr)
    fulllist = []

    if dr == 1:

        # Check if directory exists

# Path: astroNN/gaia/gaia_shared.py
# def gaia_env():
#     """
#     Get Gaia environment variable
# 
#     :return: Path to Gaia Data
#     :rtype: str
#     :History: 2017-Oct-26 - Written - Henry Leung (University of Toronto)
#     """
#     from astroNN.config import ENVVAR_WARN_FLAG
#     _GAIA = os.getenv('GAIA_TOOLS_DATA')
#     if _GAIA is None and ENVVAR_WARN_FLAG is True:
#         print("WARNING! Gaia environment variable GAIA_TOOLS_DATA not set")
#     return _GAIA
# 
# def gaia_default_dr(dr=None):
#     """
#     Check if dr argument is provided, if none then use default
# 
#     :param dr: Gaia DR
#     :type dr: Union[NoneType, int]
#     :return: Gaia DR
#     :rtype: int
#     :History: 2017-Oct-26 - Written - Henry Leung (University of Toronto)
#     """
#     if dr is None:
#         dr = 2
#         print(f'dr is not provided, using default dr={dr}')
#     else:
#         pass
#     return dr
# 
# Path: astroNN/shared/warnings.py
# def deprecated(func):
#     """
#     This is a decorator which can be used to mark functions
#     as deprecated. It will result in a warning being emitted
#     when the function is used.
#     """
# 
#     @functools.wraps(func)
#     def new_func(*args, **kwargs):
#         if inspect.isclass(func):
#             warnings.warn(f"The use of class {func.__name__}() is deprecated. It will be removed in future",
#                           category=DeprecationWarning, stacklevel=2)
#         else:
#             warnings.warn(f"Call to function {func.__name__}() is deprecated. It will be removed in future",
#                           category=DeprecationWarning, stacklevel=2)
#         return func(*args, **kwargs)
# 
#     return new_func
# 
# Path: astroNN/shared/downloader_tools.py
# class TqdmUpTo(tqdm):
#     """
#     NAME:
#         sha256_checksum
#     PURPOSE:
#         Provides `update_to(n)` which uses `tqdm.update(delta_n)`.
#     INPUT:
#     OUTPUT:
#     HISTORY:
#         2017-Oct-25 - Written - Henry Leung (University of Toronto)
#     """
# 
#     def update_to(self, b=1, bsize=1, tsize=None):
#         """
#         b  : int, optional
#             Number of blocks transferred so far [default: 1].
#         bsize  : int, optional
#             Size of each block (in tqdm units) [default: 1].
#         tsize  : int, optional
#             Total size (in tqdm units). If [default: None] remains unchanged.
#         """
#         if tsize is not None:
#             self.total = tsize
#         self.update(b * bsize - self.n)  # will also set self.n = b * bsize
# 
# def filehash(filename, block_size=65536, algorithm='sha256'):
#     """
#     Computes the hash value for a file by using a specified hash algorithm.
# 
#     :param filename: filename
#     :type filename: str
#     :param block_size: blocksize used to compute file hash
#     :type block_size: int
#     :param algorithm: hash algorithms like 'sha256' or 'md5' etc.
#     :type algorithm: str
#     :return: None
#     :History: 2019-Mar-12 - Written - Henry Leung (University of Toronto)
#     """
#     algorithm = algorithm.lower()
#     if algorithm not in hashlib.algorithms_guaranteed:
#         raise ValueError(f"{algorithm} is an unsupported hashing algorithm")
# 
#     func_algorithm = getattr(hashlib, algorithm)()
#     with open(filename, 'rb') as f:
#         for block in iter(lambda: f.read(block_size), b''):
#             func_algorithm.update(block)
#     return func_algorithm.hexdigest()


# Path: astroNN/gaia/downloader.py
import os
import urllib.request
import numpy as np
import astroNN
import astroNN.data
from astropy.io import fits
from astroNN.gaia.gaia_shared import gaia_env, gaia_default_dr
from astroNN.shared.warnings import deprecated
from astroNN.shared.downloader_tools import TqdmUpTo, filehash

        parallax_gaia = parallax_gaia[filtered_index]
        parallax_error_gaia = parallax_error_gaia[filtered_index]
        g_band_gaia = g_band_gaia[filtered_index]

    return {'ra': ra, 'dec': dec, 'pmra': pmra_gaia, 'pmdec': pmdec_gaia, 'parallax': parallax_gaia,
            'parallax_err': parallax_error_gaia, 'gmag': g_band_gaia}


@deprecated
def gaia_source(dr=None, flag=None):
    """
    NAME:
        gaia_source
    PURPOSE:
        download the gaia_source files
    INPUT:
        dr (int): Gaia DR, example dr=1
        flag (int): 0: normal, 1: force to re-download
    OUTPUT:
        list of file path
    HISTORY:
        2017-Oct-13 - Written - Henry Leung (University of Toronto)
        2017-Nov-26 - Update - Henry Leung (University of Toronto)
    """
    dr = gaia_default_dr(dr=dr)
    fulllist = []

    if dr == 1:

        # Check if directory exists

        folderpath = os.path.join(gaia_env(), 'Gaia/gdr1/gaia_source/fits/')