Skip to content

Instantly share code, notes, and snippets.

@bmorris3
Last active September 7, 2023 15:51
Show Gist options
  • Save bmorris3/0749f56a97533eaf192fd8dd6e5eaec0 to your computer and use it in GitHub Desktop.
Save bmorris3/0749f56a97533eaf192fd8dd6e5eaec0 to your computer and use it in GitHub Desktop.
Demo of spacetelescope/jdaviz#2376 for RTB meeting on Sept 7, 2023
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "5c889c41-03a1-46e2-b2ee-e814f892c842",
"metadata": {
"tags": []
},
"source": [
"# jdaviz demo for RTB\n",
"\n",
"Brett Morris, Sept 7, 2023.\n",
"\n",
"This demo is based on a [branch of jdaviz](https://github.com/bmorris3/jdaviz/tree/ramp-nbs-roman-rebased) which supports Roman Level 1 files, featured in [this proof-of-concept pull request](https://github.com/spacetelescope/jdaviz/pull/2376). Public comments are welcome in the PR.\n",
"\n",
"If you have GitHub CLI installed, you can get to this branch by cloning jdaviz and checking out this branch with:\n",
"```bash\n",
"gh repo clone spacetelescope/jdaviz\n",
"gh pr checkout 2376\n",
"```\n",
"\n",
"#### jdaviz links\n",
"* [Source (GitHub)](https://github.com/spacetelescope/jdaviz/)\n",
"* [Docs](https://jdaviz.readthedocs.io/)\n",
"\n",
"\n",
"## L1 ramps in Cubeviz"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4dec235f-1f34-4af8-a465-3814655dcc0c",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import os\n",
"import warnings\n",
"from urllib.request import urlretrieve\n",
"\n",
"from asdf.exceptions import AsdfWarning\n",
"from erfa.core import ErfaWarning\n",
"\n",
"ignore_warnings = (AsdfWarning, ErfaWarning, UserWarning)"
]
},
{
"cell_type": "markdown",
"id": "6e800bba-9cd0-4342-94d5-a564f9de1b87",
"metadata": {},
"source": [
"Download data from Box for the demo:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dd4560fa-d984-4323-86b4-ff31b2f3136f",
"metadata": {},
"outputs": [],
"source": [
"force_download = False\n",
"\n",
"path_L1_sca1 = \"L1.asdf\"\n",
"path_L2_sca1_exp0 = \"r0000501001001001001_01101_0001_WFI01_cal.asdf\"\n",
"path_L2_sca1_exp1 = \"r0000501001001001001_01101_0002_WFI01_cal.asdf\"\n",
"path_L3_exp0 = \"exp0.asdf\"\n",
"path_L3_exp1 = \"exp1.asdf\"\n",
"\n",
"paths_and_urls = {\n",
" # the L1 file linked below is compatible with roman_datamodels==0.17.1:\n",
" path_L1_sca1: \"https://stsci.box.com/shared/static/4zjln12uc72d6rwu8mkorsyt2s84zfhj.asdf\",\n",
" \n",
" # L2 products for individual SCAs:\n",
" path_L2_sca1_exp0: \"https://stsci.box.com/shared/static/f33pctgepvdqtu7x6c24rvuptaxb96cn.asdf\",\n",
" path_L2_sca1_exp1: \"https://stsci.box.com/shared/static/1mplx2bmoan9upc20vmhngf9j8imdgnj.asdf\",\n",
"\n",
" # full WFI exposures for all SCAs:\n",
" path_L3_exp0: \"https://stsci.box.com/shared/static/jdwkjird889084pbxlnpzmz6c0tgno1k.asdf\",\n",
" path_L3_exp1: \"https://stsci.box.com/shared/static/tshoxuufqcj3e64p4ds0hpzaba3x4nts.asdf\",\n",
"}\n",
"\n",
"for local_path, url in paths_and_urls.items():\n",
" if not os.path.exists(local_path) or force_download:\n",
" urlretrieve(url, local_path)"
]
},
{
"cell_type": "markdown",
"id": "67547a7f-007f-4504-a391-efe19daa0097",
"metadata": {},
"source": [
"Open the ramp in Cubeviz:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "82a0749f-993a-47a9-ab78-ebf6ddd5c718",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from jdaviz import Cubeviz\n",
"\n",
"cubeviz = Cubeviz()\n",
"\n",
"with warnings.catch_warnings():\n",
" warnings.simplefilter('ignore', ignore_warnings)\n",
"\n",
" cubeviz.load_data(path_L1_sca1, data_label='Roman L1')\n",
"\n",
"po = cubeviz.plugins['Plot Options']\n",
"\n",
"po.viewer = 'group-viewer'\n",
"po.stretch_function = 'arcsinh'\n",
"po.stretch_vmin = 100\n",
"po.stretch_vmax = 500\n",
"\n",
"po.viewer = 'group-diff-viewer'\n",
"po.stretch_function = 'arcsinh'\n",
"po.stretch_vmin = 0\n",
"po.stretch_vmax = 200\n",
"\n",
"cubeviz.show(height=1000)"
]
},
{
"cell_type": "markdown",
"id": "c7a14c4b-e797-43c8-9627-b1ddbc25167b",
"metadata": {},
"source": [
"## L2 images in Imviz\n",
"\n",
"#### Single SCAs"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9ab15ed0-2e9f-40e9-b3ad-f451b3788a01",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from jdaviz import Imviz\n",
"\n",
"imviz = Imviz()\n",
"\n",
"with warnings.catch_warnings():\n",
" warnings.simplefilter('ignore', ignore_warnings)\n",
" \n",
" # load each SCA:\n",
" imviz.load_data(path_L2_sca1_exp0, ext='data', data_label='exposure0')\n",
" imviz.load_data(path_L2_sca1_exp1, ext='data', data_label='exposure1')\n",
"\n",
"# set a good color and colormap stretch for each layer:\n",
"po = imviz.plugins['Plot Options']\n",
"colors = ['cyan', 'orangered']\n",
"for i, (choice, color) in enumerate(zip(po.layer.choices, colors)):\n",
" po.layer = choice\n",
" po.stretch_vmin = -0.5\n",
" po.stretch_vmax = 5\n",
" po.image_color_mode = 'Monochromatic'\n",
" po.image_color = color\n",
"\n",
"# link the layers by their WCS:\n",
"imviz.link_data(link_type='wcs')\n",
" \n",
"imviz.show(height=1000)"
]
},
{
"cell_type": "markdown",
"id": "ef9a0b78-a93c-44b1-912f-e0dafee259f6",
"metadata": {},
"source": [
"#### Full exposures"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "21bfc59b-4e5e-4557-9a98-654548306176",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from jdaviz import Imviz\n",
"\n",
"imviz = Imviz()\n",
"\n",
"with warnings.catch_warnings():\n",
" warnings.simplefilter('ignore', ignore_warnings)\n",
" \n",
" # load each exposure:\n",
" imviz.load_data(path_L3_exp0, ext='data', data_label='exposure0')\n",
" imviz.load_data(path_L3_exp1, ext='data', data_label='exposure1')\n",
"\n",
"# set a good color and colormap stretch for each layer:\n",
"po = imviz.plugins['Plot Options']\n",
"colors = ['cyan', 'orangered']\n",
"for i, (choice, color) in enumerate(zip(po.layer.choices, colors)):\n",
" po.layer = choice\n",
" po.stretch_vmin = -0.5\n",
" po.stretch_vmax = 5\n",
" po.image_color_mode = 'Monochromatic'\n",
" po.image_color = color\n",
"\n",
"# link the layers by their WCS:\n",
"imviz.link_data(link_type='wcs')\n",
" \n",
"imviz.show(height=1000)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dfcb1d6f-53af-4790-8cc9-2697ad7943e4",
"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.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment