Skip to content

Commit

Permalink
Merge pull request #3105 from andamian/alma_coords
Browse files Browse the repository at this point in the history
Fixed galactic coord problem
  • Loading branch information
bsipocz authored Oct 11, 2024
2 parents a3542f5 + 92adbe8 commit 22db7f2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ alma

- Added support for frequency_resolution in KHz [#3035]

- Changed the way galactic ranges are used in queries [#3105]

ehst
^^^^

Expand Down
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)
ra_min = coord.Angle(ra_min, unit=u.degree).deg
ra_max = coord.Angle(ra_max, unit=u.degree).deg
dec_min = coord.Angle(dec_min, unit=u.degree).deg
dec_max = coord.Angle(dec_max, unit=u.degree).deg
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 common 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
27 changes: 16 additions & 11 deletions astroquery/alma/tests/test_alma.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_gen_pos_sql():
"-90.0,4.338888888888889), s_region) = 1)"
assert _gen_sql({'ra_dec': '!(10..20) >60'}) == common_select + \
"((INTERSECTS(RANGE_S2D(0.0,10.0,60.0,90.0), s_region) = 1) OR " \
"(INTERSECTS(RANGE_S2D(20.0,0.0,60.0,90.0), s_region) = 1))"
"(INTERSECTS(RANGE_S2D(20.0,360.0,60.0,90.0), s_region) = 1))"
assert _gen_sql({'ra_dec': '0..20|40..60 <-50|>50'}) == common_select + \
"((INTERSECTS(RANGE_S2D(0.0,20.0,-90.0,-50.0), s_region) = 1) OR " \
"(INTERSECTS(RANGE_S2D(0.0,20.0,50.0,90.0), s_region) = 1) OR " \
Expand All @@ -123,18 +123,23 @@ 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)

# test extremities
assert _gen_sql({'galactic': '0..360 -90..90'}) == \
common_select + ('gal_longitude>=0.0 AND gal_longitude<=360.0 AND '
'gal_latitude>=-90.0 AND gal_latitude<=90.0')

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

0 comments on commit 22db7f2

Please sign in to comment.