Skip to content

Commit 221877a

Browse files
authored
Merge pull request #259 from jkrick/sia_cleanup
Sia v2 cleanup
2 parents ddab546 + 7b39e19 commit 221877a

1 file changed

Lines changed: 111 additions & 85 deletions

File tree

Lines changed: 111 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
---
2+
authors:
3+
- name: IRSA Data Science Team
4+
- name: Troy Raen
5+
- name: "Brigitta Sipőcz"
6+
- name: Jessica Krick
7+
- name: Andreas Faisst
8+
- name: Jaladh Singhal
9+
- name: Vandana Desai
10+
- name: Dave Shupe
211
jupytext:
312
text_representation:
413
extension: .md
514
format_name: myst
615
format_version: 0.13
7-
jupytext_version: 1.16.2
16+
jupytext_version: 1.19.1
817
kernelspec:
9-
display_name: Python 3 (ipykernel)
10-
language: python
1118
name: python3
12-
authors:
13-
- name: David Shupe
14-
- name: IRSA Science Team
19+
display_name: python3
20+
language: python
1521
---
1622

17-
# Searching for AllWISE Atlas Images
18-
19-
+++
20-
21-
This notebook tutorial demonstrates the process of querying IRSA's Simple Image Access (SIA) service for AllWISE Atlas images, making a cutout image (thumbnail), and displaying the cutout.
23+
# Searching for AllWISE Images with SIA v2
2224

2325
+++
2426

25-
26-
2727
## Learning Goals
2828

2929
By the end of this tutorial, you will:
3030

31-
* Learn how to search the NASA Astronomical Virtual Observatory Directory web portal for a service that provides access to IRSA's WISE AllWISE Atlas (L3a) coadded images.
32-
* Use the Python pyvo package to identify which of IRSA's AllWISE Atlas images cover a specified coordinate.
33-
* Download one of the identified images.
31+
* Learn how to access IRSA's WISE AllWISE Atlas (L3a) coadded images via the Simple Image Access (SIA) service.
32+
* Identify which of IRSA's AllWISE Atlas images cover a specified coordinate.
33+
* Visualize one of the identified images using Firefly.
3434
* Create and display a cutout of the downloaded image.
3535

3636
+++
@@ -41,51 +41,49 @@ The AllWISE program builds upon the work of the successful Wide-field Infrared S
4141

4242
https://irsa.ipac.caltech.edu/Missions/wise.html
4343

44-
The [NASA/IPAC Infrared Science Archive (IRSA)](https://irsa.ipac.caltech.edu) at Caltech is the archive for AllWISE images and catalogs. The AllWISE Atlas images that are the subject of this tutorial are made accessible via the [International Virtual Observatory Alliance (IVOA)](https://ivoa.net) [Simple Image Access (SIA)](https://wiki.ivoa.net/internal/IVOA/SiaInterface/SIA-V2-Analysis.pdf) protocol. IRSA's AllWISE SIA service is registered in the NASA Astronomical Virtual Observatory (NAVO) [Directory](https://vao.stsci.edu). Based on the registered information, the Python package [pyvo](https://pyvo.readthedocs.io) can be used to query the SEIP SIA service for a list of images that meet specified criteria, and standard Python libraries can be used to download and manipulate the images.
45-
Other datasets at IRSA are available through other SIA services:
44+
The [NASA/IPAC Infrared Science Archive (IRSA)](https://irsa.ipac.caltech.edu) at Caltech is the archive for AllWISE images and catalogs. The AllWISE Atlas images that are the subject of this tutorial are made accessible via the [International Virtual Observatory Alliance (IVOA)](https://ivoa.net) [Simple Image Access (SIA)](https://www.ivoa.net/documents/SIA/) protocol.
4645

47-
https://irsa.ipac.caltech.edu/docs/program_interface/api_images.html
4846

47+
```{note}
48+
IRSA supports both SIA v1 and SIA v2 protocols. The version used depends on the specific dataset. This IRSA [website](https://irsa.ipac.caltech.edu/ibe/sia.html) provides information on which version each service uses and how to access them. Further information on how to access IRSA data with different techniques is available [here](https://irsa.ipac.caltech.edu/docs/program_interface/api_images.html). This tutorial uses SIA v2 for AllWISE Atlas images.
49+
```
4950

5051
+++
5152

5253
## Imports
53-
54-
- `pyvo` for querying IRSA's AllWISE Atlas SIA service
54+
- `numpy` for working with tables
5555
- `astropy.coordinates` for defining coordinates
5656
- `astropy.nddata` for creating an image cutout
5757
- `astropy.wcs` for interpreting the World Coordinate System header keywords of a fits file
5858
- `astropy.units` for attaching units to numbers passed to the SIA service
5959
- `matplotlib.pyplot` for plotting
60-
- `astropy.utils.data` for downloading files
6160
- `astropy.io` to manipulate FITS files
61+
- `firefly_client` for visualizing images
62+
- `astroquery.ipac.irsa` for IRSA data access
63+
- `astropy.visualization` for color stretch display
6264

6365
```{code-cell} ipython3
6466
# Uncomment the next line to install dependencies if needed.
65-
# !pip install matplotlib astropy pyvo
67+
# %pip install matplotlib astropy astroquery jupyter_firefly_extensions
6668
```
6769

6870
```{code-cell} ipython3
69-
import pyvo as vo
71+
import numpy as np
7072
from astropy.coordinates import SkyCoord
7173
from astropy.nddata import Cutout2D
7274
from astropy.wcs import WCS
7375
import astropy.units as u
7476
import matplotlib.pyplot as plt
75-
from astropy.utils.data import download_file
7677
from astropy.io import fits
78+
from firefly_client import FireflyClient
79+
from astroquery.ipac.irsa import Irsa
80+
from astropy.visualization import simple_norm
7781
```
7882

79-
## Section 1 - Setup
83+
## 1. Define the target
8084

8185
+++
8286

83-
Set images to display in the notebook
84-
85-
```{code-cell} ipython3
86-
%matplotlib inline
87-
```
88-
8987
Define coordinates of a bright star
9088

9189
```{code-cell} ipython3
@@ -94,119 +92,147 @@ dec = 77.595559
9492
pos = SkyCoord(ra=ra, dec=dec, unit='deg')
9593
```
9694

97-
## Section 2 - Lookup and define a service for AllWISE Atlas images
95+
## 2. Discover AllWISE Atlas images
9896

9997
+++
10098

101-
Start at STScI VAO Registry at https://vao.stsci.edu/keyword-search/
99+
IRSA provides Simple Image Access (SIA) services for various datasets. A list of available datasets and their access URLs can be found [here](https://irsa.ipac.caltech.edu/ibe/sia.html).
100+
This tutorial uses SIA v2 for AllWISE Atlas images.
101+
To search for other datasets on SIA v2, try changing the filter string.
102+
Or remove the filter keyword altogether to get a full list of available SIA v2 datasets at IRSA.
102103

103-
Limit by Publisher "NASA/IPAC Infrared Science Archive" and Capability Type "Simple Image Access Protocol" then search on "AllWISE Atlas"
104-
105-
Locate the SIA2 URL https://irsa.ipac.caltech.edu/ibe/sia/wise/allwise/p3am_cdd?
104+
First we need to know the name of the dataset on the IRSA system.
106105

107106
```{code-cell} ipython3
108-
allwise_service = vo.dal.SIAService("https://irsa.ipac.caltech.edu/ibe/sia/wise/allwise/p3am_cdd?")
107+
names = Irsa.list_collections(filter="allwise")
108+
names
109109
```
110110

111-
## Section 3 - Search the service
111+
We see from the resulting table that the dataset collection we are interested in is called "wise_allwise".
112+
Use this collection name in query below.
112113

113114
+++
114115

115-
Search for images covering within 1 arcsecond of the star
116+
## 3. Search for images
117+
Which images in the IRSA allwise dataset include our target of interest?
118+
119+
Get a table of all images within 1 arcsecond of our target position.
116120

117121
```{code-cell} ipython3
118-
im_table = allwise_service.search(pos=pos, size=1.0*u.arcsec)
122+
im_table = Irsa.query_sia(pos=(pos, 1 * u.arcsec), collection='wise_allwise')
119123
```
120124

121-
Inspect the table that is returned
125+
Inspect the table that is returned.
122126

123127
```{code-cell} ipython3
124128
im_table
125129
```
126130

131+
Look at a list of the column names included in this table.
132+
127133
```{code-cell} ipython3
128-
im_table.to_table().colnames
134+
im_table.colnames
129135
```
130136

137+
Look at the unique values in one of the columns.
138+
131139
```{code-cell} ipython3
132-
im_table.to_table()['sia_bp_id']
140+
print(np.unique(im_table['energy_bandpassname']))
133141
```
134142

135-
## Section 4 - Locate and download an image of interest
143+
## 4.Locate and visualize an image of interest
136144

137-
+++
145+
We start by filtering the image results for the W3 band images.
146+
Then look at the header of one of the resulting W3 band images of our target star.
147+
Finally, we create an interactive FITS display of the W3 image(s) by [using Firefly](https://caltech-ipac.github.io/firefly_client/index.html), an open-source interactive visualization tool for astronomical data.
148+
To understand how to open the Firefly viewer in a new tab from your Python notebook, refer to [this documentation](https://caltech-ipac.github.io/firefly_client/usage/initializing-vanilla.html) on how to initialize FireflyClient.
138149

139-
Let's search the image results for the W3 band image.
150+
You can put the URL from the column "access_url" into a browser to download the file.
151+
Or you can work with it in Python, as shown below.
140152

141153
```{code-cell} ipython3
142-
for i in range(len(im_table)):
143-
if im_table[i]['sia_bp_id'] == 'W3':
144-
break
145-
print(im_table[i].getdataurl())
154+
w3_mask = im_table['energy_bandpassname'] == 'W3'
155+
w3_table = im_table[w3_mask]
146156
```
147157

148-
Download the image and open it in Astropy
158+
Lets look at the access_url of the first one.
159+
Then use Astropy to examine the header of the URL from the previous step,
160+
and grab the data and wcs from the header.
149161

150162
```{code-cell} ipython3
151-
fname = download_file(im_table[i].getdataurl(), cache=True)
152-
image1 = fits.open(fname)
153-
```
154-
155-
## Section 5 - Extract a cutout and plot it
163+
image_url = w3_table['access_url'][0]
164+
image_url
156165
157-
```{code-cell} ipython3
158-
wcs = WCS(image1[0].header)
166+
with fits.open(image_url, memmap=False) as hdul:
167+
hdul.info()
168+
data = hdul[0].data
169+
wcs = WCS(hdul[0].header)
159170
```
160171

161-
```{code-cell} ipython3
162-
cutout = Cutout2D(image1[0].data, pos, (60, 60), wcs=wcs)
163-
wcs = cutout.wcs
164-
```
172+
Visualize an image by sending its URL to the Firefly viewer.
173+
Try using the interactive tools in the viewer to explore the data.
165174

166175
```{code-cell} ipython3
167-
fig = plt.figure()
176+
# Uncomment when opening a Firefly viewer in a tab within Jupyter Lab with jupyter_firefly_extensions installed
177+
# fc = FireflyClient.make_lab_client()
168178
169-
ax = fig.add_subplot(1, 1, 1, projection=wcs)
170-
ax.imshow(cutout.data, cmap='gray_r', origin='lower',
171-
vmax = 1000)
172-
ax.scatter(ra, dec, transform=ax.get_transform('fk5'), s=500, edgecolor='red', facecolor='none')
179+
# Uncomment when opening Firefly viewer in contexts other than the above
180+
fc = FireflyClient.make_client(url="https://irsa.ipac.caltech.edu/irsaviewer")
181+
182+
# Visualize an image by sending its URL to the viewer.
183+
fc.show_fits_image(file_input=image_url,
184+
plot_id="image",
185+
Title="Image"
186+
)
173187
```
174188

189+
## 5. Extract a cutout and plot it
190+
If you want to see just a cutout of a certain region around the target, we do that below using astropy's Cutout2D.
191+
175192
```{code-cell} ipython3
193+
# make 1' x 1' cutout
194+
cutout = Cutout2D(data, position=pos, size=1 * u.arcmin, wcs=wcs)
195+
196+
#add quick normalization/stretch
197+
norm = simple_norm(cutout.data, stretch="sqrt", percent=99)
176198
199+
# display
200+
plt.imshow(cutout.data, origin='lower', norm = norm)
201+
plt.colorbar(label="Image value")
202+
plt.title("ALLWISE W3 (quicklook)")
203+
plt.xlabel("Pixel X")
204+
plt.ylabel("Pixel Y")
177205
```
178206

179207
***
180208

181209
+++
182210

183-
## About this notebook
184-
185-
+++
186-
187-
**Updated:** 2022-02-14
188-
189-
**Contact:** [the IRSA Helpdesk](https://irsa.ipac.caltech.edu/docs/help_desk.html) with questions or reporting problems.
211+
## Acknowledgements
190212

213+
- [Caltech/IPAC-IRSA](https://irsa.ipac.caltech.edu/)
191214

192215
+++
193216

194-
## Citations
217+
## About this notebook
195218

196-
+++
219+
**Updated:** 2 March 2026
197220

198-
If you use `astropy` for published research, please cite the authors. Follow these links for more information about citing `astropy`:
221+
**Contact:** [IRSA Helpdesk](https://irsa.ipac.caltech.edu/docs/help_desk.html) with questions or problems.
199222

200-
* [Citing `astropy`](https://www.astropy.org/acknowledging.html)
223+
**Runtime:** As of the date above, this notebook takes about 20 seconds to run to completion on a machine with 8GB RAM and 4 CPU.
224+
This runtime is dependent on archive servers which means runtime will vary for users.
201225

202226
+++
203227

204-
Please include the following in any published material that makes use of the WISE data products:
228+
## Citations
205229

206-
"This publication makes use of data products from the Wide-field Infrared Survey Explorer, which is a joint project of the University of California, Los Angeles, and the Jet Propulsion Laboratory/California Institute of Technology, funded by the National Aeronautics and Space Administration."
230+
**Astropy:**
231+
This work made use of [Astropy](http://www.astropy.org) a community-developed core Python package and an ecosystem of tools and resources for astronomy (Astropy Collaboration et al., 2013, Astropy Collaboration et al., 2018, Astropy Collaboration et al.,2022).
207232

208-
Please also cite the dataset Digital Object Identifier (DOI): [10.26131/IRSA153](https://www.ipac.caltech.edu/doi/irsa/10.26131/IRSA153)
233+
**Astroquery:**
234+
This work made use of [Astroquery](https://astroquery.readthedocs.io/en/latest/) a set of tools for querying astronomical web forms and databases (Ginsburg, Sipőcz, Brasseur et al 2019.).
209235

210-
```{code-cell} ipython3
211-
212-
```
236+
**WISE:**
237+
This publication makes use of data products from the Wide-field Infrared Survey Explorer, which is a joint project of the University of California, Los Angeles, and the Jet Propulsion Laboratory/California Institute of Technology, funded by the National Aeronautics and Space Administration."
238+
Digital Object Identifier (DOI): [10.26131/IRSA153](https://www.ipac.caltech.edu/doi/irsa/10.26131/IRSA153)

0 commit comments

Comments
 (0)