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
@@ -105,6 +107,8 @@ def get_access_url(service='tap'):
105
107
url = conf .url_tap
106
108
elif service == 'api' :
107
109
url = conf .url_api
110
+ elif service == 'aliaslookup' :
111
+ url = conf .url_aliaslookup
108
112
return url
109
113
110
114
@@ -138,7 +142,7 @@ class NasaExoplanetArchiveClass(BaseQuery):
138
142
"""
139
143
140
144
# When module us imported, __init__.py runs and loads a configuration object,
141
- # setting the configuration parameters con .url, conf.timeout and conf.cache
145
+ # setting the configuration parameters conf .url, conf.timeout and conf.cache
142
146
URL_API = conf .url_api
143
147
URL_TAP = conf .url_tap
144
148
TIMEOUT = conf .timeout
@@ -377,7 +381,7 @@ def query_aliases(self, object_name, *, cache=None):
377
381
Parameters
378
382
----------
379
383
object_name : str
380
- The name of a planet or star to regularize using the ``aliastable `` table .
384
+ The name of a planet or star to regularize using the ``aliaslookup `` service .
381
385
cache : bool, optional
382
386
Should the request result be cached? This can be useful for large repeated queries,
383
387
but since the data in the archive is updated regularly, this defaults to ``False``.
@@ -387,24 +391,47 @@ def query_aliases(self, object_name, *, cache=None):
387
391
response : list
388
392
A list of aliases found for the object name. The default name will be listed first.
389
393
"""
390
- return list (
391
- self .query_criteria (
392
- "aliastable" , objname = object_name .strip (), cache = cache , format = "csv"
393
- )["aliasdis" ]
394
- )
394
+ data = self ._request_query_aliases (object_name )
395
+
396
+ try :
397
+ objname_split = object_name .split ()
398
+ if len (objname_split ) > 1 and len (objname_split [- 1 ]) == 1 and objname_split [- 1 ].isalpha ():
399
+ pl_letter = object_name .split ()[- 1 ]
400
+ else :
401
+ pl_letter = ''
402
+
403
+ default_objname = [data ['system' ]['system_info' ]['alias_set' ]['default_name' ]]
404
+ other_objnames = list (set (data ['system' ]['objects' ]['stellar_set' ]['stars' ][default_objname [0 ]]['alias_set' ]['aliases' ]) - set (default_objname ))
405
+ other_objnames .sort ()
406
+ aliases = default_objname + other_objnames
407
+
408
+ if pl_letter :
409
+ aliases = [a + ' ' + pl_letter for a in aliases ]
410
+
411
+ except KeyError :
412
+ aliases = []
413
+ warnings .warn ("No aliases found for name: '{0}'" .format (object_name ), NoResultsWarning )
414
+
415
+ return aliases
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
421
aliases = self .query_aliases (object_name , cache = False )
401
- except RemoteServiceError :
422
+ except KeyError :
402
423
aliases = []
403
424
if aliases :
404
425
return aliases [0 ]
405
426
warnings .warn ("No aliases found for name: '{0}'" .format (object_name ), NoResultsWarning )
406
427
return object_name
407
428
429
+ def _request_query_aliases (self , object_name ):
430
+ """Service request for query_aliases()"""
431
+ url = requests .get (get_access_url ('aliaslookup' )+ object_name )
432
+ response = json .loads (url .text )
433
+ return response
434
+
408
435
# Look for response errors. This might need to be updated for TAP
409
436
def _handle_error (self , text ):
410
437
"""
@@ -653,7 +680,7 @@ def _request_to_sql(self, request_payload):
653
680
@deprecated (since = "v0.4.1" , alternative = "query_object" )
654
681
@deprecated_renamed_argument (["show_progress" , "table_path" ],
655
682
[None , None ], "v0.4.1" , arg_in_kwargs = True )
656
- def query_planet (self , planet_name , cache = None , regularize = True , ** criteria ):
683
+ def query_planet (self , planet_name , cache = None , ** criteria ):
657
684
"""
658
685
Search the ``exoplanets`` table for a confirmed planet
659
686
@@ -665,22 +692,18 @@ def query_planet(self, planet_name, cache=None, regularize=True, **criteria):
665
692
cache : bool, optional
666
693
Should the request result be cached? This can be useful for large repeated queries,
667
694
but since the data in the archive is updated regularly, this defaults to ``False``.
668
- regularize : bool, optional
669
- If ``True``, the ``aliastable`` will be used to regularize the target name.
670
695
**criteria
671
696
Any other filtering criteria to apply. Values provided using the ``where`` keyword will
672
697
be ignored.
673
698
"""
674
- if regularize :
675
- planet_name = self ._regularize_object_name (planet_name )
676
699
criteria = self ._handle_all_columns_argument (** criteria )
677
700
criteria ["where" ] = "pl_name='{0}'" .format (planet_name .strip ())
678
701
return self .query_criteria ("exoplanets" , cache = cache , ** criteria )
679
702
680
703
@deprecated (since = "v0.4.1" , alternative = "query_object" )
681
704
@deprecated_renamed_argument (["show_progress" , "table_path" ],
682
705
[None , None ], "v0.4.1" , arg_in_kwargs = True )
683
- def query_star (self , host_name , cache = None , regularize = True , ** criteria ):
706
+ def query_star (self , host_name , cache = None , ** criteria ):
684
707
"""
685
708
Search the ``exoplanets`` table for a confirmed planet host
686
709
@@ -692,14 +715,10 @@ def query_star(self, host_name, cache=None, regularize=True, **criteria):
692
715
cache : bool, optional
693
716
Should the request result be cached? This can be useful for large repeated queries,
694
717
but since the data in the archive is updated regularly, this defaults to ``False``.
695
- regularize : bool, optional
696
- If ``True``, the ``aliastable`` will be used to regularize the target name.
697
718
**criteria
698
719
Any other filtering criteria to apply. Values provided using the ``where`` keyword will
699
720
be ignored.
700
721
"""
701
- if regularize :
702
- host_name = self ._regularize_object_name (host_name )
703
722
criteria = self ._handle_all_columns_argument (** criteria )
704
723
criteria ["where" ] = "pl_hostname='{0}'" .format (host_name .strip ())
705
724
return self .query_criteria ("exoplanets" , cache = cache , ** criteria )
0 commit comments