Example #1
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
Example #2
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
Example #3
0
       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']])
        except TypeError:
            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']])