8
8
from astropy .table import QTable
9
9
from astropy .coordinates import SkyCoord
10
10
import astropy .units as u
11
+ from urllib .parse import quote
11
12
12
13
__all__ = ['NasaExoplanetArchive' ]
13
14
14
- EXOPLANETS_CSV_URL = ('http://exoplanetarchive.ipac.caltech.edu/cgi-bin/'
15
- 'nstedAPI/nph-nstedAPI?table=exoplanets' )
15
+ EXOPLANETS_CSV_URL = ('http://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI?table=exoplanets' )
16
16
TIME_ATTRS = {'rowupdate' : 'iso' }
17
17
BOOL_ATTRS = ('pl_kepflag' , 'pl_ttvflag' , 'pl_k2flag' , 'st_massblend' ,
18
18
'st_optmagblend' , 'st_radblend' , 'st_teffblend' )
19
19
20
20
21
21
class NasaExoplanetArchiveClass (object ):
22
22
"""
23
- Exoplanet Archive querying object. Use the ``get_confirmed_planets_table``
24
- or ``query_planet`` methods to get information about exoplanets via the NASA
25
- Exoplanet Archive.
23
+ Querying object for `NExScI Exoplanet Archive Confirmed Planets archive
24
+ <http://exoplanetarchive.ipac.caltech.edu/index.html>`_
25
+
26
+ The Exoplanet Archive table returns lots of columns of data. A full
27
+ description of the columns can be found `here
28
+ <https://exoplanetarchive.ipac.caltech.edu/docs/API_exoplanet_columns.html>`_
29
+
30
+ Use the ``query_planet`` or ``query_star`` methods to get information
31
+ about exoplanets via the Archive.
26
32
"""
27
33
def __init__ (self ):
28
34
self ._param_units = None
29
35
self ._table = None
36
+ self ._cache_planet = None
37
+ self ._cache_star = None
30
38
31
39
@property
32
40
def param_units (self ):
@@ -38,18 +46,16 @@ def param_units(self):
38
46
39
47
return self ._param_units
40
48
41
- def get_confirmed_planets_table (self , cache = True , show_progress = True ,
42
- table_path = None , all_columns = False ):
49
+ def query_planet (self , planet_name , cache = True , show_progress = True ,
50
+ table_path = None , all_columns = False ):
43
51
"""
44
- Download (and optionally cache) the `NExScI Exoplanet Archive Confirmed
45
- Planets table <http://exoplanetarchive.ipac.caltech.edu/index.html>`_.
46
-
47
- The Exoplanet Archive table returns lots of columns of data. A full
48
- description of the columns can be found `here
49
- <https://exoplanetarchive.ipac.caltech.edu/docs/API_exoplanet_columns.html>`_
52
+ Download (and optionally cache) the NASA Exoplanet
53
+ table for a certain planet.
50
54
51
55
Parameters
52
56
----------
57
+ planet_name : str
58
+ Name of planet
53
59
cache : bool (optional)
54
60
Cache exoplanet table to local astropy cache? Default is `True`.
55
61
show_progress : bool (optional)
@@ -65,27 +71,26 @@ def get_confirmed_planets_table(self, cache=True, show_progress=True,
65
71
Returns
66
72
-------
67
73
table : `~astropy.table.QTable`
68
- Table of exoplanet properties.
74
+ Table of one exoplanet's properties.
69
75
"""
70
- if self ._table is None or not cache :
76
+
77
+ planet_name = '\' ' + planet_name + '\' '
78
+ EXOPLANET_URL_PLANET = EXOPLANETS_CSV_URL + '&where=pl_name=' + quote (planet_name )
79
+
80
+ if self ._table is not None and self ._cache_planet is planet_name and cache :
81
+ pass
82
+
83
+ else :
71
84
if table_path is None :
72
- exoplanets_url = EXOPLANETS_CSV_URL
85
+ exoplanets_url = EXOPLANET_URL_PLANET
73
86
if all_columns :
74
- exoplanets_url = EXOPLANETS_CSV_URL + '&select=*'
87
+ exoplanets_url = EXOPLANET_URL_PLANET + '&select=*'
75
88
76
89
table_path = download_file (exoplanets_url , cache = cache ,
77
90
show_progress = show_progress ,
78
91
timeout = 120 )
79
92
exoplanets_table = ascii .read (table_path )
80
93
81
- # Store column of lowercase names for indexing:
82
- lowercase_names = [host_name .lower ().replace (' ' , '' ) + letter
83
- for host_name , letter in
84
- zip (exoplanets_table ['pl_hostname' ].data ,
85
- exoplanets_table ['pl_letter' ].data )]
86
- exoplanets_table ['NAME_LOWERCASE' ] = lowercase_names
87
- exoplanets_table .add_index ('NAME_LOWERCASE' )
88
-
89
94
# Create sky coordinate mixin column
90
95
exoplanets_table ['sky_coord' ] = SkyCoord (ra = exoplanets_table ['ra' ] * u .deg ,
91
96
dec = exoplanets_table ['dec' ] * u .deg )
@@ -98,28 +103,70 @@ def get_confirmed_planets_table(self, cache=True, show_progress=True,
98
103
exoplanets_table [col ].unit = u .Unit (self .param_units [col ])
99
104
100
105
self ._table = QTable (exoplanets_table )
106
+ self ._cache_planet = planet_name
101
107
102
108
return self ._table
103
109
104
- def query_planet (self , planet_name , ** kwargs ):
110
+ def query_star (self , host_name , cache = True , show_progress = True ,
111
+ table_path = None , all_columns = False ):
105
112
"""
106
- Get table of exoplanet properties.
113
+ Download (and optionally cache) the NASA Exoplanet
114
+ table for a certain planet.
107
115
108
116
Parameters
109
117
----------
110
- planet_name : str
111
- Name of planet
112
- kwargs : dict (optional)
113
- Extra keyword arguments passed to ``get_confirmed_planets_table``.
118
+ host_name : str
119
+ Name of stellar system
120
+ cache : bool (optional)
121
+ Cache exoplanet table to local astropy cache? Default is `True`.
122
+ show_progress : bool (optional)
123
+ Show progress of exoplanet table download (if no cached copy is
124
+ available). Default is `True`.
125
+ table_path : str (optional)
126
+ Path to a local table file. Default `None` will trigger a
127
+ download of the table from the internet.
128
+ all_columns : bool (optional)
129
+ Return all available columns. The default returns only the
130
+ columns in the default category at the link above.
114
131
115
132
Returns
116
133
-------
117
134
table : `~astropy.table.QTable`
118
135
Table of one exoplanet's properties.
119
136
"""
120
137
121
- exoplanet_table = self .get_confirmed_planets_table (** kwargs )
122
- return exoplanet_table .loc [planet_name .strip ().lower ().replace (' ' , '' )]
138
+ host_name = '\' ' + host_name + '\' '
139
+ EXOPLANET_URL_PLANET = EXOPLANETS_CSV_URL + '&where=pl_hostname=' + quote (host_name )
140
+
141
+ if self ._table is not None and self ._cache_star is host_name and cache :
142
+ pass
143
+
144
+ else :
145
+ if table_path is None :
146
+ exoplanets_url = EXOPLANET_URL_PLANET
147
+ if all_columns :
148
+ exoplanets_url = EXOPLANET_URL_PLANET + '&select=*'
149
+
150
+ table_path = download_file (exoplanets_url , cache = cache ,
151
+ show_progress = show_progress ,
152
+ timeout = 120 )
153
+ exoplanets_table = ascii .read (table_path )
154
+
155
+ # Create sky coordinate mixin column
156
+ exoplanets_table ['sky_coord' ] = SkyCoord (ra = exoplanets_table ['ra' ] * u .deg ,
157
+ dec = exoplanets_table ['dec' ] * u .deg )
158
+
159
+ # Assign units to columns where possible
160
+ for col in exoplanets_table .colnames :
161
+ if col in self .param_units :
162
+ # Check that unit is implemented in this version of astropy
163
+ if hasattr (u , self .param_units [col ]):
164
+ exoplanets_table [col ].unit = u .Unit (self .param_units [col ])
165
+
166
+ self ._table = QTable (exoplanets_table )
167
+ self ._cache_star = host_name
168
+
169
+ return self ._table
123
170
124
171
125
172
NasaExoplanetArchive = NasaExoplanetArchiveClass ()
0 commit comments