Skip to content

Commit fac66a1

Browse files
authored
Merge pull request #2362 from keflavich/query_regions_hsa
Add query_regions to esa.hsa
2 parents 1368992 + 115b0aa commit fac66a1

File tree

3 files changed

+71
-12
lines changed

3 files changed

+71
-12
lines changed

astroquery/esa/hsa/core.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def get_columns(self, table_name, *, only_names=True, verbose=False):
379379
else:
380380
return columns
381381

382-
def query_observations(self, coordinate, radius, *, n_obs=10):
382+
def query_observations(self, coordinate, radius, *, n_obs=10, **kwargs):
383383
"""
384384
Get the observation IDs from a given region
385385
@@ -391,6 +391,31 @@ def query_observations(self, coordinate, radius, *, n_obs=10):
391391
the radius of the region
392392
n_obs : int, optional
393393
the number of observations
394+
kwargs : dict
395+
passed to `query_hsa_tap`
396+
397+
Returns
398+
-------
399+
A table object with the list of observations in the region
400+
"""
401+
return self.query_region(coordinate, radius, n_obs=n_obs, columns="observation_id", **kwargs)
402+
403+
def query_region(self, coordinate, radius, *, n_obs=10, columns='*', **kwargs):
404+
"""
405+
Get the observation metadata from a given region
406+
407+
Parameters
408+
----------
409+
coordinate : string / `astropy.coordinates`
410+
the identifier or coordinates around which to query
411+
radius : int / `~astropy.units.Quantity`
412+
the radius of the region
413+
n_obs : int, optional
414+
the number of observations
415+
columns : str, optional
416+
the columns to retrieve from the data table
417+
kwargs : dict
418+
passed to `query_hsa_tap`
394419
395420
Returns
396421
-------
@@ -401,11 +426,11 @@ def query_observations(self, coordinate, radius, *, n_obs=10):
401426
r = radius*u.deg
402427
coord = commons.parse_coordinates(coordinate).icrs
403428

404-
query = (f"select top {n_obs} observation_id from hsa.v_active_observation "
429+
query = (f"select top {n_obs} {columns} from hsa.v_active_observation "
405430
f"where contains("
406431
f"point('ICRS', hsa.v_active_observation.ra, hsa.v_active_observation.dec), "
407432
f"circle('ICRS', {coord.ra.degree},{coord.dec.degree},{r.to(u.deg).value}))=1")
408-
return self.query_hsa_tap(query)
433+
return self.query_hsa_tap(query, **kwargs)
409434

410435

411436
HSA = HSAClass()

astroquery/esa/hsa/tests/test_hsa.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,12 @@ def test_query_observations(self):
5757
hsa = HSAClass(self.get_dummy_tap_handler())
5858
hsa.query_observations(**parameters)
5959
dummyTapHandler.check_call("query_observations", parameters)
60+
61+
def test_query_region(self):
62+
c = SkyCoord(ra=100.2417*u.degree, dec=9.895*u.degree, frame='icrs')
63+
parameters = {'coordinate': c,
64+
'radius': 0.5}
65+
dummyTapHandler = DummyHSATapHandler("query_region", parameters)
66+
hsa = HSAClass(self.get_dummy_tap_handler())
67+
hsa.query_region(**parameters)
68+
dummyTapHandler.check_call("query_region", parameters)

docs/esa/hsa.rst

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ space missions and groundbased facilities. Herschel successfully performed ~3700
1212
~6600 science calibration observations which are publicly available to the worldwide astronomical community
1313
through the Herschel Science Archive.
1414

15-
This package allows the access to the `Herschel Science Archive <http://archives.esac.esa.int/hsa/whsa/>`__.
15+
This package allows the access to the `Herschel Science Archive <http://archives.esac.esa.int/hsa/whsa/>`_.
1616

1717
Examples
1818
========
@@ -109,7 +109,7 @@ Query Language (`ADQL <https://www.ivoa.net/documents/ADQL/20180112/PR-ADQL-2.1-
109109
PACS-A - G345.39-3.97 -43.47405026924179 ... G345.39-3.97-1 883176
110110
PRISMAS_g34_hifi7b_1897GHz_B_C3 1.2495150652937468 ... G34.3+0.1 921086
111111

112-
This will execute an ADQL query to download the first 10 observations in the Herschel Science Archive.
112+
This will execute an ADQL query to download the first 10 observations in the `Herschel Science Archive`_.
113113
The result of the query will be stored in the file ``results.csv``.
114114

115115

@@ -126,7 +126,7 @@ The result of the query will be stored in the file ``results.csv``.
126126
INFO: Done. [astroquery.utils.tap.core]
127127
['hpdp.latest_observation_hpdp', 'hpdp.vizier_links', 'hpdp.unique_observation_hpdp', 'hpdp.latest_unique_observation_requests', 'hpdp.files', 'hpdp.latest_requests', 'public.dual', 'public.image_formats', 'tap_schema.tables', 'tap_schema.columns', 'tap_schema.keys', 'tap_schema.schemas', 'tap_schema.key_columns', 'hsa.observation_science', 'hsa.proposal_coauthor', 'hsa.proposal_observation', 'hsa.instrument', 'hsa.observing_mode_per_instrument', 'hsa.spire_spectral_feature_finder_catalogue', 'hsa.hifi_spectral_line_smoothed', 'hsa.publication', 'hsa.quality_flag', 'hsa.v_active_observation', 'hsa.proposal_info', 'hsa.pacs_point_source_070', 'hsa.observing_mode', 'hsa.proposal', 'hsa.proposal_pi_user', 'hsa.spire_point_source_350', 'hsa.spire_point_source_250', 'hsa.v_publication', 'hsa.spire_point_source_500', 'hsa.pacs_point_source_100', 'hsa.v_proposal_observation', 'hsa.hifi_spectral_line_native', 'hsa.pacs_point_source_160', 'hsa.ancillary', 'hsa.metadata_expert_panels', 'pubtool.institutions', 'pubtool.v_first_pub_date', 'pubtool.v_first_pub_date_single', 'pubtool.archival_type', 'pubtool.publication', 'pubtool.publication_details', 'pubtool.authors_institutions', 'pubtool.publication_observation', 'pubtool.authors', 'updp2.latest_observation_updp', 'updp2.vizier_links', 'updp2.latest_unique_observation_requests', 'updp2.files', 'updp2.latest_requests', 'updp2.unique_observation_updp']
128128

129-
This will show the available tables in HSA TAP service in the Herschel Science Archive.
129+
This will show the available tables in HSA TAP service in the `Herschel Science Archive`_.
130130

131131

132132
6. Getting columns details of HSA TAP
@@ -142,13 +142,38 @@ This will show the available tables in HSA TAP service in the Herschel Science A
142142
INFO: Done. [astroquery.utils.tap.core]
143143
['aor', 'bii', 'dec', 'duration', 'end_time', 'fov', 'global_science_area', 'icon_image', 'icon_location', 'image_2_5_location', 'image_location', 'ingest_queue_oid', 'instrument_oid', 'is_active_version', 'is_public', 'lii', 'naif_id', 'num_publications', 'observation_id', 'observation_oid', 'observer', 'observing_mode_oid', 'obsstate', 'od_number', 'pa', 'polygon_fov', 'position', 'prop_end', 'proposal_id', 'quality_report_location', 'ra', 'science_area', 'science_category', 'spg_id', 'start_time', 'status', 'target_name', 'urn_version']
144144

145-
This will show the column details of the table 'hsa.v_active_observation' in HSA TAP service in the Herschel Science Archive.
145+
This will show the column details of the table ``'hsa.v_active_observation'`` in HSA TAP service in the
146+
`Herschel Science Archive`_.
146147

147148

148-
7. Query Observations
149+
7. Query Region
150+
---------------
151+
152+
.. doctest-remote-data::
153+
154+
>>> from astroquery.esa.hsa import HSA
155+
>>> from astropy.coordinates import SkyCoord
156+
>>> from astropy import units as u
157+
>>>
158+
>>> c = SkyCoord(ra=100.2417*u.degree, dec=9.895*u.degree, frame='icrs')
159+
>>> result = HSA.query_region(c, 0.5)
160+
>>> result.pprint(max_width=100)
161+
aor bii ... target_name urn_version
162+
...
163+
------------------------------------------- ------------------ ... ---------------- -----------
164+
KPOT_wlanger_1-HPoint-0007 - CII_G202.6+2.0 10.062774289985356 ... CII_G202.6+2.0-1 921022
165+
n2264-o 9.45754288889945 ... NGC2264 919399
166+
n2264-n 9.45754288889945 ... NGC2264 919398
167+
n2264-n 9.450299102175919 ... NGC2264 898497
168+
n2264-o 9.450499719127244 ... NGC2264 898535
169+
170+
Retrieve a VOTable with the observations metadata of a given region.
171+
172+
173+
8. Query Observations
149174
---------------------
150175

151-
.. doctest-skip::
176+
.. doctest-remote-data::
152177

153178
>>> from astroquery.esa.hsa import HSA
154179
>>> from astropy.coordinates import SkyCoord
@@ -166,15 +191,15 @@ This will show the column details of the table 'hsa.v_active_observation' in HSA
166191
1342205056
167192
1342205057
168193

169-
Retrieve a VOTable with the observation IDs of a given region
194+
Retrieve a VOTable with the observation IDs of a given region.
170195

171196

172-
8. Procedure example
197+
9. Procedure example
173198
--------------------
174199

175200
First retrieve the observation IDs based on a position on the sky. To achive this, query the TAP service.
176201

177-
.. doctest-skip::
202+
.. doctest-remote-data::
178203

179204
>>> from astroquery.esa.hsa import HSA
180205
>>>

0 commit comments

Comments
 (0)