Skip to content

Commit 70762dc

Browse files
authored
Merge pull request #2837 from bsipocz/irsa_sia
ENH: ipac.irsa to have SIA backend
2 parents 176f77f + f8f36eb commit 70762dc

File tree

5 files changed

+129
-5
lines changed

5 files changed

+129
-5
lines changed

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ ipac.irsa
2626
``columns``, and the ``cache`` and ``verbose`` kwargs have been
2727
deprecated as they have no effect. [#2823]
2828

29+
- Method to run SIAv2 VO queries is added. [#2837]
30+
2931
gaia
3032
^^^^
3133

@@ -75,7 +77,7 @@ esa.xmm_newton
7577
simbad
7678
^^^^^^
7779

78-
- new ``query_tap`` method to access SIMBAD. This comes with additional methods to explore SIMBAD's tables and
80+
- new ``query_tap`` method to access SIMBAD. This comes with additional methods to explore SIMBAD's tables and
7981
their links: ``Simbad.list_tables``, ``Simbad.list_columns``, and ``Simbad.list_linked_tables``. [#2856]
8082

8183
solarsystem.neodys

astroquery/ipac/irsa/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Conf(_config.ConfigNamespace):
2727
timeout = _config.ConfigItem(
2828
60,
2929
'Time limit for connecting to the IRSA server.')
30+
sia_url = _config.ConfigItem('https://irsa.ipac.caltech.edu/SIA', 'IRSA SIA URL')
3031
tap_url = _config.ConfigItem('https://irsa.ipac.caltech.edu/TAP', 'IRSA TAP URL')
3132

3233

astroquery/ipac/irsa/core.py

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@
1111
from astropy.coordinates import SkyCoord, Angle
1212
from astropy import units as u
1313
from astropy.utils.decorators import deprecated_renamed_argument
14+
1415
from pyvo.dal import TAPService
16+
17+
try:
18+
from pyvo.dal.sia2 import SIA2Service, SIA2_PARAMETERS_DESC
19+
except ImportError:
20+
# Can be removed once min version of pyvo is 1.5
21+
from pyvo.dal.sia2 import SIA_PARAMETERS_DESC as SIA2_PARAMETERS_DESC
22+
from pyvo.dal.sia2 import SIAService as SIA2Service
23+
1524
from astroquery import log
1625
from astroquery.query import BaseVOQuery
1726
from astroquery.utils.commons import parse_coordinates
@@ -26,9 +35,17 @@ class IrsaClass(BaseVOQuery):
2635

2736
def __init__(self):
2837
super().__init__()
38+
self.sia_url = conf.sia_url
2939
self.tap_url = conf.tap_url
40+
self._sia = None
3041
self._tap = None
3142

43+
@property
44+
def sia(self):
45+
if not self._sia:
46+
self._sia = SIA2Service(baseurl=self.sia_url, session=self._session)
47+
return self._sia
48+
3249
@property
3350
def tap(self):
3451
if not self._tap:
@@ -60,10 +77,59 @@ def query_tap(self, query, *, maxrec=None):
6077
log.debug(f'TAP query: {query}')
6178
return self.tap.search(query, language='ADQL', maxrec=maxrec)
6279

80+
def query_sia(self, *, pos=None, band=None, time=None, pol=None,
81+
field_of_view=None, spatial_resolution=None,
82+
spectral_resolving_power=None, exptime=None,
83+
timeres=None, publisher_did=None,
84+
facility=None, collection=None,
85+
instrument=None, data_type=None,
86+
calib_level=None, target_name=None,
87+
res_format=None, maxrec=None,
88+
**kwargs):
89+
"""
90+
Use standard SIA2 attributes to query the IRSA SIA service.
91+
92+
Parameters
93+
----------
94+
_SIA2_PARAMETERS
95+
96+
Returns
97+
-------
98+
Results in `pyvo.dal.SIAResults` format.
99+
result.table in Astropy table format
100+
"""
101+
return self.sia.search(
102+
pos=pos,
103+
band=band,
104+
time=time,
105+
pol=pol,
106+
field_of_view=field_of_view,
107+
spatial_resolution=spatial_resolution,
108+
spectral_resolving_power=spectral_resolving_power,
109+
exptime=exptime,
110+
timeres=timeres,
111+
publisher_did=publisher_did,
112+
facility=facility,
113+
collection=collection,
114+
instrument=instrument,
115+
data_type=data_type,
116+
calib_level=calib_level,
117+
target_name=target_name,
118+
res_format=res_format,
119+
maxrec=maxrec,
120+
**kwargs)
121+
122+
# SIA2_PARAMETERS_DESC contains links that Sphinx can't resolve.
123+
# SIA2_PARAMETERS_DESC contains links that Sphinx can't resolve.
124+
for var in ('POLARIZATION_STATES', 'CALIBRATION_LEVELS'):
125+
SIA2_PARAMETERS_DESC = SIA2_PARAMETERS_DESC.replace(f'`pyvo.dam.obscore.{var}`',
126+
f'pyvo.dam.obscore.{var}')
127+
query_sia.__doc__ = query_sia.__doc__.replace('_SIA2_PARAMETERS', SIA2_PARAMETERS_DESC)
128+
63129
@deprecated_renamed_argument(("selcols", "cache", "verbose"), ("columns", None, None), since="0.4.7")
64130
def query_region(self, coordinates=None, *, catalog=None, spatial='Cone',
65131
radius=10 * u.arcsec, width=None, polygon=None,
66-
get_query_payload=False, columns=None,
132+
get_query_payload=False, columns='*',
67133
verbose=False, cache=True):
68134
"""
69135
Queries the IRSA TAP server around a coordinate and returns a `~astropy.table.Table` object.
@@ -106,9 +172,6 @@ def query_region(self, coordinates=None, *, catalog=None, spatial='Cone',
106172
if catalog is None:
107173
raise InvalidQueryError("Catalog name is required!")
108174

109-
if columns is None:
110-
columns = '*'
111-
112175
adql = f'SELECT {columns} FROM {catalog}'
113176

114177
if spatial == 'All-Sky':

docs/ipac/irsa/irsa.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,63 @@ returned as a `~pyvo.dal.TAPResults` object. Its ``to_table`` or ``to_qtable`` m
220220
202.809023 46.964558 15.874 0.081 ... 15.322 0.188 AAC 000
221221

222222

223+
Simple image access queries
224+
---------------------------
225+
226+
`~astroquery.ipac.irsa.IrsaClass.query_sia` provides a way to access IRSA's Simple
227+
Image Access VO service. In the following example we are looking for Spitzer
228+
Enhanced Imaging products in the centre of the COSMOS field as an `~astropy.table.Table`.
229+
230+
.. doctest-remote-data::
231+
232+
>>> from astroquery.ipac.irsa import Irsa
233+
>>> from astropy.coordinates import SkyCoord
234+
>>> from astropy import units as u
235+
>>>
236+
>>> coord = SkyCoord('150.01d 2.2d', frame='icrs')
237+
>>> spitzer_images = Irsa.query_sia(pos=(coord, 1 * u.arcmin), collection='spitzer_seip').to_table()
238+
239+
Now open a cutout image for one of the science images. You could either use
240+
the the IRSA on-premise data or the cloud version of it using the
241+
``access_url`` or ``cloud_access`` columns. For more info about fits
242+
cutouts, please visit :ref:`astropy:fits_io_cloud`.
243+
244+
.. doctest-remote-data::
245+
246+
>>> from astropy.io import fits
247+
>>> from astropy.nddata import Cutout2D
248+
>>> from astropy.wcs import WCS
249+
>>> science_image = spitzer_images[spitzer_images['dataproduct_subtype'] == 'science'][0]
250+
>>> with fits.open(science_image['access_url'], use_fsspec=True) as hdul:
251+
... cutout = Cutout2D(hdul[0].section, position=coord, size=2 * u.arcmin, wcs=WCS(hdul[0].header))
252+
253+
Now plot the cutout.
254+
255+
.. doctest-skip::
256+
257+
>>> import matplotlib.pyplot as plt
258+
>>> plt.imshow(cutout.data, cmap='grey')
259+
>>> plt.show()
260+
261+
.. plot::
262+
263+
from astroquery.ipac.irsa import Irsa
264+
from astropy.coordinates import SkyCoord
265+
from astropy import units as u
266+
from astropy.io import fits
267+
from astropy.nddata import Cutout2D
268+
from astropy.wcs import WCS
269+
import matplotlib.pyplot as plt
270+
coord = SkyCoord('150.01d 2.2d', frame='icrs')
271+
spitzer_images = Irsa.query_sia(pos=(coord, 1 * u.arcmin), collection='spitzer_seip').to_table()
272+
science_image = spitzer_images[spitzer_images['dataproduct_subtype'] == 'science'][0]
273+
with fits.open(science_image['access_url'], use_fsspec=True) as hdul:
274+
cutout = Cutout2D(hdul[0].section, position=coord, size=2 *
275+
u.arcmin, wcs=WCS(hdul[0].header))
276+
plt.imshow(cutout.data, cmap='grey')
277+
plt.show()
278+
279+
223280
Other Configurations
224281
--------------------
225282

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ docs=
152152
matplotlib
153153
sphinx-astropy>=1.5
154154
scipy
155+
fsspec[http]
155156
all=
156157
mocpy>=0.9
157158
astropy-healpix

0 commit comments

Comments
 (0)