Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated data visualization notebook with comments from summer testing. #47

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 98 additions & 14 deletions content/notebooks/data_visualization/data_visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
"%matplotlib inline\n",
"from astropy.visualization import simple_norm\n",
"from astropy.coordinates import SkyCoord\n",
"from astropy.table import Table\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"from jdaviz import Imviz\n",
"import roman_datamodels as rdm\n",
Expand Down Expand Up @@ -193,6 +195,8 @@
"source": [
"## Interactively Examine the Data Using Imviz\n",
"\n",
"### Introduction and Setup\n",
"\n",
"We can also use Imviz, the 2-D image viewer from the Jdaviz package, to visualize and explore the 2-D arrays contained within WFI L2 ASDF files. We highly recommend that users consult the [Imviz documentation](https://jdaviz.readthedocs.io/en/latest/imviz/index.html), which describes many of the features in Imviz in detail. In this tutorial, we will cover the basics to get you started.\n",
"\n",
"**Note:** An enhancement to Cubeviz, the 3-D datacube visualization tool in Jdaviz, will soon allow interactive exploration of WFI L1 data cubes. This functionality is currently being tested and will be available in a future Jdaviz release.\n",
Expand All @@ -207,13 +211,17 @@
"outputs": [],
"source": [
"imviz = Imviz()\n",
"imviz.show('sidecar:split-right', height=1000)"
"imviz.show('sidecar', height=1000)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Note:** You may need to expand the Imviz window to see all of the menubar items. You can also minimize the viewer by clicking on the tab on the far-right of your browser that says \"imviz.\" Clicking the \"x\" symbol next to it will close the tab, but clicking on the word \"imviz\" will hide the viewer until it is clicked again.\n",
"\n",
"### Loading Data and Programmatically Adjusting Display\n",
"\n",
"Next, we load the image into Imviz. By default, for Roman WFI data, Imviz only loads the data array in the viewer to improve performance. Additional arrays (e.g., the data quality array) may be loaded using the `ext` optional argument. An example demonstrating how to load the data quality array is provided in a commented line in the following cell. For more information on the arrays contained within WFI L2 files, please see the RDox article on WFI [Data Levels and Products](https://roman-docs.stsci.edu/data-handbook-home/wfi-data-format/data-levels-and-products#DataLevelsandProducts-L2ScienceDataSpecifications)."
]
},
Expand Down Expand Up @@ -259,7 +267,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we will display a second image, showing the same field but slightly dithered, and we will link the two images by their WCS."
"Now we will display a second image, showing the same field but slightly dithered, and we will link the two images by their WCS. The second image is dithered by ~100 arcseconds compared to the first, so sources should move by ~1000 pixels between the two images. This is easy to observe with the galaxy in the bottom-left quadrant of the first image, which is located in the bottom-middle of the second image."
]
},
{
Expand All @@ -284,6 +292,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now that the second image has been displayed, we can blink between the two using the \"b\" button. Make sure that your cursor is placed over the image to make it the active window, then blink between the images.\n",
"\n",
"Similarly to our matplotlib demonstration, let's investigate a region of interest and focus on the large extended source in the lower portion of the image. In this case, we know the galaxy has science pixel coordinates of (X, Y) ~ (1189, 737) pixels or sky coordinates of (RA, Dec) ~ (0.836, 0.598) degrees. This information can be determined from the catalog used to simulate the products, or may come from interactive examintion of the image or a source detection algorithm. Regardless of how we obtained the coordinates, we can center the viewer on them using the API as shown below:"
]
},
Expand Down Expand Up @@ -311,7 +321,7 @@
"* 0.5: zoomed out by a factor of 2.\n",
"* 'fit' means zoomed to fit the whole image into display.\n",
"\n",
"In this case, we will set the zoom level to 0.4 so we can see the extended source in both images and blink between them. To blink the images, place the cursor over the viewer and press the \"b\" key on your keyboard."
"In this case, we will set the zoom level to 0.4 so we can see the extended source in both images and blink between them. Recall that to blink the images, place the cursor over the viewer and press the \"b\" key on your keyboard."
]
},
{
Expand Down Expand Up @@ -346,7 +356,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also save the current view to a PNG file on disk:"
"You can also save the current view to a PNG file on your cloud storage:"
]
},
{
Expand All @@ -358,6 +368,87 @@
"viewer.save('my_image.png')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This should save the file to your current working directory on the the science platform. If you want to download this file, you can do so by right-clicking on the file in the file browser and selecting the \"Download\" option.\n",
"\n",
"### Overlaying Catalog Data\n",
"\n",
"First, let's read in the catalog used to generate this image using Roman I-Sim:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Read in catalog data from S3\n",
"cat_uri = asdf_dir_uri + 'ROMANISIM/CATALOGS_SCRIPTS/fullcat_101M_pared_ra0.50_dec0.50_WFI16.ecsv'\n",
"with fs.open(cat_uri, 'rb') as f:\n",
" tab = Table.read(f, format='ascii.ecsv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are a lot of sources in this file, but let's pare them down somewhat for display purposes. In this case, let's filter down to the brightest ($m_{AB}$ < 15) sources in the F158 filter. The flux columns in the table are in units of maggies, which may be converted to AB magnitudes as $m_{AB} = -2.5\\log_{10}(f)$ where $m_{AB}$ is the magnitude in AB mags and $f$ is the flux in maggies."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create SkyCoord objects\n",
"bright = np.where(-2.5 * np.log10(tab['F158']) < 15)\n",
"coords = Table({'coord': [SkyCoord(ra = tab['ra'][bright], dec = tab['dec'][bright], unit = 'deg')]})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now let's set up the markers and add them to the viewer:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Set up viewer marker parameters\n",
"viewer.marker = {'color': 'white', 'alpha': 0.8, 'markersize': 120, 'fill': False}\n",
"\n",
"# Overlay markers\n",
"viewer.add_markers(coords, use_skycoord=True, marker_name='My_Markers')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also remove them if we don't want them any longer, or if we want to replace them with other markers:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Remove only My_Markers\n",
"viewer.remove_markers(marker_name='My_Markers')\n",
"\n",
"# Remove ALL markers\n",
"# viewer.reset_markers()"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -386,7 +477,7 @@
"source": [
"## About this notebook\n",
"**Author:** Tyler Desjardins, Brett Morris \n",
"**Updated On:** 2024-05-03"
"**Updated On:** 2024-09-20"
]
},
{
Expand All @@ -403,20 +494,13 @@
"[Top of Page](#top)\n",
"<img style=\"float: right;\" src=\"https://raw.githubusercontent.com/spacetelescope/notebooks/master/assets/stsci_pri_combo_mark_horizonal_white_bkgd.png\" alt=\"Space Telescope Logo\" width=\"200px\"/> "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Roman Calibration latest (2024-03-25)",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "roman-cal"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand Down
Loading