Skip to content

Commit 1c4ae71

Browse files
authored
Merge pull request #125 from bsipocz/MAINT_spherex_switch_astroquery
2 parents 272ec6e + 9497fc9 commit 1c4ae71

File tree

1 file changed

+24
-38
lines changed

1 file changed

+24
-38
lines changed

tutorials/spherex/spherex_intro.md

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ jupytext:
77
format_version: 0.13
88
jupytext_version: 1.17.2
99
kernelspec:
10-
name: python3
1110
display_name: Python 3 (ipykernel)
1211
language: python
12+
name: python3
1313
---
1414

1515
# Introduction to SPHEREx Spectral Images
@@ -43,7 +43,7 @@ More information is available in the [SPHEREx Explanatory Supplement](https://ir
4343
The following packages must be installed to run this notebook. Comment out the following lines if they are already installed.
4444

4545
```{code-cell} ipython3
46-
# !pip install numpy matplotlib astropy pyvo firefly-client
46+
# pip install numpy matplotlib astropy astroquery firefly-client
4747
```
4848

4949
## 4. Imports
@@ -58,8 +58,7 @@ from astropy.table import Table
5858
from astropy import units as u
5959
from astropy.coordinates import SkyCoord
6060
61-
import pyvo
62-
from pyvo.dal.adhoc import DatalinkResults
61+
from astroquery.ipac.irsa import Irsa
6362
6463
from firefly_client import FireflyClient
6564
```
@@ -73,31 +72,32 @@ Define some coordinates of interest.
7372
```{code-cell} ipython3
7473
ra_deg = 304.693508808
7574
dec_deg = 42.4436872991
75+
76+
coord = SkyCoord(ra_deg, dec_deg, unit='deg')
77+
search_radius = 1 * u.arcsec
7678
```
7779

78-
Query IRSA for a list of Spectral Image MEFs that overlap this position.
80+
Query IRSA for a list of Spectral Image MEFs that overlap this position. We use the [IRSA module in astroquery](https://astroquery.readthedocs.io/en/latest/ipac/irsa/irsa.html) and the Simple Image Access (SIA) API.
7981

80-
```{code-cell} ipython3
81-
# Define the TAP service URL for IRSA
82-
tap_url = "https://irsa.ipac.caltech.edu/TAP"
82+
+++
8383

84-
# Connect to the TAP service
85-
service = pyvo.dal.TAPService(tap_url)
84+
```{tip}
85+
The IRSA SIA collections can be listed using using the ``list_collections`` method, we can filter on the ones containing "spherex" in the collection name:
8686
87-
# Define your ADQL query
88-
query = "SELECT * FROM spherex.obscore WHERE CONTAINS(POINT('ICRS',"+str(ra_deg)+","+str(dec_deg)+"), s_region)=1"
87+
Irsa.list_collections(filter='spherex')
88+
```
8989

90-
# Submit the asynchronous query
91-
job = service.submit_job(query)
90+
+++
9291

93-
# Run the job (starts the query execution on the server)
94-
job.run()
92+
The collections are documented at [SPHEREx Data Access: Application Program Interfaces (APIs)](https://caltech-ipac.github.io/spherex-archive-documentation/spherex-data-access#application-program-interfaces-apis)
93+
There are currently three collections available:
9594

96-
# Wait for the job to complete (polling)
97-
job.wait(phases=["COMPLETED", "ERROR", "ABORTED"], timeout=300)
95+
* `'spherex_qr'` -- Quick Release Spectral Image MEFs that are part of the SPHEREx **Wide Survey**
96+
* `'spherex_qr_cal'` -- Quick Release **Calibration files**
97+
* `'spherex_qr_deep'` -- Quick Release Spectral Image MEFs that are part of the SPHEREx **Deep Survey**
9898

99-
# Capture the results
100-
results = job.fetch_result()
99+
```{code-cell} ipython3
100+
results = Irsa.query_sia(pos=(coord, search_radius), collection='spherex_qr')
101101
```
102102

103103
Each row of the results of your query represents a different spectral image.
@@ -112,28 +112,14 @@ len(results)
112112
The query results provide a lot of metadata about each spectral image. These columns have standard names as defined by the IVOA. Let's list them:
113113

114114
```{code-cell} ipython3
115-
list(results.fieldnames)
115+
results.colnames
116116
```
117117

118-
The 'access_url' column is particularly important because it tells you how to access the data. Let's look at the 'access_url' value for the first row:
119-
120-
```{code-cell} ipython3
121-
results['access_url'][0]
122-
```
123-
124-
Examining this URL, it does not provide direct access to the SPHEREx spectral image. Rather, it returns a file that lists all the data products and services associated with this spectral image. For the SPHEREx Quick Release products, this includes:
125-
126-
(1) the primary product, a Spectral Image MEF ('semantics' column is #this); and
127-
128-
(2) a cutout service ('semantics' is #cutout).
129-
130-
Most users will be interested in the primary (#this) product. Here's how you get the URL to download it for the first row:
118+
The `'access_url'` column is particularly important because it tells you how to access the data. Let's look at the `'access_url'` value for the first row:
131119

132120
```{code-cell} ipython3
133-
datalink_url = results['access_url'][0]
134-
datalink_content = DatalinkResults.from_result_url(datalink_url)
135-
spectral_image_url = next(datalink_content.bysemantics("#this")).access_url
136-
spectral_image_url
121+
spectral_image_url = results['access_url'][0]
122+
print(spectral_image_url)
137123
```
138124

139125
You can put this URL into a browser to download the file. Or you can work with it in Python, as shown below.

0 commit comments

Comments
 (0)