Esempio n. 1
0
def allVisit(dr=None):
    """
    NAME:
       allVisit
    PURPOSE:
       download the allVisit file
    INPUT:
       dr= return the path corresponding to this data release (general default)
    OUTPUT:
       (none; just downloads)
    HISTORY:
       2014-11-26 - Written - Bovy (IAS)
       2015-08-17 - Adjusted for new path (mv old to new) - Bovy (UofT)
    """
    if dr is None: dr= path._default_dr()
    # First make sure the file doesn't exist
    filePath= path.allVisitPath(dr=dr)
    if os.path.exists(filePath): return None
    # Check whether we can find it in its old place
    oldFilePath= path.allVisitPath(dr=dr,_old=True)
    if os.path.exists(oldFilePath):
        # mv to new place
        try:
            os.makedirs(os.path.dirname(filePath))
        except OSError: pass
        shutil.move(oldFilePath,filePath)
        return None
    # Create the file path
    downloadPath= filePath.replace(os.path.join(path._APOGEE_DATA,
                                                _dr_string(dr)),
                                   _base_url(dr=dr))
    _download_file(downloadPath,filePath,dr,verbose=True)
    return None
Esempio n. 2
0
def allVisit(dr=None):
    """
    NAME:
       allVisit
    PURPOSE:
       download the allVisit file
    INPUT:
       dr= return the path corresponding to this data release (general default)
    OUTPUT:
       (none; just downloads)
    HISTORY:
       2014-11-26 - Written - Bovy (IAS)
       2015-08-17 - Adjusted for new path (mv old to new) - Bovy (UofT)
    """
    if dr is None: dr = path._default_dr()
    # First make sure the file doesn't exist
    filePath = path.allVisitPath(dr=dr)
    if os.path.exists(filePath): return None
    # Check whether we can find it in its old place
    oldFilePath = path.allVisitPath(dr=dr, _old=True)
    if os.path.exists(oldFilePath):
        # mv to new place
        try:
            os.makedirs(os.path.dirname(filePath))
        except OSError:
            pass
        shutil.move(oldFilePath, filePath)
        return None
    # Create the file path
    downloadPath = filePath.replace(
        os.path.join(path._APOGEE_DATA, _dr_string(dr)), _base_url(dr=dr))
    _download_file(downloadPath, filePath, dr, verbose=True)
    return None
Esempio n. 3
0
def allVisit(dr=None):
    """
    NAME:
       allVisit
    PURPOSE:
       download the allVisit file
    INPUT:
       dr= return the path corresponding to this data release (general default)
    OUTPUT:
       (none; just downloads)
    HISTORY:
       2014-11-26 - Written - Bovy (IAS)
    """
    if dr is None: dr= path._default_dr()
    # First make sure the file doesn't exist
    filePath= path.allVisitPath(dr=dr)
    if os.path.exists(filePath): return None
    # Create the file path, hacked from aspcapStar path
    aspPath= path.aspcapStarPath(4140,'dum',dr=dr)
    downloadPath= aspPath.replace(os.path.join(path._APOGEE_DATA,
                                               'dr%s' % dr),
                                  _base_url(dr=dr))
    head, tail= os.path.split(downloadPath) #strips off filename
    downloadPath, tail= os.path.split(head) #strips off location_id
    downloadPath= os.path.join(downloadPath,os.path.basename(filePath))
    _download_file(downloadPath,filePath,dr,verbose=True)
    return None
Esempio n. 4
0
def allVisit(rmcommissioning=True,
             main=False,
             ak=True,
             akvers='targ'):
    """
    NAME:
       allVisit
    PURPOSE:
       read the allVisit file
    INPUT:
       rmcommissioning= (default: True) if True, only use data obtained after commissioning
       main= (default: False) if True, only select stars in the main survey
       ak= (default: True) only use objects for which dereddened mags exist
       akvers= 'targ' (default) or 'wise': use target AK (AK_TARG) or AK derived from all-sky WISE (AK_WISE)
    OUTPUT:
       allVisit data
    HISTORY:
       2013-11-07 - Written - Bovy (IAS)
    """
    #read allStar file
    data= fitsio.read(path.allVisitPath())
    #Some cuts
    if rmcommissioning:
        indx= numpy.array(['apogee.n.c' in s for s in data['VISIT_ID']])
        indx+= numpy.array(['apogee.s.c' in s for s in data['VISIT_ID']])
        data= data[True-indx]
    if main:
        indx= mainIndx(data)
        data= data[indx]
    if akvers.lower() == 'targ':
        aktag= 'AK_TARG'
    elif akvers.lower() == 'wise':
        aktag= 'AK_WISE'
    if ak:
        data= data[True-numpy.isnan(data[aktag])]
        data= data[(data[aktag] > -50.)]
    #Add dereddened J, H, and Ks
    aj= data[aktag]*2.5
    ah= data[aktag]*1.55
    data= esutil.numpy_util.add_fields(data,[('J0', float),
                                             ('H0', float),
                                             ('K0', float)])
    data['J0']= data['J']-aj
    data['H0']= data['H']-ah
    data['K0']= data['K']-data[aktag]
    data['J0'][(data[aktag] <= -50.)]= -9999.9999
    data['H0'][(data[aktag] <= -50.)]= -9999.9999
    data['K0'][(data[aktag] <= -50.)]= -9999.9999
    return data
Esempio n. 5
0
def rcsample(dr=None):
    """
    NAME:
       rcsample
    PURPOSE:
       download the rcsample file
    INPUT:
       dr= return the path corresponding to this data release (general default)
    OUTPUT:
       (none; just downloads)
    HISTORY:
       2014-11-26 - Written - Bovy (IAS)
    """
    if dr is None: dr= path._default_dr()
    # First make sure the file doesn't exist
    filePath= path.allVisitPath(dr=dr)
    if os.path.exists(filePath): return None
    # Create the file path
    downloadPath=\
        os.path.join(_base_url(dr=dr,rc=True),
                     'apogee/vac/apogee-rc/cat/apogee-rc-DR%s.fits' % dr)
    _download_file(downloadPath,filePath,dr)
    return None
Esempio n. 6
0
def allVisit(rmcommissioning=True,
             main=False,
             ak=True,
             akvers='targ',
             plateInt=False,
             plateS4=False,
             raw=False):
    """
    NAME:
       allVisit
    PURPOSE:
       read the allVisit file
    INPUT:
       rmcommissioning= (default: True) if True, only use data obtained after commissioning
       main= (default: False) if True, only select stars in the main survey
       ak= (default: True) only use objects for which dereddened mags exist
       akvers= 'targ' (default) or 'wise': use target AK (AK_TARG) or AK derived from all-sky WISE (AK_WISE)
       plateInt= (False) if True, cast plate as an integer and give special plates -1
       plateS4= (False) if True, cast plate as four character string
       raw= (False) if True, just return the raw file, read w/ fitsio
    OUTPUT:
       allVisit data
    HISTORY:
       2013-11-07 - Written - Bovy (IAS)
    """
    filePath = path.allVisitPath()
    if not os.path.exists(filePath):
        download.allVisit()
    #read allVisit file
    data = fitsio.read(path.allVisitPath())
    if raw: return data
    #Some cuts
    if rmcommissioning:
        indx = numpy.array(
            ['apogee.n.c'.encode('utf-8') in s for s in data['VISIT_ID']])
        indx += numpy.array(
            ['apogee.s.c'.encode('utf-8') in s for s in data['VISIT_ID']])
        data = data[True - indx]
    if main:
        indx = mainIndx(data)
        data = data[indx]
    if akvers.lower() == 'targ':
        aktag = 'AK_TARG'
    elif akvers.lower() == 'wise':
        aktag = 'AK_WISE'
    if ak:
        data = data[True - numpy.isnan(data[aktag])]
        data = data[(data[aktag] > -50.)]
    if plateInt or plateS4:
        #If plate is a string, cast it as an integer
        if isinstance(data['PLATE'][0], str):
            #First cast the special plates as -1
            plateDtype = data['PLATE'].dtype
            data['PLATE'][data['PLATE'] == 'calibration'.ljust(
                int(str(plateDtype)[2:]))] = '-1'
            data['PLATE'][data['PLATE'] == 'hip'.ljust(int(
                str(plateDtype)[2:]))] = '-1'
            data['PLATE'][data['PLATE'] == 'misc'.ljust(
                int(str(plateDtype)[2:]))] = '-1'
            data['PLATE'][data['PLATE'] == 'moving_groups'.ljust(
                int(str(plateDtype)[2:]))] = -1
            data['PLATE'][data['PLATE'] == 'rrlyr'.ljust(
                int(str(plateDtype)[2:]))] = '-1'
            #Now change the dtype to make plate an int
            dt = data.dtype
            dt = dt.descr
            plateDtypeIndx = dt.index(('PLATE', '|S13'))
            if plateInt:
                dt[plateDtypeIndx] = (dt[plateDtypeIndx][0], 'int')
            elif plateS4:
                dt[plateDtypeIndx] = (dt[plateDtypeIndx][0], '|S4')
            dt = numpy.dtype(dt)
            data = data.astype(dt)
    #Add dereddened J, H, and Ks
    aj = data[aktag] * 2.5
    ah = data[aktag] * 1.55
    if _ESUTIL_LOADED:
        data = esutil.numpy_util.add_fields(data,
                                            [('J0', float), ('H0', float),
                                             ('K0', float)])
        data['J0'] = data['J'] - aj
        data['H0'] = data['H'] - ah
        data['K0'] = data['K'] - data[aktag]
        data['J0'][(data[aktag] <= -50.)] = -9999.9999
        data['H0'][(data[aktag] <= -50.)] = -9999.9999
        data['K0'][(data[aktag] <= -50.)] = -9999.9999
    else:
        warnings.warn(
            "Extinction-corrected J,H,K not added because esutil is not installed",
            RuntimeWarning)
    return data
Esempio n. 7
0
def allVisit(rmcommissioning=True,
             main=False,
             ak=True,
             akvers='targ',
             plateInt=False,
             plateS4=False,
             raw=False):
    """
    NAME:
       allVisit
    PURPOSE:
       read the allVisit file
    INPUT:
       rmcommissioning= (default: True) if True, only use data obtained after commissioning
       main= (default: False) if True, only select stars in the main survey
       ak= (default: True) only use objects for which dereddened mags exist
       akvers= 'targ' (default) or 'wise': use target AK (AK_TARG) or AK derived from all-sky WISE (AK_WISE)
       plateInt= (False) if True, cast plate as an integer and give special plates -1
       plateS4= (False) if True, cast plate as four character string
       raw= (False) if True, just return the raw file, read w/ fitsio
    OUTPUT:
       allVisit data
    HISTORY:
       2013-11-07 - Written - Bovy (IAS)
    """
    filePath= path.allVisitPath()
    if not os.path.exists(filePath):
        download.allVisit()
    #read allVisit file
    data= fitsio.read(path.allVisitPath())
    if raw: return data
    #Some cuts
    if rmcommissioning:
        indx= numpy.array(['apogee.n.c' in s for s in data['VISIT_ID']])
        indx+= numpy.array(['apogee.s.c' in s for s in data['VISIT_ID']])
        data= data[True-indx]
    if main:
        indx= mainIndx(data)
        data= data[indx]
    if akvers.lower() == 'targ':
        aktag= 'AK_TARG'
    elif akvers.lower() == 'wise':
        aktag= 'AK_WISE'
    if ak:
        data= data[True-numpy.isnan(data[aktag])]
        data= data[(data[aktag] > -50.)]
    if plateInt or plateS4:
        #If plate is a string, cast it as an integer
        if isinstance(data['PLATE'][0],str):
            #First cast the special plates as -1
            plateDtype= data['PLATE'].dtype
            data['PLATE'][data['PLATE'] == 'calibration'.ljust(int(str(plateDtype)[2:]))]= '-1'
            data['PLATE'][data['PLATE'] == 'hip'.ljust(int(str(plateDtype)[2:]))]= '-1'
            data['PLATE'][data['PLATE'] == 'misc'.ljust(int(str(plateDtype)[2:]))]= '-1'
            data['PLATE'][data['PLATE'] == 'moving_groups'.ljust(int(str(plateDtype)[2:]))]= -1
            data['PLATE'][data['PLATE'] == 'rrlyr'.ljust(int(str(plateDtype)[2:]))]= '-1'
            #Now change the dtype to make plate an int
            dt= data.dtype
            dt= dt.descr
            plateDtypeIndx= dt.index(('PLATE', '|S13'))
            if plateInt:
                dt[plateDtypeIndx]= (dt[plateDtypeIndx][0],'int')
            elif plateS4:
                dt[plateDtypeIndx]= (dt[plateDtypeIndx][0],'|S4')
            dt= numpy.dtype(dt)
            data= data.astype(dt)
    #Add dereddened J, H, and Ks
    aj= data[aktag]*2.5
    ah= data[aktag]*1.55
    data= esutil.numpy_util.add_fields(data,[('J0', float),
                                             ('H0', float),
                                             ('K0', float)])
    data['J0']= data['J']-aj
    data['H0']= data['H']-ah
    data['K0']= data['K']-data[aktag]
    data['J0'][(data[aktag] <= -50.)]= -9999.9999
    data['H0'][(data[aktag] <= -50.)]= -9999.9999
    data['K0'][(data[aktag] <= -50.)]= -9999.9999
    return data
Esempio n. 8
0
       plateInt= (False) if True, cast plate as an integer and give special plates -1
       plateS4= (False) if True, cast plate as four character string
       mjd= (58104) MJD of version for monthly internal pipeline runs
       raw= (False) if True, just return the raw file, read w/ fitsio
    OUTPUT:
       allVisit data
    HISTORY:
       2013-11-07 - Written - Bovy (IAS)
<<<<<<< HEAD
       2016-11-23 - Modified - Price-Jones (UofT)
    """
    filePath= path.allVisitPath(dr=dr)
=======
       2018-02-28 - Edited for new monthly pipeline runs - Bovy (UofT)
    """
    filePath= path.allVisitPath(mjd=mjd)
>>>>>>> upstream/master
    if not os.path.exists(filePath):
        download.allVisit(mjd=mjd)
    #read allVisit file
<<<<<<< HEAD
    data= fitsio.read(path.allVisitPath(dr=dr))
=======
    data= fitsread(path.allVisitPath(mjd=mjd))
>>>>>>> upstream/master
    if raw: return data
    #Some cuts
    if rmcommissioning:
        try:
            indx= numpy.array(['apogee.n.c'.encode('utf-8') in s for s in data['VISIT_ID']])
            indx+= numpy.array(['apogee.s.c'.encode('utf-8') in s for s in data['VISIT_ID']])