Skip to content

Commit c029146

Browse files
committed
Remove *CoordGenerator classes from utils
`astroquery.utils.commons` defined a few classes which allowed constructing `astropy.coordinates.SkyCoord` instances without having to specify the `frame` keyword at the cost of having to specify the correct class instead. They provided little value, and all the code that used them now uses `SkyCoord` directly.
1 parent 5af5780 commit c029146

File tree

18 files changed

+128
-191
lines changed

18 files changed

+128
-191
lines changed

astroquery/heasarc/tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import hashlib
55
import requests
66
import pytest
7+
from astropy.coordinates import SkyCoord
78
from ... import log
89

910
"""
@@ -17,6 +18,10 @@
1718
"""
1819

1920

21+
# The quasar 3C 273
22+
skycoord_3C_273 = SkyCoord("12h29m06.70s +02d03m08.7s", frame="icrs")
23+
24+
2025
class MockResponse:
2126
def __init__(self, text):
2227
self.text = text

astroquery/heasarc/tests/test_heasarc_remote.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
import requests
55

66
from ...heasarc import Heasarc
7-
from ...utils import commons
87

9-
from .conftest import parametrization_local_save_remote, MockResponse
8+
from .conftest import MockResponse, parametrization_local_save_remote, skycoord_3C_273
109

1110

1211
@parametrization_local_save_remote
@@ -84,18 +83,16 @@ def test_query_object_async(self):
8483
def test_query_region_async(self):
8584
heasarc = Heasarc()
8685
mission = 'rosmaster'
87-
c = commons.coord.SkyCoord('12h29m06.70s +02d03m08.7s', frame='icrs')
88-
response = heasarc.query_region_async(c, mission=mission,
89-
radius='1 degree')
86+
response = heasarc.query_region_async(
87+
skycoord_3C_273, mission=mission, radius="1 degree")
9088
assert response is not None
9189
assert isinstance(response, (requests.models.Response, MockResponse))
9290

9391
def test_query_region(self):
9492
heasarc = Heasarc()
9593
mission = 'rosmaster'
9694

97-
# Define coordinates for '3c273' object
98-
c = commons.coord.SkyCoord('12h29m06.70s +02d03m08.7s', frame='icrs')
99-
table = heasarc.query_region(c, mission=mission, radius='1 degree')
95+
table = heasarc.query_region(
96+
skycoord_3C_273, mission=mission, radius="1 degree")
10097

10198
assert len(table) == 63

astroquery/heasarc/tests/test_heasarc_remote_isdc.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import astropy.units as u
77

88
from ...heasarc import Heasarc, Conf
9-
from ...utils import commons
10-
from .conftest import parametrization_local_save_remote, MockResponse
9+
from .conftest import MockResponse, parametrization_local_save_remote, skycoord_3C_273
1110

1211

1312
@parametrization_local_save_remote
@@ -191,24 +190,19 @@ def test_query_object_async(self):
191190
def test_query_region_async(self):
192191
heasarc = Heasarc()
193192
mission = 'integral_rev3_scw'
194-
c = commons.coord.SkyCoord('12h29m06.70s +02d03m08.7s', frame='icrs')
195193

196194
with self.isdc_context:
197-
response = heasarc.query_region_async(c, mission=mission,
198-
radius='1 degree')
195+
response = heasarc.query_region_async(
196+
skycoord_3C_273, mission=mission, radius="1 degree")
199197
assert response is not None
200198
assert isinstance(response, (requests.models.Response, MockResponse))
201199

202200
def test_query_region(self):
203201
heasarc = Heasarc()
204202
mission = 'integral_rev3_scw'
205203

206-
# Define coordinates for '3c273' object
207204
with self.isdc_context:
208-
c = commons.coord.SkyCoord(
209-
'12h29m06.70s +02d03m08.7s',
210-
frame='icrs'
211-
)
212-
table = heasarc.query_region(c, mission=mission, radius='1 degree')
205+
table = heasarc.query_region(
206+
skycoord_3C_273, mission=mission, radius="1 degree")
213207

214208
assert len(table) >= 274

astroquery/image_cutouts/first/tests/test_first.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
import numpy.testing as npt
55
import pytest
66
import astropy.units as u
7+
from astropy.coordinates import SkyCoord
78

89
from ....utils import commons
910
from astroquery.utils.mocks import MockResponse
1011
from ... import first
1112

1213
DATA_FILES = {'image': 'image.fits'}
1314

15+
skycoord = SkyCoord(162.530 * u.deg, 30.677 * u.deg, frame="icrs")
16+
1417

1518
def data_path(filename):
1619
data_dir = os.path.join(os.path.dirname(__file__), 'data')
@@ -42,15 +45,12 @@ def post_mockreturn(method, url, data, timeout, **kwargs):
4245

4346
def test_get_images_async(patch_post, patch_parse_coordinates):
4447
response = first.core.First.get_images_async(
45-
commons.ICRSCoordGenerator(162.530, 30.677, unit=(u.deg, u.deg)),
46-
image_size=0.2 * u.deg, get_query_payload=True)
48+
skycoord, image_size=0.2 * u.deg, get_query_payload=True)
4749
npt.assert_approx_equal(response['ImageSize'], 12, significant=3)
48-
response = first.core.First.get_images_async(
49-
commons.ICRSCoordGenerator(162.530, 30.677, unit=(u.deg, u.deg)))
50+
response = first.core.First.get_images_async(skycoord)
5051
assert response is not None
5152

5253

5354
def test_get_images(patch_post, patch_parse_coordinates):
54-
image = first.core.First.get_images(
55-
commons.ICRSCoordGenerator(162.530, 30.677, unit=(u.deg, u.deg)))
55+
image = first.core.First.get_images(skycoord)
5656
assert image is not None

astroquery/ipac/irsa/irsa_dust/core.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2+
3+
from astropy.coordinates import Angle, SkyCoord
4+
from astropy.coordinates.name_resolve import NameResolveError
25
from astropy.table import Table, Column
36
import astropy.units as u
4-
from astropy import coordinates
57

68
from astroquery.ipac.irsa.irsa_dust import utils
79
from astroquery.ipac.irsa.irsa_dust import conf
@@ -336,18 +338,18 @@ def _args_to_payload(self, coordinate, radius=None):
336338
# If the coordinate is a resolvable name, pass that name
337339
# directly to irsa_dust because it can handle it (and that
338340
# changes the return value associated metadata)
339-
C = commons.ICRSCoord.from_name(coordinate)
341+
C = SkyCoord.from_name(coordinate, frame="icrs")
340342
payload = {"locstr": coordinate}
341-
except coordinates.name_resolve.NameResolveError:
343+
except NameResolveError:
342344
C = commons.parse_coordinates(coordinate).transform_to('fk5')
343345
# check if this is resolvable?
344346
payload = {"locstr": "{0} {1}".format(C.ra.deg, C.dec.deg)}
345-
elif isinstance(coordinate, coordinates.SkyCoord):
347+
elif isinstance(coordinate, SkyCoord):
346348
C = coordinate.transform_to('fk5')
347349
payload = {"locstr": "{0} {1}".format(C.ra.deg, C.dec.deg)}
348350
# check if radius is given with proper units
349351
if radius is not None:
350-
reg_size = coordinates.Angle(radius).deg
352+
reg_size = Angle(radius).deg
351353
# check if radius falls in the acceptable range
352354
if reg_size < 2 or reg_size > 37.5:
353355
raise ValueError("Radius (in any unit) must be in the"

astroquery/ipac/irsa/irsa_dust/tests/test_irsa_dust.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import pytest
55

66
import astropy.units as u
7-
from astropy import coordinates
7+
from astropy.coordinates import SkyCoord
8+
from astropy.coordinates.name_resolve import NameResolveError
89

910
from astroquery.utils import commons
1011

@@ -36,13 +37,9 @@
3637
'http://irsa.ipac.caltech.edu//workspace/TMP_kRQo9a_8160/DUST/m31.v0002/p338temp.fits']
3738

3839

39-
galcoords = {'m31': coordinates.SkyCoord(ra=10.6847083 * u.deg,
40-
dec=41.26875 * u.deg,
41-
frame='icrs'),
42-
'm81': coordinates.SkyCoord(ra=148.888221083 * u.deg,
43-
dec=69.065294722 * u.deg,
44-
frame='icrs'),
45-
}
40+
galcoords = {"m31": SkyCoord(ra=10.6847083 * u.deg, dec=41.26875 * u.deg, frame="icrs"),
41+
"m81": SkyCoord(ra=148.888221083 * u.deg, dec=69.065294722 * u.deg,
42+
frame="icrs")}
4643

4744

4845
def format(coord):
@@ -63,14 +60,12 @@ def patch_request(request):
6360
def patch_fromname(request):
6461
mp = request.getfixturevalue("monkeypatch")
6562

66-
def fromname(self, name):
63+
def fromname(self, name, frame=None):
6764
if isinstance(name, str):
6865
return galcoords[name]
6966
else:
70-
raise coordinates.name_resolve.NameResolveError
71-
mp.setattr(commons.ICRSCoord,
72-
'from_name',
73-
types.MethodType(fromname, commons.ICRSCoord))
67+
raise NameResolveError
68+
mp.setattr(SkyCoord, "from_name", types.MethodType(fromname, SkyCoord))
7469

7570

7671
class DustTestCase:
@@ -117,21 +112,17 @@ def test_xml_err(self):
117112
# TODO : Add more examples. Add for "1 degree"-like parameters
118113
@pytest.mark.parametrize(
119114
('coordinate', 'radius', 'expected_payload'),
120-
[(galcoords["m81"], None, dict(locstr=format(galcoords['m81']))),
121-
(galcoords["m31"], "5d0m", dict(locstr=format(galcoords['m31']),
122-
regSize=5.0)),
123-
(galcoords["m31"], 5 * u.deg, dict(locstr=format(galcoords['m31']),
124-
regSize=5)),
125-
("m31", 5 * u.deg, dict(locstr='m31', regSize=5)),
126-
(coordinates.SkyCoord(ra=148.888221083 * u.deg,
127-
dec=69.065294722 * u.deg, frame='icrs'),
128-
5 * u.deg,
129-
{'locstr': format(coordinates.SkyCoord(ra=148.888221083 * u.deg,
130-
dec=69.065294722 * u.deg,
131-
frame='icrs')),
132-
'regSize': 5}), ])
115+
((galcoords["m81"], None, {}),
116+
(galcoords["m31"], "5d0m", {"regSize": 5.0}),
117+
(galcoords["m31"], 5 * u.deg, {"regSize": 5}),
118+
("m31", 5 * u.deg, {"locstr": "m31", "regSize": 5}),
119+
(galcoords["m81"], 5 * u.deg, {"regSize": 5})))
133120
def test_args_to_payload_instance_1(self, coordinate, radius,
134121
expected_payload, patch_fromname):
122+
if isinstance(coordinate, str):
123+
expected_payload["locstr"] = coordinate
124+
else:
125+
expected_payload["locstr"] = format(coordinate)
135126
payload = IrsaDust()._args_to_payload(coordinate, radius=radius)
136127
assert payload == expected_payload
137128

astroquery/ipac/irsa/tests/test_irsa.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
import numpy as np
66

77
import pytest
8+
from astropy.coordinates import SkyCoord
89
from astropy.table import Table
9-
import astropy.coordinates as coord
1010
import astropy.units as u
1111

1212
from astroquery.utils.mocks import MockResponse
13-
from astroquery.utils import commons
1413
from astroquery.ipac.irsa import Irsa, conf
1514
from astroquery.ipac import irsa
1615

@@ -19,8 +18,7 @@
1918
'Polygon': 'Polygon.xml'}
2019

2120
OBJ_LIST = ["m31", "00h42m44.330s +41d16m07.50s",
22-
commons.GalacticCoordGenerator(l=121.1743, b=-21.5733,
23-
unit=(u.deg, u.deg))]
21+
SkyCoord(l=121.1743 * u.deg, b=-21.5733 * u.deg, frame="galactic")]
2422

2523

2624
def data_path(filename):
@@ -120,9 +118,9 @@ def test_query_region_box(coordinates, patch_get):
120118
assert isinstance(result, Table)
121119

122120

123-
poly1 = [coord.SkyCoord(ra=10.1, dec=10.1, unit=(u.deg, u.deg)),
124-
coord.SkyCoord(ra=10.0, dec=10.1, unit=(u.deg, u.deg)),
125-
coord.SkyCoord(ra=10.0, dec=10.0, unit=(u.deg, u.deg))]
121+
poly1 = [SkyCoord(ra=10.1 * u.deg, dec=10.1 * u.deg),
122+
SkyCoord(ra=10.0 * u.deg, dec=10.1 * u.deg),
123+
SkyCoord(ra=10.0 * u.deg, dec=10.0 * u.deg)]
126124
poly2 = [(10.1 * u.deg, 10.1 * u.deg), (10.0 * u.deg, 10.1 * u.deg),
127125
(10.0 * u.deg, 10.0 * u.deg)]
128126

astroquery/ipac/ned/tests/test_ned.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ def test_query_region_async(monkeypatch, patch_get):
221221
assert response['search_type'] == "Near Name Search"
222222
# check with Galactic coordinates
223223
response = ned.core.Ned.query_region_async(
224-
commons.GalacticCoordGenerator(l=-67.02084, b=-29.75447,
225-
unit=(u.deg, u.deg)),
224+
coord.SkyCoord(l=-67.02084 * u.deg, b=-29.75447 * u.deg, frame="galactic"),
226225
get_query_payload=True)
227226
assert response['search_type'] == 'Near Position Search'
228227
npt.assert_approx_equal(

astroquery/magpis/tests/test_magpis.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
import numpy.testing as npt
66
import pytest
77
import astropy.units as u
8+
from astropy.coordinates import SkyCoord
89

910
from ...utils import commons
1011
from astroquery.utils.mocks import MockResponse
1112
from ... import magpis
1213

14+
15+
skycoord = SkyCoord(10.5 * u.deg, 0.0 * u.deg, frame="galactic")
16+
1317
DATA_FILES = {'image': 'image.fits'}
1418

1519

@@ -50,23 +54,18 @@ def test_list_surveys():
5054

5155
def test_get_images_async(patch_post, patch_parse_coordinates):
5256
response = magpis.core.Magpis.get_images_async(
53-
commons.GalacticCoordGenerator(10.5, 0.0, unit=(u.deg, u.deg)),
54-
image_size=2 * u.deg, survey="gps6epoch3", get_query_payload=True)
57+
skycoord, image_size=2 * u.deg, survey="gps6epoch3", get_query_payload=True)
5558
npt.assert_approx_equal(response['ImageSize'], 120, significant=3)
5659
assert response['Survey'] == 'gps6epoch3'
57-
response = magpis.core.Magpis.get_images_async(
58-
commons.GalacticCoordGenerator(10.5, 0.0, unit=(u.deg, u.deg)))
60+
response = magpis.core.Magpis.get_images_async(skycoord)
5961
assert response is not None
6062

6163

6264
def test_get_images(patch_post, patch_parse_coordinates):
63-
image = magpis.core.Magpis.get_images(
64-
commons.GalacticCoordGenerator(10.5, 0.0, unit=(u.deg, u.deg)))
65+
image = magpis.core.Magpis.get_images(skycoord)
6566
assert image is not None
6667

6768

6869
@pytest.mark.xfail
6970
def test_get_images_fail(patch_post, patch_parse_coordinates):
70-
magpis.core.Magpis.get_images(
71-
commons.GalacticCoordGenerator(10.5, 0.0, unit=(u.deg, u.deg)),
72-
survey='Not a survey')
71+
magpis.core.Magpis.get_images(skycoord, survey="Not a survey")

astroquery/nvas/tests/test_nvas.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
import numpy.testing as npt
99
import astropy.units as u
1010
import pytest
11+
from astropy.coordinates import SkyCoord
1112
from astropy.io.fits.verify import VerifyWarning
1213

1314
from ...import nvas
1415
from astroquery.utils.mocks import MockResponse
1516
from ...utils import commons
1617

17-
COORDS_GAL = commons.GalacticCoordGenerator(
18-
l=49.489, b=-0.37, unit=(u.deg, u.deg)) # ARM 2000
19-
COORDS_ICRS = commons.ICRSCoordGenerator(
20-
"12h29m06.69512s +2d03m08.66276s") # 3C 273
18+
COORDS_GAL = SkyCoord(l=49.489 * u.deg, b=-0.37 * u.deg, frame="galactic") # ARM 2000
19+
COORDS_ICRS = SkyCoord("12h29m06.69512s +2d03m08.66276s", frame="icrs") # 3C 273
2120

2221
DATA_FILES = {'image': 'image.imfits',
2322
'image_search': 'image_results.html'}
@@ -84,8 +83,8 @@ def deparse_coordinates(cstr):
8483
@pytest.mark.parametrize(('coordinates'), [COORDS_GAL, COORDS_ICRS])
8584
def test_parse_coordinates(coordinates):
8685
out_str = nvas.core._parse_coordinates(coordinates)
87-
new_coords = commons.ICRSCoordGenerator(
88-
deparse_coordinates(out_str), unit=(u.hour, u.deg))
86+
new_coords = SkyCoord(
87+
deparse_coordinates(out_str), unit=(u.hour, u.deg), frame="icrs")
8988
# if all goes well new_coords and coordinates have same ra and dec
9089
npt.assert_approx_equal(new_coords.ra.degree,
9190
coordinates.transform_to('fk5').ra.degree,

0 commit comments

Comments
 (0)