Skip to content

Commit 91e9f38

Browse files
jkrickbsipocz
authored andcommitted
hdu context manager, unique bandnames, improve plot colorscale
1 parent 0fc1b95 commit 91e9f38

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

tutorials/irsa-sia-examples/sia_allwise_atlas.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ IRSA supports both SIA v1 and SIA v2 protocols. The version used depends on the
4242
+++
4343

4444
## Imports
45+
- `numpy` for working with tables
4546
- `astropy.coordinates` for defining coordinates
4647
- `astropy.nddata` for creating an image cutout
4748
- `astropy.wcs` for interpreting the World Coordinate System header keywords of a fits file
@@ -50,13 +51,15 @@ IRSA supports both SIA v1 and SIA v2 protocols. The version used depends on the
5051
- `astropy.io` to manipulate FITS files
5152
- `firefly_client` for visuzlizing images
5253
- `astroquery.ipac.irsa` for IRSA data access
54+
- `astropy.visualization` for color stretch display
5355

5456
```{code-cell} ipython3
5557
# Uncomment the next line to install dependencies if needed.
5658
%pip install matplotlib astropy jupyter_firefly_extensions
5759
```
5860

5961
```{code-cell} ipython3
62+
import numpy as np
6063
from astropy.coordinates import SkyCoord
6164
from astropy.nddata import Cutout2D
6265
from astropy.wcs import WCS
@@ -65,6 +68,7 @@ import matplotlib.pyplot as plt
6568
from astropy.io import fits
6669
from firefly_client import FireflyClient
6770
from astroquery.ipac.irsa import Irsa
71+
from astropy.visualization import simple_norm
6872
```
6973

7074
## 1. Define the target
@@ -116,8 +120,8 @@ im_table.colnames
116120
```
117121

118122
```{code-cell} ipython3
119-
# Let's look at the values in one of the columns
120-
im_table['energy_bandpassname']
123+
# Let's look at the unique values in one of the columns
124+
print(np.unique(im_table['energy_bandpassname']))
121125
```
122126

123127
## 4.Locate and visualize an image of interest
@@ -139,9 +143,12 @@ w3_table = im_table[w3_mask]
139143
image_url = w3_table['access_url'][0]
140144
image_url
141145
142-
#Use Astropy to examine the header of the URL from the previous step.
143-
hdulist = fits.open(image_url)
144-
hdulist.info()
146+
# Use Astropy to examine the header of the URL from the previous step,
147+
# and grab the data and wcs from the header.
148+
with fits.open(image_url, memmap=False) as hdul:
149+
hdul.info()
150+
data = hdul[0].data
151+
wcs = WCS(hdul[0].header)
145152
```
146153

147154
```{code-cell} ipython3
@@ -164,16 +171,18 @@ fc.show_fits_image(file_input=image_url,
164171
If you want to see just a cutout of a certain region around the target, we do that below using astropy's Cutout2D.
165172

166173
```{code-cell} ipython3
167-
data = hdulist[0].data
168-
wcs = WCS(hdulist[0].header)
169-
170174
# make 1' x 1' cutout
171175
cutout = Cutout2D(data, position=pos, size=1 * u.arcmin, wcs=wcs)
172176
177+
#add quick normalization/stretch
178+
norm = simple_norm(cutout.data, stretch="sqrt", percent=99)
179+
173180
# display
174-
plt.figure()
175-
plt.imshow(cutout.data, origin='lower')
176-
plt.colorbar()
181+
plt.imshow(cutout.data, origin='lower', norm = norm)
182+
plt.colorbar(label="Image value")
183+
plt.title("ALLWISE W3 (quicklook)")
184+
plt.xlabel("Pixel X")
185+
plt.ylabel("Pixel Y")
177186
```
178187

179188
***
@@ -190,7 +199,7 @@ plt.colorbar()
190199

191200
**Authors:** IRSA Data Science Team, including Troy Raen, Brigitta Sipőcz, Jessica Krick, Andreas Faisst, Jaladh Singhal, Vandana Desai, Dave Shupe
192201

193-
**Updated:** 19 February 2026
202+
**Updated:** 2 March 2026
194203

195204
**Contact:** [IRSA Helpdesk](https://irsa.ipac.caltech.edu/docs/help_desk.html) with questions or problems.
196205

0 commit comments

Comments
 (0)