Skip to content

Instantly share code, notes, and snippets.

@bmorris3
Created September 16, 2026 15:08
Show Gist options
  • Select an option

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

Select an option

Save bmorris3/41bfcd59656574a47fdc16d37e6a6443 to your computer and use it in GitHub Desktop.
Requires access to MAST test to run (STScI folks only)
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "4625318a-754a-4c24-813b-35ecf6d6297a",
"metadata": {},
"source": [
"# MAST tools on the Roman Research Nexus"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "243e6354-e366-4b53-be91-f1a19f698789",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import warnings\n",
"\n",
"import numpy as np\n",
"from sidecar import Sidecar\n",
"Sidecar.close_all()\n",
"\n",
"import astropy.units as u\n",
"from astropy.coordinates import SkyCoord\n",
"from astropy.table import Table\n",
"\n",
"from astroquery.mast import MastMissions, conf\n",
"\n",
"conf.server = \"https://masttest.stsci.edu\"\n",
"\n",
"def use_mast_test(mast):\n",
" mast._service_api_connection.SERVICE_URL = 'https://masttest.stsci.edu'\n",
" mast._service_api_connection.REQUEST_URL = 'https://masttest.stsci.edu/search/roman/api/v0.1/'\n",
" mast._service_api_connection.MISSIONS_DOWNLOAD_URL = 'https://masttest.stsci.edu/search/'\n",
" my_session = mast.login(token=os.environ['MAST_API_TOKEN'])\n",
"\n",
"from mast_table import MastTable\n",
"from mast_aladin import MastAladin\n",
"import roman_datamodels.datamodels as rdd\n",
"import jdaviz\n",
"\n",
"# sky coordinate in the region of interest\n",
"coord = SkyCoord(ra=78, dec=-70, unit=u.degree)"
]
},
{
"cell_type": "markdown",
"id": "cd055109-3e71-4ce4-b5e6-cf8de18b5d61",
"metadata": {},
"source": [
"## Query MAST for observations"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "13f49719-4c82-4589-bc0a-518d34819a4d",
"metadata": {},
"outputs": [],
"source": [
"# get access to Roman testing data:\n",
"mast = MastMissions(mission='roman')\n",
"use_mast_test(mast)\n",
"\n",
"select_cols = [\n",
" # default columns\n",
" 'fileSetName',\n",
" 'ra',\n",
" 'dec',\n",
" 'science_category',\n",
" 'productLevel',\n",
" 'optical_element',\n",
" 'exposure_time',\n",
" 'program',\n",
" 'pass',\n",
" 'segment',\n",
" 'exposure_type',\n",
" 'program_category',\n",
" 'program_subcategory',\n",
" 'program_title',\n",
" 'detector',\n",
" 'origin',\n",
" 'calibration_software_version',\n",
" 'ArchiveFileID',\n",
" 'product_type',\n",
" 'exposure_start_time',\n",
" 'ang_sep',\n",
"\n",
" # add non-default columns\n",
" 's_region',\n",
"]\n",
"\n",
"\n",
"one_detector = mast.query_criteria(\n",
" coordinates=coord, \n",
" radius=360 * u.arcsec, \n",
" detector='WFI02',\n",
" select_cols=select_cols\n",
")\n",
"\n",
"# load observations into mast-table\n",
"observations = MastTable(one_detector)\n",
"\n",
"observations"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "655a4331-0c2d-4765-95a9-0c0e96638ac4",
"metadata": {},
"outputs": [],
"source": [
"# initialize a sidecar. this will pop the widget\n",
"# into its own tab:\n",
"observations.selected_rows = observations.items[:1]\n",
"selected_obs = observations.selected_rows_table\n",
"\n",
"product_list = mast.get_product_list(selected_obs)\n",
"\n",
"products = MastTable(\n",
" product_list\n",
")\n",
"\n",
"footprint_sidecar = Sidecar(\n",
" anchor='split-right', \n",
" title='mast-aladin'\n",
")\n",
"with footprint_sidecar:\n",
" # use a Pan-STARRS color sky backgorund\n",
" survey_url = (\n",
" 'https://alaskybis.cds.unistra.fr/2MASS/Color/'\n",
" )\n",
"\n",
" # initialize mast-aladin: \n",
" mast_aladin = MastAladin(\n",
" survey=survey_url,\n",
" fov=0.7 * u.deg,\n",
" full_screen=True\n",
" )\n",
"\n",
" # draw footprints in mast-aladin\n",
" footprint_layers = mast_aladin.load_table(\n",
" one_detector\n",
" )\n",
" \n",
" # show mast-aladin in the sidecar\n",
" mast_aladin.target = coord\n",
" display(mast_aladin)\n",
"\n",
"\n",
"display(products)"
]
},
{
"cell_type": "markdown",
"id": "bcd0eff7-c41f-4b56-b86e-318f0f8b5228",
"metadata": {},
"source": [
"## Stream rate image and source catalog"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4bbb6873-a90c-4f16-bb0d-fa36abf154d8",
"metadata": {},
"outputs": [],
"source": [
"products.selected_rows = products.items[1:4:2]\n",
"selected_products = mast.download_products(products.selected_rows_table)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1020e739-33e6-412e-bfca-90dfa6233ca9",
"metadata": {},
"outputs": [],
"source": [
"catalog_path, level2_path = selected_products['Local Path']"
]
},
{
"cell_type": "markdown",
"id": "3e710060-d7c1-4e6e-8e98-812e4c2ea2cc",
"metadata": {},
"source": [
"## `mast-aladin`: Load source catalog"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "af35309a-3d75-4f4d-806c-b118aa1815d4",
"metadata": {},
"outputs": [],
"source": [
"with warnings.catch_warnings():\n",
" # suppress a units warning:\n",
" warnings.simplefilter('ignore')\n",
" \n",
" # load the Roman catalog `parquet` file with astropy:\n",
" source_catalog = Table.read(catalog_path)\n",
"\n",
" # add the sources to mast-aladin\n",
" catalog_layer = mast_aladin.add_table(\n",
" source_catalog, \n",
" shape='circle', \n",
" color='lime', \n",
" sourceSize=10,\n",
" name='catalog'\n",
" )"
]
},
{
"cell_type": "markdown",
"id": "23cc7b1c-43ec-4110-bfe5-eeb6fe1ec58d",
"metadata": {},
"source": [
"## `jdaviz`: Load image and catalog"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f23cb57e-4ac1-4429-bb55-a09adf92bdf3",
"metadata": {},
"outputs": [],
"source": [
"imviz = jdaviz.App()\n",
"\n",
"# open it in a sidecar:\n",
"imviz_sidecar = Sidecar(\n",
" title='jdaviz',\n",
"\n",
" # place the jdaviz sidecar below \n",
" # the mast-aladin sidecar:\n",
" ref=footprint_sidecar,\n",
" anchor='split-bottom', \n",
")\n",
"\n",
"with imviz_sidecar:\n",
" display(imviz._app)\n",
"\n",
"\n",
"# use `roman_datamodels to open the L2 file:\n",
"roman_image_datamodel = rdd.open(level2_path)\n",
"\n",
"# load the L2 file into imviz:\n",
"imviz.load(\n",
" roman_image_datamodel, \n",
" format='Image', \n",
" extension='data'\n",
")\n",
"\n",
"\n",
"# adjust the colormap of the image\n",
"plot_options = imviz.plugins['Plot Options']\n",
"plot_options.layer = imviz._app.data_collection[0].label\n",
"plot_options.stretch_function = 'Arcsinh'\n",
"plot_options.stretch_vmin = 0.5\n",
"plot_options.stretch_vmax = 3.3\n",
"plot_options.image_colormap = 'Gray'\n",
"\n",
"# load the source catalog into imviz:\n",
"ldr = imviz.loaders['object']\n",
"ldr.object = source_catalog\n",
"ldr.importer.col_x = 'x_centroid'\n",
"ldr.importer.col_y = 'y_centroid'\n",
"ldr.load()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "22fa3b65-be6c-4c2f-85d5-51abd43fdda2",
"metadata": {},
"outputs": [],
"source": [
"ldr.load()\n",
"\n",
"# adjust the marker style for the catalog:\n",
"plot_options.layer = 'Catalog'\n",
"plot_options.marker_size_scale = 10\n",
"plot_options.marker_size = 10\n",
"plot_options.marker_fill = False"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d6afe173-9295-416a-8a08-6f889586913d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "a13dc7b1-d650-44f4-b5bb-33c368c5d0c7",
"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.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment