Skip to content

Commit f56ca1a

Browse files
authored
Merge pull request astropy#3615 from snbianco/resolver-fix
MAST: Resolve objects more performantly
2 parents 596c02e + 86571ea commit f56ca1a

2 files changed

Lines changed: 21 additions & 23 deletions

File tree

astroquery/mast/tests/test_mast_remote.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22

3+
import json
34
import logging
5+
import os
46
from pathlib import Path
7+
8+
import astropy.units as u
59
import numpy as np
6-
import os
710
import pytest
8-
import json
9-
10-
from requests.models import Response
11-
12-
from astropy.table import Table, unique
1311
from astropy.coordinates import SkyCoord
1412
from astropy.io import fits
15-
import astropy.units as u
13+
from astropy.table import Table, unique
14+
from requests.models import Response
1615

17-
from astroquery.mast import Observations, utils, Mast, Catalogs, Hapcut, Tesscut, Zcut, MastMissions
16+
from astroquery.mast import (Catalogs, Hapcut, Mast, MastMissions, Observations, Tesscut, Zcut, utils)
1817

18+
from ...exceptions import (InputWarning, InvalidQueryError, MaxResultsWarning, NoResultsWarning)
1919
from ..utils import ResolverError
20-
from ...exceptions import (InputWarning, InvalidQueryError, MaxResultsWarning,
21-
NoResultsWarning)
2220

2321

2422
@pytest.fixture(scope="module")
@@ -66,8 +64,10 @@ def test_resolve_object(self):
6664

6765
# Try the same object with different resolvers
6866
# The position of objects can change with different resolvers
69-
ned_loc = utils.resolve_object("jw100", resolver="NED")
70-
assert round(ned_loc.separation(SkyCoord("354.10436 21.15083", unit='deg')).value, 4) == 0
67+
# TODO: Commenting out NED resolver test for now since we've been having issues with NED service availability.
68+
# Re-enable this test once the service is stable.
69+
# ned_loc = utils.resolve_object("jw100", resolver="NED")
70+
# assert round(ned_loc.separation(SkyCoord("354.10436 21.15083", unit='deg')).value, 4) == 0
7171

7272
simbad_loc = utils.resolve_object("jw100", resolver="simbad")
7373
assert round(simbad_loc.separation(SkyCoord("83.70341477 -5.55918309", unit="deg")).value, 4) == 0
@@ -79,16 +79,16 @@ def test_resolve_object(self):
7979
# Use resolve_all to get all resolvers
8080
loc_dict = utils.resolve_object("jw100", resolve_all=True)
8181
assert isinstance(loc_dict, dict)
82-
assert loc_dict['NED'] == ned_loc
82+
# assert loc_dict['NED'] == ned_loc
8383
assert loc_dict['SIMBAD'] == simbad_loc
8484

8585
# Error if coordinates cannot be resolved
8686
with pytest.raises(ResolverError, match='Could not resolve "invalid" to a sky position.'):
8787
utils.resolve_object("invalid")
8888

8989
# Error if coordinates cannot be resolved with a specific resolver
90-
with pytest.raises(ResolverError, match='Could not resolve "invalid" to a sky position using resolver "NED"'):
91-
utils.resolve_object("invalid", resolver="NED")
90+
with pytest.raises(ResolverError, match='not resolve "invalid" to a sky position using resolver "SIMBAD"'):
91+
utils.resolve_object("invalid", resolver="SIMBAD")
9292

9393
###########################
9494
# MissionSearchClass Test #

astroquery/mast/utils.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@
66
Miscellaneous functions used throughout the MAST module.
77
"""
88

9+
import platform
910
import re
1011
import warnings
1112

1213
import numpy as np
1314
import requests
14-
import platform
15+
from astropy import units as u
1516
from astropy.coordinates import SkyCoord
1617
from astropy.table import Table
1718
from astropy.utils import deprecated
1819
from astropy.utils.console import ProgressBarOrSpinner
1920
from astropy.utils.decorators import deprecated_renamed_argument
20-
from astropy import units as u
2121

2222
from .. import log
23-
from ..version import version
24-
from ..exceptions import InputWarning, NoResultsWarning, ResolverError, InvalidQueryError
23+
from ..exceptions import (InputWarning, InvalidQueryError, NoResultsWarning, ResolverError)
2524
from ..utils import commons
26-
25+
from ..version import version
2726

2827
__all__ = []
2928

@@ -227,10 +226,9 @@ def resolve_object(object_name, *, resolver=None, resolve_all=False, batch_size=
227226
break
228227

229228
# Send request to STScI Archive Name Translation Application (SANTA)
230-
params = {'outputFormat': 'json',
231-
'resolveAll': resolve_all or is_catalog} # Always set resolveAll to True for MAST catalogs
229+
params = {'outputFormat': 'json', 'resolveAll': resolve_all} # Always set resolveAll to True for MAST catalogs
232230
if resolver and not params['resolveAll']:
233-
params['resolver'] = resolver
231+
params['resolver'] = [resolver, catalog] if is_catalog else [resolver]
234232

235233
# Fetch results (batching if necessary)
236234
results = _batched_request(

0 commit comments

Comments
 (0)