Creating a Color-Magnitude Diagram for Messier 13#


Learning Goals#

By the end of this tutorial, you will:

  • Understand how to use astroquery.mast to download the SDSS Legacy Imaging Survey Data from the MAST archive.

  • Plot a Color-Magnitude Diagram of Messier 13

  • Calculate the distance to Messier 13 using the Gaia catalog

  • Approximate the age of Messier 13 using stellar isochrones

Table of Contents#

  • Introduction

  • Imports

  • Accessing SDSS Legacy Imaging Survey Data from MAST

    • Querying SDSS Legacy Imaging Survey

    • Sampling SDSS Legacy Imaging Survey for M13

    • Downloading Data Products

    • Creating a Color-Magnitude Diagram

  • Finding the Distance to M13 Using Gaia

  • Determining the Age of M13 Using Stellar Isochrone Matching

  • End of Tutorial

  • Exercises

  • Exercise Solutions

  • Additional Resources

  • Citations

  • About this Notebook

Introduction#

The Hertzsprung-Russell (HR) Diagram was independently discovered by Ejnar Hertzsprung and Henry Norris Russell in the early 20th century. This diagram effectively plots a star’s theoretical luminosity against its temperature. By examining the position of stars on the HR diagram, we can infer stellar properties such as age, metallicity, or mass. An HR Diagram is also useful for tracking the life cycle of stars. Stars in their hydrogen-core burning phases evolve leftwards on the HR diagram. Eventually, they leave the main sequence to start their red giant phases and move upwards as they begin burning helium in their cores [1].

An observational variation of the HR Diagram is the Color-Magnitude Diagram (CMD), which uses color (a proxy for temperature) and magnitude (a proxy for luminosity). We can use photometric data from a star cluster to create a CMD, and then estimate the age by comparing the main sequence tracks and red giant branch to theoretical isochrones — curves that represent stars of the same age but with different masses, mapping their expected positions at various evolutionary stages. For example, an older cluster will have more stars on the red giant branch whereas a younger cluster will have more stars on the main sequence. The transition between the two evolutionary stages, called the Main Sequence Turn-Off, is the key to determining the age of a stellar cluster [2]

Color Magnitude Diagram for Globular Clusters
Color Magnitude Diagram for Global Clusters from L. Krauss and B. Chaboyer [3].

Messier 13 (M13) is a globular cluster located in the constellation Hercules [4]. M13 is estimated to contain over 100,000 stars with a total metallicity ([Fe/H]) of approximately -1.33 dex [5]. This is consistent with the ancient stellar populations found in other globular clusters [6].

In this notebook, we’ll estimate the age of M13 using photometric data from the Sloan Digital Sky Survey’s (SDSS) Legacy Imaging Survey and stellar isochrones from the PARSEC database [7]. By plotting isochrone tracks for a range of ages and comparing them to the observed stellar distribution of M13, we can identify the isochrone that best fits the cluster’s data and thereby estimate its age.

Imports#

The main packages and their use-cases in this tutorial are as follows:

  • numpy to handle array functions

  • matplotlib.pyplot for plotting data

  • matplotlib.image for displaying .jpg images

  • astroquery.mast.Observations to access SDSS data from MAST

  • astroquery.mast.Catalogs to access data Gaia data from MAST

  • pandas to handle large data tables

  • astropy.io.fits for accessing FITS files

%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

from astroquery.mast import Observations
from astroquery.mast import Catalogs
import pandas as pd
import astropy.io.fits as fits

If you’re not sure if you have the required versions of packages installed on your device, you can run the following cell:

with open("requirements.txt") as f:
    print(f"Required packages for this notebook:\n{f.read()}")
Required packages for this notebook:
pandas >= 2.3.0
astroquery >= 0.4.9
matplotlib >= 3.9.1
numpy >= 1.26.4

To ensure these requirements are installed, you can run the following command in the terminal:

pip install -r requirements.txt

Accessing SDSS Legacy Imaging Survey Data from MAST#

The Mikulski Archive for Space Telescopes (MAST) hosts a large array of data from several telescope missions. In this tutorial, we will be specifically focusing on data from the Sloan Digital Sky Survey’s (SDSS) Imaging Survey.

The SDSS Legacy Imaging Survey was the first SDSS survey completed! Beginning in 1998, the SDSS Legacy Imaging Survey captured around 35,000 square degrees of images until 2009, which covers about one-third of the whole sky. To do this, the survey took millions of 10 by 13 arcminute pictures (called “fields”). Not only does the SDSS Legacy Imaging Survey data at MAST provide users with preview images in .jpg format, but it also has photometric data in all five broad band SDSS filters (u, g, r, i, and z). For more information about the data and products from the SDSS Legacy Imaging Survey, you can check out the SDSS Imaging Archive Manual.

Querying SDSS Legacy Imaging Survey#

You can query data from MAST using the website portal. You can also query MAST data in Python using the package astroquery.mast!

We can query all of the SDSS Legacy Imaging data using Observations.query_criteria with provenance_name = "SDSS Legacy Imaging". Since there is a large amount of data in the SDSS Legacy Imaging archive, we can display the first 10 results using the pagesize parameter as well as the page parameter.

# Querying SDSS Legacy Imaging
imaging_data = Observations.query_criteria(
    provenance_name="SDSS Legacy Imaging", pagesize=10, page=1
)

# Display first 10 entries
imaging_data
Table masked=True length=10
intentTypeobs_collectionprovenance_nameinstrument_nameprojectfilterswavelength_regiontarget_nametarget_classificationobs_ids_ras_decdataproduct_typeproposal_picalib_levelt_mint_maxt_exptimeem_minem_maxobs_titlet_obs_releaseproposal_idproposal_typesequence_numbers_regionjpegURLdataURLdataRightsmtFlagsrcDenobsidobjID
str7str4str19str11str4str9str7str13str5str24float64float64str5str18int64float64float64float64float64float64str51float64str3str1int64str200str61str61str6boolfloat64str9str9
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL002078-3-0167FIELDsdss_image_002078-3-0167206.69554325763.0177013205imageSDSS Collaboration351935.4772883101851935.4812292529653.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 206.44311934985296 62.93879497802275 206.60833150811592 63.15105421719121 206.94925014740446 63.096052132725326 206.7818799496204 62.884191693001185 206.44311934985296 62.93879497802275mast:SDSS/sdss/imaging/2078/3/167/frame-irg-002078-3-0167.jpgmast:SDSS/sdss/imaging/2078/3/167/photoObj-002078-3-0167.fitsPUBLICFalsenan298343609885416481
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL002194-1-0285FIELDsdss_image_002194-1-0285152.869657846-3.2755938384imageSDSS Collaboration351988.1928664351951988.19680726222653.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 152.78511234273577 -3.3862528729608115 152.79033624075242 -3.1612357507592015 152.95418212658387 -3.165037614161347 152.94899504029814 -3.390055585629325 152.78511234273577 -3.3862528729608115mast:SDSS/sdss/imaging/2194/1/285/frame-irg-002194-1-0285.jpgmast:SDSS/sdss/imaging/2194/1/285/photoObj-002194-1-0285.fitsPUBLICFalsenan298343610885416492
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL005225-5-0133FIELDsdss_image_005225-5-0133184.64505677620.7327234172imageSDSS Collaboration353462.3384637731553462.3424047159353.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 184.55788662645972 20.61993841643831 184.5572477241854 20.845030007654525 184.73235708474328 20.845354482055942 184.7327357839082 20.620262376381806 184.55788662645972 20.61993841643831mast:SDSS/sdss/imaging/5225/5/133/frame-irg-005225-5-0133.jpgmast:SDSS/sdss/imaging/5225/5/133/photoObj-005225-5-0133.fitsPUBLICFalsenan298343611885416506
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL004858-6-0249FIELDsdss_image_004858-6-0249344.2415093211.15381316275imageSDSS Collaboration353272.2786252314853272.282566868753.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 344.15965958456337 1.041212092866372 344.1596943026822 1.2663112299621455 344.3233655138016 1.2663019133447613 344.323317845429 1.0412027786177585 344.15965958456337 1.041212092866372mast:SDSS/sdss/imaging/4858/6/249/frame-irg-004858-6-0249.jpgmast:SDSS/sdss/imaging/4858/6/249/photoObj-004858-6-0249.fitsPUBLICFalsenan298343612885416514
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL002582-6-0205FIELDsdss_image_002582-6-0205268.97007844758.7101198185imageSDSS Collaboration352172.1686777777852172.1726190677853.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 268.73357713748663 58.77581547331432 269.1640050891814 58.806194348537204 269.20547666561987 58.643978106272655 268.77701141158826 58.613740457077064 268.73357713748663 58.77581547331432mast:SDSS/sdss/imaging/2582/6/205/frame-irg-002582-6-0205.jpgmast:SDSS/sdss/imaging/2582/6/205/photoObj-002582-6-0205.fitsPUBLICFalsenan298343613885416525
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL002334-5-0055FIELDsdss_image_002334-5-0055204.099321966-1.62845725617imageSDSS Collaboration352053.2414303240752053.2453712668553.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 204.0190907036801 -1.7421845537130678 204.0158750814634 -1.517165110030603 204.1795457533824 -1.5148366936051512 204.1827796471254 -1.7398558755962128 204.0190907036801 -1.7421845537130678mast:SDSS/sdss/imaging/2334/5/55/frame-irg-002334-5-0055.jpgmast:SDSS/sdss/imaging/2334/5/55/photoObj-002334-5-0055.fitsPUBLICFalsenan298343614885416535
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL004458-3-0015FIELDsdss_image_004458-3-0015114.26439683415.342802083imageSDSS Collaboration353051.24212731481453051.2460683733353.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 114.26777710700871 15.203657689382686 114.12614582383821 15.382482137913923 114.26108127887179 15.481859046974169 114.40266436479314 15.302949517900048 114.26777710700871 15.203657689382686mast:SDSS/sdss/imaging/4458/3/15/frame-irg-004458-3-0015.jpgmast:SDSS/sdss/imaging/4458/3/15/photoObj-004458-3-0015.fitsPUBLICFalsenan298343615885416541
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL004010-4-0246FIELDsdss_image_004010-4-0246249.2109582218.5875365301imageSDSS Collaboration352815.24729942129552815.25124071129553.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 249.07365681145677 18.538175418201423 249.20380147756816 18.7264812331994 249.3482754372224 18.636706257135376 249.2180397462069 18.448499593172688 249.07365681145677 18.538175418201423mast:SDSS/sdss/imaging/4010/4/246/frame-irg-004010-4-0246.jpgmast:SDSS/sdss/imaging/4010/4/246/photoObj-004010-4-0246.fitsPUBLICFalsenan298343616885416559
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL004576-1-0139FIELDsdss_image_004576-1-0139133.64614242222.3292231629imageSDSS Collaboration353111.17782627314653111.1817675631553.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 133.62163699433665 22.191910213846533 133.5125232652787 22.393027904369976 133.6707494372974 22.466434137733156 133.77969244300363 22.26521068958443 133.62163699433665 22.191910213846533mast:SDSS/sdss/imaging/4576/1/139/frame-irg-004576-1-0139.jpgmast:SDSS/sdss/imaging/4576/1/139/photoObj-004576-1-0139.fitsPUBLICFalsenan298343617885416566
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL008111-5-0027FIELDsdss_image_008111-5-0027350.59087365432.2052009672imageSDSS Collaboration355121.3594901620455121.3634313362953.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 350.51286706932166 32.08266403669717 350.47716434729176 32.3056892175588 350.66910789936856 32.327580899664774 350.70434905996353 32.104502194976256 350.51286706932166 32.08266403669717mast:SDSS/sdss/imaging/8111/5/27/frame-irg-008111-5-0027.jpgmast:SDSS/sdss/imaging/8111/5/27/photoObj-008111-5-0027.fitsPUBLICFalsenan298343618885416583

The table above provides some basic information for each object:

  • instrument_name: SDSS Camera indicates that the imaging data were collected using the SDSS camera.

  • filters: Indicates the SDSS filters used in the survey (u, g, r, i, and z).

  • wavelength_region: Indicates the region of the electromagnetic spectrum observed. This should be OPTICAL, since the SDSS Legacy Imaging Survey observed in the optical wavelength range.

  • target_classification: FIELD indicates the survey captured images of the sky.

  • obs_id: Observation ID associated with the image.

  • s_ra and s_dec: Right ascension and declination.

  • dataproduct_type: This should be image since we’re focusing on an imaging survey.

  • t_min and t_max: The modified Julian dates indicating the start and end times of the exposures.

  • em_min and em_max: The minimum and maximum wavelengths observed by the survey. For the SDSS Legacy Imaging survey, this range is approximately 304.8 - 1083.3 nanometers (optical).

Sampling SDSS Legacy Imaging Survey for M13#

In this tutorial, we will be gathering g-band and r-band magnitudes of stars in M13 measured by the SDSS Legacy Imaging survey by querying and downloading data through MAST. We’ll plot these on a CMD where the apparent r-band magnitude is on the y-axis, and color (g-band minus r-band) is on the x-axis. We’ll later plot this CMD with a CMD of isochrones from the PARSEC database.

For the purpose of this tutorial, we will only focus on querying by object name. We can query the SDSS Legacy Imaging Survey for M13 data using objectname="M13".

# Querying SDSS Legacy Imaging for M13
obs_table = Observations.query_criteria(
    objectname="M13", provenance_name="SDSS Legacy Imaging"
)

# Displaying the table
obs_table
Table masked=True length=17
intentTypeobs_collectionprovenance_nameinstrument_nameprojectfilterswavelength_regiontarget_nametarget_classificationobs_ids_ras_decdataproduct_typeproposal_picalib_levelt_mint_maxt_exptimeem_minem_maxobs_titlet_obs_releaseproposal_idproposal_typesequence_numbers_regionjpegURLdataURLdataRightsmtFlagsrcDenobsidobjIDobjID1distance
str7str4str19str11str4str9str7str13str5str24float64float64str5str18int64float64float64float64float64float64str51float64str3str1int64str195str61str61str6boolfloat64str9str9str9float64
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL003226-5-0126FIELDsdss_image_003226-5-0126250.39386698136.6493290806imageSDSS Collaboration352434.3849324074152434.3888732344453.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.22044996940195 36.64428282774371 250.44154003131922 36.7830573250709 250.5671980243839 36.65405635086531 250.34625148107756 36.51551412556894 250.22044996940195 36.64428282774371mast:SDSS/sdss/imaging/3226/5/126/frame-irg-003226-5-0126.jpgmast:SDSS/sdss/imaging/3226/5/126/photoObj-003226-5-0126.fitsPUBLICFalsenan295131553872834007872834007291.37717938143663
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL003225-5-0265FIELDsdss_image_003225-5-0265250.77269734336.5988511392imageSDSS Collaboration352434.2869163194452434.2908577251953.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.59946781174085 36.59430692699014 250.82094276799123 36.732493216455595 250.945838402895 36.603077335526315 250.72451085188032 36.46512219070452 250.59946781174085 36.59430692699014mast:SDSS/sdss/imaging/3225/5/265/frame-irg-003225-5-0265.jpgmast:SDSS/sdss/imaging/3225/5/265/photoObj-003225-5-0265.fitsPUBLICFalsenan297955991881857628881857628695.9044368869569
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL002328-1-0077FIELDsdss_image_002328-1-0077250.53184989636.5546030081imageSDSS Collaboration352052.3804945601952052.3844357344453.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.35859561201013 36.5540642416826 250.5849169880205 36.68707104123642 250.7049953700791 36.55482636287762 250.47885415962534 36.422046570943465 250.35859561201013 36.5540642416826mast:SDSS/sdss/imaging/2328/1/77/frame-irg-002328-1-0077.jpgmast:SDSS/sdss/imaging/2328/1/77/photoObj-002328-1-0077.fitsPUBLICFalsenan29513154187283315287283315245.926438874565356
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL003225-4-0263FIELDsdss_image_003225-4-0263250.13158156536.5763631387imageSDSS Collaboration352434.286086921352434.29002832703653.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 249.9584663869535 36.57087345241625 250.17866018972612 36.7102635461507 250.30461310469724 36.58153460434509 250.08455864103615 36.442376203777485 249.9584663869535 36.57087345241625mast:SDSS/sdss/imaging/3225/4/263/frame-irg-003225-4-0263.jpgmast:SDSS/sdss/imaging/3225/4/263/photoObj-003225-4-0263.fitsPUBLICFalsenan297954450881848318881848318552.7628408052574
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL003225-4-0264FIELDsdss_image_003225-4-0264250.24671045136.4586237958imageSDSS Collaboration352434.2865017361152434.2904431418553.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.07380618478217 36.45332038759552 250.29390605041334 36.59250454483102 250.4195301652173 36.463610007146634 250.19957027912378 36.32465655078415 250.07380618478217 36.45332038759552mast:SDSS/sdss/imaging/3225/4/264/frame-irg-003225-4-0264.jpgmast:SDSS/sdss/imaging/3225/4/264/photoObj-003225-4-0264.fitsPUBLICFalsenan29795520688185291888185291814.088016661483353
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL003206-5-0047FIELDsdss_image_003206-5-0047250.38348380436.6600485065imageSDSS Collaboration352424.3915314814852424.39547207703453.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.21006556260414 36.65497749936012 250.43111640889498 36.79378288075555 250.55681621645243 36.66480048402042 250.33590870037474 36.526227436667 250.21006556260414 36.65497749936012mast:SDSS/sdss/imaging/3206/5/47/frame-irg-003206-5-0047.jpgmast:SDSS/sdss/imaging/3206/5/47/photoObj-003206-5-0047.fitsPUBLICFalsenan298315987885162046885162046340.1997581534808
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL002328-1-0079FIELDsdss_image_002328-1-0079250.75095278736.3126609264imageSDSS Collaboration352052.3813239583352052.3852650168553.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.578252364172 36.31247050799863 250.80425448876198 36.44501655574568 250.92354299824817 36.312538406297975 250.69772164198693 36.180216970539945 250.578252364172 36.31247050799863mast:SDSS/sdss/imaging/2328/1/79/frame-irg-002328-1-0079.jpgmast:SDSS/sdss/imaging/2328/1/79/photoObj-002328-1-0079.fitsPUBLICFalsenan295131548872833580872833580698.8182536420179
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL003226-5-0128FIELDsdss_image_003226-5-0128250.62320208136.4133581779imageSDSS Collaboration352434.3857616898252434.3897024011153.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.45026832382496 36.40860979104661 250.67107742007923 36.547001839458886 250.79604843682253 36.417789795153695 250.57538360434452 36.27962787829743 250.45026832382496 36.40860979104661mast:SDSS/sdss/imaging/3226/5/128/frame-irg-003226-5-0128.jpgmast:SDSS/sdss/imaging/3226/5/128/photoObj-003226-5-0128.fitsPUBLICFalsenan295131561872834493872834493197.2958680603298
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL002328-1-0076FIELDsdss_image_002328-1-0076250.42176155936.6753974425imageSDSS Collaboration352052.3800799768552052.3840211511153.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.24825412597377 36.67468245014842 250.47469149264754 36.80794394562259 250.59516092735302 36.67579584579734 250.36890336174514 36.54276250299432 250.24825412597377 36.67468245014842mast:SDSS/sdss/imaging/2328/1/76/frame-irg-002328-1-0076.jpgmast:SDSS/sdss/imaging/2328/1/76/photoObj-002328-1-0076.fitsPUBLICFalsenan295131565872834928872834928333.0209007636813
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL003225-4-0266FIELDsdss_image_003225-4-0266250.47591260536.2228649182imageSDSS Collaboration352434.2873310185252434.29127242425653.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.3035437634285 36.217875087370984 250.52334971401882 36.35664194279063 250.6481953945402 36.22753993420965 250.42853037114884 36.08900145821686 250.3035437634285 36.217875087370984mast:SDSS/sdss/imaging/3225/4/266/frame-irg-003225-4-0266.jpgmast:SDSS/sdss/imaging/3225/4/266/photoObj-003225-4-0266.fitsPUBLICFalsenan297954617881849320881849320475.1195995236801
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL003225-4-0265FIELDsdss_image_003225-4-0265250.36149718636.340810178imageSDSS Collaboration352434.2869163194452434.2908577251953.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.18888442184692 36.33566994315121 250.4088170275986 36.47465028763916 250.53402462257387 36.34563447238449 250.31423253225782 36.20688359738639 250.18888442184692 36.33566994315121mast:SDSS/sdss/imaging/3225/4/265/frame-irg-003225-4-0265.jpgmast:SDSS/sdss/imaging/3225/4/265/photoObj-003225-4-0265.fitsPUBLICFalsenan2979546258818493688818493683.866197461580117
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL003206-5-0049FIELDsdss_image_003206-5-0049250.61289304336.4240856059imageSDSS Collaboration352424.39236076388652424.396301243753.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.43997310231262 36.41934331740604 250.66076727431061 36.557717739869794 250.78572556890498 36.42851114443372 250.5650757278609 36.29036684119189 250.43997310231262 36.41934331740604mast:SDSS/sdss/imaging/3206/5/49/frame-irg-003206-5-0049.jpgmast:SDSS/sdss/imaging/3206/5/49/photoObj-003206-5-0049.fitsPUBLICFalsenan298315923885161315885161315148.4875090756533
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL002328-1-0078FIELDsdss_image_002328-1-0078250.64157580236.4336890977imageSDSS Collaboration352052.38090937552052.3848504335253.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.46857394708124 36.433292936339456 250.69477708949267 36.56611004476571 250.81446826187815 36.43377099259526 250.58844552127275 36.30117975030792 250.46857394708124 36.433292936339456mast:SDSS/sdss/imaging/2328/1/78/frame-irg-002328-1-0078.jpgmast:SDSS/sdss/imaging/2328/1/78/photoObj-002328-1-0078.fitsPUBLICFalsenan295131545872833370872833370165.0330293374257
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL003226-5-0127FIELDsdss_image_003226-5-0127250.50870585236.5313775037imageSDSS Collaboration352434.3853471064852434.3892877020353.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.33553477042537 36.52648700305302 250.55648135804705 36.66507314658227 250.68179021520078 36.53595013848635 250.46098757081998 36.397595183888505 250.33553477042537 36.52648700305302mast:SDSS/sdss/imaging/3226/5/127/frame-irg-003226-5-0127.jpgmast:SDSS/sdss/imaging/3226/5/127/photoObj-003226-5-0127.fitsPUBLICFalsenan2951315578728342468728342460.0
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL003225-5-0264FIELDsdss_image_003225-5-0264250.65818345336.7170700025imageSDSS Collaboration352434.2865017361152434.2904431418553.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.48467210361827 36.712352507710065 250.7062922106185 36.8507365527109 250.8316071569812 36.72146825665738 250.61013383419206 36.58331657086478 250.48467210361827 36.712352507710065mast:SDSS/sdss/imaging/3225/5/264/frame-irg-003225-5-0264.jpgmast:SDSS/sdss/imaging/3225/5/264/photoObj-003225-5-0264.fitsPUBLICFalsenan297956572881861114881861114696.0625286367105
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL003206-5-0048FIELDsdss_image_003206-5-0048250.49836173136.5421282405imageSDSS Collaboration352424.3919460648252424.3958867761153.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.3251783392619 36.53722296813955 250.5460945557796 36.67581178341232 250.67145849499735 36.54671558141969 250.4506860481943 36.408358051183676 250.3251783392619 36.53722296813955mast:SDSS/sdss/imaging/3206/5/48/frame-irg-003206-5-0048.jpgmast:SDSS/sdss/imaging/3206/5/48/photoObj-003206-5-0048.fitsPUBLICFalsenan2983155448851575018851575010.0
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL003206-5-0050FIELDsdss_image_003206-5-0050250.72710563336.3059574758imageSDSS Collaboration352424.39277523148552424.3967162953.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 250.55442273973065 36.301364449432214 250.77506303756408 36.43955055679796 250.89970041241125 36.31023484630317 250.67920474779717 36.172277813761866 250.55442273973065 36.301364449432214mast:SDSS/sdss/imaging/3206/5/50/frame-irg-003206-5-0050.jpgmast:SDSS/sdss/imaging/3206/5/50/photoObj-003206-5-0050.fitsPUBLICFalsenan298315811885160096885160096687.4444027605829

From the query results, we can see that there are 17 SDSS fields that cover M13! The distance column shows how far each field is from the center of the cluster in arcseconds.

Downloading SDSS Legacy Imaging Survey Data Products#

For each image, there are 7 available products: The preview .jpg image, the FITS files in each respective SDSS filter (u, g, r, i, and z), and the full FITS file with all five filters combined. The full FITS file is listed as SDSS Imaging Catalogs for the productSubGroupDescription parameter.

For more information about products available at MAST, you can check out the SDSS Legacy Imaging Survey Documentation.

# Viewing available products
products = Observations.get_product_list(obs_table)
products
Table masked=True length=153
obsIDobs_collectiondataproduct_typeobs_iddescriptiontypedataURIproductTypeproductGroupDescriptionproductSubGroupDescriptionproductDocumentationURLprojectprvversionproposal_idproductFilenamesizeparent_obsiddataRightscalib_levelfilters
str9str4str12str28str246str1str64str7str28str21str48str19str3str3str30int64str9str6int64str9
295131541SDSSimagesdss_image_002328-1-0077Preview-FullSmast:SDSS/sdss/imaging/2328/1/77/frame-irg-002328-1-0077.jpgPREVIEW------SDSS Legacy ImagingDR8N/Aframe-irg-002328-1-0077.jpg1195118295131541PUBLIC3u;g;r;i;z
295131541SDSSimagesdss_image_002328-1-0077SDSS calibrated, sky-subtracted corrected photometry frame and associated calibration metadata for each run number, camera column, and field name within SDSS.Smast:SDSS/sdss/imaging/2328/1/77/frame-g-002328-1-0077.fits.bz2SCIENCEMinimum Recommended ProductsIMAGEhttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/Aframe-g-002328-1-0077.fits.bz23466198295131541PUBLIC2g
295131541SDSSimagesdss_image_002328-1-0077SDSS calibrated, sky-subtracted corrected photometry frame and associated calibration metadata for each run number, camera column, and field name within SDSS.Smast:SDSS/sdss/imaging/2328/1/77/frame-i-002328-1-0077.fits.bz2SCIENCEMinimum Recommended ProductsIMAGEhttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/Aframe-i-002328-1-0077.fits.bz23731895295131541PUBLIC2i
295131541SDSSimagesdss_image_002328-1-0077SDSS calibrated, sky-subtracted corrected photometry frame and associated calibration metadata for each run number, camera column, and field name within SDSS.Smast:SDSS/sdss/imaging/2328/1/77/frame-r-002328-1-0077.fits.bz2SCIENCEMinimum Recommended ProductsIMAGEhttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/Aframe-r-002328-1-0077.fits.bz23206091295131541PUBLIC2r
295131541SDSSimagesdss_image_002328-1-0077SDSS calibrated, sky-subtracted corrected photometry frame and associated calibration metadata for each run number, camera column, and field name within SDSS.Smast:SDSS/sdss/imaging/2328/1/77/frame-u-002328-1-0077.fits.bz2SCIENCEMinimum Recommended ProductsIMAGEhttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/Aframe-u-002328-1-0077.fits.bz23331655295131541PUBLIC2u
295131541SDSSimagesdss_image_002328-1-0077SDSS calibrated, sky-subtracted corrected photometry frame and associated calibration metadata for each run number, camera column, and field name within SDSS.Smast:SDSS/sdss/imaging/2328/1/77/frame-z-002328-1-0077.fits.bz2SCIENCEMinimum Recommended ProductsIMAGEhttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/Aframe-z-002328-1-0077.fits.bz23077494295131541PUBLIC2z
295131541SDSSimagesdss_image_002328-1-0077SDSS Legacy Imaging photoObj catalog. This contains the full, calibrated outputs of the SDSS Imaging Pipeline including source detection, classification, magnitude measurements, and quality flags for each field and all five filters in that field.Smast:SDSS/sdss/imaging/2328/1/77/photoObj-002328-1-0077.fitsSCIENCEMinimum Recommended ProductsSDSS Imaging Catalogshttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/AphotoObj-002328-1-0077.fits8640295131541PUBLIC3u;g;r;i;z
295131545SDSSimagesdss_image_002328-1-0078Preview-FullSmast:SDSS/sdss/imaging/2328/1/78/frame-irg-002328-1-0078.jpgPREVIEW------SDSS Legacy ImagingDR8N/Aframe-irg-002328-1-0078.jpg1150088295131545PUBLIC3u;g;r;i;z
295131545SDSSimagesdss_image_002328-1-0078SDSS calibrated, sky-subtracted corrected photometry frame and associated calibration metadata for each run number, camera column, and field name within SDSS.Smast:SDSS/sdss/imaging/2328/1/78/frame-g-002328-1-0078.fits.bz2SCIENCEMinimum Recommended ProductsIMAGEhttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/Aframe-g-002328-1-0078.fits.bz23251645295131545PUBLIC2g
............................................................
298436348SDSSmeasurementssdss_image_photorunallSDSS Legacy Imaging PhotoRunAll summary catalog. This contains observation dates, coordinates, run identifiers, and reference information for all photometric runs completed during the survey.Dmast:SDSS/sdss/imaging/photoRunAll-dr13.fitsSCIENCE--SDSS Imaging Catalogshttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/AphotoRunAll-dr13.fits187200297954450PUBLIC3--
298436348SDSSmeasurementssdss_image_photorunallSDSS Legacy Imaging PhotoRunAll summary catalog. This contains observation dates, coordinates, run identifiers, and reference information for all photometric runs completed during the survey.Dmast:SDSS/sdss/imaging/photoRunAll-dr13.fitsSCIENCE--SDSS Imaging Catalogshttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/AphotoRunAll-dr13.fits187200297954617PUBLIC3--
298436348SDSSmeasurementssdss_image_photorunallSDSS Legacy Imaging PhotoRunAll summary catalog. This contains observation dates, coordinates, run identifiers, and reference information for all photometric runs completed during the survey.Dmast:SDSS/sdss/imaging/photoRunAll-dr13.fitsSCIENCE--SDSS Imaging Catalogshttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/AphotoRunAll-dr13.fits187200297954625PUBLIC3--
298436348SDSSmeasurementssdss_image_photorunallSDSS Legacy Imaging PhotoRunAll summary catalog. This contains observation dates, coordinates, run identifiers, and reference information for all photometric runs completed during the survey.Dmast:SDSS/sdss/imaging/photoRunAll-dr13.fitsSCIENCE--SDSS Imaging Catalogshttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/AphotoRunAll-dr13.fits187200297955206PUBLIC3--
298436348SDSSmeasurementssdss_image_photorunallSDSS Legacy Imaging PhotoRunAll summary catalog. This contains observation dates, coordinates, run identifiers, and reference information for all photometric runs completed during the survey.Dmast:SDSS/sdss/imaging/photoRunAll-dr13.fitsSCIENCE--SDSS Imaging Catalogshttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/AphotoRunAll-dr13.fits187200297955991PUBLIC3--
298436348SDSSmeasurementssdss_image_photorunallSDSS Legacy Imaging PhotoRunAll summary catalog. This contains observation dates, coordinates, run identifiers, and reference information for all photometric runs completed during the survey.Dmast:SDSS/sdss/imaging/photoRunAll-dr13.fitsSCIENCE--SDSS Imaging Catalogshttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/AphotoRunAll-dr13.fits187200297956572PUBLIC3--
298436348SDSSmeasurementssdss_image_photorunallSDSS Legacy Imaging PhotoRunAll summary catalog. This contains observation dates, coordinates, run identifiers, and reference information for all photometric runs completed during the survey.Dmast:SDSS/sdss/imaging/photoRunAll-dr13.fitsSCIENCE--SDSS Imaging Catalogshttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/AphotoRunAll-dr13.fits187200298315544PUBLIC3--
298436348SDSSmeasurementssdss_image_photorunallSDSS Legacy Imaging PhotoRunAll summary catalog. This contains observation dates, coordinates, run identifiers, and reference information for all photometric runs completed during the survey.Dmast:SDSS/sdss/imaging/photoRunAll-dr13.fitsSCIENCE--SDSS Imaging Catalogshttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/AphotoRunAll-dr13.fits187200298315811PUBLIC3--
298436348SDSSmeasurementssdss_image_photorunallSDSS Legacy Imaging PhotoRunAll summary catalog. This contains observation dates, coordinates, run identifiers, and reference information for all photometric runs completed during the survey.Dmast:SDSS/sdss/imaging/photoRunAll-dr13.fitsSCIENCE--SDSS Imaging Catalogshttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/AphotoRunAll-dr13.fits187200298315923PUBLIC3--
298436348SDSSmeasurementssdss_image_photorunallSDSS Legacy Imaging PhotoRunAll summary catalog. This contains observation dates, coordinates, run identifiers, and reference information for all photometric runs completed during the survey.Dmast:SDSS/sdss/imaging/photoRunAll-dr13.fitsSCIENCE--SDSS Imaging Catalogshttps://archive.stsci.edu/missions-and-data/sdssSDSS Legacy ImagingDR8N/AphotoRunAll-dr13.fits187200298315987PUBLIC3--

We can examine the preview image of the field of stars we’ll be creating a CMD with! We’ll download the preview .jpg file to your directory using the parameter flat=True.

# Selecting .jpg image
img_products = Observations.filter_products(
    products,
    # Select .jpg file for photoObj
    productFilename="frame-irg-003226-5-0126.jpg",
)
# Downloading preview images
Observations.download_products(img_products, flat=True, verbose=False)
Table length=1
Local PathStatusMessageURL
str29str8objectobject
./frame-irg-003226-5-0126.jpgCOMPLETENoneNone

Now we can preview the image!

img = mpimg.imread("frame-irg-003226-5-0126.jpg")
plt.figure(figsize=(10, 8))
imgplot = plt.imshow(img)
plt.axis("off")
plt.title("Preview Image of M13")
plt.show()
../../../_images/c1329aa10fd83e06aa04def1414456e018cdc8e0a3c6f218e651d8ead697c184.png

While the field isn’t directly capturing the center of cluster, it will contain enough cluster stars to create a CMD with! We’ll now download the full FITS files and select photoObj-003226-5-0126.fits due to its CMD congruency.

Each photoObj FITS file follows the following naming scheme: photoObj-{RUN}-{CAMCOL}-{FIELD} where RUN is the zero-padded, six-digit identification number for that photometric run, CAMCOL is the camera column identifying the scanline within the run, and FIELD is field number for that observation. The photoObj file contains the fully calibrated FITS files from the SDSS Imaging Pipeline and other respective measurements such as photometry in all five SDSS filters (u, g, r, i, and z), source classification, and quality flags. There is one photoObj file for each run-camcol-field combination.

# Masking the data to extract only the full FITS file
new_products = Observations.filter_products(
    products,
    # Specify FITS files only
    productGroupDescription="Minimum Recommended Products",
    # Select photoObj files (ugriz)
    productSubGroupDescription="SDSS Imaging Catalogs",
    # Select photoObj-003226-5-0126.fits
    productFilename="photoObj-003226-5-0126.fits",
)

# Downloading photoObj-003226-5-0126.fits
manifest = Observations.download_products(new_products, verbose=False)

We can now open the file and examine it. For this tutorial, we will focus on the g-band and r-band magnitudes provided in the first file extension.

The various file extensions are broken down on the SDSS website:

  • HDU 0: The primary header information.

  • HDU 1: The photoObj table. This contains information such as magnitudes, coordinates, and flux.

# Opening file
star_array = fits.open(manifest["Local Path"][0])

# Display header info
star_array.info()
Filename: ./mastDownload/SDSS/sdss_image_003226-5-0126/photoObj-003226-5-0126.fits
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU      39   ()      
  1                1 BinTableHDU    302   2677R x 139C   [19A, 19A, 19A, B, B, B, I, 3A, B, I, I, I, I, J, E, J, J, E, E, E, E, E, E, E, E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5J, 5J, 5J, 5E, 5J, 75E, 75E, 5E, 5E, 5E, 5J, 5E, D, D, D, D, D, D, D, D, D, 5E, 5E, 5E, J, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 5E, 40E, 40E, 5J, 5J, 5E, 5E, 5D, J, J, J, J, J, J, J, E]   

Creating a Color-Magnitude Diagram of M13#

To obtain magnitudes from the FITS file, we’ll be using PSFMAG from the first file extension. Within PSFMAG there are 5 total columns, each one corresponding to the apparent magnitudes in the u, g, r, i, or z filters. We’ll extract the g-band magnitudes from the second column and the r-band magnitudes from the third column.

# Sending the PSFMAG data to a numpy array
magnitudes = star_array[1].data["PSFMAG"]
magnitudes = np.array(magnitudes)

# Creating arrays for g-band and r-band magnitudes
g_band = magnitudes[:, 1]
r_band = magnitudes[:, 2]

# Calculating color (g - r)
color_data1 = g_band - r_band

To create a CMD, we simply need to plot the r-band magnitudes against the color (g-r) for these stars!

# Plotting the CMD
plt.figure(figsize=(8, 6))
plt.scatter(color_data1, r_band, s=3, color="black", label="M13 data")
plt.ylim(10, 30)
plt.gca().invert_yaxis()
plt.xlim(-2, 2)
plt.title("CMD of M13")
plt.ylabel("Apparent Magnitude (r-band)")
plt.xlabel("Color (g - r)")
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
../../../_images/b22d7c3e8e8324f3a2b2d71c60855687163311da95cbefa9c5f22c11e703f89c.png

Finding the Distance to M13 Using Data from Gaia#

Gaia was launched by the European Space Agency (ESA) in December 2013. Orbiting at L2, its main purpose is to observe billions of stars to create a 3D map of our galaxy. Gaia provides data such as astrometry, photometry, and radial velocities For more information about Gaia, visit the ESA website.

We’ll query Gaia for M13 data using a search radius of 0.375 degrees. This narrows our search so that we focus on the cluster stars rather than foreground stars, allowing us to get a more accurate distance.

The catalog search should take around a minute or so.

# querying Gaia
coordinates = "16h41m41.24s 36d27m35.5s"  # Coordinates of M13
catalog_data = Catalogs.query_region(
    coordinates, catalog="GaiaDR3", radius=0.375
)
WARNING: InputWarning: Coordinate string is being interpreted as an ICRS coordinate. [astroquery.utils.commons]

Gaia provides parallax measurements for a wide variety of astronomical objects. Stellar parallax is the apparent shift in position of a nearby star caused by Earth’s motion around the Sun.

Stellar Parallax
Stellar Parallax Diagram by R. Pogge [8].

We can determine the distance to these objects from the parallax angle using small-angle approximation:

\[ d = \frac{1}{p} \]

where \(d\) is distance in parsecs and \(p\) is parallax in arcseconds.

# Extracting parallax measurements from Gaia
parallax = catalog_data["parallax"]  # in milliarcseconds
distance_array = 1 / parallax  # distance array from parallax (kiloparsecs)
ra = catalog_data["ra"]  # right ascension
dec = catalog_data["dec"]  # declination

# Sorting data
sorted_indices = np.argsort(distance_array)
ra_sorted = ra[sorted_indices]
dec_sorted = dec[sorted_indices]
distance_sorted = distance_array[sorted_indices]

# Creating a histogram of the parallax measurements and RA/DEC map
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(15, 6))

# Histogram
ax[0].hist(parallax, bins=100, color="gray")
ax[0].axvline(
    np.nanmedian(parallax),
    color="red",
    label=f"Median Parallax \n {np.nanmedian(parallax):.3f} milliarcsec",
)
ax[0].set_xlim(-5, 5)
ax[0].set_xticks(np.arange(-5, 5, 1))
ax[0].set_xlabel("Parallax (milliarcseconds)")
ax[0].set_ylabel("Frequency")
ax[0].set_title("Histogram of M13 Parallax Measurements from Gaia")
ax[0].legend()

# RA/DEC map
plot = ax[1].scatter(
    ra_sorted,
    dec_sorted,
    s=2,
    c=distance_sorted,
    cmap="viridis",
    vmin=0,
    vmax=8,
)
cbar = fig.colorbar(plot, ax=ax[1])
cbar.set_label("Distance (kpc)")
ax[1].set_xlabel("RA (degrees)")
ax[1].set_ylabel("DEC (degrees)")
ax[1].set_title("Position of Parallax Measurements Colored by Distance")

plt.show()
/opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/site-packages/numpy/lib/_function_base_impl.py:4049: UserWarning: Warning: 'partition' will ignore the 'mask' of the MaskedColumn.
  part.partition(kth)
../../../_images/da0be14ae5dd57550bd3f554bcf47a3d389f6664efc81a9ffab5e68cb4037ab3.png

The histogram above shows the distribution of the various parallax measurements Gaia made for M13. We’ll take the median of these measurements to use as a general distance for the cluster.

# Finding the median parallax of the data
cluster_median = np.nanmedian(parallax)

# Calculating distance using stellar parallax formula
distance = 1.0 / cluster_median

print(f"Median Parallax: {cluster_median} milliarcseconds")
print(f"Distance to M13: {distance:.4f} kpc")
Median Parallax: 0.1299530647655502 milliarcseconds
Distance to M13: 7.6951 kpc

Therefore, according to Gaia data, the distance to M13 is approximately 7.6951 kpc. We can now use this to convert the isochrones to apparent magnitudes in the next steps.


Determining the Age of M13 Using Stellar Isochrone Matching#

We can determine the approximate age of M13 by plotting its CMD with isochrones of varying ages, and match the best fit isochrone track to the M13 data.

The isochrones are located in the .txt file isochrones.txt. These were the result of generating isochrones from the PARSEC database with a metallicity of -1.33 dex and ages from 2 billion years old to 14 billion years old in step sizes of 1 billion years. The other settings were left as default.

Since the SDSS Legacy Survey observed apparent magnitudes, we’ll need to convert the absolute magnitudes from the isochrones to apparent magnitudes. We’ll use the distance modulus formula since we know the approximate distance to M13 [9]:

\[ m-M=5log_{10}(\frac{d}{10}) \]

where \(m\) is apparent magnitude, \(M\) is absolute magnitude, and \(d\) is the distance to the object in parsecs.

# Distance to M13
d = distance * 10**3  # parsecs


# Converting absolute magnitudes from isochrones to apparent
def app_mag(M):
    return M + 5 * np.log10(d / 10)
# Importing isochrone .txt file
parsec_data = pd.read_csv(
    "isochrones.txt", sep=r"\s+", comment="#", header=None
)

# Converting the data file to an array
parsec_data = np.array(parsec_data)
# The isochrone data file is broken up into age bins
log_age = [
    9.30103,
    9.47712,
    9.60206,
    9.69897,
    9.77815,
    9.84510,
    9.90309,
    9.95424,
    10.00000,
    10.04139,
    10.07918,
    10.11394,
    10.14613,
]

# Setting up a dictionary
age_data = {}

# Looping through .txt file to separate by age
for i, age in enumerate(log_age, start=1):
    age_data[f"age{i}"] = parsec_data[parsec_data[:, 2] == age]

# Extracting g and r magnitudes, applying distance modulus formula
# Setting up arrays
r_data = []
g_data = []
color_data2 = []

# Sending g and r magnitudes and color to an array
for i in range(1, len(log_age) + 1):
    data = age_data[f"age{i}"]
    g_mag = app_mag(data[:, 29])
    r_mag = app_mag(data[:, 30])
    color = g_mag - r_mag

    r_data.append(r_mag)
    g_data.append(g_mag)
    color_data2.append(color)

# Plotting the isochrones
color = [
    "brown",
    "pink",
    "magenta",
    "purple",
    "navy",
    "darkturquoise",
    "teal",
    "olive",
    "green",
    "gold",
    "orange",
    "lightcoral",
    "red",
]
fig, ax = plt.subplots(figsize=(10, 8))
for i, j, k, r in zip(color_data2, r_data, log_age, color):
    ax.plot(
        i,
        j,
        alpha=0.5,
        label=f"{(10**k) / 1e9:.0f} billion years old",
        color=r,
    )

# Plotting the data
ax.scatter(
    color_data1,
    r_band,
    marker="x",
    linewidth=0.9,
    s=20,
    color="black",
    label="SDSS data of M13",
)
ax.set_ylabel("Apparent Magnitude (r-band)")
ax.set_xlabel("Color (g - r)")
ax.set_title("Color - Magnitude Diagram of M13 with Isochrones")
ax.set_ylim(10, 30)
ax.set_xlim(-2, 2)
ax.invert_yaxis()
ax.legend(fontsize=10)
ax.grid(True)
fig.tight_layout()
../../../_images/ba30dcd11c6ad05d7405f2dd20b829aa0d8dd3108367d1ed420b6499cb5da63a.png

While the isochrones extend beyond 27.5 r-band magnitude, the M13 data doesn’t quite reach this far due to the limiting magnitude of the SDSS camera.

We’ll create a zoomed-in plot to further study the terminal age main sequence (TAMS) and main sequence turnoff phases.

# Replotting with different x and y limits
ax.set_xlim(0, 0.9)
ax.set_ylim(16, 20)
ax.invert_yaxis()
ax.legend(fontsize=8)

# Adding annotation for main sequence turnoff
circle = plt.Circle(
    (0.35, 17.75),
    0.25,
    color="red",
    fill=False,
    linewidth=2,
    label="Main Sequence Turnoff",
)
ax.add_patch(circle)
ax.annotate(
    "Main Sequence Turnoff",
    xy=(0.6, 17.75),
    xytext=(0.6 + 0.05, 17.75 - 0.2),
    arrowprops=dict(arrowstyle="->", color="red"),
    fontsize=12,
    color="red",
)

fig
../../../_images/1afe6e768c0b493dacf471f729af5325c88c918e463bc74a41363b053adec4ef.png

From examining the data and isochrones within the main sequence turnoff circle, it appears the data follow the orange track, indicating the cluster is approximately 12 billion years old. This isn’t far from the 11.65 billion year old estimate made by D. Forbes and T. Bridges in Accreted Versus in situ Milky Way Globular Clusters [5].


End of Tutorial#

Congratulations, you now know how to determine the age of a star cluster from isochrone matching using the SDSS Legacy Imaging Survey!


Exercises#

Now it’s your turn to determine the age of Messier 3! M3 has a metallicity of -1.34 dex, which is nearly identical to M13, so you can use the same isochrone file isochrones.txt [5].

There are six different fields available for M3, you can choose whichever one visually has the best looking CMD when plotted, so answers can vary slightly.

# Query SDSS Legacy Imaging Survey for M3 data
# View available products
# Download products
# Plot CMD of M3
# Find distance to M3 using Gaia
# Plot CMD with isochrones

Exercise Solutions#

# Query SDSS Legacy Imaging Survey for M3 data

obs_table2 = Observations.query_criteria(
    objectname="M3", provenance_name="SDSS Legacy Imaging"
)

# Displaying the table
obs_table2
Table masked=True length=10
intentTypeobs_collectionprovenance_nameinstrument_nameprojectfilterswavelength_regiontarget_nametarget_classificationobs_ids_ras_decdataproduct_typeproposal_picalib_levelt_mint_maxt_exptimeem_minem_maxobs_titlet_obs_releaseproposal_idproposal_typesequence_numbers_regionjpegURLdataURLdataRightsmtFlagsrcDenobsidobjIDobjID1distance
str7str4str19str11str4str9str7str13str5str24float64float64str5str18int64float64float64float64float64float64str51float64str3str1int64str197str61str61str6boolfloat64str9str9str9float64
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL004649-3-0146FIELDsdss_image_004649-3-0146205.49065181928.085188819imageSDSS Collaboration353148.29254479166453148.2964863131553.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 205.37706850623056 27.988627871719682 205.42159486278487 28.210231791472925 205.60441753406982 28.181547849750537 205.5595262109013 27.960003124274728 205.37706850623056 27.988627871719682mast:SDSS/sdss/imaging/4649/3/146/frame-irg-004649-3-0146.jpgmast:SDSS/sdss/imaging/4649/3/146/photoObj-004649-3-0146.fitsPUBLICFalsenan297016644877000851877000851662.4582359914772
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL004649-3-0145FIELDsdss_image_004649-3-0145205.32355373528.1112790851imageSDSS Collaboration353148.2921304398153148.29607149833553.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 205.2100784323227 28.01456697081828 205.25425945894472 28.23622770285823 205.43721195883117 28.207789375478082 205.392665007371 27.986187458585785 205.2100784323227 28.01456697081828mast:SDSS/sdss/imaging/4649/3/145/frame-irg-004649-3-0145.jpgmast:SDSS/sdss/imaging/4649/3/145/photoObj-004649-3-0145.fitsPUBLICFalsenan297021749877008987877008987704.6808153444647
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL004649-4-0147FIELDsdss_image_004649-4-0147205.74189508328.47212241imageSDSS Collaboration353148.29295937553148.2969007807453.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 205.62768552230045 28.37577168647357 205.67284676286525 28.597293482580454 205.85629075716403 28.568269370809166 205.81075776098697 28.346808356990465 205.62768552230045 28.37577168647357mast:SDSS/sdss/imaging/4649/4/147/frame-irg-004649-4-0147.jpgmast:SDSS/sdss/imaging/4649/4/147/photoObj-004649-4-0147.fitsPUBLICFalsenan297041189877038782877038782251.12717566712155
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL004649-4-0146FIELDsdss_image_004649-4-0146205.57427835628.4985213252imageSDSS Collaboration353148.29254479166453148.2964861974153.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 205.4602440816663 28.401990585237147 205.50501052174238 28.623614315047135 205.68849923575618 28.594848487893643 205.64336014259345 28.37328506246469 205.4602440816663 28.401990585237147mast:SDSS/sdss/imaging/4649/4/146/frame-irg-004649-4-0146.jpgmast:SDSS/sdss/imaging/4649/4/146/photoObj-004649-4-0146.fitsPUBLICFalsenan29705529887706102087706102038.70436560786968
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL004649-4-0145FIELDsdss_image_004649-4-0145205.40651820428.5247113578imageSDSS Collaboration353148.2921299768553148.29607138259653.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 205.29256303409997 28.428055614125235 205.33703079237077 28.649688467782617 205.52066047872054 28.621163594869746 205.47581916619885 28.399590727008345 205.29256303409997 28.428055614125235mast:SDSS/sdss/imaging/4649/4/145/frame-irg-004649-4-0145.jpgmast:SDSS/sdss/imaging/4649/4/145/photoObj-004649-4-0145.fitsPUBLICFalsenan297060525877069703877069703243.55720045892613
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL004646-3-0082FIELDsdss_image_004646-3-0082205.65630888428.2721588412imageSDSS Collaboration353147.30206481481653147.30600564185453.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 205.5423832905099 28.175729968111437 205.58730682675895 28.39725991057679 205.77041863016308 28.368384857511558 205.7251269725764 28.146914991664634 205.5423832905099 28.175729968111437mast:SDSS/sdss/imaging/4646/3/82/frame-irg-004646-3-0082.jpgmast:SDSS/sdss/imaging/4646/3/82/photoObj-004646-3-0082.fitsPUBLICFalsenan298416340886143838886143838108.59459460943275
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL004646-3-0083FIELDsdss_image_004646-3-0083205.82359094328.2456434759imageSDSS Collaboration353147.30247939814653147.30642022518453.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 205.7095285185484 28.149375294418277 205.75479948691986 28.370854782021958 205.93783702450116 28.341708656515983 205.89219879256294 28.120289646216374 205.7095285185484 28.149375294418277mast:SDSS/sdss/imaging/4646/3/83/frame-irg-004646-3-0083.jpgmast:SDSS/sdss/imaging/4646/3/83/photoObj-004646-3-0083.fitsPUBLICFalsenan298419600886176841886176841647.5256341960012
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL004649-3-0147FIELDsdss_image_004649-3-0147205.65767194428.0589023561imageSDSS Collaboration353148.2929594907453148.2969008964853.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 205.54394470283248 27.962474450750673 205.5888145108555 28.184009933873277 205.77158117037538 28.15512819922499 205.72634720424867 27.933652309716898 205.54394470283248 27.962474450750673mast:SDSS/sdss/imaging/4649/3/147/frame-irg-004649-3-0147.jpgmast:SDSS/sdss/imaging/4649/3/147/photoObj-004649-3-0147.fitsPUBLICFalsenan297003774876981454876981454707.4595416072544
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL004646-3-0081FIELDsdss_image_004646-3-0081205.48894325228.2984535321imageSDSS Collaboration353147.3016553147.30559059555553.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 205.3751517797895 28.20190784674507 205.41974839794054 28.423509196402975 205.60291927098706 28.394796490690652 205.55795372445033 28.173254838069173 205.3751517797895 28.20190784674507mast:SDSS/sdss/imaging/4646/3/81/frame-irg-004646-3-0081.jpgmast:SDSS/sdss/imaging/4646/3/81/photoObj-004646-3-0081.fitsPUBLICFalsenan2984167498861476178861476170.0
scienceSDSSSDSS Legacy ImagingSDSS CameraSDSSu;g;r;i;zOPTICAL004646-3-0080FIELDsdss_image_004646-3-0080205.32150174328.3245630156imageSDSS Collaboration353147.30123541666453147.30517612796453.907456304.799999999999951083.3000000000002Sloan Digital Sky Survey (SDSS) Legacy Imaging Data55571.0N/A----POLYGON 205.20778823297513 28.22786559996562 205.2520733711031 28.449521548371912 205.43540036111 28.421057749901465 205.39074528505412 28.1994611700242 205.20778823297513 28.22786559996562mast:SDSS/sdss/imaging/4646/3/80/frame-irg-004646-3-0080.jpgmast:SDSS/sdss/imaging/4646/3/80/photoObj-004646-3-0080.fitsPUBLICFalsenan298418227886162128886162128379.99380206335434
# Download products
products2 = Observations.get_product_list(obs_table2)

# Download products
new_products2 = Observations.filter_products(
    products2,
    # Specify FITS files only
    productGroupDescription="Minimum Recommended Products",
    # Select photoObj files (ugriz)
    productSubGroupDescription="SDSS Imaging Catalogs",
    # Select photoObj-003226-5-0126.fits
    productFilename="photoObj-004649-4-0145.fits",
)

# Downloading photoObj-003226-5-0126.fits
manifest2 = Observations.download_products(new_products2)
Downloading URL https://mast.stsci.edu/api/v0.1/Download/file?uri=mast:SDSS/sdss/imaging/4649/4/145/photoObj-004649-4-0145.fits to ./mastDownload/SDSS/sdss_image_004649-4-0145/photoObj-004649-4-0145.fits ...
 [Done]
# Plot CMD of M3

# Opening file
star_array2 = fits.open(manifest2["Local Path"][0])

# Sending the PSFMAG data to a numpy array
magnitudes2 = star_array2[1].data["PSFMAG"]
magnitudes2 = np.array(magnitudes2)

# Creating arrays for g-band and r-band magnitudes
g_band2 = magnitudes2[:, 1]
r_band2 = magnitudes2[:, 2]

# Calculating color (g - r)
color_data3 = g_band2 - r_band2

# Plotting the CMD
plt.figure(figsize=(8, 6))
plt.scatter(color_data3, r_band2, s=3, color="black", label="M3 Data")
plt.ylim(10, 30)
plt.gca().invert_yaxis()
plt.xlim(-2, 2)
plt.title("CMD of M3")
plt.ylabel("Apparent Magnitude (r-band)")
plt.xlabel("Color (g - r)")
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
../../../_images/43aa61b2beba145f45ce7f5f73fc9f0ad3146c26979ce50f26a2cce1781d2791.png
# Find distance to M3 using Gaia

# querying Gaia
coordinates2 = "13h42m11.80s 28d22m31.69s"  # Coordinates of M3

catalog_data2 = Catalogs.query_region(
    coordinates2, catalog="GaiaDR3", radius=0.35
)

# Extracting parallax measurements from Gaia
parallax2 = catalog_data2["parallax"]  # in milliarcseconds
distance_array2 = 1 / parallax2  # distance array from parallax (kiloparsecs)
ra2 = catalog_data2["ra"]  # right ascension
dec2 = catalog_data2["dec"]  # declination

# Sorting data
sorted_indices2 = np.argsort(distance_array2)
ra_sorted2 = ra2[sorted_indices2]
dec_sorted2 = dec2[sorted_indices2]
distance_sorted2 = distance_array2[sorted_indices2]

# Creating a histogram of the parallax measurements and RA/DEC map
fig2, ax2 = plt.subplots(nrows=1, ncols=2, figsize=(15, 6))

# Histogram
ax2[0].hist(parallax2, bins=100, color="gray")
ax2[0].axvline(
    np.nanmedian(parallax2),
    color="red",
    label=f"Median Parallax \n {np.nanmedian(parallax2):.3f} milliarcsec",
)
ax2[0].set_xlim(-5, 5)
ax2[0].set_xticks(np.arange(-5, 5, 1))
ax2[0].set_xlabel("Parallax (milliarcseconds)")
ax2[0].set_ylabel("Frequency")
ax2[0].set_title("Histogram of M3 Parallax Measurements from Gaia")
ax2[0].legend()

# RA/DEC map
plot2 = ax2[1].scatter(
    ra_sorted2,
    dec_sorted2,
    s=2,
    c=distance_sorted2,
    cmap="viridis",
    vmin=0,
    vmax=8,
)
cbar2 = fig.colorbar(plot2, ax=ax2[1])
cbar2.set_label("Distance (kpc)")
ax2[1].set_xlabel("RA (degrees)")
ax2[1].set_ylabel("DEC (degrees)")
ax2[1].set_title("Position of Parallax Measurements Colored by Distance")

plt.show()

# Finding the median parallax of the data
cluster_median2 = np.nanmedian(parallax2)

# Calculating distance using stellar parallax formula
distance2 = 1.0 / cluster_median2

print(f"Median Parallax: {cluster_median2} milliarcseconds")
print(f"Distance to M3: {distance2:.4f} kpc")

# Distance to M3
d2 = distance2 * 10**3  # parsecs
WARNING: InputWarning: Coordinate string is being interpreted as an ICRS coordinate. [astroquery.utils.commons]
/opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/site-packages/numpy/lib/_function_base_impl.py:4049: UserWarning: Warning: 'partition' will ignore the 'mask' of the MaskedColumn.
  part.partition(kth)
/tmp/ipykernel_2143/104144980.py:49: UserWarning: Adding colorbar to a different Figure <Figure size 1500x600 with 3 Axes> than <Figure size 1000x800 with 1 Axes> which fig.colorbar is called on.
  cbar2 = fig.colorbar(plot2, ax=ax2[1])
../../../_images/2cc4e053736acf8c1716d8aa387d5e2cc436b88c7466b48634989798fdc65425.png
Median Parallax: 0.09967599714927582 milliarcseconds
Distance to M3: 10.0325 kpc
# Plot CMD with isochrones


def app_mag2(M):
    return M + 5 * np.log10(d2 / 10)


r_data2 = []
g_data2 = []
color_data4 = []

for i in range(1, len(log_age) + 1):
    data = age_data[f"age{i}"]
    g_mag = app_mag2(data[:, 29])
    r_mag = app_mag2(data[:, 30])
    color2 = g_mag - r_mag

    r_data2.append(r_mag)
    g_data2.append(g_mag)
    color_data4.append(color2)

fig, ax = plt.subplots(figsize=(10, 8))
for i, j, k, r in zip(color_data4, r_data2, log_age, color):
    ax.plot(
        i,
        j,
        alpha=0.5,
        label=f"{(10**k) / 1e9:.0f} billion years old",
        color=r,
    )

# Plotting the data
ax.scatter(
    color_data3,
    r_band2,
    marker="x",
    linewidth=0.9,
    s=20,
    color="black",
    label="SDSS data of M3",
)
ax.set_ylabel("Apparent Magnitude (r-band)")
ax.set_xlabel("Color (g - r)")
ax.set_title("Color - Magnitude Diagram of M3 with Isochrones")
ax.set_ylim(10, 30)
ax.set_xlim(-2, 2)
ax.invert_yaxis()
ax.legend(fontsize=10)
ax.grid(True)
fig.tight_layout()
../../../_images/2b25ca890f228c32c2a3bd9c2042ddadb8dd87b8e88d0ec30f1fcb650cb1ebde.png
# Replotting with different x and y limits
ax.set_xlim(0, 0.9)
ax.set_ylim(16, 20)
ax.invert_yaxis()
ax.legend(fontsize=8)

# Adding annotation for main sequence turnoff
circle = plt.Circle(
    (0.35, 18.25),
    0.25,
    color="red",
    fill=False,
    linewidth=2,
    label="Main Sequence Turnoff",
)
ax.add_patch(circle)
ax.annotate(
    "Main Sequence Turnoff",
    xy=(0.6, 18.25),
    xytext=(0.6 + 0.05, 17.75 - 0.2),
    arrowprops=dict(arrowstyle="->", color="red"),
    fontsize=12,
    color="red",
)

fig
../../../_images/a04801dae17847e7daae40fa8b12ae2fae070fb17f3b3e3ff9b3d49f572210cc.png

Results: The data for M3 appear to fit between the yellow and orange lines. Therefore, M3 is between 11-12 billion years old!

This matches the age estimates of approximately 8-11.4 billion years.


Addtional Resources#

Additional resources are linked below:

Citations#

If you use data from MAST for published research, please see the following links for information on which citations to include in your paper:

About this Notebook#

Author(s): Natalie Haugen (nhaugen@terpmail.umd.edu) and Julie Imig (jimig@stsci.edu)
Keyword(s): Tutorial, SDSS, SDSS Legacy Imaging Survey, stars, HR diagram, CMD, imaging
First published: July 2025
Last updated: July 2025


Top of Page Space Telescope Logo