Skip to content

Commit bee65b1

Browse files
authored
Merge pull request #60 from bsipocz/euclid_swap_pyvo_for_astroquery
ENH: Euclid swap pyvo for astroquery
2 parents b6c79ea + 0555f9b commit bee65b1

4 files changed

Lines changed: 62 additions & 113 deletions

File tree

tutorials/euclid_access/1_Euclid_intro_MER_images.md

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Each MER image is approximately 1.47 GB. Downloading can take some time.
5858

5959
```{code-cell} ipython3
6060
# Uncomment the next line to install dependencies if needed.
61-
# !pip install numpy 'astropy>=5.3' matplotlib pyvo 'sep>=1.4' fsspec pandas
61+
# !pip install numpy 'astropy>=5.3' matplotlib 'astroquery>=0.4.10' 'sep>=1.4' fsspec
6262
```
6363

6464
```{code-cell} ipython3
@@ -78,7 +78,7 @@ from astropy.visualization import ImageNormalize, PercentileInterval, AsinhStret
7878
from astropy.wcs import WCS
7979
from astropy import units as u
8080
81-
import pyvo as vo
81+
from astroquery.ipac.irsa import Irsa
8282
import sep
8383
8484
# Copy-on-write is more performant and avoids unexpected modifications of the original DataFrame.
@@ -95,44 +95,23 @@ coord = SkyCoord.from_name('HD 168151')
9595

9696
Use IRSA's Simple Image Access (SIA) API to search for all Euclid MER mosaics that overlap with the search region you have specified. We specify the euclid_DpdMerBksMosaic "collection" because it lists all of the multiwavelength MER mosaics, along with their associated catalogs.
9797

98-
```{code-cell} ipython3
99-
irsa_service= vo.dal.sia2.SIA2Service('https://irsa.ipac.caltech.edu/SIA')
100-
101-
image_table = irsa_service.search(pos=(coord, search_radius), collection='euclid_DpdMerBksMosaic')
102-
```
103-
104-
Convert the table to pandas dataframe
105-
106-
```{code-cell} ipython3
107-
df_im_irsa=image_table.to_table().to_pandas().reset_index()
108-
```
98+
```{tip}
99+
The IRSA SIA collections can be listed using using the ``list_collections`` method, we can filter on the ones containing "euclid" in the collection name:
109100
110-
Change the settings so we can see all the columns in the dataframe and the full column width (to see the full long URL)
111-
112-
```{code-cell} ipython3
113-
pd.set_option('display.max_columns', None)
114-
pd.set_option('display.max_colwidth', None)
115-
116-
117-
## Can use the following lines to reset the max columns and column width of pandas
118-
# pd.reset_option('display.max_columns')
119-
# pd.reset_option('display.max_colwidth')
101+
Irsa.list_collections(filter='euclid')
120102
```
121103

122104
```{code-cell} ipython3
123-
df_im_irsa
105+
image_table = Irsa.query_sia(pos=(coord, search_radius), collection='euclid_DpdMerBksMosaic')
124106
```
125107

126-
This dataframe contains lots of datasets that have been "Euclidized", which means that they have been put on a common pixel scale chosen for the Euclid mission. Choose "science" as the data product subtype to see all science images of this tile.
108+
This table lists all MER mosaic images available in this search position. These mosaics include the Euclid VIS, Y, J, H images, as well as ground-based telescopes which have been put on the same pixel scale. For more information, see the [Euclid documentation at IPAC](https://euclid.caltech.edu/page/euclid-faq-tech/).
127109

128-
```{code-cell} ipython3
129-
df_im_euclid=df_im_irsa[ (df_im_irsa['dataproduct_subtype']=='science')].reset_index()
130-
131-
df_im_euclid
132-
```
110+
Note that there are various image types are returned as well, we filter out the `science` images from these:
133111

134112
```{code-cell} ipython3
135-
print('There are',len(df_im_euclid),'MER images of this object/MER tile.')
113+
science_images = image_table[image_table['dataproduct_subtype'] == 'science']
114+
science_images
136115
```
137116

138117
## 2. Retrieve a Euclid Q1 MER mosaic image in the VIS bandpass
@@ -144,8 +123,8 @@ print('There are',len(df_im_euclid),'MER images of this object/MER tile.')
144123
Note that 'access_estsize' is in units of kb
145124

146125
```{code-cell} ipython3
147-
filename = df_im_euclid[df_im_euclid['energy_bandpassname']=='VIS']['access_url'].to_list()[0]
148-
filesize = df_im_euclid[df_im_euclid['energy_bandpassname']=='VIS']['access_estsize'].to_list()[0]/1000000
126+
filename = science_images[science_images['energy_bandpassname']=='VIS']['access_url'][0]
127+
filesize = science_images[science_images['energy_bandpassname']=='VIS']['access_estsize'][0]/1000000
149128
150129
print(filename)
151130
@@ -216,7 +195,7 @@ We'd like to take a look at the multiwavelength images of our object, but the fu
216195
```
217196

218197
```{code-cell} ipython3
219-
urls = df_im_euclid['access_url'].to_list()
198+
urls = science_images['access_url']
220199
221200
urls
222201
```

tutorials/euclid_access/2_Euclid_intro_MER_catalog.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,24 @@ If you have questions about this notebook, please contact the [IRSA helpdesk](ht
5050

5151
```{code-cell} ipython3
5252
# Uncomment the next line to install dependencies if needed
53-
# !pip install numpy matplotlib pyvo
53+
# !pip install numpy matplotlib 'astroquery>=0.4.10'
5454
```
5555

5656
```{code-cell} ipython3
5757
import numpy as np
5858
import matplotlib.pyplot as plt
5959
60-
import pyvo as vo
60+
from astroquery.ipac.irsa import Irsa
6161
```
6262

6363
## 1. Download MER catalog from IRSA directly to this notebook
6464

65-
```{code-cell} ipython3
66-
service = vo.dal.TAPService("https://irsa.ipac.caltech.edu/TAP")
67-
```
65+
+++
66+
67+
First, have a look at what Euclid catalogs are available. With the ``list_catalogs`` functionality, we'll receive a list of the name of the catalogs as well as their brief desciption.
6868

6969
```{code-cell} ipython3
70-
tables = service.tables
71-
for tablename in tables.keys():
72-
if "tap_schema" not in tablename and "euclid_q1" in tablename:
73-
tables[tablename].describe()
70+
Irsa.list_catalogs(filter='euclid')
7471
```
7572

7673
### Choose the Euclid MER table
@@ -79,18 +76,17 @@ for tablename in tables.keys():
7976
table_mer = 'euclid_q1_mer_catalogue'
8077
```
8178

82-
### Learn some information about the table:
79+
### Learn some information about the MER catalog:
8380
- How many columns are there?
8481
- List the column names
8582

8683
```{code-cell} ipython3
87-
columns = tables[table_mer].columns
88-
print(len(columns))
84+
columns_info = Irsa.list_columns(catalog=table_mer)
85+
print(len(columns_info))
8986
```
9087

9188
```{code-cell} ipython3
92-
for col in columns:
93-
print(f'{f"{col.name}":30s} {col.unit} {col.description}')
89+
columns_info
9490
```
9591

9692
```{tip}
@@ -121,7 +117,7 @@ adql_stars = ("SELECT TOP 10000 mer.object_id, mer.ra, mer.dec, mer.flux_vis_psf
121117
122118
# Run the query
123119
124-
result_stars = service.search(adql_stars)
120+
result_stars = Irsa.query_tap(adql_stars)
125121
```
126122

127123
```{code-cell} ipython3

tutorials/euclid_access/4_Euclid_intro_PHZ_catalog.md

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ If you have questions about this notebook, please contact the [IRSA helpdesk](ht
5151

5252
```{code-cell} ipython3
5353
# Uncomment the next line to install dependencies if needed.
54-
# !pip install requests matplotlib pandas 'astropy>=5.3' pyvo fsspec firefly_client
54+
# !pip install requests matplotlib pandas 'astropy>=5.3' 'astroquery>=0.4.10' fsspec firefly_client
5555
```
5656

5757
```{code-cell} ipython3
@@ -72,7 +72,7 @@ from astropy.visualization import ImageNormalize, PercentileInterval, AsinhStret
7272
from astropy.wcs import WCS
7373
7474
from firefly_client import FireflyClient
75-
import pyvo as vo
75+
from astroquery.ipac.irsa import Irsa
7676
```
7777

7878
## 1. Find the MER Tile ID that corresponds to a given RA and Dec
@@ -92,9 +92,7 @@ coord = SkyCoord(ra, dec, unit='deg', frame='icrs')
9292
This searches specifically in the euclid_DpdMerBksMosaic "collection" which is the MER images and catalogs.
9393

9494
```{code-cell} ipython3
95-
irsa_service= vo.dal.sia2.SIA2Service('https://irsa.ipac.caltech.edu/SIA')
96-
97-
image_table = irsa_service.search(pos=(coord, search_radius), collection='euclid_DpdMerBksMosaic').to_table()
95+
image_table = Irsa.query_sia(pos=(coord, search_radius), collection='euclid_DpdMerBksMosaic')
9896
```
9997

10098
```{note}
@@ -123,47 +121,42 @@ print('The MER tile ID for this object is :',tileID)
123121

124122
## 2. Download PHZ catalog from IRSA
125123

126-
```{code-cell} ipython3
127-
## Use IRSA to search for catalogs
128-
129-
service = vo.dal.TAPService("https://irsa.ipac.caltech.edu/TAP")
124+
Use IRSA's TAP to search catalogs
130125

131-
132-
## Search for all tables in IRSA labled as euclid_q1
133-
tables = service.tables
134-
for tablename in tables.keys():
135-
if "tap_schema" not in tablename and "euclid_q1" in tablename:
136-
tables[tablename].describe()
126+
```{code-cell} ipython3
127+
Irsa.list_catalogs(filter='euclid')
137128
```
138129

139130
```{code-cell} ipython3
140-
table_mer= 'euclid_q1_mer_catalogue'
141-
table_phz= 'euclid_q1_phz_photo_z'
142-
table_1dspectra= 'euclid.objectid_spectrafile_association_q1'
131+
table_mer = 'euclid_q1_mer_catalogue'
132+
table_phz = 'euclid_q1_phz_photo_z'
133+
table_1dspectra = 'euclid.objectid_spectrafile_association_q1'
143134
```
144135

145-
### Learn some information about the table:
136+
### Learn some information about the photo-z catalog:
146137

147138
- How many columns are there?
148139
- List the column names
149140

150141
```{code-cell} ipython3
151-
columns = tables[table_phz].columns
152-
print(len(columns))
153-
```
154-
155-
```{code-cell} ipython3
156-
for col in columns:
157-
print(f'{f"{col.name}":30s} {col.unit} {col.description}') ## Currently no descriptions
142+
columns_info = Irsa.list_columns(catalog=table_phz)
143+
print(len(columns_info))
158144
```
159145

146+
```{tip}
160147
The PHZ catalog contains 67 columns, below are a few highlights:
161148
162149
- object_id
163150
- flux_vis_unif, flux_y_unif, flux_j_unif, flux_h_unif
164151
- median redshift (phz_median)
165152
- phz_classification
166153
- phz_90_int1, phz_90_int2 (The phz PDF interval containing 90% of the probability, upper and lower values)
154+
```
155+
156+
```{code-cell} ipython3
157+
# Full list of columns and their description
158+
columns_info
159+
```
167160

168161
```{note}
169162
The phz_catalog on IRSA has more columns than it does on the ESA archive.
@@ -228,8 +221,8 @@ AND phz.phz_median BETWEEN 1.4 AND 1.6 \
228221
adql
229222
230223
231-
## Use TAP with this ADQL string using pyvo
232-
result = service.search(adql)
224+
## Use TAP with this ADQL string
225+
result = Irsa.query_tap(adql)
233226
234227
235228
## Convert table to pandas dataframe
@@ -326,7 +319,7 @@ FROM {table_1dspectra} \
326319
WHERE objectid = {obj_id}"
327320
328321
## Pull the data on this particular galaxy
329-
result2 = service.search(adql_object)
322+
result2 = Irsa.query_tap(adql_object)
330323
df2=result2.to_table().to_pandas()
331324
df2
332325
```

tutorials/euclid_access/5_Euclid_intro_SPE_catalog.md

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ If you have questions about this notebook, please contact the [IRSA helpdesk](ht
5050

5151
```{code-cell} ipython3
5252
# Uncomment the next line to install dependencies if needed
53-
# !pip install matplotlib pandas astropy pyvo
53+
# !pip install matplotlib pandas astropy 'astroquery>=0.4.10'
5454
```
5555

5656
```{code-cell} ipython3
@@ -69,7 +69,7 @@ from astropy import units as u
6969
from astropy.utils.data import download_file
7070
from astropy.visualization import ImageNormalize, PercentileInterval, AsinhStretch
7171
72-
import pyvo as vo
72+
from astroquery.ipac.irsa import Irsa
7373
```
7474

7575
## 1. Find the MER Tile ID that corresponds to a given RA and Dec
@@ -86,12 +86,10 @@ coord = SkyCoord.from_name('HD 168151')
8686
This searches specifically in the euclid_DpdMerBksMosaic "collection" which is the MER images and catalogs.
8787

8888
```{code-cell} ipython3
89-
irsa_service= vo.dal.sia2.SIA2Service('https://irsa.ipac.caltech.edu/SIA')
90-
91-
im_table = irsa_service.search(pos=(coord, search_radius), collection='euclid_DpdMerBksMosaic')
89+
im_table = Irsa.query_sia(pos=(coord, search_radius), collection='euclid_DpdMerBksMosaic')
9290
9391
## Convert the table to pandas dataframe
94-
df_im_irsa=im_table.to_table().to_pandas()
92+
df_im_irsa=im_table.to_pandas()
9593
```
9694

9795
```{code-cell} ipython3
@@ -125,45 +123,28 @@ print('The MER tile ID for this object is :',tileID)
125123
Search for all tables in IRSA labeled as euclid
126124

127125
```{code-cell} ipython3
128-
service = vo.dal.TAPService("https://irsa.ipac.caltech.edu/TAP")
129-
130-
tables = service.tables
131-
for tablename in tables.keys():
132-
if "tap_schema" not in tablename and "euclid" in tablename:
133-
tables[tablename].describe()
126+
Irsa.list_catalogs(filter='euclid')
134127
```
135128

136129
```{code-cell} ipython3
137-
table_mer= 'euclid_q1_mer_catalogue'
138-
table_galaxy_candidates= 'euclid_q1_spectro_zcatalog_spe_galaxy_candidates'
139-
table_1dspectra= 'euclid.objectid_spectrafile_association_q1'
140-
table_lines= 'euclid_q1_spe_lines_line_features'
130+
table_mer = 'euclid_q1_mer_catalogue'
131+
table_galaxy_candidates = 'euclid_q1_spectro_zcatalog_spe_galaxy_candidates'
132+
table_1dspectra = 'euclid.objectid_spectrafile_association_q1'
133+
table_lines = 'euclid_q1_spe_lines_line_features'
141134
```
142135

143136
### Learn some information about the table:
144137
- How many columns are there?
145138
- List the column names
146139

147140
```{code-cell} ipython3
148-
columns = tables[table_lines].columns
149-
print(len(columns))
150-
```
151-
152-
```{code-cell} ipython3
153-
for col in columns:
154-
print(f'{f"{col.name}":30s} {col.unit} {col.description}') ## Currently no descriptions
141+
columns_info = Irsa.list_columns(catalog=table_lines)
142+
print(len(columns_info))
155143
```
156144

157145
```{code-cell} ipython3
158-
## Change the settings so we can see all the columns in the dataframe and the full column width
159-
## (to see the full long URL)
160-
pd.set_option('display.max_columns', None)
161-
pd.set_option('display.max_colwidth', None)
162-
163-
164-
## Can use the following lines to reset the max columns and column width of pandas
165-
# pd.reset_option('display.max_columns')
166-
# pd.reset_option('display.max_colwidth')
146+
# Full list of columns and their description
147+
columns_info
167148
```
168149

169150
## Find some objects with spectra in our tileID
@@ -196,8 +177,8 @@ AND lines.spe_line_flux_gf > 2E-16 \
196177
ORDER BY lines.spe_line_snr_gf DESC \
197178
"
198179
199-
# Use TAP with this ADQL string using pyvo
200-
result = service.search(adql)
180+
# Use TAP with this ADQL string
181+
result = Irsa.query_tap(adql)
201182
202183
# Convert table to pandas dataframe and drop duplicates
203184
result_table = result.to_qtable()
@@ -222,7 +203,7 @@ obj_tab
222203
```{code-cell} ipython3
223204
adql_object = f"SELECT * FROM {table_1dspectra} WHERE objectid = {obj_id}"
224205
225-
result2 = service.search(adql_object)
206+
result2 = Irsa.query_tap(adql_object)
226207
df2 = result2.to_table().to_pandas()
227208
df2
228209
```

0 commit comments

Comments
 (0)