@@ -41,7 +41,7 @@ By the end of this tutorial, you will:
4141
4242## Introduction
4343
44- The COSMOS Archive serves data taken for the Cosmic Evolution Survey with HST (COSMOS) project, using IRSA's general search service, Atlas . COSMOS is an HST Treasury Project to survey a 2 square degree equatorial field with the ACS camera. For more information about COSMOS, see:
44+ The COSMOS Archive at IRSA serves data taken for the Cosmic Evolution Survey with HST (COSMOS) project. COSMOS is an HST Treasury Project to survey a 2 square degree equatorial field with the ACS camera. For more information about COSMOS, see:
4545
4646https://irsa.ipac.caltech.edu/Missions/cosmos.html
4747
@@ -56,30 +56,32 @@ This SIA v1 service is based on an older set of SIA protocols and is limited to
5656
5757## Imports
5858
59- - ` pyvo ` for querying IRSA's COSMOS SIA service
59+ - ` pyvo ` for discovering and querying IRSA's COSMOS SIA service
60+ - ` numpy ` for working with tables
6061- ` astropy.coordinates ` for defining coordinates
6162- ` astropy.nddata ` for creating an image cutout
6263- ` astropy.wcs ` for interpreting the World Coordinate System header keywords of a fits file
6364- ` astropy.units ` for attaching units to numbers passed to the SIA service
6465- ` matplotlib.pyplot ` for plotting
65- - ` astropy.utils.data ` for downloading files
6666- ` astropy.io ` to manipulate FITS files
67+ - ` firefly_client ` for visualizing data
6768
6869``` {code-cell} ipython3
6970# Uncomment the next line to install dependencies if needed.
70- !pip -q install matplotlib astropy pyvo jupyter_firefly_extensions
71+ # !pip -q install matplotlib astropy pyvo jupyter_firefly_extensions
7172```
7273
7374``` {code-cell} ipython3
74- import pyvo as vo
75+ from pyvo import regsearch
7576import numpy as np
7677from astropy.coordinates import SkyCoord
7778from astropy.nddata import Cutout2D
7879from astropy.wcs import WCS
80+ import astropy.units as u
7981import matplotlib.pyplot as plt
8082from astropy.io import fits
81- import astropy.units as u
8283from firefly_client import FireflyClient
84+ from astropy.visualization import simple_norm
8385```
8486
8587## 1. Define the target
@@ -94,38 +96,53 @@ pos = SkyCoord(ra=ra, dec=dec, unit='deg')
9496## 2. Discover COSMOS images
9597
9698``` {code-cell} ipython3
97- 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&")
99+ # Search the Virtual Observatory Registry for image services at IRSA associated with the COSMOS survey.
100+ image_services = regsearch(
101+ servicetype='sia1',
102+ keywords=['cosmos', 'irsa']
103+ )
104+
105+ # Make sure we got what we were looking for
106+ for i, r in enumerate(image_services):
107+ print(f"{i:2d} {r.short_name:20s} {r.res_title}")
108+
109+ # Turn the result into a usable image access service
110+ resource = image_services[0]
111+ cosmos_service = resource.get_service("sia1")
98112```
99113
100114## 3. Search for images
101115Which images in the COSMOS dataset include our target of interest?
102116
103117``` {code-cell} ipython3
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)
118+ # Get a table of all images that cover this position.
119+ # Choose the size of the returned image.
120+ im_results = cosmos_service.search(pos=pos, size=150*u.arcsec)
121+
122+ # Convert the PyVO result to an Astropy Table
123+ im_table = im_results.to_table()
107124```
108125
109126``` {code-cell} ipython3
110127# Inspect the top of the table that is returned
111- im_table.to_table() [:10]
128+ im_table[:10]
112129```
113130
114131``` {code-cell} ipython3
115132# Look at a list of the column names included in this table
116- im_table.to_table(). colnames
133+ im_table.colnames
117134```
118135
119136``` {code-cell} ipython3
120137# Let's look at the unique values in one of the columns
121- print(np.unique(im_table ['band_name']))
138+ print(np.unique(im_results ['band_name']))
122139```
123140
124141##
125142
126143+++
127144
128- ## 4.Locate and visualize an image of interest
145+ ## 4. Locate and visualize an image of interest
129146
130147We start by filtering the image results for the first IRAC1 band images.
131148Then look at the header of one of the resulting image of our target star.
@@ -136,24 +153,24 @@ To understand how to open the Firefly viewer in a new tab from your Python noteb
136153# You can put the URL from the column "sia_url" into a browser to download the file.
137154# Or you can work with it in Python, as shown below.
138155
139- im_table_astropy = im_table.to_table()
140-
141- irac1_rows = im_table_astropy[
142- im_table_astropy['band_name'] == 'IRAC1'
143- ]
156+ irac1_rows = im_table[im_table['band_name'] == 'IRAC1']
144157```
145158
146159``` {code-cell} ipython3
147- # Lets look at the data access url in the column named 'sia_url'.
160+ # Let's look at the data access url in the column named 'sia_url'.
148161# We will focus on the first image for now.
149162image_url = irac1_rows[0]['sia_url']
150163print(image_url)
151164```
152165
153166``` {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()
167+ # Use Astropy to examine the header of the URL from the previous step,
168+ # and grab the data and wcs from the header.
169+ with fits.open(image_url, memmap=False) as hdul:
170+ hdul.info()
171+ data = hdul[0].data
172+ wcs = WCS(hdul[0].header)
173+
157174```
158175
159176``` {code-cell} ipython3
@@ -169,23 +186,27 @@ fc.show_fits_image(file_input=image_url,
169186 Title="Image"
170187 )
171188
172- #Try use the interactive tools in the viewer to explore the data.
189+ #Try using the interactive tools in the viewer to explore the data.
173190```
174191
175192## 5. Extract a cutout and plot it
176193If you want to see just a cutout of a certain region around the target, we do that below using astropy's Cutout2D.
177194
178195``` {code-cell} ipython3
179- data = hdulist[0].data
180- wcs = WCS(hdulist[0].header)
181196
182197# make 0.5' x 0.5' cutout
183198cutout = Cutout2D(data, position=pos, size=0.5 * u.arcmin, wcs=wcs)
184199
200+ #add quick normalization/stretch
201+ norm = simple_norm(cutout.data, stretch="sqrt", percent=99)
202+
185203# display
186204plt.figure()
187- plt.imshow(cutout.data, origin='lower')
188- plt.colorbar()
205+ plt.imshow(cutout.data, origin='lower', norm = norm)
206+ plt.colorbar(label="Image value")
207+ plt.title("COSMOS IRAC1 (quicklook)")
208+ plt.xlabel("Pixel X")
209+ plt.ylabel("Pixel Y")
189210```
190211
191212***
0 commit comments