Skip to content

Instantly share code, notes, and snippets.

@bmorris3
Last active July 29, 2026 15:01
Show Gist options
  • Select an option

  • Save bmorris3/c2503e165e545b47efe172558b31b5d6 to your computer and use it in GitHub Desktop.

Select an option

Save bmorris3/c2503e165e545b47efe172558b31b5d6 to your computer and use it in GitHub Desktop.
Identify cluster members in omega Centauri with Gaia DR2 in jdaviz
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "e465df10-53b2-4c9a-8794-9404db92d554",
"metadata": {},
"source": [
"# omega Centauri\n",
"\n",
"For a thorough analysis of omega Cen with Gaia EDR3, see [Soltis, Casertano & Riess (2021)](https://ui.adsabs.harvard.edu/abs/2021ApJ...908L...5S/abstract)\n",
"\n",
"**Outline**\n",
"\n",
"1. Load Gaia source catalog near the center of omega Centauri \n",
"2. Load a JWST NIRcam image in the same location\n",
"3. Open the image and catalog in jdaviz\n",
"4. Plot a color-magnitude diagram\n",
"5. Plot the proper motions (to ID likely cluster members)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "32ea5ec7-9664-4d93-924d-6f8e2739e7c2",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import astropy.units as u\n",
"from astropy.coordinates import SkyCoord, Distance\n",
"from astroquery.mast import MastMissions, Catalogs\n",
"\n",
"import jdaviz as jd"
]
},
{
"cell_type": "markdown",
"id": "ee8264b8-e7ab-40f4-b863-f10af8e28fb9",
"metadata": {},
"source": [
"Query for Gaia DR2 sources near the center of omega Centauri."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a536f8b5-e9f0-4780-a6be-c5e0e3cb1f3f",
"metadata": {},
"outputs": [],
"source": [
"target = SkyCoord(ra=201.69959, dec=-47.47732, unit=u.deg)\n",
"\n",
"catalog = Catalogs.query_region(\n",
" target,\n",
" radius=0.03,\n",
" catalog=\"gaia\",\n",
" version=2\n",
")\n",
"\n",
"# # Note: more sources are available via Gaia TAP from DR3, though the server is flaky\n",
"# from astroquery.gaia import Gaia\n",
"# Gaia.MAIN_GAIA_TABLE = \"gaiadr3.gaia_source\"\n",
"# r = Gaia.query_object_async(\n",
"# coordinate=target, \n",
"# radius='0.03 deg'\n",
"# )"
]
},
{
"cell_type": "markdown",
"id": "f7f72f6e-4c72-4a40-8249-e91088d151af",
"metadata": {},
"source": [
"Calculate the absolute magnitudes and colors of the Gaia sources, add corresponding columns to the catalog table:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6bcb68cf-faec-47b4-992d-168506a999ed",
"metadata": {},
"outputs": [],
"source": [
"parallax = catalog['parallax'] * u.milliarcsecond\n",
"distance = Distance(parallax=parallax, allow_negative=True)\n",
"\n",
"g_mag = catalog['phot_g_mean_mag']\n",
"bp_mag = catalog['phot_bp_mean_mag']\n",
"rp_mag = catalog['phot_rp_mean_mag']\n",
"\n",
"# Gaia color:\n",
"bp_minus_rp = bp_mag - rp_mag\n",
"\n",
"# absolute magnitude in G:\n",
"G_abs_mag = g_mag - 5 * (np.log10(distance.to_value(u.parsec)) - 1)\n",
"\n",
"# add the new quantities to the table:\n",
"catalog['G_abs_mag'] = G_abs_mag\n",
"catalog['bp-rp'] = bp_minus_rp\n",
"catalog['distance'] = distance.to_value(u.kpc)"
]
},
{
"cell_type": "markdown",
"id": "2435d489-237a-4d16-b558-1c0b4fa55ed9",
"metadata": {},
"source": [
"For those who love a labeled color magnitude diagram:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "260777d3-9f24-4cd6-9b77-44f119844fc7",
"metadata": {},
"outputs": [],
"source": [
"ax = plt.gca()\n",
"ax.scatter(bp_minus_rp, G_abs_mag, marker='.')\n",
"ax.annotate(\"ω Cen RGB\", (1.8, -8)) # red giant branch\n",
"ax.annotate(\"?\", (0.4, -2)) # blue stragglers\n",
"ax.annotate(\"(not in DR2 query result)\", (0.6, 15)) # blue stragglers\n",
"ax.axhspan(10, 25, alpha=0.2, color='gray')\n",
"ax.set(\n",
" xlabel='$\\\\rm B_p - R_p$',\n",
" ylabel='$\\\\rm M_G$',\n",
" xlim=[0, 2.2],\n",
" ylim=[25, -15],\n",
")"
]
},
{
"cell_type": "markdown",
"id": "a64633d0-4e38-4d0e-8987-4e0e2c1f547e",
"metadata": {},
"source": [
"Load a JWST NIRCam image into jdaviz near the center of the catalog query. File size: 126 MB."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c3dfae36-3387-4403-88f8-f3c7a29f935d",
"metadata": {},
"outputs": [],
"source": [
"jd.load('mast:jwst/products/jw04343-o002_t001_nircam_clear-f444w_i2d.fits', format='Image')\n",
"\n",
"orientation = jd.plugins['Orientation']\n",
"orientation.align_by = 'WCS'\n",
"# jd.load('mast:jwst/products/jw04343-o002_t001_nircam_clear-f444w_cat.ecsv', format='Catalog')"
]
},
{
"cell_type": "markdown",
"id": "893d27f9-0de1-422b-9706-5eea3bb971f6",
"metadata": {},
"source": [
"Load the source catalog into jdaviz, including all columns:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b8631055-db99-4ba8-993e-72f112aa20b3",
"metadata": {},
"outputs": [],
"source": [
"# load the catalog from an astropy Table\n",
"ldr = jd.loaders['object']\n",
"ldr.object = catalog\n",
"ldr.format = 'Catalog'\n",
"\n",
"# import *all* columns from the table\n",
"ldr.importer.col_other.select_all()\n",
"\n",
"ldr.load()\n",
"\n",
"jd.show()"
]
},
{
"cell_type": "markdown",
"id": "10f06b42-9c17-4bb7-8dfb-835b0f9c4b9c",
"metadata": {},
"source": [
"You can rearrange the viewers by dragging their tabs.\n",
"\n",
"Create a new scatter viewer for a color magnitude diagram, adjust the plot options:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f99605e3-0936-4046-959b-a48d70d9e16a",
"metadata": {},
"outputs": [],
"source": [
"# create a new scatter viewer:\n",
"create_scatter_viewer = jd.new_viewers['Scatter']\n",
"create_scatter_viewer.dataset = 'Catalog'\n",
"scatter_viewer = create_scatter_viewer()\n",
"\n",
"# change the x, y values of the scatter plot\n",
"plot_opts = jd.plugins['Plot Options']\n",
"plot_opts.viewer = 'Scatter'\n",
"plot_opts.xatt = 'bp-rp'\n",
"plot_opts.yatt = 'G_abs_mag'\n",
"\n",
"# change marker styles\n",
"plot_opts.viewer = 'Scatter'\n",
"plot_opts.marker_size = 30\n",
"\n",
"# to map marker colors to a third catalog column (effective temperature)\n",
"plot_opts.marker_color_mode = 'Linear'\n",
"plot_opts.marker_color_col = 'teff_val'\n",
"plot_opts.marker_colormap = 'viridis'\n",
"plot_opts.marker_colormap_vmin = 4000\n",
"plot_opts.marker_colormap_vmax = 6000\n",
"\n",
"\n",
"# Make image marker shape = open circles\n",
"plot_opts.viewer = 'Image'\n",
"plot_opts.marker_fill = False\n",
"\n",
"# set the viewer limits\n",
"scatter_viewer.set_limits(\n",
" x_min=0, x_max=2.5,\n",
" y_min=15, y_max=-10\n",
")"
]
},
{
"cell_type": "markdown",
"id": "c9081442-3ff1-4f0a-a855-a69eaa87086c",
"metadata": {},
"source": [
"Create another scatter viewer, this time for proper motions to identify cluster members:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "27c57d20-0e68-45fb-89c1-f88e5f1f8c26",
"metadata": {},
"outputs": [],
"source": [
"# create a new scatter viewer:\n",
"create_scatter_viewer.dataset = 'Catalog'\n",
"scatter_viewer_pm = create_scatter_viewer()\n",
"\n",
"# change the x, y values of the scatter plot\n",
"plot_opts = jd.plugins['Plot Options']\n",
"plot_opts.viewer = 'Scatter (1)'\n",
"plot_opts.xatt = 'pmra'\n",
"plot_opts.yatt = 'pmdec'\n",
"\n",
"# change marker styles\n",
"plot_opts.viewer = 'Scatter (1)'\n",
"plot_opts.marker_size = 30"
]
},
{
"cell_type": "markdown",
"id": "2cafbeb0-9a01-42fd-9cb7-8086b1da21bc",
"metadata": {},
"source": [
"Optionally add a histogram viewer:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "98efe5e1-1c30-45b3-883c-887a19ae64f9",
"metadata": {},
"outputs": [],
"source": [
"# create_hist_viewer = jd.new_viewers['Histogram']\n",
"# create_hist_viewer.dataset = 'Catalog'\n",
"# create_hist_viewer.xatt = 'teff_val'\n",
"# hist_viewer = create_hist_viewer()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9511a96b-3882-4142-a2b5-becc7bc0f1d8",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.13.14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment