Skip to content

Commit 9cd4f45

Browse files
snbiancobsipocz
authored andcommitted
resolve_objects should accept int
1 parent 1e3eb77 commit 9cd4f45

File tree

5 files changed

+52
-44
lines changed

5 files changed

+52
-44
lines changed

astroquery/mast/tests/data/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ To generate `~astroquery.mast.tests.data.resolver.json`, use the following:
5757
>>> import json
5858
>>> from astroquery.mast import utils
5959
...
60-
>>> objects = ["TIC 307210830", "Barnard's Star", "M1", "M101", "M103", "M8", "M10"]
60+
>>> objects = ["TIC 307210830", "Barnard's Star", "M1", "M101", "M103", "M8", "M10", 251813740]
6161
>>> resp = utils._simple_request('http://mastresolver.stsci.edu/Santa-war/query',
6262
... {'name': objects, 'outputFormat': 'json', 'resolveAll': 'true'})
6363
>>> with open('resolver.json', 'w') as file:

astroquery/mast/tests/data/resolver.json

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"searchString": "tic 307210830",
55
"resolver": "TIC",
66
"cached": false,
7-
"resolverTime": 2,
7+
"resolverTime": 6,
88
"searchRadius": 0.000333,
99
"canonicalName": "TIC 307210830",
1010
"ra": 124.531756290083,
@@ -14,31 +14,19 @@
1414
"searchString": "tic 307210830",
1515
"resolver": "SIMBAD",
1616
"cached": true,
17-
"resolverTime": 294,
17+
"resolverTime": 282,
1818
"cacheDate": "Apr 17, 2025, 3:47:59 PM",
1919
"searchRadius": -1.0,
2020
"canonicalName": "L 98-59",
2121
"ra": 124.5317560026638,
2222
"decl": -68.3130014904408,
2323
"objectType": "HighPM*"
2424
},
25-
{
26-
"searchString": "tic 307210830",
27-
"resolver": "SIMBADCFA",
28-
"cached": true,
29-
"resolverTime": 296,
30-
"cacheDate": "Mar 19, 2025, 4:36:27 PM",
31-
"searchRadius": -1.0,
32-
"canonicalName": "L 98-59",
33-
"ra": 124.5317560026638,
34-
"decl": -68.3130014904408,
35-
"objectType": "HighPM*"
36-
},
3725
{
3826
"searchString": "barnard's star",
3927
"resolver": "SIMBAD",
4028
"cached": true,
41-
"resolverTime": 302,
29+
"resolverTime": 284,
4230
"cacheDate": "May 7, 2025, 2:29:06 PM",
4331
"searchRadius": -1.0,
4432
"canonicalName": "NAME Barnard's star",
@@ -50,7 +38,7 @@
5038
"searchString": "m1",
5139
"resolver": "SIMBAD",
5240
"cached": true,
53-
"resolverTime": 292,
41+
"resolverTime": 332,
5442
"cacheDate": "Apr 29, 2025, 1:57:27 PM",
5543
"searchRadius": -1.0,
5644
"canonicalName": "M 1",
@@ -65,7 +53,7 @@
6553
"searchString": "m1",
6654
"resolver": "NED",
6755
"cached": false,
68-
"resolverTime": 1417,
56+
"resolverTime": 915,
6957
"searchRadius": -1.0,
7058
"canonicalName": "MESSIER 001",
7159
"ra": 83.63311,
@@ -76,8 +64,8 @@
7664
"searchString": "m101",
7765
"resolver": "SIMBAD",
7866
"cached": true,
79-
"resolverTime": 290,
80-
"cacheDate": "Sep 2, 2025, 8:13:51 PM",
67+
"resolverTime": 376,
68+
"cacheDate": "Sep 30, 2025, 8:16:12 PM",
8169
"searchRadius": -1.0,
8270
"canonicalName": "M 101",
8371
"ra": 210.802429,
@@ -91,7 +79,7 @@
9179
"searchString": "m101",
9280
"resolver": "SIMBADCFA",
9381
"cached": true,
94-
"resolverTime": 289,
82+
"resolverTime": 340,
9583
"cacheDate": "May 14, 2025, 8:04:05 PM",
9684
"searchRadius": -1.0,
9785
"canonicalName": "M 101",
@@ -106,7 +94,7 @@
10694
"searchString": "m101",
10795
"resolver": "NED",
10896
"cached": false,
109-
"resolverTime": 1181,
97+
"resolverTime": 917,
11098
"searchRadius": -1.0,
11199
"canonicalName": "MESSIER 101",
112100
"ra": 210.80227,
@@ -118,7 +106,7 @@
118106
"searchString": "m103",
119107
"resolver": "SIMBAD",
120108
"cached": true,
121-
"resolverTime": 294,
109+
"resolverTime": 286,
122110
"cacheDate": "May 2, 2025, 4:33:25 AM",
123111
"searchRadius": -1.0,
124112
"canonicalName": "M 103",
@@ -134,7 +122,7 @@
134122
"searchString": "m103",
135123
"resolver": "NED",
136124
"cached": false,
137-
"resolverTime": 1094,
125+
"resolverTime": 821,
138126
"searchRadius": -1.0,
139127
"canonicalName": "MESSIER 103",
140128
"ra": 23.34086,
@@ -145,7 +133,7 @@
145133
"searchString": "m8",
146134
"resolver": "SIMBAD",
147135
"cached": true,
148-
"resolverTime": 294,
136+
"resolverTime": 313,
149137
"cacheDate": "May 1, 2025, 1:11:47 PM",
150138
"searchRadius": -1.0,
151139
"canonicalName": "M 8",
@@ -157,7 +145,7 @@
157145
"searchString": "m8",
158146
"resolver": "NED",
159147
"cached": false,
160-
"resolverTime": 1165,
148+
"resolverTime": 826,
161149
"searchRadius": -1.0,
162150
"canonicalName": "MESSIER 008",
163151
"ra": 270.92194,
@@ -168,7 +156,7 @@
168156
"searchString": "m10",
169157
"resolver": "SIMBAD",
170158
"cached": true,
171-
"resolverTime": 290,
159+
"resolverTime": 278,
172160
"cacheDate": "Apr 29, 2025, 2:00:16 PM",
173161
"searchRadius": -1.0,
174162
"canonicalName": "M 10",
@@ -184,12 +172,22 @@
184172
"searchString": "m10",
185173
"resolver": "NED",
186174
"cached": false,
187-
"resolverTime": 998,
175+
"resolverTime": 838,
188176
"searchRadius": -1.0,
189177
"canonicalName": "MESSIER 010",
190178
"ra": 254.28771,
191179
"decl": -4.10031,
192180
"objectType": "*Cl"
181+
},
182+
{
183+
"searchString": "251813740",
184+
"resolver": "K2",
185+
"cached": false,
186+
"resolverTime": 3,
187+
"searchRadius": 0.000333,
188+
"canonicalName": "EPIC 251813740",
189+
"ra": 343.48308,
190+
"decl": -0.98468872
193191
}
194192
],
195193
"status": ""

astroquery/mast/tests/test_mast.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,10 @@ def test_resolve_object_single(patch_post):
577577
assert isinstance(obj_loc, SkyCoord)
578578
assert round(obj_loc.separation(tic_coord).value, 10) == 0
579579

580+
# Resolve with integer input
581+
obj_loc = mast.Mast.resolve_object(251813740)
582+
assert isinstance(obj_loc, SkyCoord)
583+
580584
# Resolve using a specific resolver and an object that belongs to a MAST catalog
581585
obj_loc_simbad = mast.Mast.resolve_object(obj, resolver="SIMBAD")
582586
assert round(obj_loc_simbad.separation(simbad_coord).value, 10) == 0
@@ -613,39 +617,40 @@ def test_resolve_object_single(patch_post):
613617

614618

615619
def test_resolve_object_multi(patch_post):
616-
objects = ["TIC 307210830", "M1", "Barnard's Star"]
620+
objects = ["TIC 307210830", "M1", "Barnard's Star", 251813740]
617621

618622
# No resolver specified
619623
coord_dict = mast.Mast.resolve_object(objects)
620624
assert isinstance(coord_dict, dict)
621625
for obj in objects:
622-
assert obj in coord_dict
623-
assert isinstance(coord_dict[obj], SkyCoord)
624-
625-
# Warn if one of the objects cannot be resolved
626-
with pytest.warns(InputWarning, match='Could not resolve "nonexisting" to a sky position.'):
627-
coord_dict = mast.Mast.resolve_object(["M1", "nonexisting"])
626+
obj_str = str(obj)
627+
assert obj_str in coord_dict
628+
assert isinstance(coord_dict[obj_str], SkyCoord)
628629

629630
# Resolver specified
630-
coord_dict = mast.Mast.resolve_object(objects, resolver="SIMBAD")
631+
coord_dict = mast.Mast.resolve_object(objects[:3], resolver="SIMBAD")
631632
assert isinstance(coord_dict, dict)
632-
for obj in objects:
633+
for obj in objects[:3]:
633634
assert obj in coord_dict
634635
assert isinstance(coord_dict[obj], SkyCoord)
635636

636-
# Warn if one of the objects can't be resolved with given resolver
637-
with pytest.warns(InputWarning, match='Could not resolve "TIC 307210830" to a sky position using resolver "NED"'):
638-
mast.Mast.resolve_object(objects[:2], resolver="NED")
639-
640637
# Resolve all
641-
coord_dict = mast.Mast.resolve_object(objects, resolve_all=True)
638+
coord_dict = mast.Mast.resolve_object(objects[:3], resolve_all=True)
642639
assert isinstance(coord_dict, dict)
643-
for obj in objects:
640+
for obj in objects[:3]:
644641
assert obj in coord_dict
645642
obj_dict = coord_dict[obj]
646643
assert isinstance(obj_dict, dict)
647644
assert isinstance(obj_dict["SIMBAD"], SkyCoord)
648645

646+
# Warn if one of the objects cannot be resolved
647+
with pytest.warns(InputWarning, match='Could not resolve "nonexisting" to a sky position.'):
648+
coord_dict = mast.Mast.resolve_object(["M1", "nonexisting"])
649+
650+
# Warn if one of the objects can't be resolved with given resolver
651+
with pytest.warns(InputWarning, match='Could not resolve "TIC 307210830" to a sky position using resolver "NED"'):
652+
mast.Mast.resolve_object(objects[:2], resolver="NED")
653+
649654
# Error if none of the objects can be resolved
650655
warnings.simplefilter("ignore", category=InputWarning) # ignore warnings
651656
with pytest.raises(ResolverError, match='Could not resolve any of the given object names to sky positions.'):

astroquery/mast/tests/test_mast_remote.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def test_resolve_object(self):
5252
ticobj_loc = utils.resolve_object("TIC 141914082")
5353
assert round(ticobj_loc.separation(SkyCoord("94.6175354 -72.04484622", unit='deg')).value, 4) == 0
5454

55+
# Integer input
56+
int_loc = utils.resolve_object(251813740)
57+
assert round(int_loc.separation(SkyCoord("343.48308 -0.98468872", unit='deg')).value, 4) == 0
58+
5559
# Try the same object with different resolvers
5660
# The position of objects can change with different resolvers
5761
ned_loc = utils.resolve_object("jw100", resolver="NED")

astroquery/mast/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ def resolve_object(objectname, *, resolver=None, resolve_all=False):
179179
`~astropy.coordinates.SkyCoord` objects with the resolved coordinates.
180180
"""
181181
# Normalize input
182-
object_names = [objectname] if isinstance(objectname, str) else list(objectname)
182+
object_names = [objectname] if isinstance(objectname, (str, int)) else list(objectname)
183+
object_names = [str(name) for name in object_names] # Convert all names to strings
183184
single = len(object_names) == 1
184185

185186
is_catalog = False # Flag to check if object name belongs to a MAST catalog

0 commit comments

Comments
 (0)