Skip to content

Commit 06dfd0d

Browse files
committed
test case, modify comments, add debug logs
1 parent a7f6306 commit 06dfd0d

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

astroquery/mast/core.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,17 @@ def resolve_object(self, objectname, resolver=None, resolve_all=False):
122122
The resolver to use when resolving a named target into coordinates. Valid options are "SIMBAD" and "NED".
123123
If not specified, the default resolver order will be used. Please see the
124124
`STScI Archive Name Translation Application (SANTA) <https://mastresolver.stsci.edu/Santa-war/>`__
125-
for more information. Default is None.
125+
for more information. If ``resolve_all`` is True, this parameter will be ignored. Default is None.
126126
resolve_all : bool, optional
127127
If True, will try to resolve the object name using all available resolvers ("NED", "SIMBAD").
128128
Function will return a dictionary where the keys are the resolver names and the values are the
129129
resolved coordinates. Default is False.
130130
131131
Returns
132132
-------
133-
response : `~astropy.coordinates.SkyCoord`
134-
The sky position of the given object.
133+
response : `~astropy.coordinates.SkyCoord`, dict
134+
If `resolve_all` is False, returns a `~astropy.coordinates.SkyCoord` object with the resolved coordinates.
135+
If `resolve_all` is True, returns a dictionary where the keys are the resolver names and the values are
136+
`~astropy.coordinates.SkyCoord` objects with the resolved coordinates.
135137
"""
136138
return utils.resolve_object(objectname, resolver, resolve_all)

astroquery/mast/tests/test_mast.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,3 +1187,37 @@ def test_zcut_get_cutouts(patch_post, tmpdir):
11871187
assert isinstance(cutout_list, list)
11881188
assert len(cutout_list) == 1
11891189
assert isinstance(cutout_list[0], fits.HDUList)
1190+
1191+
1192+
################
1193+
# Utils tests #
1194+
################
1195+
1196+
1197+
def test_parse_input_location(patch_post):
1198+
# Test with coordinates
1199+
coord = SkyCoord(23.34086, 60.658, unit="deg")
1200+
loc = mast.utils.parse_input_location(coordinates=coord)
1201+
assert isinstance(loc, SkyCoord)
1202+
assert loc.ra == coord.ra
1203+
assert loc.dec == coord.dec
1204+
1205+
# Test with object name
1206+
obj_coord = SkyCoord(124.531756290083, -68.3129998725044, unit="deg")
1207+
loc = mast.utils.parse_input_location(objectname="TIC 307210830")
1208+
assert isinstance(loc, SkyCoord)
1209+
assert loc.ra == obj_coord.ra
1210+
assert loc.dec == obj_coord.dec
1211+
1212+
# Error if both coordinates and object name are provided
1213+
with pytest.raises(InvalidQueryError, match="Only one of objectname and coordinates may be specified"):
1214+
mast.utils.parse_input_location(coordinates=coord, objectname="M101")
1215+
1216+
# Error if neither coordinates nor object name is provided
1217+
with pytest.raises(InvalidQueryError, match="One of objectname and coordinates must be specified"):
1218+
mast.utils.parse_input_location()
1219+
1220+
# Warn if resolver is specified without an object name
1221+
with pytest.warns(InputWarning, match="Resolver is only used when resolving object names"):
1222+
loc = mast.utils.parse_input_location(coordinates=coord, resolver="SIMBAD")
1223+
assert isinstance(loc, SkyCoord)

astroquery/mast/utils.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,18 @@ def resolve_object(objectname, resolver=None, resolve_all=False):
101101
The resolver to use when resolving a named target into coordinates. Valid options are "SIMBAD" and "NED".
102102
If not specified, the default resolver order will be used. Please see the
103103
`STScI Archive Name Translation Application (SANTA) <https://mastresolver.stsci.edu/Santa-war/>`__
104-
for more information. Default is None.
104+
for more information. If ``resolve_all`` is True, this parameter will be ignored. Default is None.
105105
resolve_all : bool, optional
106106
If True, will try to resolve the object name using all available resolvers ("NED", "SIMBAD").
107107
Function will return a dictionary where the keys are the resolver names and the values are the
108108
resolved coordinates. Default is False.
109109
110110
Returns
111111
-------
112-
response : `~astropy.coordinates.SkyCoord`
113-
The sky position of the given object.
112+
response : `~astropy.coordinates.SkyCoord`, dict
113+
If `resolve_all` is False, returns a `~astropy.coordinates.SkyCoord` object with the resolved coordinates.
114+
If `resolve_all` is True, returns a dictionary where the keys are the resolver names and the values are
115+
`~astropy.coordinates.SkyCoord` objects with the resolved coordinates.
114116
"""
115117
is_catalog = False # Flag to check if object name belongs to a MAST catalog
116118
catalog = None # Variable to store the catalog name
@@ -171,8 +173,9 @@ def resolve_object(objectname, resolver=None, resolve_all=False):
171173
if resolver_coord.separation(catalog_coord) > 1 * u.arcsec:
172174
# Warn user if the coordinates differ by more than 1 arcsec
173175
warnings.warn(f'Resolver {resolver} returned coordinates that differ from MAST {catalog} catalog '
174-
'by more than 0.1 arcsec. ', InputWarning)
176+
'by more than 1 arcsec. ', InputWarning)
175177

178+
log.debug(f'Coordinates resolved using {resolver}: {resolver_coord}')
176179
return resolver_coord
177180

178181
if not result:
@@ -187,7 +190,9 @@ def resolve_object(objectname, resolver=None, resolve_all=False):
187190

188191
# Case when resolve_all is False and no resolver is specified
189192
# SANTA returns result from first compatible resolver
190-
return SkyCoord(result[0]['ra'], result[0]['decl'], unit='deg')
193+
coord = SkyCoord(result[0]['ra'], result[0]['decl'], unit='deg')
194+
log.debug(f'Coordinates resolved using {result[0]["resolver"]}: {coord}')
195+
return coord
191196

192197

193198
def parse_input_location(coordinates=None, objectname=None, resolver=None):
@@ -224,7 +229,7 @@ def parse_input_location(coordinates=None, objectname=None, resolver=None):
224229
raise InvalidQueryError("One of objectname and coordinates must be specified.")
225230

226231
if not objectname and resolver:
227-
warnings.warn("Resolver is only used when resolving object names. It will be ignored.", InputWarning)
232+
warnings.warn("Resolver is only used when resolving object names and will be ignored.", InputWarning)
228233

229234
if objectname:
230235
obj_coord = resolve_object(objectname, resolver)

0 commit comments

Comments
 (0)