Skip to content

Commit 9a2864c

Browse files
authored
Merge pull request #2152 from astrozot/patch-1
Allow a frame specification in query_region_async for VizieR queries
2 parents 0f2c8b9 + d49c3a0 commit 9a2864c

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

CHANGES.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ New Tools and Services
1010
Service fixes and enhancements
1111
------------------------------
1212

13+
vizier
14+
^^^^^^
15+
16+
- It is now possible to specify 'galatic' centers in region queries to
17+
have box queries oriented along the galactic axes [#2152]
18+
19+
splatalogue
20+
^^^^^^^^^^^
21+
1322
- Splatalogue table merging can now handle unmasked columns [#2136]
1423

1524

astroquery/vizier/core.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ def query_object_async(self, object_name, catalog=None, radius=None,
326326
def query_region_async(self, coordinates, radius=None, inner_radius=None,
327327
width=None, height=None, catalog=None,
328328
get_query_payload=False, cache=True,
329-
return_type='votable', column_filters={}):
329+
return_type='votable', column_filters={},
330+
frame='fk5'):
330331
"""
331332
Serves the same purpose as `query_region` but only
332333
returns the HTTP response rather than the parsed result.
@@ -357,35 +358,52 @@ def query_region_async(self, coordinates, radius=None, inner_radius=None,
357358
column_filters: dict, optional
358359
Constraints on columns of the result. The dictionary contains
359360
the column name as keys, and the constraints as values.
361+
frame : str, optional
362+
The frame to use for the request. It should be 'fk5', 'icrs',
363+
or 'galactic'. This choice influences the the orientation of
364+
box requests.
360365
361366
Returns
362367
-------
363368
response : `requests.Response`
364369
The response of the HTTP request.
365370
366371
"""
372+
if frame not in ('galactic', 'fk5', 'icrs'):
373+
raise ValueError("Only the 'galactic', 'icrs', and 'fk5' frames are supported by VizieR")
367374
catalog = VizierClass._schema_catalog.validate(catalog)
368375
center = {}
369376
columns = []
370377

371378
# Process coordinates
372379
if isinstance(coordinates, (commons.CoordClasses,) + six.string_types):
373-
c = commons.parse_coordinates(coordinates).transform_to('fk5')
380+
target = commons.parse_coordinates(coordinates).transform_to(frame)
374381

375-
if not c.isscalar:
382+
if not target.isscalar:
376383
center["-c"] = []
377-
for pos in c:
378-
ra_deg = pos.ra.to_string(unit="deg", decimal=True,
379-
precision=8)
380-
dec_deg = pos.dec.to_string(unit="deg", decimal=True,
381-
precision=8, alwayssign=True)
382-
center["-c"] += ["{}{}".format(ra_deg, dec_deg)]
384+
for pos in target:
385+
if frame == 'galactic':
386+
glon_deg = pos.l.to_string(unit="deg", decimal=True, precision=8)
387+
glat_deg = pos.b.to_string(unit="deg", decimal=True, precision=8,
388+
alwayssign=True)
389+
center["-c"] += ["G{}{}".format(glon_deg, glat_deg)]
390+
else:
391+
ra_deg = pos.ra.to_string(unit="deg", decimal=True, precision=8)
392+
dec_deg = pos.dec.to_string(unit="deg", decimal=True,
393+
precision=8, alwayssign=True)
394+
center["-c"] += ["{}{}".format(ra_deg, dec_deg)]
383395
columns += ["_q"] # Always request reference to input table
384396
else:
385-
ra = c.ra.to_string(unit='deg', decimal=True, precision=8)
386-
dec = c.dec.to_string(unit="deg", decimal=True, precision=8,
387-
alwayssign=True)
388-
center["-c"] = "{ra}{dec}".format(ra=ra, dec=dec)
397+
if frame == 'galactic':
398+
glon = target.l.to_string(unit='deg', decimal=True, precision=8)
399+
glat = target.b.to_string(unit="deg", decimal=True, precision=8,
400+
alwayssign=True)
401+
center["-c"] = "G{glon}{glat}".format(glon=glon, glat=glat)
402+
else:
403+
ra = target.ra.to_string(unit='deg', decimal=True, precision=8)
404+
dec = target.dec.to_string(unit="deg", decimal=True, precision=8,
405+
alwayssign=True)
406+
center["-c"] = "{ra}{dec}".format(ra=ra, dec=dec)
389407
elif isinstance(coordinates, tbl.Table):
390408
if (("_RAJ2000" in coordinates.keys()) and ("_DEJ2000" in
391409
coordinates.keys())):

astroquery/vizier/tests/test_vizier_remote.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,17 @@ def test_query_region(self):
3838
def test_query_region_async(self):
3939
response = vizier.core.Vizier.query_region_async(
4040
self.target, radius=5 * u.deg, catalog=["HIP", "NOMAD", "UCAC"])
41+
assert response is not None
4142

43+
def test_query_region_async_galactic(self):
44+
response = vizier.core.Vizier.query_region_async(
45+
self.target, radius=0.5 * u.deg, catalog="HIP",
46+
frame="galactic")
4247
assert response is not None
48+
payload = vizier.core.Vizier.query_region_async(
49+
self.target, radius=0.5 * u.deg, catalog="HIP",
50+
frame="galactic", get_query_payload=True)
51+
assert "-c=G" in payload
4352

4453
def test_query_Vizier_instance(self):
4554
v = vizier.core.Vizier(

0 commit comments

Comments
 (0)