# Path: apogee/tools/path.py
# _APOGEE_DATA= os.getenv('SDSS_LOCAL_SAS_MIRROR')
#     _APOGEE_DATA= os.getenv('APOGEE_DATA')
# _APOGEE_REDUX= os.getenv('RESULTS_VERS')
#     _APOGEE_REDUX= os.getenv('APOGEE_REDUX')
# _APOGEE_ASPCAP_REDUX= os.getenv('APOGEE_ASPCAP_REDUX')
# _APOGEE_APOKASC_REDUX= os.getenv('APOGEE_APOKASC_REDUX')
# _DR10REDUX='v304'
# _DR11REDUX='v402'
# _DR12REDUX='v603'
# _DR13REDUX='l30e.2'
# _DR14REDUX='l31c.2'
# _DR16REDUX='l33'
# _DR17REDUX='dr17'
# _CURRENTREDUX='current'
#     _APOGEE_REDUX= _DR12REDUX
#     _APOGEE_APOKASC_REDUX= 'v7.3'
#     _APOGEE_ASPCAP_REDUX= 'v0.4'
# _ASPCAP= True
# _CODEV= '1'
#     if str(dr) == '10': _APOGEE_REDUX=_DR10REDUX
#     elif str(dr) == '11': _APOGEE_REDUX=_DR11REDUX
#     elif str(dr) == '12': _APOGEE_REDUX=_DR12REDUX
#     elif str(dr) == '13': _APOGEE_REDUX=_DR13REDUX
#     elif str(dr) == '14': _APOGEE_REDUX=_DR14REDUX
#     elif str(dr) == '16': _APOGEE_REDUX=_DR16REDUX
#     elif str(dr) == '17': _APOGEE_REDUX=_DR17REDUX
#     elif str(dr) == 'current': _APOGEE_REDUX=_CURRENTREDUX
# def apallPath(visit=False):
# def allStarPath(dr=None,lite=False,_old=False,mjd=58104):
# def allVisitPath(dr=None,_old=False,mjd=58104):
# def apokascPath():
# def distPath(dr=None):
# def rcsamplePath(dr=None,_old=False):
# def astroNNPath(dr=None):
# def astroNNDistancesPath(dr=None):
# def astroNNAgesPath(dr=None):
# def obslogPath(year=None, hemisphere=None):
# def apogeeTargetDirPath(dr=None):
# def apogeePlatePath(dr=None):
# def apogeeDesignPath(dr=None):
# def apogeeFieldPath(dr=None):
# def apogeeObjectPath(field_name,dr=None):
# def aspcapStarPath(loc_id,apogee_id,telescope='apo25m',dr=None):
# def apStarPath(loc_id,apogee_id,telescope='apo25m',dr=None):
# def apVisitPath(plateid, mjd, fiberid, telescope='apo25m', dr=None):
# def modelSpecPath(lib='GK',teff=4500,logg=2.5,metals=0.,
#                   cfe=0.,nfe=0.,afe=0.,vmicro=2.,
#                   dr=None):
# def ferreModelLibraryPath(lib='GK',pca=True,sixd=True,unf=False,dr=None,
#                           header=False):
# def modelAtmospherePath(lib='kurucz_filled',teff=4500,logg=2.5,metals=0.,
#                         cfe=0.,afe=0.,vmicro=2.,dr=None):
# def linelistPath(linelist,dr=None):
# def apWavePath(chip,dr=None):
# def apLSFPath(chip,dr=None):
# def apogeeSpectroReduxDirPath(dr=None):
# def apogeeSpectroASPCAPDirPath(dr=None):
# def apogeeModelSpectroLibraryDirPath(dr=None,lib='GK'):
# def apogeeModelAtmosphereLibraryDirPath(dr=None,lib='kurucz_filled'):
# def change_dr(dr=None):
# def _default_dr():
# def _redux_dr(dr=None):
# def _py2_round(fl):
# def _modelAtmKurucz_metalsString(metals):
# def _modelAtmKurucz_cfeString(cfe,metals):
# def _modelAtmKurucz_afeString(afe,metals):
# def _modelAtmKurucz_teffString(teff):
# def _modelAtmKurucz_loggString(logg,teff):


import os
import sys
import shutil
import tempfile
import subprocess
import numpy
        import astropy.io.fits as apyfits
        import warnings
from apogee.tools import path
    from . import read as apread
    from . import read as apread
        from astropy.utils.exceptions import AstropyUserWarning
#   apogee.tools.download: download APOGEE data files
#
###############################################################################
_DR10_URL= 'http://data.sdss3.org/sas/dr10'
_DR12_URL= 'http://data.sdss3.org/sas/dr12'
_DR13_URL= 'http://data.sdss.org/sas/dr13'
_DR14_URL= 'http://data.sdss.org/sas/dr14'
_DR16_URL= 'https://data.sdss.org/sas/dr16'
_DR17_URL= 'https://data.sdss.org/sas/dr17'
_PROPRIETARY_URL= 'https://data.sdss.org/sas/apogeework'
_MAX_NTRIES= 2
_ERASESTR= "                                                                                "
def allStar(dr=None,lite=False,mjd=58104):
    """
    NAME:
       allStar
    PURPOSE:
       download the allStar file
    INPUT:
       dr= return the path corresponding to this data release (general default)
       lite= (False) if True, use the 'lite' version of allStar that only contains a subset of all columns (only available for DR16 and DR17)
       mjd= (58104) MJD of version for monthly internal pipeline runs
    OUTPUT:
       (none; just downloads)
    HISTORY:
       2014-11-26 - Written - Bovy (IAS)
       2015-08-17 - Adjusted for new path (mv old to new) - Bovy (UofT)
       2018-01-22 - Edited for new monthly pipeline runs - Bovy (UofT)
       2022-02-11 - Added lite option - Bovy (UofT)
    """

# Path: apogee/tools/path.py
# _APOGEE_DATA= os.getenv('SDSS_LOCAL_SAS_MIRROR')
#     _APOGEE_DATA= os.getenv('APOGEE_DATA')
# _APOGEE_REDUX= os.getenv('RESULTS_VERS')
#     _APOGEE_REDUX= os.getenv('APOGEE_REDUX')
# _APOGEE_ASPCAP_REDUX= os.getenv('APOGEE_ASPCAP_REDUX')
# _APOGEE_APOKASC_REDUX= os.getenv('APOGEE_APOKASC_REDUX')
# _DR10REDUX='v304'
# _DR11REDUX='v402'
# _DR12REDUX='v603'
# _DR13REDUX='l30e.2'
# _DR14REDUX='l31c.2'
# _DR16REDUX='l33'
# _DR17REDUX='dr17'
# _CURRENTREDUX='current'
#     _APOGEE_REDUX= _DR12REDUX
#     _APOGEE_APOKASC_REDUX= 'v7.3'
#     _APOGEE_ASPCAP_REDUX= 'v0.4'
# _ASPCAP= True
# _CODEV= '1'
#     if str(dr) == '10': _APOGEE_REDUX=_DR10REDUX
#     elif str(dr) == '11': _APOGEE_REDUX=_DR11REDUX
#     elif str(dr) == '12': _APOGEE_REDUX=_DR12REDUX
#     elif str(dr) == '13': _APOGEE_REDUX=_DR13REDUX
#     elif str(dr) == '14': _APOGEE_REDUX=_DR14REDUX
#     elif str(dr) == '16': _APOGEE_REDUX=_DR16REDUX
#     elif str(dr) == '17': _APOGEE_REDUX=_DR17REDUX
#     elif str(dr) == 'current': _APOGEE_REDUX=_CURRENTREDUX
# def apallPath(visit=False):
# def allStarPath(dr=None,lite=False,_old=False,mjd=58104):
# def allVisitPath(dr=None,_old=False,mjd=58104):
# def apokascPath():
# def distPath(dr=None):
# def rcsamplePath(dr=None,_old=False):
# def astroNNPath(dr=None):
# def astroNNDistancesPath(dr=None):
# def astroNNAgesPath(dr=None):
# def obslogPath(year=None, hemisphere=None):
# def apogeeTargetDirPath(dr=None):
# def apogeePlatePath(dr=None):
# def apogeeDesignPath(dr=None):
# def apogeeFieldPath(dr=None):
# def apogeeObjectPath(field_name,dr=None):
# def aspcapStarPath(loc_id,apogee_id,telescope='apo25m',dr=None):
# def apStarPath(loc_id,apogee_id,telescope='apo25m',dr=None):
# def apVisitPath(plateid, mjd, fiberid, telescope='apo25m', dr=None):
# def modelSpecPath(lib='GK',teff=4500,logg=2.5,metals=0.,
#                   cfe=0.,nfe=0.,afe=0.,vmicro=2.,
#                   dr=None):
# def ferreModelLibraryPath(lib='GK',pca=True,sixd=True,unf=False,dr=None,
#                           header=False):
# def modelAtmospherePath(lib='kurucz_filled',teff=4500,logg=2.5,metals=0.,
#                         cfe=0.,afe=0.,vmicro=2.,dr=None):
# def linelistPath(linelist,dr=None):
# def apWavePath(chip,dr=None):
# def apLSFPath(chip,dr=None):
# def apogeeSpectroReduxDirPath(dr=None):
# def apogeeSpectroASPCAPDirPath(dr=None):
# def apogeeModelSpectroLibraryDirPath(dr=None,lib='GK'):
# def apogeeModelAtmosphereLibraryDirPath(dr=None,lib='kurucz_filled'):
# def change_dr(dr=None):
# def _default_dr():
# def _redux_dr(dr=None):
# def _py2_round(fl):
# def _modelAtmKurucz_metalsString(metals):
# def _modelAtmKurucz_cfeString(cfe,metals):
# def _modelAtmKurucz_afeString(afe,metals):
# def _modelAtmKurucz_teffString(teff):
# def _modelAtmKurucz_loggString(logg,teff):


# Path: apogee/tools/download.py
import os
import sys
import shutil
import tempfile
import subprocess
import numpy
        import astropy.io.fits as apyfits
        import warnings
from apogee.tools import path
    from . import read as apread
    from . import read as apread
        from astropy.utils.exceptions import AstropyUserWarning

#   apogee.tools.download: download APOGEE data files
#
###############################################################################
_DR10_URL= 'http://data.sdss3.org/sas/dr10'
_DR12_URL= 'http://data.sdss3.org/sas/dr12'
_DR13_URL= 'http://data.sdss.org/sas/dr13'
_DR14_URL= 'http://data.sdss.org/sas/dr14'
_DR16_URL= 'https://data.sdss.org/sas/dr16'
_DR17_URL= 'https://data.sdss.org/sas/dr17'
_PROPRIETARY_URL= 'https://data.sdss.org/sas/apogeework'
_MAX_NTRIES= 2
_ERASESTR= "                                                                                "
def allStar(dr=None,lite=False,mjd=58104):
    """
    NAME:
       allStar
    PURPOSE:
       download the allStar file
    INPUT:
       dr= return the path corresponding to this data release (general default)
       lite= (False) if True, use the 'lite' version of allStar that only contains a subset of all columns (only available for DR16 and DR17)
       mjd= (58104) MJD of version for monthly internal pipeline runs
    OUTPUT:
       (none; just downloads)
    HISTORY:
       2014-11-26 - Written - Bovy (IAS)
       2015-08-17 - Adjusted for new path (mv old to new) - Bovy (UofT)
       2018-01-22 - Edited for new monthly pipeline runs - Bovy (UofT)
       2022-02-11 - Added lite option - Bovy (UofT)
    """

    if dr is None: dr= path._default_dr()