5
5
import io
6
6
import re
7
7
import warnings
8
+ import requests
9
+ import json
8
10
9
11
# Import various astropy modules
10
12
import astropy .coordinates as coord
@@ -370,14 +372,14 @@ def query_object_async(self, object_name, *, table="ps", get_query_payload=False
370
372
return self .query_criteria_async (table , get_query_payload = get_query_payload , cache = cache , ** criteria )
371
373
372
374
@class_or_instance
373
- def query_aliases (self , object_name , * , cache = None ):
375
+ def query_aliases (self , object_name ):
374
376
"""
375
377
Search for aliases for a given confirmed planet or planet host
376
378
377
379
Parameters
378
380
----------
379
381
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 .
381
383
cache : bool, optional
382
384
Should the request result be cached? This can be useful for large repeated queries,
383
385
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):
387
389
response : list
388
390
A list of aliases found for the object name. The default name will be listed first.
389
391
"""
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
+
395
416
396
417
@class_or_instance
397
418
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 """
399
420
try :
400
- aliases = self .query_aliases (object_name , cache = False )
401
- except RemoteServiceError :
421
+ aliases = self .query_aliases (object_name )
422
+ except KeyError :
402
423
aliases = []
403
424
if aliases :
404
425
return aliases [0 ]
0 commit comments