Skip to content

Commit

Permalink
Fixed galactic range coord problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Damian authored and Adrian Damian committed Oct 9, 2024
1 parent 0667ec8 commit 1aa9bfd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
25 changes: 15 additions & 10 deletions astroquery/alma/tapsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,21 @@ def _gen_pos_sql(field, value):
dec_min = -90
if dec_max is None:
dec_max = 90
min_pt = coord.SkyCoord(ra_min, dec_min, unit=u.deg,
frame=frame)
max_pt = coord.SkyCoord(ra_max, dec_max, unit=u.deg,
frame=frame)
result += \
"(INTERSECTS(RANGE_S2D({},{},{},{}), s_region) = 1)".\
format(min_pt.icrs.ra.to(u.deg).value,
max_pt.icrs.ra.to(u.deg).value,
min_pt.icrs.dec.to(u.deg).value,
max_pt.icrs.dec.to(u.deg).value)
min_pt = coord.SkyCoord(ra_min, dec_min, unit=u.deg)
ra_min, dec_min = min_pt.ra.value, min_pt.dec.value
max_pt = coord.SkyCoord(ra_max, dec_max, unit=u.deg)
ra_max, dec_max = max_pt.ra.value, max_pt.dec.value
if frame == 'galactic':
# intersect with s_region is too complicated. ALMA indicated that
# the use of gal_longitude and gal_latitude is good enough
# approximation in this less comon use case
result += ('gal_longitude>={} AND gal_longitude<={} AND '
'gal_latitude>={} and gal_latitude<={}').format(
ra_min, ra_max, dec_min, dec_max)
else:
result += \
"(INTERSECTS(RANGE_S2D({},{},{},{}), s_region) = 1)".\
format(ra_min, ra_max, dec_min, dec_max)
else:
raise ValueError('Cannot interpret ra({}), dec({}'.
format(ra, dec))
Expand Down
20 changes: 10 additions & 10 deletions astroquery/alma/tests/test_alma.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ def test_gen_pos_sql():
assert _gen_sql({'galactic': '1 2, 3'}) == common_select + "(INTERSECTS(" \
"CIRCLE('ICRS',{},{},3.0), s_region) = 1)".format(
center.icrs.ra.to(u.deg).value, center.icrs.dec.to(u.deg).value)
min_point = coord.SkyCoord('12:13:14.0', '-00:01:02.1', unit=u.deg,
frame='galactic')
max_point = coord.SkyCoord('12:14:14.0', '-00:00:02.1', unit=(u.deg, u.deg),
frame='galactic')
gal_longitude = ('12:13:14.0', '12:14:14.0')
gal_latitude = ('-00:01:02.1', '-00:00:02.1')
min_pt = coord.SkyCoord(gal_longitude[0], gal_latitude[0], unit=u.deg)
long_min, lat_min = min_pt.ra.value, min_pt.dec.value
max_pt = coord.SkyCoord(gal_longitude[1], gal_latitude[1], unit=u.deg)
long_max, lat_max = max_pt.ra.value, max_pt.dec.value
assert _gen_sql(
{'galactic': '12:13:14.0..12:14:14.0 -00:01:02.1..-00:00:02.1'}) == \
{'galactic': '{}..{} {}..{}'.format(
gal_longitude[0], gal_longitude[1], gal_latitude[0], gal_latitude[1])}) == \
common_select +\
"(INTERSECTS(RANGE_S2D({},{},{},{}), s_region) = 1)".format(
min_point.icrs.ra.to(u.deg).value,
max_point.icrs.ra.to(u.deg).value,
min_point.icrs.dec.to(u.deg).value,
max_point.icrs.dec.to(u.deg).value)
'gal_longitude>={} AND gal_longitude<={} AND gal_latitude>={} and gal_latitude<={}'.format(
long_min, long_max, lat_min, lat_max)

# combination of frames
center = coord.SkyCoord(1, 2, unit=u.deg, frame='galactic')
Expand Down

0 comments on commit 1aa9bfd

Please sign in to comment.