Mini Tools for APOGEE data
Note
astroNN only contains a limited amount of necessary tools. For a more comprehensive python tool to deal with APOGEE data, please refer to Jo Bovy’s APOGEE tools
astroNN.apogee
module has a handful of tool to deal with APOGEE data.
The APO Galactic Evolution Experiment employs high-resolution, high signal-to-noise infrared spectroscopy
to penetrate the dust that obscures significant fractions of the disk and bulge of our Galaxy. APOGEE is surveying
red giant stars across the full range of the Galactic bulge, bar, disk, and halo. APOGEE generated precise
radial velocities and detailed chemical abundances, providing unprecedented insights into the dynamical structure and
chemical history of the Galaxy. In conjunction with the planet-finding surveys, Kepler and CoRoT, APOGEE unravels
problems in fundamental astrophysics.
SDSS APOGEE: https://www.sdss.org/surveys/apogee-2/
Continuum Normalization of APOGEE Spectra
You can access the default astroNN continuum mask fro APOGEE spectra by
1import os
2import astroNN
3import numpy as np
4
5dr = 14
6
7dir = os.path.join(os.path.dirname(astroNN.__path__[0]), 'astroNN', 'data', f'dr{dr}_contmask.npy')
8cont_mask = np.load(dir)
When you do continuum normalization using astroNN, you can just use con_mask=None to use default mask provided by Jo Bovy’s APOGEE Tools. astroNN will use a SINGLE continuum pixel mask to normalize all spectra you provided. Moreover, astroNN will normalize the spectra by chips instead of normalize them all together.
- astroNN.apogee.apogee_continuum(spectra, spectra_err, cont_mask=None, deg=2, dr=None, bitmask=None, target_bit=None, mask_value=1.0)[source]
It is designed only for apogee spectra by fitting Chebyshev polynomials to the flux values in the continuum mask by chips. The resulting continuum will have the same shape as fluxes.
- Parameters:
spectra (ndarray) – spectra
spectra_err (ndarray) – spectra uncertainty, same shape as spectra
cont_mask (ndarray[bool]) – continuum mask
deg (int) – The degree of Chebyshev polynomial to use in each region, default is 2 which works the best so far
dr (int) – apogee dr
bitmask (ndarray) – bitmask array of the spectra, same shape as spectra
target_bit (Union(int, list[int], ndarray[int])) – a list of bit to be masked
mask_value (Union(int, float)) – if a pixel is determined to be a bad pixel, this value will be used to replace that pixel flux
- Returns:
normalized spectra, normalized spectra uncertainty
- Return type:
ndarray, ndarray
- History:
2018-Mar-21 - Written - Henry Leung (University of Toronto)
1from astroNN.apogee import apogee_continuum
2
3# spectra_errs refers to the 1-sigma error array provided by APOGEE
4# spectra can be multiple spectra at a time
5norm_spec, norm_spec_err = apogee_continuum(apogee_spectra, spectra_errs, cont_mask=None, deg=2, dr=14)
6
7# If you deal with bitmask too and want to set some target bits to zero, you can add additional arguement in apogee_continuum()
8# You target_bit=[a list of number] or target_bit=None to use default target_bit
9apogee_continuum(apogee_spectra, spectra_errs, cont_mask=None, deg=2, dr=14, bitmask=apogee_bitmask, target_bit=None)
norm_spec refers to the normalized spectra while norm_spec_err refers to the normalized spectra error

You can use continuum()
to normalize any spectra while apogee_continuum()
is specifically designed for APOGEE spectra.
1from astroNN.apogee import continuum
2
3spec, spec_err = continuum(spectra, spectra_errs, cont_mask, deg=2)
APOGEE Data Downloader
astroNN APOGEE data downloader always act as functions that will return you the path of downloaded file(s),
and download it if it does not exist locally. If the file cannot be found on server, astroNN will generally return False
as the path.
General Way to Open Fits File
astropy.io.fits documentation: https://docs.astropy.org/en/stable/io/fits/
1from astropy.io import fits
2
3data = fits.open(local_path_to_file)
allstar file
Data Model: https://data.sdss.org/datamodel/files/APOGEE_ASPCAP/APRED_VERS/ASPCAP_VERS/allStar.html
- astroNN.apogee.allstar(dr=None, flag=None)[source]
Download the allStar file (catalog of ASPCAP stellar parameters and abundances from combined spectra)
1from astroNN.apogee import allstar
2
3local_path_to_file = allstar(dr=16)
allvisit file
Data Model: https://data.sdss.org/datamodel/files/APOGEE_ASPCAP/APRED_VERS/ASPCAP_VERS/allVisit.html
- astroNN.apogee.allvisit(dr=None, flag=None)[source]
Download the allVisit file (catalog of properties from individual visit spectra)
1from astroNN.apogee import allvisit
2
3local_path_to_file = allvisit(dr=16)
Combined Spectra (aspcapStar)
Data Model: https://data.sdss.org/datamodel/files/APOGEE_ASPCAP/APRED_VERS/ASPCAP_VERS/TELESCOPE/FIELD/aspcapStar.html
- astroNN.apogee.combined_spectra(dr=None, location=None, field=None, apogee=None, telescope=None, verbose=1, flag=None)[source]
Download the required combined spectra file a.k.a aspcapStar
- Parameters:
- Returns:
full file path and download in background if not found locally, False if cannot be found on server
- Return type:
- History:
- 2017-Oct-15 - Written - Henry Leung (University of Toronto)2018-Aug-31 - Updated - Henry Leung (University of Toronto)
1from astroNN.apogee import combined_spectra
2
3local_path_to_file = combined_spectra(dr=16, location=a_location_id, apogee=a_apogee_id)
Visit Spectra (apStar)
Data Model: https://data.sdss.org/datamodel/files/APOGEE_REDUX/APRED_VERS/stars/TELESCOPE/FIELD/apStar.html
- astroNN.apogee.visit_spectra(dr=None, location=None, field=None, apogee=None, telescope=None, verbose=1, flag=None, commission=False)[source]
Download the required individual spectra file a.k.a apStar or asStar
- Parameters:
dr (int) – APOGEE DR
location (int) – Location ID [Optional]
field (str) – Field [Optional]
apogee (str) – Apogee ID
telescope (str) – Telescope ID, for example ‘apo25m’ or ‘lco25m’
verbose (int) – verbose, set 0 to silent most logging
flag (int) – 0: normal, 1: force to re-download
commission (bool) – whether the spectra is taken during commissioning
- Returns:
full file path and download in background if not found locally, False if cannot be found on server
- Return type:
- History:
- 2017-Nov-11 - Written - Henry Leung (University of Toronto)2018-Aug-31 - Updated - Henry Leung (University of Toronto)
1from astroNN.apogee import visit_spectra
2
3local_path_to_file = visit_spectra(dr=16, location=a_location_id, apogee=a_apogee_id)
astroNN catalogue for APOGEE
Data Model (DR16): https://data.sdss.org/datamodel/files/APOGEE_ASTRONN/apogee_astronn.html
- astroNN.apogee.downloader.apogee_astronn(dr=None, flag=None)[source]
- Download the apogee_astroNN file (catalog of astroNN stellar parameters, abundances, distances and orbital
parameters from combined spectra)
1from astroNN.apogee import apogee_astronn
2
3local_path_to_file = apogee_astronn(dr=16)
Red Clumps of SDSS Value Added Catalogs
Introduction: https://www.sdss.org/dr16/data_access/value-added-catalogs/?vac_id=apogee-red-clump-rc-catalog
Data Model (DR16): https://data.sdss.org/datamodel/files/APOGEE_RC/cat/apogee-rc-DR16.html
- astroNN.datasets.apogee.load_apogee_rc(dr=None, unit='distance', extinction=True)[source]
Load apogee red clumps (absolute magnitude measurement)
- Parameters:
- Returns:
numpy array of ra, dec, array
- Return type:
ndarrays
- History:
- 2018-Jan-21 - Written - Henry Leung (University of Toronto)2018-May-12 - Updated - Henry Leung (University of Toronto)
1from astroNN.apogee import apogee_rc
2
3local_path_to_file = apogee_rc(dr=16)
Or you can use load_apogee_rc() to load the data by
1from astroNN.datasets import load_apogee_rc
2
3# unit can be 'distance' for distance in parsec, 'absmag' for k-band absolute magnitude
4# 'fakemag' for astroNN's k-band fakemag scale
5RA, DEC, array = load_apogee_rc(dr=16, unit='distance', extinction=True) # extinction only effective if not unit='distance'
APOGEE Distance Estimations
Introduction: https://www.sdss.org/dr14/data_access/value-added-catalogs/?vac_id=apogee-dr14-based-distance-estimations
Data Model (DR14): https://data.sdss.org/datamodel/files/APOGEE_DISTANCES/apogee_distances.html Data Model (DR16): https://data.sdss.org/datamodel/files/APOGEE_STARHORSE/apogee_starhorse.html
- astroNN.apogee.apogee_distances(dr=None, flag=None)[source]
Download the APOGEE Distances VAC catalogue (APOGEE Distances for DR14, APOGEE Starhourse for DR16/17)
1from astroNN.apogee.downloader import apogee_distances
2
3local_path_to_file = apogee_distances(dr=14)
- astroNN.datasets.load_apogee_distances(dr=None, unit='distance', cuts=True, extinction=True, keepdims=False)[source]
Load apogee distances (absolute magnitude from stellar model)
- Parameters:
dr (int) – Apogee DR
unit (string) –
which unit you want to get back
”absmag” for absolute magnitude
”fakemag” for fake magnitude
”distance” for distance in parsec
cuts (Union[boolean, float]) – Whether to cut bad data (negative parallax and percentage error more than 20%), or a float to set the threshold
extinction (bool) – Whether to take extinction into account, only affect when unit is NOT ‘distance’
keepdims (boolean) – Whether to preserve indices the same as APOGEE allstar DR14, no effect when cuts=False, set to -9999 for bad indices when cuts=True keepdims=True
- Returns:
numpy array of ra, dec, array, err_array
- Return type:
ndarrays
- History:
- 2018-Jan-25 - Written - Henry Leung (University of Toronto)2021-Jan-29 - Updated - Henry Leung (University of Toronto)
Or you can use load_apogee_distances() to load the data by
1from astroNN.datasets import load_apogee_distances
2
3# unit can be 'distance' for distance in parsec, 'absmag' for k-band absolute magnitude
4# 'fakemag' for astroNN's k-band fakemag scale
5# cuts=True to cut out those unknown values (-9999.) and measurement error > 20%
6RA, DEC, array, err_array = load_apogee_distances(dr=14, unit='distance', cuts=True, keepdims=False)
Cannon’s allstar
Data Model (DR14): https://data.sdss.org/datamodel/files/APOGEE_REDUX/APRED_VERS/APSTAR_VERS/ASPCAP_VERS/RESULTS_VERS/CANNON_VERS/allStarCannon.html
- astroNN.apogee.allstar_cannon(dr=None, flag=None)[source]
Download the allStarCannon file (catalog of Cannon stellar parameters and abundances from combined spectra)
1from astroNN.apogee import allstar_cannon
2
3local_path_to_file = allstar_cannon(dr=14)