diff --git a/_toc.yml b/_toc.yml
index c1b238ab5..4c0d0fc36 100644
--- a/_toc.yml
+++ b/_toc.yml
@@ -82,8 +82,11 @@ parts:
- caption: SDSS
chapters:
- - file: notebooks/SDSS/MaNGA_HST_tutorial/MaNGA_HST_tutorial.ipynb
-
+ - file: notebooks/SDSS/sdss.md
+ sections:
+ - file: notebooks/SDSS/MaNGA_HST_tutorial/MaNGA_HST_tutorial.ipynb
+ - file: notebooks/SDSS/APOGEE_TESS_tutorial/APOGEE_TESS_tutorial.ipynb
+
- caption: Multi-Mission Tools
chapters:
- file: notebooks/multi_mission/astroquery.md
diff --git a/notebooks/SDSS/APOGEE_TESS_tutorial/APOGEE_TESS_tutorial.ipynb b/notebooks/SDSS/APOGEE_TESS_tutorial/APOGEE_TESS_tutorial.ipynb
new file mode 100644
index 000000000..ffbebf255
--- /dev/null
+++ b/notebooks/SDSS/APOGEE_TESS_tutorial/APOGEE_TESS_tutorial.ipynb
@@ -0,0 +1,945 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "\n",
+ "# Characterizing Variable Stars with APOGEE + TESS\n",
+ "***\n",
+ "\n",
+ "## Learning Goals\n",
+ "\n",
+ "By the end of this tutorial, you will:\n",
+ "\n",
+ "- Understand how to search the MAST Archive and download SDSS APOGEE data using `astroquery.mast`\n",
+ "- Plot a stellar spectrum and an HR diagram and using APOGEE data\n",
+ "- Understand how to search for TESS light curves complementing the APOGEE observations\n",
+ "- Explore different types of variable stars using their APOGEE parameters and TESS light curves\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "## Table of Contents\n",
+ "* [Introduction](#Introduction)\n",
+ "* [Imports](#Imports)\n",
+ "* [Accessing APOGEE data at MAST](#APOGEE)\n",
+ " * [Querying all APOGEE data](#APOGEE-query)\n",
+ " * [Searching for a specific star](#APOGEE-star)\n",
+ " * [Downloading APOGEE data products](#APOGEE-download)\n",
+ " * [Plotting an APOGEE spectrum](#APOGEE-spectrum)\n",
+ " * [Downloading the APOGEE allStar catalog](#APOGEE-allstar)\n",
+ " * [Plotting an HR diagram from APOGEE](#APOGEE-plot)\n",
+ " \n",
+ "* [Searching for TESS data of this star](#TESS)\n",
+ " * [Coordinate search using astroquery.mast](#TESS-query)\n",
+ " * [Plotting a light curve from TESS](#TESS-lightcurve)\n",
+ "\n",
+ "* [Combining APOGEE and TESS data](#Combining-APOGEE-and-TESS-data)\n",
+ " * [Plotting APOGEE and TESS data together](Plotting-APOGEE-and-TESS-data-together)\n",
+ " * [Exploring Different types of Variable Stars](#Exploring-Variables)\n",
+ " * [RR-Lyrae Variable: 2M11361176+8117369](#rr-lyrae)\n",
+ " * [Rotationally Variable - 2M19181706+5141323](#rotationally-variable)\n",
+ " * [Eclipsing Binary - 2M19203184+3830492](#eclipsing-binary)\n",
+ "\n",
+ "* [Additional Resources](#Resources)\n",
+ " * [How to Cite](#Citations)\n",
+ " * [About This Notebook](#About)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Introduction\n",
+ "\n",
+ "\n",
+ "The [Apache Point Observatory Galactic Evolution Experiment (APOGEE)](https://www.sdss4.org/dr17/irspec/) survey provides infrared-wavelength high-resolution spectroscopy for over 650,000 unique stars from the Milky Way and nearby dwarf galaxies. APOGEE collected data between 2011 - 2020 as part of the [Sloan Digital Sky Survey (SDSS-IV) project](https://www.sdss4.org). APOGEE data is now available at the [Mikulski Archive for Space Telescopes (MAST)](https://archive.stsci.edu) through the [SDSS Legacy Archive at MAST](https://outerspace.stsci.edu/display/SDSS/The+SDSS+Legacy+Archive+at+MAST). \n",
+ "\n",
+ "In this notebook tutorial, we will demonstrate how to access APOGEE data at MAST using Python. One APOGEE star, a Cepheid Variable named `V1154-Cyg` will be used to demonstrate the basics of how to download and plot APOGEE data. We will then combine this APOGEE spectrum with light curves from the TESS mission, also accessible from MAST, to study this variable star."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "## Imports\n",
+ "\n",
+ "\n",
+ "The main packages we're using for this notebook and their use-cases are:\n",
+ "- *astroquery.mast Observations* for searching the MAST archive\n",
+ "- *astropy.io fits* for accessing FITS files\n",
+ "- *astropy.table Table* for accessing FITS tables\n",
+ "- *astropy.units* for working with astronomical units\n",
+ "- *astropy.coordinates* for handling astronomical coordinates\n",
+ "- *matplotlib.pyplot* for plotting data\n",
+ "- *numpy* to handle array functions"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "slideshow": {
+ "slide_type": "fragment"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "%matplotlib inline\n",
+ "\n",
+ "from astroquery.mast import Observations\n",
+ "import astropy.io.fits as fits\n",
+ "from astropy.table import Table\n",
+ "from astropy.coordinates import SkyCoord\n",
+ "\n",
+ "import astropy.units as u\n",
+ "import matplotlib.pyplot as plt\n",
+ "import numpy as np"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "This cell updates some of the settings in `matplotlib` to use larger font sizes in the figures:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Update Plotting Parameters\n",
+ "params = {'axes.labelsize': 12, 'xtick.labelsize': 12, 'ytick.labelsize': 12, \n",
+ " 'text.usetex': False, 'lines.linewidth': 1,\n",
+ " 'axes.titlesize': 18, 'font.family': 'serif', 'font.size': 12}\n",
+ "plt.rcParams.update(params)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "***\n",
+ "\n",
+ "# Accessing APOGEE data at MAST\n",
+ "\n",
+ "The [SDSS Legacy Archive at MAST](https://outerspace.stsci.edu/display/SDSS/The+SDSS+Legacy+Archive+at+MAST) hosts all of the science-ready data products from the [SDSS-IV APOGEE Survey](https://www.sdss4.org/dr17/irspec/), which includes spectra for over 650,000 unique stars in the Milky Way. APOGEE acquired observations in both the northern and southern hemispheres, targeting the disk, bulge, bar, and halo components of the Milky Way, as well as several hundred stars in nearby satellite galaxies (including the LMC and SMC). This notebook will demonstrate how to search and download APOGEE data using MAST!\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "## Querying all APOGEE data\n",
+ "\n",
+ "Searching for APOGEE data is straightforward with `astroquery.mast`. In this example, we use `Observations.query_criteria` and search for `provenance_name = 'APOGEE'`. This will return a table describing all of the APOGEE data hosted by the MAST archive.\n",
+ "\n",
+ "Other useful search parameters for APOGEE data might include:\n",
+ "* `obs_collection = 'SDSS'`: searches for all SDSS data\n",
+ "* To specify telescope, use the `instrument_name` field. For example, `instrument_name = 'apogee-lco25m'` limits the search to the stars that were observed with the Las Campanas Observatory 2.5-m telescope in the southern hemisphere.\n",
+ "* Use `target_name` to search for stars using their APOGEE ID (usually the 2MASS ID - for example `'2M05320041-0017041'`)\n",
+ "* `obs_id` can help search for specific targets or fields. Note that wild cards (`*`) are allowed in the search fields, for example: \n",
+ " * `obs_id='*n7789*'` for anything in the \"N7789\" field\n",
+ " * `obs_id='*2M05320041-0017041*'` for a specific star name (2MASS ID)\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "# Search for APOGEE data\n",
+ "# Using the pagesize and page parameters to only return first 10 results\n",
+ "apogee_obs_list = Observations.query_criteria(provenance_name='APOGEE', pagesize=10, page=1)\n",
+ "\n",
+ "# Display First Ten Entries in Table\n",
+ "apogee_obs_list"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "## Searching for a specific star\n",
+ "\n",
+ "Let's narrow down the search to one particular star: cepheid variable \"V1154-Cyg\". Cepheid Variables are pulsating stars, which physically grow larger and smaller, and as a result brighter and dimmer, on a regular rhythm of few days. Cepheid variables in particular are useful to study in astronomy because their pulsation period correlates with their intrinsic brightness, making it easy to determine how far away the star is! Later in this notebook, we will look at some other kinds of variable stars.\n",
+ "\n",
+ "We can search for this star in particular using the `target_name` keyword:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Search for APOGEE star V1154_Cyg\n",
+ "apogee_obs_list = Observations.query_criteria(provenance_name='APOGEE',\n",
+ " target_name='V1154_Cyg')\n",
+ "\n",
+ "# Display results\n",
+ "apogee_obs_list"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "From this results table, we can see some basic metadata related to this observation:\n",
+ "* This star was observed with the APO 1-M telescope (`instrument_name`)\n",
+ "* It's coordinates are in the `s_ra` and `s_dec` columns\n",
+ "* From the `t_min` column, we can see that this star was first observed on the date of MJD 58002 (Correpsonding to 2017-09-06) and last observed on MJD 58069 (2017-11-12 )\n",
+ "* APOGEE provides infrared-wavelength (`wavelength_region`) spectra (`dataproduct_type`) with wavelength range of 1514 - 1696 nanometers (`em_min`, `em_max`)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "## Downloading APOGEE data products\n",
+ "\n",
+ "List all of the data products available for this star using `Observations.get_product_list()`.\n",
+ "\n",
+ "There are 8 total files available for this star, which include the individual spectra from each visit (APVISIT; `apVisit-dr17-*-V1154_Cyg.fits`), the combined spectrum (APSTAR; `apStar-dr17-V1154_Cyg.fits`), the processed and anaylzed spectrum (ASPCAPSTAR; `aspcapStar-dr17-V1154_Cyg.fits`) which contains the best-fit model and stellar parameters from the [APOGEE Stellar Parameters and Chemical Abundance Pipeline (ASPCAP)](https://www.sdss4.org/dr17/irspec/aspcap/). Only the apStar and aspcapStar files are tagged as \"Minimum Recommended Products'\n",
+ "\n",
+ "More information on the APOGEE data products available at MAST can be found on the [APOGEE Data Products](https://outerspace.stsci.edu/display/DraftSDSS/APOGEE+Data+Products) in the Archive Manual, and more information on all of these products can be seen in the search results table:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# List all products available for this observation\n",
+ "products = Observations.get_product_list(apogee_obs_list)\n",
+ "\n",
+ "# Show table\n",
+ "products"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now we will download the aspcapStar spectrum for this star using `Observations.download_products()`. The download will print a status message when completed."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "manifest = Observations.download_products(products, productSubGroupDescription='ASPCAPSTAR')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "# Plotting an APOGEE Spectrum\n",
+ "\n",
+ "Now let's take a look at the file and plot the spectrum.\n",
+ "\n",
+ "Based on the descriptions in the [aspcapStar Data Model](https://data.sdss.org/datamodel/files/APOGEE_ASPCAP/APRED_VERS/ASPCAP_VERS/TELESCOPE/FIELD/aspcapStar.html), this file has four extensions:\n",
+ "\n",
+ "* HDU0: The Primary Header and file metadata\n",
+ "* HDU1: The array containing the observed combined spectrum\n",
+ "* HDU2: The error array for the spectrum\n",
+ "* HDU3: The best fit model spectrum from ASPCAP\n",
+ "* HDU4: The ASPCAP Data Table, containing the best fit stellar parameter values and other information for this star"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Open file\n",
+ "aspcap_star = fits.open(manifest['Local Path'][0])\n",
+ "\n",
+ "# Display file information\n",
+ "aspcap_star.info()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can plot the spectrum using this information! The wavelength information can be found in the file hearer (HUD0), and observed flux is contained in the first extension (HDU1)."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "plt.figure(figsize=(15, 5))\n",
+ "\n",
+ "# Get wavelength information from the header\n",
+ "# CRVAL1 is the minimum wavlength, CDELT1 is the step size (in log space) and NAXIS1 is the number of pixels\n",
+ "apogee_wls = np.logspace(aspcap_star[1].header['CRVAL1'],\n",
+ " aspcap_star[1].header['CRVAL1']+aspcap_star[1].header['CDELT1']*aspcap_star[3].header['NAXIS1'],\n",
+ " aspcap_star[1].header['NAXIS1'])\n",
+ "\n",
+ "\n",
+ "# Get the observed and model flux from extensions 1 and 3\n",
+ "observed_flux = aspcap_star[1].data\n",
+ "model_flux = aspcap_star[3].data\n",
+ "\n",
+ "# Mask the data using the error array in extenion 2\n",
+ "pixel_mask = (aspcap_star[2].data < 0.1) # use only pixels with small errors (10% or less)\n",
+ "\n",
+ "# Plot the observed spectrum\n",
+ "plt.plot(apogee_wls[pixel_mask], observed_flux[pixel_mask], c='k', label='Observed Spectrum')\n",
+ "\n",
+ "# Plot the model spectrum\n",
+ "plt.plot(apogee_wls[pixel_mask], model_flux[pixel_mask], c='darkred', label='Best Fit Model Spectrum')\n",
+ "\n",
+ "# Set axes limits\n",
+ "plt.ylim(0.6, 1.1)\n",
+ "plt.xlim(np.min(apogee_wls), np.max(apogee_wls))\n",
+ "\n",
+ "# Set labels\n",
+ "apogee_id = aspcap_star[4].data['APOGEE_ID'][0] # String containing star's name\n",
+ "plt.title(f\"APOGEE Spectrum - {apogee_id}\")\n",
+ "plt.xlabel(r'Wavelength [$\\AA$]')\n",
+ "plt.ylabel('Flux')\n",
+ "plt.grid()\n",
+ "plt.legend()\n",
+ "\n",
+ "plt.show()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "This is the APOGEE spectrum for this star! It looks great. We can tell it must be a hot star because of the large Hydrogen Absorption lines (for example around 15346, 15443, 15560 and 16113 angstroms - this is the Hydrogen Brackett Series!) The gaps in the spectrum around 15800 and 16400 Angstroms are due to the APOGEE instrumentation: APOGEE observes across 3 ccds, which have a small gap in wavelength coverage between them."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "## Downloading the APOGEE allStar Catalog\n",
+ "We can also download the APOGEE allStar catalog, which contains a lot of useful information for the full APOGEE sample, including stellar parameters, chemical abundances, positions, and observation data for all of the stars in APOGEE.\n",
+ "\n",
+ "We can do this with the `download_file` function in astroquery, knowing the MAST data URL for the allStar catalog is `mast:SDSS/apogee/allStar-dr17-synspec_rev1.fits`.\n",
+ "\n",
+ "This is a fairly large file (3.9 GB), so this download may take a few minutes!"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Download allStar file - this may take a few minutes!\n",
+ "Observations.download_file('mast:SDSS/apogee/allStar-dr17-synspec_rev1.fits')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Open file \n",
+ "allstar = Table.read('allStar-dr17-synspec_rev1.fits', hdu=1)\n",
+ "\n",
+ "# Display table\n",
+ "allstar[:10]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "## Plotting an HR Diagram (or Kiel Diagram) with APOGEE\n",
+ "\n",
+ "When characterizing stars, a useful plot is the *HR diagram*, which helps classify stars by their different types (for example, a star can be a Sun-like main sequence star or a massive Red Giant star). Let's plot an HR Diagram using APOGEE data. \n",
+ "\n",
+ "Traditional HR diagrams plot a star's *color* on the x-axis and its brightness (or *magnitude*) on the y-axis. For this excerise, we'll be using the star's *temperature* ($T_{eff}$) as a substitute for color and the surface gravity ($\\log g$) as a proxy for brightness. This variation on the HR diagram is technically called a Kiel Diagram, but they are very similar in appearance and interpretation."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Plot HR Diagram form APOGEE catalog\n",
+ "plt.figure(figsize=(10, 10))\n",
+ "\n",
+ "# Plot Temperature (TEFF) against surface gravity (LOGG)\n",
+ "# And color points by their metallicity (FE_H)\n",
+ "im = plt.scatter(allstar['TEFF'], allstar['LOGG'], c=allstar['FE_H'],\n",
+ " marker='.', s=1, zorder=1,\n",
+ " cmap='jet', vmin=-1, vmax=0.5)\n",
+ " \n",
+ "# Add colorbar legend to plot\n",
+ "plt.colorbar(im, location='bottom', label='Metallicity [Fe/H]')\n",
+ "\n",
+ " \n",
+ "# Labels and titles\n",
+ "plt.xlim(7000, 3000)\n",
+ "plt.ylim(5.5, -0.5)\n",
+ "plt.xlabel(r'Effective Temperature [$T_{\\rm{eff}}$, K]')\n",
+ "plt.ylabel(r'Surface Gravity [$\\log(g)$]')\n",
+ "plt.grid()\n",
+ "plt.title('APOGEE Stellar Parameters - allStar')\n",
+ "\n",
+ "plt.show()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "This is an HR Diagram made with APOGEE data! The Main Sequence stars are along the bottom, and the Red Giant Branch is in the upper-right portion. The Horizontal Branch stars are the upper-left group of dark blue (metal poor) points."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "# Searching for TESS Data of this Star\n",
+ "\n",
+ "Now let's search MAST for a light curve of our Cepheid Variable star.\n",
+ "\n",
+ "\n",
+ "## Coordinate search using astroquery.mast\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "# Retrieve RA and DEC of APOGEE star\n",
+ "ra = apogee_obs_list['s_ra'][0]\n",
+ "dec = apogee_obs_list['s_dec'][0]\n",
+ "# make a SkyCoord object from these coordinates\n",
+ "coord = SkyCoord(ra=ra*u.deg, dec=dec*u.deg)\n",
+ "print(coord)\n",
+ "\n",
+ "# Search for TESS observations based on coordinates\n",
+ "tess_obs = Observations.query_criteria(coordinates=coord, # Search by coordinates\n",
+ " radius=(1/60/60)*u.deg, # search within 1 arcsecond\n",
+ " # Search for TESS observations\n",
+ " obs_collection='TESS',\n",
+ " # Select only Science observations (not calibration files)\n",
+ " intentType='science',\n",
+ " # Search for time series data (light curves)\n",
+ " dataproduct_type='timeseries',\n",
+ " dataURL='*_lc.fits'\n",
+ " )\n",
+ "\n",
+ "# Display Results\n",
+ "tess_obs"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "There are a handful of results, but we can find the closest match to this star using the \"distance\" column which returns the distance (in arcsecs) of each match to our cone search. There are several results with distance of 0, (this star was observed in multiple TESS sectors), so we will just use the first result."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "tess_obs[np.argmin(tess_obs['distance'])]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "And download this file similar to what we did with APOGEE before:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Get product list\n",
+ "tess_products = Observations.get_product_list(tess_obs[np.argmin(tess_obs['distance'])])\n",
+ "\n",
+ "# Show products\n",
+ "tess_products"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Download Products\n",
+ "manifest = Observations.download_products(tess_products, description='Light curves')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "# Plotting a light curve from TESS \n",
+ "\n",
+ "The TESS light curve file has three extensions:\n",
+ "- The primary header (HDU0)\n",
+ "- The light curve data (HDU1)\n",
+ "- aperture Information (HDU2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Open file\n",
+ "tess_lc = fits.open(manifest['Local Path'][0])\n",
+ "\n",
+ "# Print file information\n",
+ "tess_lc.info()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We can plot the light curve by using the `TIME` and `SAP_FLUX` data from the first extension:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "plt.figure(figsize=(15, 5))\n",
+ "\n",
+ "# Plot the observed spectrum\n",
+ "plt.plot(tess_lc['LIGHTCURVE'].data['TIME'], tess_lc['LIGHTCURVE'].data['SAP_FLUX'], c='k', label='TESS Light Curve')\n",
+ "\n",
+ "# Plot a vertical line for every day\n",
+ "for i in range(int(np.nanmin(tess_lc['LIGHTCURVE'].data['TIME'])), int(np.nanmax(tess_lc['LIGHTCURVE'].data['TIME']))):\n",
+ " plt.axvline(i, c='lightgrey')\n",
+ " \n",
+ "# Set labels\n",
+ "plt.title(f\"TESS-SPOC Light Curve - {tess_lc[0].header['OBJECT']}\")\n",
+ "plt.xlabel('Time [BTJD]')\n",
+ "plt.ylabel('Flux')\n",
+ "plt.grid()\n",
+ "\n",
+ "plt.show()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "This is a very typical light curve for a Cepheid Variable star, and TESS observed the variations in flux really well! This star cycles over a period of about 6 days."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "# Combining APOGEE and TESS data\n",
+ "\n",
+ "Now we are ready to combine everything: the HR Diagram, the spectrum, and the TESS light curve into a single plot!\n",
+ "\n",
+ "\n",
+ "## Plotting APOGEE and TESS data together\n",
+ "\n",
+ "In the below cell, we define a helper function to plot all of the data together for our Cepheid Variable star:\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def plot_spectrum_and_lc(apogee_spec, tess_lightcurve):\n",
+ " \"\"\"Helper function for plotting the HR Diagram, APOGEE Spectrum, and TESS Light Curve for a star\"\"\"\n",
+ " # Set up axes for subplots\n",
+ " plt.figure(figsize=(20, 10))\n",
+ " ax1 = plt.subplot2grid((3, 5), (0, 0), colspan=2, rowspan=3)\n",
+ " ax2 = plt.subplot2grid((3, 5), (0, 2), colspan=3, rowspan=1)\n",
+ " ax3 = plt.subplot2grid((3, 5), (1, 2), colspan=3, rowspan=1)\n",
+ " \n",
+ " # ===================\n",
+ " # AX1 - HR Diagram\n",
+ " # ===================\n",
+ " # Plot HR Diagram form APOGEE catalog\n",
+ " # Only plot 1 out of every 10 points with [::10] to reduce plotting time\n",
+ " im = ax1.scatter(allstar['TEFF'][::10], allstar['LOGG'][::10], c=allstar['FE_H'][::10],\n",
+ " marker='.', s=1, cmap='jet', vmin=-1, vmax=0.5, zorder=1)\n",
+ " \n",
+ " plt.colorbar(im, ax=ax1, location='bottom', label='Metallicity [Fe/H]')\n",
+ " \n",
+ " # Plot the specific star\n",
+ " indx = np.where(allstar['APOGEE_ID'] == apogee_spec[4].data['APOGEE_ID'][0])[0][0]\n",
+ " if allstar['TEFF'][indx]: # if the star has valid apogee parameters\n",
+ " ax1.scatter(allstar['TEFF'][indx], allstar['LOGG'][indx], c=allstar['FE_H'][indx],\n",
+ " marker='*', s=1000, cmap='jet', edgecolor='k', lw=2,\n",
+ " vmin=-1, vmax=0.5, zorder=5, label='APOGEE Parameters')\n",
+ " else: # params from aspcapstar (uncalibrated)\n",
+ " print('WARNING: Quality Warning Flags on ASPCAP star parameters. ASPCAP parameters may not be reliable for this star.')\n",
+ " ax1.scatter(apogee_spec[4].data['FPARAM'][0][0], apogee_spec[4].data['FPARAM'][0][1], c=apogee_spec[4].data['FPARAM'][0][3],\n",
+ " marker='*', s=1000, cmap='jet', edgecolor='k', lw=2, vmin=-1, vmax=0.5, zorder=5, label='APOGEE Parameters')\n",
+ " \n",
+ " # Labels and titles\n",
+ " ax1.set_xlim(7000, 3000)\n",
+ " ax1.set_ylim(5.5, -0.5)\n",
+ " ax1.set_xlabel(r'Effective Temperature [$T_{\\rm{eff}}$, K]')\n",
+ " ax1.set_ylabel(r'Surface Gravity [$\\log(g)$]')\n",
+ " ax1.grid()\n",
+ " ax1.set_title('APOGEE Stellar Parameters - allStar')\n",
+ " \n",
+ " # ===================\n",
+ " # AX2 - APOGEE Spectrum\n",
+ " # =================== \n",
+ " # Get the observed and model flux from extensions 1 and 3\n",
+ " observed_flux = apogee_spec[1].data\n",
+ " model_flux = apogee_spec[3].data\n",
+ " \n",
+ " # Mask the data using the error array in extenion 2\n",
+ " pixel_mask = (apogee_spec[2].data < 0.1) # use only pixels with small errors (10% or less)\n",
+ " \n",
+ " # Plot the observed spectrum\n",
+ " ax2.plot(apogee_wls[pixel_mask], observed_flux[pixel_mask], c='k', label='Observed Spectrum')\n",
+ " \n",
+ " # Plot the model spectrum\n",
+ " ax2.plot(apogee_wls[pixel_mask], model_flux[pixel_mask], c='darkred', label='Best Fit Model Spectrum')\n",
+ " \n",
+ " # Set axes limits\n",
+ " ax2.set_ylim(0.6, 1.1)\n",
+ " ax2.set_xlim(np.min(apogee_wls), np.max(apogee_wls))\n",
+ " \n",
+ " apogee_id = apogee_spec[4].data['APOGEE_ID'][0] # String containing star's name\n",
+ " ax2.set_title(f\"APOGEE Spectrum - {apogee_id}\")\n",
+ " ax2.set_xlabel(r'Wavelength [$\\AA$]')\n",
+ " ax2.set_ylabel('Flux')\n",
+ " ax2.grid()\n",
+ " ax2.legend()\n",
+ " \n",
+ " # ===================\n",
+ " # AX3 - TESS Light Curve\n",
+ " # ===================\n",
+ " # Plot Light Curve\n",
+ " ax3.plot(tess_lightcurve['LIGHTCURVE'].data['TIME'], tess_lightcurve['LIGHTCURVE'].data['SAP_FLUX'], c='k', label='TESS Light Curve')\n",
+ " \n",
+ " # Plot a vertical line for every day\n",
+ " for i in range(int(np.nanmin(tess_lightcurve['LIGHTCURVE'].data['TIME'])), int(np.nanmax(tess_lightcurve['LIGHTCURVE'].data['TIME']))):\n",
+ " ax3.axvline(i, c='lightgrey')\n",
+ " \n",
+ " # Set labels\n",
+ " ax3.set_title(f\"TESS-SPOC Light Curve - {tess_lightcurve[0].header['OBJECT']}\")\n",
+ " ax3.set_xlabel('Time [BTJD]')\n",
+ " ax3.set_ylabel('Flux')\n",
+ " ax3.grid()\n",
+ " \n",
+ " plt.tight_layout()\n",
+ " save_name = f\"{apogee_id}_APOGEE_spec_TESS_lightcurve.png\"\n",
+ " plt.savefig(save_name, bbox_inches='tight')\n",
+ " print(f\"Saved to {save_name}\")\n",
+ " plt.show()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "aspcap_star = fits.open('mastDownload/SDSS/sdss_apogee_apo1m_cepheid_v1154_cyg/aspcapStar-dr17-V1154_Cyg.fits')\n",
+ "tess_lc = fits.open(manifest['Local Path'][0])\n",
+ "\n",
+ "plot_spectrum_and_lc(aspcap_star, tess_lc)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Like we saw before, this star is a metal-poor horiztonal branch star, and has a period of about 6 days. A very cool example of a Cepheid Variable!"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "\n",
+ "## Exploring different types of Variable Stars\n",
+ "\n",
+ "So far in this notebook, we've plotted the stellar parameters, spectrum, and light curve of a Cepheid variable star. But what about other types of variables? Here are a few more stars in APOGEE that we will explore and plot in this section!\n",
+ "\n",
+ "* 2M11361176+8117369: a RR Lyrae Variable Star, a type of quickly-pulsating old, low-mass star\n",
+ "* 2M19181706+5141323: a \"Rotationally Variable\" Star, a main sequence dwarf star with large starspots blocking out some of the flux on one side of the star as it rotates\n",
+ "* 2M19223768+5044541: an Eclipsing Binary Star, a type of close binary system with two stars rotating around each other\n",
+ "\n",
+ "Since we're going to be going through the same process for each star (search for APOGEE data -> search for TESS data -> plot results), Let's write a helper function:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def plot_variable_star(apogee_id: str) -> None:\n",
+ " \"\"\"\n",
+ " This function takes a star name from APOGEE and downloads the APOGEE and TESS\n",
+ " data for this star. It then plots the APOGEE spectrum and TESS Lightcurve together.\n",
+ "\n",
+ " Parameters:\n",
+ " ============\n",
+ " apogee_id: str\n",
+ " name of star we want to plot\n",
+ " \"\"\"\n",
+ " print(\"=\"*50)\n",
+ " print(f\"Plotting Spectrum and Light Curve for {apogee_id}\")\n",
+ " print(\"=\"*50)\n",
+ "\n",
+ " # Search for APOGEE Data\n",
+ " print(\"Searching For APOGEE Data...\")\n",
+ " apogee_obs_list = Observations.query_criteria(provenance_name='APOGEE',\n",
+ " target_name=apogee_id)\n",
+ " print(\"Downloading APOGEE Data...\")\n",
+ " # Download APOGEE Spectrum\n",
+ " product_list = Observations.get_product_list(apogee_obs_list)\n",
+ " manifest = Observations.download_products(product_list, productSubGroupDescription='ASPCAPSTAR')\n",
+ " # Open APOGEE Spectrum\n",
+ " aspcapstar = fits.open(manifest['Local Path'][0])\n",
+ "\n",
+ " # Coordinates of Star\n",
+ " coord = SkyCoord(ra=apogee_obs_list['s_ra'][0]*u.deg, dec=apogee_obs_list['s_dec'][0]*u.deg)\n",
+ "\n",
+ " # Search for TESS observations based on coordinates\n",
+ " print(\"Searching For TESS Data...\")\n",
+ " tess_obs = Observations.query_criteria(coordinates=coord, # Search by coordinates\n",
+ " radius=(1/60/60)*u.deg, # search within 1 arcsecond\n",
+ " obs_collection='TESS', # Search for TESS observations\n",
+ " intentType='science', # Select only Science observations (not calibration files)\n",
+ " dataproduct_type='timeseries', dataURL=\"*lc.fits\") # Search for time series data (light curves)\n",
+ "\n",
+ " # Pick closest match by distance\n",
+ " tess_obs = tess_obs[np.argmin(tess_obs['distance'])]\n",
+ "\n",
+ " # Download TESS Light Curve\n",
+ " print(\"Downloading TESS Data...\")\n",
+ " tess_products = Observations.get_product_list(tess_obs)\n",
+ " manifest = Observations.download_products(tess_products, description='Light curves')\n",
+ "\n",
+ " # Open light curve\n",
+ " tess_lc = fits.open(manifest['Local Path'][0])\n",
+ "\n",
+ " # Plot star\n",
+ " print(\"Making Plot...\")\n",
+ " plot_spectrum_and_lc(aspcapstar, tess_lc) "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "## RR Lyrae Variable - 2M11361176+8117369"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Define the star name we want to search for\n",
+ "star_name = '2M11361176+8117369'\n",
+ "# Call our helper function to download data and plot the results\n",
+ "plot_variable_star(star_name)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "This star is also a horizontal branch star, but it is hotter and more metal-poor than the Cepheid Variable was. It pulsates a lot more quickly too - from the light curve, the pulsation period is about 12 hours!"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "## Rotationally Variable - 2M19181706+5141323 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "star_name = '2M19181706+5141323'\n",
+ "plot_variable_star(star_name)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "This star is a main-sequence dwarf star, a lot like the Sun but a little bit cooler in temperature. Its light curve is not as periodic as the other two, because the variation in flux is caused by the stars rotation, not pulsation! Large star spots likely block out the flux on part of this star, causing it to dip in brightness roughly every 14 days."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "## Eclipsing Binary Star - 2M19203184+3830492"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "star_name = '2M19203184+3830492'\n",
+ "plot_variable_star(star_name)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Every few days, this star's flux dips dramatically in brightness by over 25%! This system is an eclipsing binary pair - a pair of stars orbiting around each other, and eclipsing one another along our line-of-sight, causing the fluctuations in brightness seen in the light curve. \n",
+ "\n",
+ "Because this is an eclipsing binary pair, the ASPCAP parameters have a quality warning and may not be as reliable as the parameter estimates for other stars (which explains why the star is slightly off of the main sequence in the HR Diagram!). The single visit spectra (apVisit files) are probably more useful for most science cases involving binary stars than the combined spectrum (aspcapStar file) we plotted here. The apVisit files can be dowloaded using the `productSubGroupDescription='APVISIT'` keyword when downloading the products."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "***\n",
+ "Congratulations! You have reached the end of this tutorial notebook. You have learned how to access and download APOGEE data from MAST, and combine it with TESS light curves to characterize different types of variable stars."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "\n",
+ "# Additional Resources\n",
+ "\n",
+ "Additional resources are linked below:\n",
+ "\n",
+ "- [SDSS Legacy Archive at MAST](https://outerspace.stsci.edu/display/SDSS/The+SDSS+Legacy+Archive+at+MAST)\n",
+ "- [SDSS-IV APOGEE Survey](https://www.sdss4.org/dr17/irspec/)\n",
+ "- [astroquery.mast User Manual](https://astroquery.readthedocs.io/en/latest/mast/mast.html)\n",
+ "- [MAST API](https://mast.stsci.edu/api/v0/index.html)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Citations\n",
+ "\n",
+ "\n",
+ "If you use MaNGA data for published research, see the following links for information on which citations to include in your paper:\n",
+ "\n",
+ "* [Citing SDSS](https://sdss.org/collaboration/citing-sdss/)\n",
+ "* [Citing APOGEE](https://www.sdss4.org/dr17/irspec/technical-papers-and-additional-references/)\n",
+ "* [Citing MAST](https://archive.stsci.edu/publishing/mission-acknowledgements)\n",
+ "* [Citing astropy](https://www.astropy.org/acknowledging.html)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "## About this Notebook\n",
+ "\n",
+ "\n",
+ "\n",
+ "**Author(s):** Julie Imig (jimig@stsci.edu)
\n",
+ "**Keyword(s):** Tutorial, SDSS, APOGEE, TESS, stars
\n",
+ "**First published:** January 2025
\n",
+ "**Last updated:** January 2025
\n",
+ "\n",
+ "***\n",
+ "[Top of Page](#top)\n",
+ " "
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "sdss",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.11.10"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4
+}
diff --git a/notebooks/SDSS/APOGEE_TESS_tutorial/requirements.txt b/notebooks/SDSS/APOGEE_TESS_tutorial/requirements.txt
new file mode 100644
index 000000000..19d90bdd2
--- /dev/null
+++ b/notebooks/SDSS/APOGEE_TESS_tutorial/requirements.txt
@@ -0,0 +1,4 @@
+astropy >= 5.3
+astroquery @ git+https://github.com/astropy/astroquery@main
+matplotlib >= 3.9.1
+numpy >= 1.26.4
diff --git a/notebooks/SDSS/MaNGA_HST_tutorial/MaNGA_HST_tutorial.ipynb b/notebooks/SDSS/MaNGA_HST_tutorial/MaNGA_HST_tutorial.ipynb
index 69fd9fb3d..897716a9a 100644
--- a/notebooks/SDSS/MaNGA_HST_tutorial/MaNGA_HST_tutorial.ipynb
+++ b/notebooks/SDSS/MaNGA_HST_tutorial/MaNGA_HST_tutorial.ipynb
@@ -51,7 +51,7 @@
"## Introduction\n",
"\n",
"\n",
- "The [Mapping Nearby Galaxies at Apache Point Observatory (MaNGA)](https://www.sdss4.org/surveys/manga/) survey provides optical-wavelength integral field unit (IFU) spectroscopy for over 10,000 nearby galaxies. MaNGA collected data between 2014 - 2020 as part of the [Sloan Digital Sky Survey (SDSS-IV) project](https://www.sdss4.org). MaNGA data is now available at the [Mikulski Archive for Space Telescopes (MAST)](https://www.sdss4.org/) through the [SDSS Legacy Archive at MAST](https://outerspace.stsci.edu/display/SDSS/The+SDSS+Legacy+Archive+at+MAST). \n",
+ "The [Mapping Nearby Galaxies at Apache Point Observatory (MaNGA)](https://www.sdss4.org/surveys/manga/) survey provides optical-wavelength integral field unit (IFU) spectroscopy for over 10,000 nearby galaxies. MaNGA collected data between 2014 - 2020 as part of the [Sloan Digital Sky Survey (SDSS-IV) project](https://www.sdss4.org). MaNGA data is now available at the [Mikulski Archive for Space Telescopes (MAST)](https://archive.stsci.edu) through the [SDSS Legacy Archive at MAST](https://outerspace.stsci.edu/display/SDSS/The+SDSS+Legacy+Archive+at+MAST). \n",
"\n",
"In this notebook tutorial, we will demonstrate how to access MaNGA data at MAST using Python. One MaNGA observation, an interacting galaxy pair named `MaNGA 7443-12703` will be used to demonstrate the basics of how to download and plot MaNGA data. We will then combine this MaNGA data with HST observations, also accessible from MAST, to study this galaxy pair in detail, exploring how its gas and stars are moving as the galaxies merge together."
]
diff --git a/notebooks/SDSS/sdss.md b/notebooks/SDSS/sdss.md
index 880d04e3e..33f3410c9 100644
--- a/notebooks/SDSS/sdss.md
+++ b/notebooks/SDSS/sdss.md
@@ -1,10 +1,10 @@
# Sloan Digital Sky Survey (SDSS)
## What is SDSS?
-The Sloan Digital Sky Survey (SDSS) is an international collaboration producing wide-field imaging and high-resolution spectroscopic surveys since 1998. The [SDSS Legacy Archive](https://archive.stsci.edu/missions-and-data/sdss) is the collection of science-ready SDSS data which is hosted at MAST. This includes images, spectra, catalogs and Value Added Catalogs (VACs) from all public SDSS data releases DR 1-22.
+The Sloan Digital Sky Survey (SDSS) is an international collaboration producing wide-field imaging and high-resolution spectroscopic surveys since 1998. The [SDSS Legacy Archive at MAST](https://archive.stsci.edu/missions-and-data/sdss) is the collection of science-ready SDSS data which is hosted at MAST. This includes images, spectra, catalogs and Value Added Catalogs (VACs) from all public SDSS data releases through SDSS-V.
## For Further Reading
-The [SDSS Legacy Archive User Manual](https://outerspace.stsci.edu/display/SDSS/The+SDSS+Legacy+Archive+at+MAST) website contains summary information, data product overviews, descriptions of MAST tools, and tutorials on how to interact with SDSS data at MAST.
+The [SDSS Legacy Archive at MAST User Manual](https://outerspace.stsci.edu/display/SDSS/The+SDSS+Legacy+Archive+at+MAST) website contains summary information, data product overviews, descriptions of MAST tools, and tutorials on how to interact with SDSS data at MAST.
For more general information relating to SDSS, the documentation is available at [www.sdss.org](https://www.sdss.org)
@@ -15,6 +15,7 @@ For more general information relating to SDSS, the documentation is available at
| Notebook | Description |
|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [MaNGA HST Tutorial](https://github.com/spacetelescope/mast_notebooks/blob/main/notebooks/SDSS/MaNGA_HST_tutorial/MaNGA_HST_tutorial.ipynb) | Tutorial for how to search and download MaNGA data at MAST using `astroquery.mast`. Combines H-alpha emission maps from MaNGA and images from HST to make galaxy maps for for interacting galaxy pair Mrk-848B. |
+| [APOGEE TESS Tutorial](https://github.com/spacetelescope/mast_notebooks/blob/main/notebooks/SDSS/APOGEE_TESS_tutorial/APOGEE_TESS_tutorial.ipynb) | Tutorial for how to search and download APOGEE data at MAST using `astroquery.mast`. Combines infrared spectra from APOGEE and corresponding lightcurves from TESS to characterize different types of variable stars. |
More SDSS notebooks will be coming soon!