APOGEE Parameter Catalogs

Where to find APOGEE results

Parameters derived from APOGEE spectra (radial velocity, stellar parameters, and abundances) are stored as catalog data, and are available from several different SDSS data access tools. This page gives links and advice on how to get the data you need.

Parameter summary FITS files

Summary tables for all publicly-released APOGEE objects are available as FITS files through the Science Archive Server (SAS). The parameter summary files are:

allStar
provides information for each individual star observed in APOGEE-1, which includes mean barycentric radial velocity, the standard deviation of the mean velocity, ASPCAP parameters and abundances as derived from the combined spectra, and a compilation of ancillary targeting data (for DR13, allStar-l30e.2.fits); complete description in datamodel
allVisit
provides information for each individual visit of each star in APOGEE-1, which includes the barycentric radial velocity of each visit, along with a compilation of ancillary targeting data (for DR13, allVisit-l30e.2.fits); complete description in datamodel

Parameter tables for queries

The Catalog Archive Server (CAS) database includes several tables with APOGEE information. You can search these tables by submitting SQL queries to the DR13 context in CasJobs Available tables are:

apogeeVisit
contains information about each visit to each object, including the radial velocity of the visit and the information needed to locate visit spectra files (apVisit files) in the Science Archive Server (SAS)
apogeeStar
contains information about each observed object, including catalog information, derived average radial velocities, the standard deviation of the average radial velocities, a data quality flag, and the information needed to locate the combined spectra files (apStar files) in the SAS. See the bulk download documentation to learn how to get the spectra for many stars at once.
aspcapStar
contains pipeline (ASPCAP) output information about each observed object, including the derived stellar parameters, abundances, several data quality flags, and the information needed to locate the pseudocontinuum-normalized spectra and ASPCAP best fit spectra (aspcapStar files) in the SAS (also see the bulk download page).
apogeeObject
contains targeting information about all possible targets in each of the APOGEE fields. The APOGEE targets are selected from this master catalog according to the target selection algorithms.

The DR13 CAS has several predefined table-based functions that can be used to return ALL stellar parameters or ALL chemical abundances from the aspcapStar table rather than specifying each element separately in a SELECT statements. These include:

dbo.fAspcapParams
returns all parameters (Teff, logg, vmicro, vmacro, vsini, [M/H], [α/M])
dbo.fAspcapElems
returns abundances of all 25 elements

Uncertainties and flags can also be retrieved by using dbo.fAspcapParamErrs, dbo.fAspcapParamFlags, dbo.fAspcapElemErrs, and dbo.fAspcapElemFlags, and values/errs/flags can be obtained in single calls to dbo.fAspcapParamsAll and dbo.fAspcapElemsAll. Using these functions requires the use of a CROSS APPLY statement: an example of how to use these functions can be found below .

Spectrum FITS headers

Individual stellar spectra (both visit spectra and composite spectra) are available from the Science Archive Server (SAS). These spectra can be downloaded as Flexible Image Transport System (FITS) files called apVisit, apStar, and aspcapStar. Each FITS file includes a header with metadata; the FITS headers for APOGEE spectra are explained below.

Before proceeding with analysis of catalog information, users are strongly encouraged to read the Using APOGEE parameters and the Using APOGEE abundances documentation. In particular, users should be aware that:

  • There are different target samples, as described in our target selection pages. The manner in which each target was selected can be determined by looking at the APOGEE_TARGET1 and APOGEE_TARGET2 target bitmasks, and/or the EXTRATARG bitmask.
  • Not all of the stellar parameters and abundances are reliable, and not all are calibrated. In particular, results for hotter and cooler stars are less reliable (and not all are calibrated), and stellar parameters near a grid edge should be considered unreliable.
  • There are several bitmasks that flag possible conditions with the derived quantity. In particular, the STARFLAG bitmask, the ASPCAPFLAG bitmask, and the PARAMFLAG and ELEMFLAG bitmasks. The examples below demonstrate how to use this information to obtain a set of objects.

Examples of selecting APOGEE data from catalogs

Here we include a number of examples of getting APOGEE data from the catalogs. These examples assume that you are either logged into CASJobs and using the DR13 context, or have downloaded the APOGEE catalog files. In the latter case, we assume you are using IDL with the latest version of idlutils (v5_5_11 or later) or python with numpy and astropy (in these examples, we use Python 2.X syntax for PRINT statements, but these can trivially be converted to use a PRINT() function).

Get all PLATES observed for a given LOCATION_ID

The APOGEE survey is conducted along a number of different lines of sight, each referred to as as a “field” or “location” (interchangeably). Each field has a name and an id number (LOCATION_ID). The stars in each field are observed multiple times on multiple visits, on different MJDs. These may involve one or more physical plugplates, and thus, the fiber number may change.  Field names and IDs can be found in the index embedded in the SAS.

To find all the plate visits, one can search as follows (for LOCATION_ID 4105):

In CAS:

SELECT plate, mjd FROM apogeePlate WHERE location_id=4105

The same field can be searched by its name (in this case ‘M13’):

SELECT plate, mjd FROM apogeePlate WHERE name = 'M13'

In IDL, using the allPlates file:

plates = mrdfits('allPlates-l30e.2.fits', 1)
ilocation = where(plates.location_id eq 4105, nlocation)
print, plates[ilocation].plate
print, plates[ilocation].mjd
iname = where(strtrim(plates.name, 2) eq 'M13', nname)
print, plates[ilocation].plate
print, plates[ilocation].mjd

In python, using the allPlates file :

from astropy.io import fits (or import pyfits as fits)
plates_hdus = fits.open('allPlates-l30e.2.fits')
plates = plates_hdus[1].data
plates_bylocation = plates[plates.field('LOCATION_ID') == 4105]
print plates_bylocation.field('PLATE')
print plates_bylocation.field('MJD')
plates_byname = plates[plates.field('NAME') == 'M13']
print plates_byname.field('PLATE') 
print plates_byname.field('MJD')

Get ASPCAP parameters, element abundances and errors for all stars that were targeted as part of the main APOGEE survey

The stellar parameters are available for all stars that had ASPCAP run on them. However, this includes some results known to be bad as well as stars targeted as part of ancillary programs of various sorts. Restricting to the good main survey targets requires checking on flags as in the next example. Note that this returns calibrated quantities, which means that dwarfs will have surface gravities set to -9999. It is possible to get uncalibrated quantities as well, see the pages on Using parameters and Using abundances for the appropriate tag/column names.

In CAS, limiting to the first 100 (remove “TOP 100” to retrieve all the objects):

SELECT TOP 100 s.apogee_id, s.ra, s.dec, s.glon, s.glat, s.vhelio_avg, s.vscatter,
params.*, paramerrs.*, elems.*, elemerrs.*,
dbo.fApogeeAspcapFlagN(a.aspcapflag),
dbo.fApogeeStarFlagN(s.starflag)
FROM apogeeStar s
JOIN aspcapStar a on a.apstar_id = s.apstar_id
CROSS APPLY dbo.fAspcapParams(a.aspcap_id) params
CROSS APPLY dbo.fAspcapParamErrs(a.aspcap_id) paramerrs
CROSS APPLY dbo.fAspcapElems(a.aspcap_id) elems
CROSS APPLY dbo.fAspcapElemErrs(a.aspcap_id) elemerrs
WHERE (a.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and s.extratarg = 0

In IDL, printing first 100 stars it finds. This uses the allStar file :

star = mrdfits('allStar-l30e.2.fits', 1)
badbits = sdss_flagval('APOGEE_ASPCAPFLAG', 'STAR_BAD')
gd = where((star.aspcapflag and badbits) eq 0 and star.extratarg eq 0, ngd)
for i=0, (ngd < 100)-1 do begin
    print, star[gd[i]].apogee_id
    print, star[gd[i]].ra, star[gd[i]].dec, star[gd[i]].glon, star[gd[i]].glat, $
        star[gd[i]].vhelio_avg, star[gd[i]].vscatter, $
        star[gd[i]].teff, star[gd[i]].teff_err, $
        star[gd[i]].logg, star[gd[i]].logg_err, $
        star[gd[i]].m_h, star[gd[i]].m_h_err, $
        star[gd[i]].alpha_m, star[gd[i]].alpha_m_err, $
        star[gd[i]].c_fe, star[gd[i]].c_fe_err,$
        star[gd[i]].cI_fe, star[gd[i]].cI_fe_err,$
        star[gd[i]].n_fe, star[gd[i]].n_fe_err,$
        star[gd[i]].o_fe, star[gd[i]].o_fe_err,$
        star[gd[i]].na_fe, star[gd[i]].na_fe_err,$
        star[gd[i]].mg_fe, star[gd[i]].mg_fe_err,$
        star[gd[i]].al_fe, star[gd[i]].al_fe_err,$
        star[gd[i]].si_fe, star[gd[i]].si_fe_err,$
        star[gd[i]].p_fe, star[gd[i]].p_fe_err,$
        star[gd[i]].s_fe, star[gd[i]].s_fe_err,$
        star[gd[i]].k_fe, star[gd[i]].k_fe_err,$
        star[gd[i]].ca_fe, star[gd[i]].ca_fe_err,$
        star[gd[i]].ti_fe, star[gd[i]].ti_fe_err,$
        star[gd[i]].v_fe, star[gd[i]].v_fe_err,$
        star[gd[i]].cr_fe, star[gd[i]].cr_fe_err,$
        star[gd[i]].mn_fe, star[gd[i]].mn_fe_err,$
        star[gd[i]].fe_h, star[gd[i]].fe_h_err,$
        star[gd[i]].co_fe, star[gd[i]].co_fe_err,$
        star[gd[i]].ni_fe, star[gd[i]].ni_fe_err,$
        star[gd[i]].cu_fe, star[gd[i]].cu_fe_err,$
        star[gd[i]].ge_fe, star[gd[i]].ge_fe_err,$
        star[gd[i]].rb_fe, star[gd[i]].rb_fe_err,$
        star[gd[i]].aspcapflags, star[gd[i]].starflags
endfor

In python, printing first 100 stars it finds. This uses the allStar file :

import numpy
from astropy.io import fits (or import pyfits as fits)
star_hdus = fits.open('allStar-l30e.2.fits')
star = star_hdus[1].data
star_hdus.close()
badbits = 2**23
gd = (numpy.bitwise_and(star['aspcapflag'], badbits) == 0) & (star['extratarg']==0)
ind = numpy.where(gd)[0]
for i in range(0, 100):
    j = ind[i]
    print star['ra'][j], star['dec'][j], star['glon'][j], star['glat'][j],\
        star['vhelio_avg'][j], star['vscatter'][j],\
        star['teff'][j], star['teff_err'][j],\
        star['logg'][j], star['logg_err'][j],\
        star['m_h'][j], star['m_h_err'][j],\
        star['alpha_m'][j], star['alpha_m_err'][j],\ 
        star['c_fe'][j], star['c_fe_err'][j],\ 
        star['cI_fe'][j], star['cI_fe_err'][j],\
        star['n_fe'][j], star['n_fe_err'][j],\
        star['o_fe'][j], star['o_fe_err'][j],\
        star['na_fe'][j], star['na_fe_err'][j],\
        star['mg_fe'][j], star['mg_fe_err'][j],\
        star['al_fe'][j], star['al_fe_err'][j],\
        star['si_fe'][j], star['si_fe_err'][j],\
        star['p_fe'][j], star['p_fe_err'][j],\
        star['s_fe'][j], star['s_fe_err'][j],\
        star['k_fe'][j], star['k_fe_err'][j],\
        star['ca_fe'][j], star['ca_fe_err'][j],\
        star['ti_fe'][j], star['ti_fe_err'][j],\
        star['v_fe'][j], star['v_fe_err'][j],\
        star['cr_fe'][j], star['cr_fe_err'][j],\
        star['mn_fe'][j], star['mn_fe_err'][j],\
        star['fe_h'][j], star['fe_h_err'][j],\
        star['co_fe'][j], star['co_fe_err'][j],\
        star['ni_fe'][j], star['ni_fe_err'][j],\
        star['cu_fe'][j], star['cu_fe_err'][j],\
        star['ge_fe'][j], star['ge_fe_err'][j],\
        star['rb_fe'][j], star['rb_fe_err'][j],\
        star['aspcapflags'][j], star['starflags'][j]

Get element abundances for all stars with [Fe/H] < -2 with no BAD FLAGS set

You can also select a subset of the stars based on their properties. This example finds a set of metal-poor stars, without any flags set indicating that the observations or analysis is bad.

In CAS, limiting to the first 100:

SELECT TOP 100 s.apogee_id, s.ra, s.dec, s.glon, s.glat, s.vhelio_avg, s.vscatter,
a.teff, a.logg, a.m_h, a.alpha_m, dbo.fApogeeAspcapFlagN(a.aspcapflag),
dbo.fApogeeStarFlagN(s.starflag)
FROM apogeeStar s
JOIN aspcapStar a on a.apstar_id = s.apstar_id
WHERE (a.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 
and a.m_h < -2

In IDL, printing first 100 stars it finds. This uses the allStar file :

star = mrdfits('allStar-l30e.2.fits', 1)
badbits = sdss_flagval('APOGEE_ASPCAPFLAG', 'STAR_BAD')
gd = where((star.aspcapflag and badbits) eq 0 and star.teff gt 0 $
    and star.m_h lt -2, ngd)
for i=0,(ngd < 100)-1 do begin
    print, star[gd[i]].apogee_id,$
        star[gd[i]].ra, star[gd[i]].dec, star[gd[i]].glon, star[gd[i]].glat,$
        star[gd[i]].vhelio_avg, star[gd[i]].vscatter, star[gd[i]].teff,$
        star[gd[i]].logg, star[gd[i]].m_h, star[gd[i]].alpha_m,$
        star[gd[i]].aspcapflags, star[gd[i]].starflags
endfor

In python, printing first 100 stars it finds. This uses the allStar file :

import numpy
from astropy.io import fits (or import pyfits as fits)
star_hdus = fits.open('allStar-l30e.2.fits')
star = star_hdus[1].data
star_hdus.close()
badbits = 2**23
gd = (numpy.bitwise_and(star['aspcapflag'], badbits) == 0) & (star['teff']>0)\
    & (star['m_h'] < -2.)
ind = numpy.where(gd)[0]
for i in range(0, 100):
    j = ind[i]
    print star['ra'][j], star['dec'][j], star['glon'][j], star['glat'][j],\
        star['vhelio_avg'][j], star['vscatter'][j], star['teff'][j], star['logg'][j],\
        star['m_h'][j], star['alpha_m'][j], star['aspcapflags'][j],\
        star['starflags'][j]

Get element abundances for stars flagged as known cluster members

In addition to selecting main survey targets, you can select other objects according how they were selected. This is an example of selecting objects chosen to be calibrator stars in clusters with known metallicities (APOGEE_CALIB_CLUSTER) but were not observed during commissioning.

In CAS:

SELECT TOP 100 s.apogee_id, s.ra, s.dec, s.glon, s.glat, s.vhelio_avg,
s.vscatter, a.teff, a.teff_err, a.logg, a.logg_err, a.m_h, a.m_h_err,
a.alpha_m, a.alpha_m_err, dbo.fApogeeAspcapFlagN(a.aspcapflag),
dbo.fApogeeStarFlagN(s.starflag)
FROM apogeeStar s
JOIN aspcapStar a on a.apstar_id = s.apstar_id
WHERE (a.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and s.commiss = 0
and (s.apogee_target2 & (dbo.fApogeeTarget2('APOGEE_CALIB_CLUSTER')) != 0)

In IDL, printing first 100 stars it finds. This uses the allStar file :

star = mrdfits('allStar-l30e.2.fits', 1)
badbits = sdss_flagval('APOGEE_ASPCAPFLAG', 'STAR_BAD')
clusterbits = sdss_flagval('APOGEE_TARGET2', 'APOGEE_CALIB_CLUSTER')
gd = where((star.aspcapflag and badbits) eq 0 and star.commiss eq 0 and $
    (star.apogee_target2 and clusterbits) ne 0, ngd)
for i=0,(ngd<100)-1 do begin
    print, star[gd[i]].apogee_id,$
       star[gd[i]].ra, star[gd[i]].dec, star[gd[i]].glon, star[gd[i]].glat,$
       star[gd[i]].vhelio_avg, star[gd[i]].vscatter, star[gd[i]].teff,$
       star[gd[i]].logg, star[gd[i]].m_h, star[gd[i]].alpha_m,$
       star[gd[i]].aspcapflags, star[gd[i]].starflags
endfor

In python, printing first 100 stars it finds. This uses the allStar file :

import numpy
from astropy.io import fits (or import pyfits as fits)
star_hdus = fits.open('allStar-l30e.2.fits')
star = star_hdus[1].data
star_hdus.close()
badbits = 2**23
clusterbits= 2**10
gd = (numpy.bitwise_and(star['aspcapflag'], badbits) == 0) &\
     (numpy.bitwise_and(star['apogee_target2'], clusterbits) != 0) &\
     (star['commiss'] == 0)
ind = numpy.where(gd)[0]
for i in range(0, 100):
    j = ind[i]
    print star['ra'][j], star['dec'][j], star['glon'][j], star['glat'][j],\
        star['vhelio_avg'][j], star['vscatter'][j], star['teff'][j],\
        star['logg'][j], star['m_h'][j], star['alpha_m'][j],\
        star['aspcapflags'][j], star['starflags'][j]

Get proper motions, JHK mag and errors, K-band extinction and radial velocities, for stars with RVs > 300 km/s (with no BAD flags for RVs).

There is photometric data associated with each target, including proper motions and other information. This example looks for such information for larger (heliocentric) radial velocity stars. It restricts to objects with good measured ASPCAP parameters. In CAS, this requires joining the apogeeStar and aspcapStar tables with the apogeeObject table, which has the target information. In the flat-files, enough of the target information is included in the allStar file in this case.

In CAS:

SELECT TOP 100 star.apogee_id, star.ra, star.dec, star.glon, star.glat,
star.vhelio_avg, star.vscatter, obj.j, obj.h, obj.k, obj.ak_targ,
obj.ak_targ_method, obj.ak_wise, aspcap.teff, aspcap.logg, aspcap.m_h
FROM apogeeStar star
JOIN aspcapStar aspcap on aspcap.apstar_id = star.apstar_id
JOIN apogeeObject obj on aspcap.target_id = obj.target_id
WHERE (aspcap.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and
aspcap.teff > 0 and (star.vhelio_avg > 300) and
(star.starflag & dbo.fApogeeStarFlag('SUSPECT_RV_COMBINATION')) = 0
and star.nvisits > 2
order by aspcap.apogee_id

In IDL, printing first 100 stars it finds. This uses the allStar file :

star = mrdfits('allStar-l30e.2.fits', 1)
badbits = sdss_flagval('APOGEE_ASPCAPFLAG', 'STAR_BAD')
suspectbits = sdss_flagval('APOGEE_STARFLAG', 'SUSPECT_RV_COMBINATION')
gd = where((star.aspcapflag and badbits) eq 0 $
     and (star.starflag and suspectbits) eq 0 $
     and (star.vhelio_avg gt 300.) and (star.teff gt 0.) $
     and (star.nvisits gt 2), ngd)
for i=0,(ngd<100)-1 do begin
     print, star[gd[i]].apogee_id,$
        star[gd[i]].ra, star[gd[i]].dec, star[gd[i]].glon, star[gd[i]].glat,$
        star[gd[i]].vhelio_avg, star[gd[i]].vscatter, star[gd[i]].teff,$
        star[gd[i]].logg, star[gd[i]].m_h, star[gd[i]].alpha_m,$
        star[gd[i]].aspcapflags, star[gd[i]].starflags
endfor

In python, printing first 10 stars it finds. This uses the allStar file :

import numpy
from astropy.io import fits (or import pyfits as fits)
star_hdus = fits.open('allStar-l30e.2.fits')
star = star_hdus[1].data
star_hdus.close()
badbits = 2**23
suspectbits = 2**16
gd = (numpy.bitwise_and(star['aspcapflag'], badbits) == 0) &\
     (numpy.bitwise_and(star['starflag'], suspectbits) == 0) &\
     (star['vhelio_avg'] > 300.) &\
     (star['teff'] > 0.) &\
     (star['nvisits'] > 2)
ind = numpy.where(gd)[0]
for i in range(0, 10):
    j = ind[i]
    print star['ra'][j], star['dec'][j], star['glon'][j], star['glat'][j],\
        star['vhelio_avg'][j], star['vscatter'][j], star['teff'][j],\
        star['logg'][j], star['m_h'][j], star['alpha_m'][j],\
        star['aspcapflags'][j], star['starflags'][j]

Get ASPCAP parameters and targeting flags for all stars with 1 degree of a cluster center.

CASJobs allows search for objects near any particular RA and Dec. The following example searches for ASPCAP parameters and targeting flags for the stars observed near M13. For completeness, we include the equivalent using IDL and idlutils.

In CAS, using Equatorial coordinates:

SELECT star.apstar_id, star.apogee_id, star.ra, star.dec, star.glon, star.glat,
star.apogee_target1, star.apogee_target2, aspcap.teff, aspcap.logg, aspcap.m_h
FROM apogeeStar star
JOIN fGetNearbyApogeeStarEq(250.423458,36.461306,60) near
on star.apstar_id=near.apstar_id
JOIN aspcapStar aspcap on aspcap.apstar_id=star.apstar_id

In IDL, using the allStar file:

star = mrdfits('allStar-l30e.2.fits', 1)
ra_m13 = 250.423458
dec_m13 = 36.461306
istar = where(star.ra gt 0. and star.dec gt -90., nstar)
spherematch, ra_m13, dec_m13, star[istar].ra, star[istar].dec, 1., m1, m2, max=0
stars_near_m13 = star[m2]
for i=0,n_elements(stars_near_m13)-1 do begin
     print, stars_near_m13[i].apstar_id,' ',stars_near_m13[i].apogee_id,' ',$
         stars_near_m13[i].ra,stars_near_m13[i].dec,stars_near_m13[i].glon,stars_near_m13[i].glat,$
         stars_near_m13[i].apogee_target1,stars_near_m13[i].apogee_target2,$
         stars_near_m13[i].teff,stars_near_m13[i].logg,stars_near_m13[i].m_h
endfor

Get RVs from individual visits and the element abundances for the combined spectra for stars which have more than 6 visits.

Each star is visited several times, and in some case many times, in order to build up signal-to-noise and to detect radial velocity variations. The information about each visit to each star is in the apogeeVisit table. One could join this table with apogeeStar on apogee_id in order to literally find all visits to each star. However, in this example we are interested in just finding those visits that actually contributed to each combined spectrum. In this case, bad visits are excluded and commissioning data and survey data are kept separate (not combined). To find these stars, one may use the apogeeStarVisit table in CAS, or the array visit_pk which exists for each star in the allStar file. Alternatively, if you wanted to find all visits to a particular star, one could replace in the code below apogeeStarVisit with apogeeStarAllVisit and visit_pk with all_visit_pk.

In CAS:

SELECT  top 100 visit.*, aspcap.teff, aspcap.logg, aspcap.m_h
FROM apogeeVisit visit
JOIN apogeeStarVisit starvisit on visit.visit_id = starvisit.visit_id
JOIN aspcapStar aspcap on aspcap.apstar_id = starvisit.apstar_id
JOIN apogeeStar star on star.apstar_id = starvisit.apstar_id
WHERE (aspcap.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and aspcap.teff > 0
and (star.apogee_target1 & dbo.fApogeeTarget1('APOGEE_LONG')) > 0
and star.nvisits > 6
ORDER BY visit.apogee_id

In IDL. This uses the allStar file and the allVisit:

star = mrdfits('allStar-l30e.2.fits', 1)
visit = mrdfits('allVisit-l30e.2.fits', 1)
badbits = sdss_flagval('APOGEE_ASPCAPFLAG', 'STAR_BAD')
longbits = sdss_flagval('APOGEE_TARGET1', 'APOGEE_LONG')
gd = where((star.aspcapflag and badbits) eq 0 and $
     (star.apogee_target1 and longbits) ne 0 $
     and (star.nvisits gt 6) and (star.teff gt 0.), ngd)
for i=0L, (ngd<100)-1L do begin
    for j=0L, star[gd[i]].nvisits-1L do begin
        print, visit[star[gd[i]].visit_pk[j]].target_id + " " + $
            visit[star[gd[i]].visit_pk[j]].visit_id
    endfor
endfor

In python, printing first 100 stars it finds. This uses the allStar file :

import numpy
from astropy.io import fits (or import pyfits as fits)
star_hdus = fits.open('allStar-l30e.2.fits')
star = star_hdus[1].data
star_hdus.close()
visit_hdus = fits.open('allVisit-l30e.2.fits')
visit = visit_hdus[1].data
visit_hdus.close()
badbits = 2**23
longbits = 2**13
gd = (numpy.bitwise_and(star['aspcapflag'], badbits) == 0) &\
     (numpy.bitwise_and(star['apogee_target1'], longbits) != 0) &\
     (star['teff'] > 0.) &\
     (star['nvisits'] > 6)
ind = numpy.where(gd)[0]
for i in range(0, 100):
    k = ind[i]
    vpk = star['visit_pk'][k]
    for j in range(0, star['nvisits'][k]):
        print visit['target_id'][vpk[j]] + " " + visit['visit_id'][vpk[j]]

Get APOGEE_IDs and SDSS/BOSS plate, mjd, fiberid for all stars that have both APOGEE and SEGUE spectra.

A small number of objects have been observed both in the optical with the SDSS and/or BOSS spectrographs and in the infrared with the APOGEE spectrograph. The examples below finds all matches between primary SDSS/BOSS spectra and APOGEE stars with a 3 arcsec tolerance for such cases (note that there are some cases where an entry in one catalog matches multiple entries in the other).

In CAS, using a special function:

SELECT TOP 50 specobj.plate as specobj_plate, specobj.mjd as specobj_mjd,
specobj.fiberid as specobj_fiberid, specobj.ra as specobj_ra,
specobj.dec as specobj_dec, star.apstar_id, star.ra as star_ra, star.dec as star_dec
FROM apogeeStar AS star
CROSS APPLY dbo.fGetNearestSpecObjEq( star.ra, star.dec, 0.05) AS near
JOIN specobj ON near.specobjid=specobj.specobjid

In IDL. This uses the allStar file and also the unfortunately large specObj file for the SDSS/BOSS data.

star = mrdfits('allStar-l30e.2.fits', 1)
specobj = hogg_mrdfits(getenv('SPECTRO_REDUX') + '/specObj-dr13.fits', 1, nrow=20000,$
          columns = ['plate', 'fiberid', 'mjd', 'plug_ra', 'plug_dec', 'specprimary'])
iprimary = where(specobj.specprimary eq 1, nprimary)
spherematch, star.ra, star.dec,$
    specobj[iprimary].plug_ra, specobj[iprimary].plug_dec,$
    3./3600., m1, m2, max=0
star_match = star[m1]
specobj_match = specobj[iprimary[m2]]

Get SDSS ugriz photometry, errors and flags, ASPCAP parameters for the APOGEE stars with b > 60

In addition to matching to the SDSS spectroscopy, you can also match to the SDSS photometric imaging data. In this case, we only give an example within CAS. To do this purely with flat files requires either downloading the full photometric catalog (about 3 Tbytes) or the “datasweep” files (about 300 Gbytes), both described in the imaging data access documentation, and constructing an efficient flat-file method to do the matching. For most purposes, CAS will be the right way to do this.

In CAS, using a special function:

SELECT TOP 50 photoobj.run, photoobj.camcol, photoobj.field, photoobj.obj,
photoobj.psfmag_u, photoobj.psfmag_g, photoobj.psfmag_r, photoobj.psfmag_i,
photoobj.psfmag_z, photoobj.ra as photoobj_ra, photoobj.dec as photoobj_dec,
star.apstar_id, star.ra as star_ra, star.dec as star_dec,
aspcap.teff, aspcap.m_h, aspcap.logg
FROM apogeeStar AS star
CROSS APPLY dbo.fGetNearestObjEq( star.ra, star.dec, 0.05) AS near
JOIN photoobj ON near.objid=photoobj.objid
JOIN aspcapStar as aspcap ON star.apstar_id = aspcap.apstar_id
WHERE star.glat > 60. and aspcap.teff > 0