Mini Tools for APOGEE data - astroNN.apogee

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

The APO Galactic Evolution Experiment 1 (APOGEE-1) employed 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 surveyed over 100,000 red giant stars across the full range of the Galactic bulge, bar, disk, and halo. APOGEE-1 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: http://www.sdss.org/surveys/apogee/

Continuum Normalization of APOGEE Spectra

You can access the default astroNN continuum mask fro APOGEE spectra by

import os
import astroNN
import numpy as np

dr = 14

dir = os.path.join(os.path.dirname(astroNN.__path__[0]), 'astroNN', 'data', f'dr{dr}_contmask.npy')
cont_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)

from astroNN.apogee import apogee_continuum

# spectra_errs refers to the 1-sigma error array provided by APOGEE
# spectra can be multiple spectra at a time
norm_spec, norm_spec_err = apogee_continuum(apogee_spectra, spectra_errs, cont_mask=None, deg=2, dr=14)

# If you deal with bitmask too and want to set some target bits to zero, you can add additional arguement in apogee_continuum()
# You target_bit=[a list of number] or target_bit=None to use default target_bit
apogee_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

Note

If you are planning to compile APOGEE dataset using astroNN, you can ignore this section as astroNN H5Compiler will load data from fits files directly and will take care everything.

_images/con_mask_spectra.png

You can use continuum() to normalize any spectra while apogee_continuum() is specifically designed for APOGEE spectra.

from astroNN.apogee import continuum

spec, 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: http://docs.astropy.org/en/stable/io/fits/

from astropy.io import fits

data = 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)

Parameters
  • dr (int) – APOGEE DR

  • flag (int) – 0: normal, 1: force to re-download

Returns

full file path and download in background if not found locally, False if cannot be found on server

Return type

str

History

2017-Oct-09 - Written - Henry Leung (University of Toronto)

from astroNN.apogee import allstar

local_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)

Parameters
  • dr (int) – APOGEE DR

  • flag (int) – 0: normal, 1: force to re-download

Returns

full file path and download in background if not found locally, False if cannot be found on server

Return type

str

History

2017-Oct-11 - Written - Henry Leung (University of Toronto)

from astroNN.apogee import allvisit

local_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
  • 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

Returns

full file path and download in background if not found locally, False if cannot be found on server

Return type

str

History
2017-Oct-15 - Written - Henry Leung (University of Toronto)
2018-Aug-31 - Updated - Henry Leung (University of Toronto)
from astroNN.apogee import combined_spectra

local_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

str

History
2017-Nov-11 - Written - Henry Leung (University of Toronto)
2018-Aug-31 - Updated - Henry Leung (University of Toronto)
from astroNN.apogee import visit_spectra

local_path_to_file = visit_spectra(dr=16, location=a_location_id, apogee=a_apogee_id)

astroNN catalogue for APOGEE

Introduction: https://www.sdss.org/dr16/data_access/value-added-catalogs/?vac_id=the-astronn-catalog-of-abundances,-distances,-and-ages-for-apogee-dr16-stars

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)

Parameters
  • dr (int) – APOGEE DR

  • flag (int) – 0: normal, 1: force to re-download

Returns

full file path and download in background if not found locally, False if cannot be found on server

Return type

str

History

2019-Dec-10 - Written - Henry Leung (University of Toronto)

from astroNN.apogee import apogee_astronn

local_path_to_file = apogee_astronn(dr=16)

Red Clumps of SDSS Value Added Catalogs

Introduction: http://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_rc.load_apogee_rc(dr=None, metric='distance', extinction=True)[source]

Load apogee red clumps (absolute magnitude measurement)

Parameters
  • dr (int) – Apogee DR

  • metric (string) –

    which metric you want to get back

    • ”absmag” for k-band absolute magnitude

    • ”fakemag” for k-band fake magnitude

    • ”distance” for distance in parsec

  • extinction (bool) – Whether to take extinction into account, only affect when metric is NOT ‘distance’

Returns

numpy array of ra, dec, metrics_array

Return type

ndarrays

History
2018-Jan-21 - Written - Henry Leung (University of Toronto)
2018-May-12 - Updated - Henry Leung (University of Toronto)
from astroNN.apogee import apogee_vac_rc

local_path_to_file = apogee_vac_rc(dr=16)

Or you can use load_apogee_rc() to load the data by

from astroNN.datasets import load_apogee_rc

# metric can be 'distance' for distance in parsec, 'absmag' for k-band absolute magnitude
# 'fakemag' for astroNN's k-band fakemag scale
RA, DEC, metrics_array = load_apogee_rc(dr=16, metric='distance', extinction=True)  # extinction only effective if not metric='distance'

APOKASC in the Kepler Fields

from astroNN.datasets.apokasc import apokasc_load

ra, dec, logg = apokasc_load()

# OR you want the gold and basic standard separately
gold_ra, gold_dec, gold_logg, basic_ra, basic_dec, basic_logg = apokasc_load(combine=False)

APOGEE DR14-Based Distance Estimations

Introduction: http://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

astroNN.apogee.apogee_distances(dr=None, flag=None)[source]

Download the Apogee Distances catalogue

Parameters
  • dr (int) – Apogee DR

  • flag (int) – Force to download if flag=1

Returns

full file path

Return type

str

History

2018-Jan-24 - Written - Henry Leung (University of Toronto)

from astroNN.apogee.downloader import apogee_distances

local_path_to_file = apogee_distances(dr=14)
astroNN.datasets.load_apogee_distances(dr=None, metric='distance', cuts=True, extinction=True, keepdims=False)[source]

Load apogee distances (absolute magnitude from stellar model)

Parameters
  • dr (int) – Apogee DR

  • metric (string) –

    which metric 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 metric 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, metrics_array, metrics_err_array

Return type

ndarrays

History

2018-Jan-25 - Written - Henry Leung (University of Toronto)

Or you can use load_apogee_distances() to load the data by

from astroNN.datasets import load_apogee_distances

# metric can be 'distance' for distance in parsec, 'absmag' for k-band absolute magnitude
# 'fakemag' for astroNN's k-band fakemag scale
# cuts=True to cut out those unknown values (-9999.) and measurement error > 20%
RA, DEC, metrics_array, metrics_err_array = load_apogee_distances(dr=14, metric='distance', cuts=True, keepdims=False)

Cannon’s allstar

Introduction: https://data.sdss.org/datamodel/files/APOGEE_REDUX/APRED_VERS/APSTAR_VERS/ASPCAP_VERS/RESULTS_VERS/CANNON_VERS/cannonModel.html

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)

Parameters
  • dr (int) – APOGEE DR

  • flag (int) – 0: normal, 1: force to re-download

Returns

full file path and download in background if not found locally, False if cannot be found on server

Return type

str

History

2017-Oct-24 - Written - Henry Leung (University of Toronto)

from astroNN.apogee import allstar_cannon

local_path_to_file = allstar_cannon(dr=14)