Skip to content

Commit 137ffcb

Browse files
rickynilssonbsipocz
authored andcommitted
Fix query_aliases(). Now using aliaslookup service instead of deprecated aliastable.
1 parent 4e35238 commit 137ffcb

File tree

1 file changed

+31
-10
lines changed
  • astroquery/ipac/nexsci/nasa_exoplanet_archive

1 file changed

+31
-10
lines changed

astroquery/ipac/nexsci/nasa_exoplanet_archive/core.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import io
66
import re
77
import warnings
8+
import requests
9+
import json
810

911
# Import various astropy modules
1012
import astropy.coordinates as coord
@@ -370,14 +372,14 @@ def query_object_async(self, object_name, *, table="ps", get_query_payload=False
370372
return self.query_criteria_async(table, get_query_payload=get_query_payload, cache=cache, **criteria)
371373

372374
@class_or_instance
373-
def query_aliases(self, object_name, *, cache=None):
375+
def query_aliases(self, object_name):
374376
"""
375377
Search for aliases for a given confirmed planet or planet host
376378
377379
Parameters
378380
----------
379381
object_name : str
380-
The name of a planet or star to regularize using the ``aliastable`` table.
382+
The name of a planet or star to regularize using the ``aliaslookup`` service.
381383
cache : bool, optional
382384
Should the request result be cached? This can be useful for large repeated queries,
383385
but since the data in the archive is updated regularly, this defaults to ``False``.
@@ -387,18 +389,37 @@ def query_aliases(self, object_name, *, cache=None):
387389
response : list
388390
A list of aliases found for the object name. The default name will be listed first.
389391
"""
390-
return list(
391-
self.query_criteria(
392-
"aliastable", objname=object_name.strip(), cache=cache, format="csv"
393-
)["aliasdis"]
394-
)
392+
url = requests.get("https://exoplanetarchive.ipac.caltech.edu/cgi-bin/Lookup/nph-aliaslookup.py?objname="+object_name)
393+
data = json.loads(url.text)
394+
395+
try :
396+
objname_split = object_name.split()
397+
if len(objname_split) > 1 and len(objname_split[-1]) == 1 and objname_split[-1].isalpha():
398+
pl_letter = object_name.split()[-1]
399+
else:
400+
pl_letter = ''
401+
402+
default_objname = [data['system']['system_info']['alias_set']['default_name']]
403+
other_objnames = list(set(data['system']['objects']['stellar_set']['stars'][default_objname[0]]['alias_set']['aliases']) - set(default_objname))
404+
other_objnames.sort()
405+
aliases = default_objname + other_objnames
406+
407+
if pl_letter:
408+
aliases = [a + ' ' + pl_letter for a in aliases]
409+
410+
except KeyError:
411+
aliases = []
412+
warnings.warn("No aliases found for name: '{0}'".format(object_name), NoResultsWarning)
413+
414+
return aliases
415+
395416

396417
@class_or_instance
397418
def _regularize_object_name(self, object_name):
398-
"""Regularize the name of a planet or planet host using the ``aliastable`` table"""
419+
"""Regularize the name of a planet or planet host using the ``aliaslookup`` service"""
399420
try:
400-
aliases = self.query_aliases(object_name, cache=False)
401-
except RemoteServiceError:
421+
aliases = self.query_aliases(object_name)
422+
except KeyError:
402423
aliases = []
403424
if aliases:
404425
return aliases[0]

0 commit comments

Comments
 (0)