Skip to content

Commit

Permalink
Merge pull request #459 from bsipocz/SIA2_skycoord_aware
Browse files Browse the repository at this point in the history
BUG: SIA2 position search to be SkyCoord aware
  • Loading branch information
bsipocz committed Jul 28, 2023
2 parents b96a950 + 6e50499 commit feda0f0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

- Fix handling of nan values for Time properties in SIA2 records. [#463]

- Fix SIA2 search to accept SkyCoord position inputs. [#459]


1.4.1 (2023-03-07)
==================
Expand Down
16 changes: 14 additions & 2 deletions pyvo/dal/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import abc

from astropy import units as u
from astropy.coordinates import SkyCoord
from astropy.units import Quantity, Unit
from astropy.time import Time
from astropy.io.votable.converters import (
Expand Down Expand Up @@ -301,7 +302,7 @@ def get_dal_format(self, val):
entries in values are either quantities or assumed to be degrees
"""
self._validate_pos(val)
if len(val) == 3:
if len(val) == 2 or len(val) == 3:
shape = 'CIRCLE'
elif len(val) == 4:
shape = 'RANGE'
Expand All @@ -313,6 +314,7 @@ def get_dal_format(self, val):
'even 6 and above (POLYGON) accepted.'.format(val))
return '{} {}'.format(shape, ' '.join(
[str(val.to(u.deg).value) if isinstance(val, Quantity) else
val.transform_to('icrs').to_string() if isinstance(val, SkyCoord) else
str((val * u.deg).value) for val in val]))

def _validate_pos(self, pos):
Expand All @@ -321,7 +323,17 @@ def _validate_pos(self, pos):
This has probably done already somewhere else
"""
if len(pos) == 3:

if len(pos) == 2:
if not isinstance(pos[0], SkyCoord):
raise ValueError
if not isinstance(pos[1], Quantity):
radius = pos[1] * u.deg
else:
radius = pos[1]
if radius <= 0 * u.deg or radius.to(u.deg) > 90 * u.deg:
raise ValueError('Invalid circle radius: {}'.format(radius))
elif len(pos) == 3:
self._validate_ra(pos[0])
self._validate_dec(pos[1])
if not isinstance(pos[2], Quantity):
Expand Down
6 changes: 4 additions & 2 deletions pyvo/dal/tests/test_sia.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pyvo.dal.sia import search, SIAService

from astropy.io.fits import HDUList
from astropy.coordinates import SkyCoord
from astropy.utils.data import get_pkg_data_contents

get_pkg_data_contents = partial(
Expand Down Expand Up @@ -45,8 +46,9 @@ def _test_result(result):
@pytest.mark.usefixtures('sia')
@pytest.mark.usefixtures('register_mocks')
@pytest.mark.filterwarnings("ignore::astropy.io.votable.exceptions.W06")
def test_search():
results = search('http://example.com/sia', pos=(288, 15))
@pytest.mark.parametrize("position", ((288, 15), SkyCoord(288, 15, unit="deg")))
def test_search(position):
results = search('http://example.com/sia', pos=position)
result = results[0]

_test_result(result)
Expand Down
4 changes: 3 additions & 1 deletion pyvo/dal/tests/test_sia2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pyvo.dal.sia2 import search, SIA2Service, SIA2Query, SIAService, SIAQuery

import astropy.units as u
from astropy.coordinates import SkyCoord
from astropy.utils.data import get_pkg_data_contents
from astropy.utils.exceptions import AstropyDeprecationWarning

Expand Down Expand Up @@ -101,7 +102,8 @@ def test_capabilities(self):
(12.0 * u.deg, 34.0 * u.deg,
14.0 * u.deg, 35.0 * u.deg,
14.0 * u.deg, 36.0 * u.deg,
12.0 * u.deg, 35.0 * u.deg)]
12.0 * u.deg, 35.0 * u.deg),
(SkyCoord(2, 4, unit='deg'), 0.166 * u.deg)]

@pytest.mark.usefixtures('sia')
@pytest.mark.usefixtures('capabilities')
Expand Down

0 comments on commit feda0f0

Please sign in to comment.