Skip to content

Commit 0aa02a6

Browse files
authored
Merge pull request #594 from duytnguyendtn/radquantity
Support Astropy Quantity as radius arg for Registry SkyCoord Spatial constraint
2 parents 3431986 + 13e4abe commit 0aa02a6

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Enhancements and Fixes
4646
- Tables returned by RegistryResource.get_tables() now have a utype
4747
attribute [#576]
4848

49+
- Registry Spatial constraint now supports Astropy Quantities for the radius argument [#594]
50+
4951
Deprecations and Removals
5052
-------------------------
5153

docs/registry/index.rst

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,30 @@ And to look for tap resources *in* a specific cone, you would do
158158

159159
>>> from astropy.coordinates import SkyCoord
160160
>>> registry.search(registry.Freetext("Wolf-Rayet"),
161-
... registry.Spatial((SkyCoord("23d +3d"), 3), intersect="enclosed")) # doctest: +IGNORE_OUTPUT
162-
<DALResultsTable length=1>
163-
ivoid ...
164-
...
165-
object ...
166-
---------------------------- ...
167-
ivo://cds.vizier/j/aj/166/68 ...
161+
... registry.Spatial((SkyCoord("23d +3d"), 3), intersect="enclosed"))
162+
<DALResultsTable length=2>
163+
ivoid ...
164+
...
165+
object ...
166+
------------------------------- ...
167+
ivo://cds.vizier/j/a+a/688/a104 ...
168+
ivo://cds.vizier/j/aj/166/68 ...
169+
170+
Astropy Quantities are also supported for the radius angle of a SkyCoord-defined circular region:
171+
172+
.. doctest-remote-data::
173+
174+
>>> from astropy.coordinates import SkyCoord
175+
>>> from astropy import units as u
176+
>>> registry.search(registry.Freetext("Wolf-Rayet"),
177+
... registry.Spatial((SkyCoord("23d +3d"), 180*u.Unit('arcmin')), intersect="enclosed"))
178+
<DALResultsTable length=2>
179+
ivoid ...
180+
...
181+
object ...
182+
------------------------------- ...
183+
ivo://cds.vizier/j/a+a/688/a104 ...
184+
ivo://cds.vizier/j/aj/166/68 ...
168185

169186
Where ``intersect`` can take the following values:
170187
* 'covers' is the default and returns resources that cover the geometry provided,

pyvo/registry/rtcons.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ class Spatial(SubqueriedConstraint):
673673
are interpreted in degrees)::
674674
675675
>>> resources = registry.Spatial((SkyCoord("23d +3d"), 3))
676+
677+
Or you can provide the radius angle as an Astropy Quantity:
678+
679+
>>> resources = registry.Spatial((SkyCoord("23d +3d"), 1*u.rad))
676680
"""
677681
_keyword = "spatial"
678682
_subquery_table = "rr.stc_spatial"
@@ -689,7 +693,7 @@ def __init__(self, geom_spec, order=6, intersect="covers"):
689693
as a DALI point, a 3-sequence as a DALI circle, a 2n sequence
690694
as a DALI polygon. Additionally, strings are interpreted
691695
as ASCII MOCs, SkyCoords as points, and a pair of a
692-
SkyCoord and a float as a circle. Other types (proper
696+
SkyCoord and a float or Quantity as a circle. Other types (proper
693697
geometries or MOCPy objects) might be supported in the
694698
future.
695699
order : int, optional
@@ -719,9 +723,16 @@ def tomoc(s):
719723

720724
elif len(geom_spec) == 2:
721725
if isinstance(geom_spec[0], SkyCoord):
726+
# If radius given is astropy quantity, then convert to degrees
727+
if isinstance(geom_spec[1], u.Quantity):
728+
if geom_spec[1].unit.physical_type != 'angle':
729+
raise ValueError("Radius quantity is not of type angle.")
730+
radius = geom_spec[1].to(u.deg).value
731+
else:
732+
radius = geom_spec[1]
722733
geom = tomoc(format_function_call("CIRCLE",
723734
[geom_spec[0].ra.value, geom_spec[0].dec.value,
724-
geom_spec[1]]))
735+
radius]))
725736
else:
726737
geom = tomoc(format_function_call("POINT", geom_spec))
727738

pyvo/registry/tests/test_rtcons.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ def test_SkyCoord_Circle(self):
303303
assert cons.get_search_condition(FAKE_GAVO) == _make_subquery(
304304
"rr.stc_spatial", "1 = CONTAINS(MOC(6, CIRCLE(3.0, -30.0, 3)), coverage)")
305305

306+
def test_SkyCoord_Circle_RadiusQuantity(self):
307+
for radius in [3*u.deg, 180*u.Unit('arcmin'), 10800*u.Unit('arcsec')]:
308+
cons = registry.Spatial((SkyCoord(3 * u.deg, -30 * u.deg), radius))
309+
assert cons.get_search_condition(FAKE_GAVO) == _make_subquery(
310+
"rr.stc_spatial", "1 = CONTAINS(MOC(6, CIRCLE(3.0, -30.0, 3.0)), coverage)")
311+
312+
with pytest.raises(ValueError, match="is not of type angle."):
313+
cons = registry.Spatial((SkyCoord(3 * u.deg, -30 * u.deg), (1 * u.m)))
314+
306315
def test_enclosed(self):
307316
cons = registry.Spatial("0/1-3", intersect="enclosed")
308317
assert cons.get_search_condition(FAKE_GAVO) == _make_subquery(

0 commit comments

Comments
 (0)