Skip to content

Commit 22db7f2

Browse files
authored
Merge pull request #3105 from andamian/alma_coords
Fixed galactic coord problem
2 parents a3542f5 + 92adbe8 commit 22db7f2

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

CHANGES.rst

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ alma
2222

2323
- Added support for frequency_resolution in KHz [#3035]
2424

25+
- Changed the way galactic ranges are used in queries [#3105]
26+
2527
ehst
2628
^^^^
2729

astroquery/alma/tapsql.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,21 @@ def _gen_pos_sql(field, value):
6969
dec_min = -90
7070
if dec_max is None:
7171
dec_max = 90
72-
min_pt = coord.SkyCoord(ra_min, dec_min, unit=u.deg,
73-
frame=frame)
74-
max_pt = coord.SkyCoord(ra_max, dec_max, unit=u.deg,
75-
frame=frame)
76-
result += \
77-
"(INTERSECTS(RANGE_S2D({},{},{},{}), s_region) = 1)".\
78-
format(min_pt.icrs.ra.to(u.deg).value,
79-
max_pt.icrs.ra.to(u.deg).value,
80-
min_pt.icrs.dec.to(u.deg).value,
81-
max_pt.icrs.dec.to(u.deg).value)
72+
ra_min = coord.Angle(ra_min, unit=u.degree).deg
73+
ra_max = coord.Angle(ra_max, unit=u.degree).deg
74+
dec_min = coord.Angle(dec_min, unit=u.degree).deg
75+
dec_max = coord.Angle(dec_max, unit=u.degree).deg
76+
if frame == 'galactic':
77+
# intersect with s_region is too complicated. ALMA indicated that
78+
# the use of gal_longitude and gal_latitude is good enough
79+
# approximation in this less common use case
80+
result += ('gal_longitude>={} AND gal_longitude<={} AND '
81+
'gal_latitude>={} AND gal_latitude<={}').format(
82+
ra_min, ra_max, dec_min, dec_max)
83+
else:
84+
result += \
85+
"(INTERSECTS(RANGE_S2D({},{},{},{}), s_region) = 1)".\
86+
format(ra_min, ra_max, dec_min, dec_max)
8287
else:
8388
raise ValueError('Cannot interpret ra({}), dec({}'.
8489
format(ra, dec))

astroquery/alma/tests/test_alma.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def test_gen_pos_sql():
111111
"-90.0,4.338888888888889), s_region) = 1)"
112112
assert _gen_sql({'ra_dec': '!(10..20) >60'}) == common_select + \
113113
"((INTERSECTS(RANGE_S2D(0.0,10.0,60.0,90.0), s_region) = 1) OR " \
114-
"(INTERSECTS(RANGE_S2D(20.0,0.0,60.0,90.0), s_region) = 1))"
114+
"(INTERSECTS(RANGE_S2D(20.0,360.0,60.0,90.0), s_region) = 1))"
115115
assert _gen_sql({'ra_dec': '0..20|40..60 <-50|>50'}) == common_select + \
116116
"((INTERSECTS(RANGE_S2D(0.0,20.0,-90.0,-50.0), s_region) = 1) OR " \
117117
"(INTERSECTS(RANGE_S2D(0.0,20.0,50.0,90.0), s_region) = 1) OR " \
@@ -123,18 +123,23 @@ def test_gen_pos_sql():
123123
assert _gen_sql({'galactic': '1 2, 3'}) == common_select + "(INTERSECTS(" \
124124
"CIRCLE('ICRS',{},{},3.0), s_region) = 1)".format(
125125
center.icrs.ra.to(u.deg).value, center.icrs.dec.to(u.deg).value)
126-
min_point = coord.SkyCoord('12:13:14.0', '-00:01:02.1', unit=u.deg,
127-
frame='galactic')
128-
max_point = coord.SkyCoord('12:14:14.0', '-00:00:02.1', unit=(u.deg, u.deg),
129-
frame='galactic')
126+
gal_longitude = ('12:13:14.0', '12:14:14.0')
127+
gal_latitude = ('-00:01:02.1', '-00:00:02.1')
128+
min_pt = coord.SkyCoord(gal_longitude[0], gal_latitude[0], unit=u.deg)
129+
long_min, lat_min = min_pt.ra.value, min_pt.dec.value
130+
max_pt = coord.SkyCoord(gal_longitude[1], gal_latitude[1], unit=u.deg)
131+
long_max, lat_max = max_pt.ra.value, max_pt.dec.value
130132
assert _gen_sql(
131-
{'galactic': '12:13:14.0..12:14:14.0 -00:01:02.1..-00:00:02.1'}) == \
133+
{'galactic': '{}..{} {}..{}'.format(
134+
gal_longitude[0], gal_longitude[1], gal_latitude[0], gal_latitude[1])}) == \
132135
common_select +\
133-
"(INTERSECTS(RANGE_S2D({},{},{},{}), s_region) = 1)".format(
134-
min_point.icrs.ra.to(u.deg).value,
135-
max_point.icrs.ra.to(u.deg).value,
136-
min_point.icrs.dec.to(u.deg).value,
137-
max_point.icrs.dec.to(u.deg).value)
136+
'gal_longitude>={} AND gal_longitude<={} AND gal_latitude>={} AND gal_latitude<={}'.format(
137+
long_min, long_max, lat_min, lat_max)
138+
139+
# test extremities
140+
assert _gen_sql({'galactic': '0..360 -90..90'}) == \
141+
common_select + ('gal_longitude>=0.0 AND gal_longitude<=360.0 AND '
142+
'gal_latitude>=-90.0 AND gal_latitude<=90.0')
138143

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

0 commit comments

Comments
 (0)