Skip to content

Commit 857e02a

Browse files
jkrickbsipocz
authored andcommitted
fully functional cosmos data access tutorial with same structure as SIAv2 tutorial
1 parent 7c2a259 commit 857e02a

1 file changed

Lines changed: 99 additions & 75 deletions

File tree

tutorials/cosmos/sia_v1_cosmos.md

Lines changed: 99 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.16.2
7+
jupytext_version: 1.19.1
88
kernelspec:
9-
display_name: Python 3 (ipykernel)
10-
language: python
119
name: python3
10+
display_name: python3
11+
language: python
1212
authors:
13-
- name: David Shupe
14-
- name: IRSA Science Team
13+
- name: IRSA Data Science Team
14+
- name: Troy Raen
15+
- name: Brigitta Sipőcz
16+
- name: Jessica Krick
17+
- name: Andreas Faisst
18+
- name: Jaladh Singhal
19+
- name: Vandana Desai
20+
- name: Dave Shupe
1521
---
1622

1723
# Searching for contributed COSMOS images
@@ -20,7 +26,6 @@ authors:
2026

2127
This notebook tutorial demonstrates the process of querying IRSA's Simple Image Access (SIA) service for the COSMOS images, making a cutout image (thumbnail), and displaying the cutout.
2228

23-
2429
+++
2530

2631
## Learning Goals
@@ -40,11 +45,12 @@ The COSMOS Archive serves data taken for the Cosmic Evolution Survey with HST (C
4045

4146
https://irsa.ipac.caltech.edu/Missions/cosmos.html
4247

43-
The [NASA/IPAC Infrared Science Archive (IRSA)](https://irsa.ipac.caltech.edu) at Caltech is one of the archives for COSMOS images and catalogs. The COSMOS 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 SEIP 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 SIA service for a list of images that meet specified criteria, and standard Python libraries can be used to download and manipulate the images.
44-
Other datasets at IRSA are available through other SIA services:
45-
46-
https://irsa.ipac.caltech.edu/docs/program_interface/api_images.html
48+
The [NASA/IPAC Infrared Science Archive (IRSA)](https://irsa.ipac.caltech.edu) at Caltech is one of the [archives](https://irsa.ipac.caltech.edu/Missions/cosmos.html) for COSMOS images and catalogs. The COSMOS 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.
4749

50+
```{note}
51+
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 v1 for COSMOS images.
52+
This SIA v1 service is based on an older set of SIA protocols and is limited to the COSMOS, WISE, 2MASS, and PTF datasets. It allows for only position-based searches to a single table. The IRSA SIA v1 search service has been superseded by the SIA v2 service for datasets other than COSMOS and PTF.
53+
```
4854

4955
+++
5056

@@ -61,141 +67,159 @@ https://irsa.ipac.caltech.edu/docs/program_interface/api_images.html
6167

6268
```{code-cell} ipython3
6369
# Uncomment the next line to install dependencies if needed.
64-
# !pip install matplotlib astropy pyvo
70+
!pip -q install matplotlib astropy pyvo jupyter_firefly_extensions
6571
```
6672

6773
```{code-cell} ipython3
6874
import pyvo as vo
75+
import numpy as np
6976
from astropy.coordinates import SkyCoord
7077
from astropy.nddata import Cutout2D
7178
from astropy.wcs import WCS
72-
import astropy.units as u
7379
import matplotlib.pyplot as plt
74-
from astropy.utils.data import download_file
7580
from astropy.io import fits
81+
import astropy.units as u
82+
from firefly_client import FireflyClient
7683
```
7784

78-
## Section 1 - Setup
79-
80-
+++
81-
82-
Set images to display in the notebook
83-
84-
```{code-cell} ipython3
85-
%matplotlib inline
86-
```
87-
88-
Define coordinates of a bright source
85+
## 1. Define the target
86+
Define coordinates of a bright star
8987

9088
```{code-cell} ipython3
9189
ra = 149.99986
9290
dec = 2.24875
9391
pos = SkyCoord(ra=ra, dec=dec, unit='deg')
9492
```
9593

96-
## Section 2 - Lookup and define a service for COSMOS images
97-
98-
+++
99-
100-
Start at STScI VAO Registry at https://vao.stsci.edu/keyword-search/
101-
102-
Limit by Publisher "NASA/IPAC Infrared Science Archive" and Capability Type "Simple Image Access Protocol" then search on "COSMOS"
103-
104-
Locate the SIA2 URL https://irsa.ipac.caltech.edu/cgi-bin/Atlas/nph-atlas?mission=COSMOS&hdr_location=%5CCOSMOSDataPath%5C&collection_desc=Cosmic+Evolution+Survey+with+HST+%28COSMOS%29&SIAP_ACTIVE=1&
94+
## 2. Discover COSMOS images
10595

10696
```{code-cell} ipython3
10797
cosmos_service = vo.dal.SIAService("https://irsa.ipac.caltech.edu/cgi-bin/Atlas/nph-atlas?mission=COSMOS&hdr_location=%5CCOSMOSDataPath%5C&collection_desc=Cosmic+Evolution+Survey+with+HST+%28COSMOS%29&SIAP_ACTIVE=1&")
10898
```
10999

110-
## Section 3 - Search the service
111-
112-
+++
113-
114-
Search for images covering within 1 arcsecond of the star
100+
## 3. Search for images
101+
Which images in the COSMOS dataset include our target of interest?
115102

116103
```{code-cell} ipython3
117-
im_table = cosmos_service.search(pos=pos, size=1.0*u.arcsec)
104+
# Get a table of all images that cover this position
105+
# This service actually returns a cutout of whatever size you choose
106+
im_table = cosmos_service.search(pos=pos, size=150*u.arcsec)
118107
```
119108

120-
Inspect the table of images that is returned
121-
122109
```{code-cell} ipython3
123-
im_table
110+
# Inspect the top of the table that is returned
111+
im_table.to_table()[:10]
124112
```
125113

126114
```{code-cell} ipython3
115+
# Look at a list of the column names included in this table
127116
im_table.to_table().colnames
128117
```
129118

130-
View the first ten entries of the table
131-
132119
```{code-cell} ipython3
133-
im_table.to_table()[:10]
120+
# Let's look at the unique values in one of the columns
121+
print(np.unique(im_table['band_name']))
134122
```
135123

136-
## Section 4 - Locate and download an image of interest
124+
##
137125

138126
+++
139127

140-
Locate the first image in the band_name of i+
128+
## 4.Locate and visualize an image of interest
129+
130+
We start by filtering the image results for the first IRAC1 band images.
131+
Then look at the header of one of the resulting image of our target star.
132+
Finally, we create an interactive FITS display of the IRAC1 image by using [Firefly](https://caltech-ipac.github.io/firefly_client/index.html), an open-source interactive visualization tool for astronomical data.
133+
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.
141134

142135
```{code-cell} ipython3
143-
for i in range(len(im_table)):
144-
if im_table[i]['band_name'] == 'i+':
145-
break
146-
print(im_table[i].getdataurl())
147-
```
136+
# You can put the URL from the column "sia_url" into a browser to download the file.
137+
# Or you can work with it in Python, as shown below.
148138
149-
Download the image
139+
im_table_astropy = im_table.to_table()
150140
151-
```{code-cell} ipython3
152-
fname = download_file(im_table[i].getdataurl(), cache=True)
153-
image1 = fits.open(fname)
141+
irac1_rows = im_table_astropy[
142+
im_table_astropy['band_name'] == 'IRAC1'
143+
]
154144
```
155145

156-
## Section 5 - Extract a cutout and plot it
157-
158146
```{code-cell} ipython3
159-
wcs = WCS(image1[0].header)
147+
# Lets look at the data access url in the column named 'sia_url'.
148+
# We will focus on the first image for now.
149+
image_url = irac1_rows[0]['sia_url']
150+
print(image_url)
160151
```
161152

162-
Make a cutout centered on the position
153+
```{code-cell} ipython3
154+
#Use Astropy to examine the header of the URL from the previous step.
155+
hdulist = fits.open(image_url)
156+
hdulist.info()
157+
```
163158

164159
```{code-cell} ipython3
165-
cutout = Cutout2D(image1[0].data, pos, (60, 60), wcs=wcs)
166-
wcs = cutout.wcs
160+
# Uncomment when opening a Firefly viewer in a tab within Jupyter Lab with jupyter_firefly_extensions installed
161+
#fc = FireflyClient.make_lab_client()
162+
163+
# Uncomment when opening Firefly viewer in contexts other than the above
164+
fc = FireflyClient.make_client(url="https://irsa.ipac.caltech.edu/irsaviewer")
165+
166+
# Visualize an image by sending its URL to the viewer.
167+
fc.show_fits_image(file_input=image_url,
168+
plot_id="image",
169+
Title="Image"
170+
)
171+
172+
#Try use the interactive tools in the viewer to explore the data.
167173
```
168174

175+
## 5. Extract a cutout and plot it
176+
If you want to see just a cutout of a certain region around the target, we do that below using astropy's Cutout2D.
177+
169178
```{code-cell} ipython3
170-
fig = plt.figure()
179+
data = hdulist[0].data
180+
wcs = WCS(hdulist[0].header)
181+
182+
# make 0.5' x 0.5' cutout
183+
cutout = Cutout2D(data, position=pos, size=0.5 * u.arcmin, wcs=wcs)
171184
172-
ax = fig.add_subplot(1, 1, 1, projection=wcs)
173-
ax.imshow(cutout.data, cmap='gray_r', origin='lower')
174-
ax.scatter(ra, dec, transform=ax.get_transform('fk5'), s=500, edgecolor='red', facecolor='none')
185+
# display
186+
plt.figure()
187+
plt.imshow(cutout.data, origin='lower')
188+
plt.colorbar()
175189
```
176190

177191
***
178192

179193
+++
180194

181-
## About this notebook
195+
## Acknowledgements
196+
197+
- [Caltech/IPAC-IRSA](https://irsa.ipac.caltech.edu/)
182198

183199
+++
184200

185-
**Updated:** 2022-02-14
186201

187-
**Contact:** [the IRSA Helpdesk](https://irsa.ipac.caltech.edu/docs/help_desk.html) with questions or reporting problems.
202+
## About this notebook
188203

189-
+++
204+
**Updated:** 2 March 2026
190205

191-
## Citations
206+
**Contact:** [IRSA Helpdesk](https://irsa.ipac.caltech.edu/docs/help_desk.html) with questions or problems.
192207

193-
+++
208+
**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.
209+
This runtime is dependent on archive servers which means runtime will vary for users.
194210

195-
If you use `astropy` for published research, please cite the authors. Follow these links for more information about citing `astropy`:
211+
+++
196212

197-
* [Citing `astropy`](https://www.astropy.org/acknowledging.html)
213+
## Citations
198214

199-
+++
215+
**Astropy:**
216+
To see the Bibtex references for this, uncomment the below cell
200217

218+
**COSMOS:**
201219
If you use COSMOS ACS imaging data in published research, please cite the dataset Digital Object Identifier (DOI): [10.26131/IRSA178](https://www.ipac.caltech.edu/doi/irsa/10.26131/IRSA178).
220+
221+
```{code-cell} ipython3
222+
#import astropy
223+
224+
#astropy.__citation__
225+
```

0 commit comments

Comments
 (0)