Skip to content

Commit

Permalink
updates to carina notebook to use rgb plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Camilla Pacifici authored and gibsongreen committed Jun 10, 2024
1 parent f706668 commit 2245327
Showing 1 changed file with 89 additions and 67 deletions.
156 changes: 89 additions & 67 deletions notebooks/cross_instrument/rgb_imviz/imviz_rgb_carina.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@
"\n",
"from astroquery.mast import Observations\n",
"\n",
"from jdaviz import Imviz"
"from jdaviz import Imviz\n",
"\n",
"from IPython.display import Image"
]
},
{
"cell_type": "markdown",
"id": "aaf960cd",
"metadata": {},
"source": [
"## Download images and load Imviz\n",
"\n",
"We create an Imviz instance and grab the default viewer instance as well:"
]
},
Expand Down Expand Up @@ -118,10 +122,8 @@
{
"cell_type": "code",
"execution_count": null,
"id": "8b754faa",
"metadata": {
"scrolled": false
},
"id": "48830cc8-997f-4ec7-b278-21e6685ec7cd",
"metadata": {},
"outputs": [],
"source": [
"imviz.show()"
Expand All @@ -132,28 +134,26 @@
"id": "88b7129e",
"metadata": {},
"source": [
"## WCS Linking Controls\n",
"https://jdaviz.readthedocs.io/en/latest/imviz/plugins.html#link-control\n",
"## Align by WCS\n",
"https://jdaviz.readthedocs.io/en/latest/imviz/plugins.html#orientation\n",
"\n",
"The first thing you will probably notice is that the image doesn't take up the entire viewer area. If you press the \"b\" key to blink to the next image, you will see that this image is zoomed correctly by default. The odd default zoom on the other is because the images are linked by pixel when loaded. We can instead link by WCS (world coordinates) so that the images will be properly aligned."
]
},
{
"cell_type": "markdown",
"id": "b34dde0c",
"id": "341145e7-e595-4a58-aab8-0e1e24c19c3d",
"metadata": {},
"source": [
"There are two ways to link in Imviz. Firstly, you can do it from within the UI through the Links Control plugin by selecting \"WCS\". Either open the plugin tray to the right and search for \"Links Control\", or execute the following cell to open it automatically:"
"There are two ways to link in Imviz. Firstly, you can do it from within the UI through the Orientation plugin by selecting \"WCS\". Either open the plugin tray to the right and search for \"Orientation\", or execute the following cell to open it automatically:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "812bbbf5",
"cell_type": "raw",
"id": "19216180-6a20-44cd-a384-981431eb6a3f",
"metadata": {},
"outputs": [],
"source": [
"imviz.plugins['Links Control'].open_in_tray()"
"imviz.plugins['Orientation'].open_in_tray()"
]
},
{
Expand All @@ -172,8 +172,8 @@
"outputs": [],
"source": [
"# Link images by WCS (without affine approximation)\n",
"imviz.plugins['Links Control'].link_type = 'WCS'\n",
"imviz.plugins['Links Control'].wcs_use_affine = False"
"imviz.plugins['Orientation'].link_type = 'WCS'\n",
"imviz.plugins['Orientation'].wcs_use_affine = False"
]
},
{
Expand Down Expand Up @@ -208,98 +208,120 @@
"metadata": {},
"outputs": [],
"source": [
"plot_options = imviz.plugins['Plot Options']\n",
"plot_options.open_in_tray()"
"plot_options = imviz.plugins['Plot Options']"
]
},
{
"cell_type": "markdown",
"id": "3e1285e7",
"id": "a02ea0f6-6101-46f1-a777-2469245fe124",
"metadata": {},
"source": [
"Here you can adjust the color, opacity, contrast, and bias among other things. You can adjust them manually via the UI, or programmatically via the API to make image appear as you'd like:"
"We can use the the Assign RGB Preset button, which can be triggered in the UI or with the following cell."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c2211739",
"id": "d9f2aea4-3828-421f-bdaa-cc428a7c8e6b",
"metadata": {},
"outputs": [],
"source": [
"plot_options.image_color_mode = 'Monochromatic'\n",
"img_settings = {'f090w': {'image_color': '#cc7ace',\n",
" 'stretch_vmax': 4,\n",
" 'image_opacity': 0.32,\n",
" 'image_contrast': 0.69,\n",
" 'image_bias': 0.39},\n",
" 'f187n': {'image_color': '#66cfef',\n",
" 'stretch_vmin': 0,\n",
" 'stretch_vmax': 16,\n",
" 'image_opacity': 0.4,\n",
" 'image_contrast': 0.94,\n",
" 'image_bias': 0.74},\n",
" 'f200w': {'image_color': '#61d3e1',\n",
" 'stretch_vmax': 6,\n",
" 'image_opacity': 0.31,\n",
" 'image_contrast': 2.15,\n",
" 'image_bias': 0.66},\n",
" 'f335m': {'image_color': '#afff6b',\n",
" 'stretch_vmin': 4,\n",
" 'stretch_vmax': 27,\n",
" 'image_opacity': 0.23,\n",
" 'image_contrast': 3.13,\n",
" 'image_bias': 0.67},\n",
" 'f444w': {'image_color': '#ff767c',\n",
" 'stretch_vmax': 10,\n",
" 'image_opacity': 0.18,\n",
" 'image_contrast': 1.77,\n",
" 'image_bias': 0.56},\n",
" 'f470n': {'image_color': '#f7787d',\n",
" 'stretch_vmin': 1,\n",
" 'stretch_vmax': 11,\n",
" 'image_opacity': 0.4,\n",
" 'image_contrast': 2.53,\n",
" 'image_bias': 0.27}}"
"plot_options.image_color_mode = 'Color'\n",
"plot_options.apply_RGB_presets()"
]
},
{
"cell_type": "markdown",
"id": "78207a91",
"id": "6bce2a65-953e-436f-b6dc-e81b749cd840",
"metadata": {},
"source": [
"We can now iterate over this dictionary of settings and use the plot options API to set each of the options."
"We just need to adjust the stretch min and max!"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c342cd9d",
"id": "04482b8f-89ad-4770-8a4c-9325a72ffbaa",
"metadata": {},
"outputs": [],
"source": [
"for layer, settings in img_settings.items():\n",
" plot_options.layer = f'{layer}[DATA]'\n",
" for k, v in settings.items():\n",
" setattr(plot_options, k, v)"
"plot_options.layer = 'f090w[DATA]'\n",
"plot_options.stretch_vmin = 4\n",
"plot_options.stretch_vmax = 16\n",
"plot_options.image_bias = 0.39\n",
"\n",
"plot_options.layer = 'f187n[DATA]'\n",
"plot_options.stretch_vmin = 10\n",
"plot_options.stretch_vmax = 16\n",
"plot_options.image_bias = 0.74\n",
"\n",
"plot_options.layer = 'f200w[DATA]'\n",
"plot_options.stretch_vmin = 1\n",
"plot_options.stretch_vmax = 5\n",
"plot_options.image_bias = 0.66\n",
"\n",
"plot_options.layer = 'f335m[DATA]'\n",
"plot_options.stretch_vmin = 4\n",
"plot_options.stretch_vmax = 27\n",
"plot_options.image_bias = 0.67\n",
"\n",
"plot_options.layer = 'f444w[DATA]'\n",
"plot_options.stretch_vmin = 1\n",
"plot_options.stretch_vmax = 14\n",
"plot_options.image_bias = 0.56\n",
"\n",
"plot_options.layer = 'f470n[DATA]'\n",
"plot_options.stretch_vmin = 1\n",
"plot_options.stretch_vmax = 6\n",
"plot_options.image_bias = 0.60\n"
]
},
{
"cell_type": "markdown",
"id": "b1ac3c3f",
"id": "9d7821fd-2073-4d1b-8e97-64c46f2e074d",
"metadata": {},
"source": [
"And lastly, we can save to an image using the export plot plugin."
"Let's export the image we just made. This is a placeholder for when the export in the plugin with get the right path."
]
},
{
"cell_type": "raw",
"id": "d5266616-c257-4f93-b9d1-11185e0c5fee",
"metadata": {},
"source": [
"exportimg = imviz.plugins['Export Plot']\n",
"exportimg.viewer = 'imviz-0'\n",
"exportimg.filename = 'carina_rgb_preset.png'\n",
"exportimg.export()"
]
},
{
"cell_type": "markdown",
"id": "ca450e99-04e2-4e08-bbb7-45f6b98843f5",
"metadata": {},
"source": [
"We can use the astrowidget API for now."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8193c79d-ae58-469b-a3b0-6ac3497dbb8b",
"metadata": {},
"outputs": [],
"source": [
"viewer = imviz.default_viewer\n",
"viewer.save('./carina.png')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fce20b3d",
"id": "501ac813-a160-4180-b3e4-6f03eae3addb",
"metadata": {},
"outputs": [],
"source": [
"imviz.plugins['Export Plot'].save_figure('carina_rgb.png')"
"Image('./carina.png')"
]
},
{
Expand Down Expand Up @@ -335,7 +357,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 2245327

Please sign in to comment.