Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query_regions to esa.hsa #2362

Merged
merged 6 commits into from
Apr 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions astroquery/esa/hsa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def get_columns(self, table_name, *, only_names=True, verbose=False):
else:
return columns

def query_observations(self, coordinate, radius, *, n_obs=10):
def query_observations(self, coordinate, radius, *, n_obs=10, **kwargs):
"""
Get the observation IDs from a given region

Expand All @@ -391,6 +391,8 @@ def query_observations(self, coordinate, radius, *, n_obs=10):
the radius of the region
n_obs : int, optional
the number of observations
kwargs : dict
passed to `query_hsa_tap`

Returns
-------
Expand All @@ -405,7 +407,40 @@ def query_observations(self, coordinate, radius, *, n_obs=10):
f"where contains("
f"point('ICRS', hsa.v_active_observation.ra, hsa.v_active_observation.dec), "
f"circle('ICRS', {coord.ra.degree},{coord.dec.degree},{r.to(u.deg).value}))=1")
return self.query_hsa_tap(query)
return self.query_hsa_tap(query, **kwargs)


def query_region(self, coordinate, radius, *, n_obs=10, columns='*', **kwargs):
"""
Get the observation metadata from a given region

Parameters
----------
coordinate : string / `astropy.coordinates`
the identifier or coordinates around which to query
radius : int / `~astropy.units.Quantity`
the radius of the region
n_obs : int, optional
the number of observations
columns : str, optional
the columns to retrieve from the data table
kwargs : dict
passed to `query_hsa_tap`

Returns
-------
A table object with the list of observations in the region
"""
r = radius
if not isinstance(radius, u.Quantity):
r = radius*u.deg
coord = commons.parse_coordinates(coordinate).icrs

query = (f"select top {n_obs} {columns} from hsa.v_active_observation "
f"where contains("
f"point('ICRS', hsa.v_active_observation.ra, hsa.v_active_observation.dec), "
f"circle('ICRS', {coord.ra.degree},{coord.dec.degree},{r.to(u.deg).value}))=1")
return self.query_hsa_tap(query, **kwargs)


HSA = HSAClass()