7
7
"""
8
8
9
9
import requests
10
- import warnings
11
10
12
- from astropy .table import Table
13
11
import astropy .units as u
14
12
import astropy .coordinates as coord
15
13
16
14
from astroquery .utils import commons , async_to_sync
17
15
from astroquery .utils .class_or_instance import class_or_instance
18
- from astroquery .exceptions import InvalidQueryError , MaxResultsWarning
16
+ from astroquery .exceptions import InvalidQueryError
19
17
20
18
from astroquery .mast import utils
21
19
from astroquery .mast .core import MastQueryWithLogin
29
27
class MastMissionsClass (MastQueryWithLogin ):
30
28
"""
31
29
MastMissions search class.
32
- Class that allows direct programatic access to retrieve metadata via the MAST search API for a given mission.
30
+
31
+ Class that allows direct programatic access to the MAST search API for a given mission.
33
32
"""
34
33
35
34
def __init__ (self , * , mission = 'hst' , service = 'search' ):
@@ -39,12 +38,11 @@ def __init__(self, *, mission='hst', service='search'):
39
38
'skip_count' , 'user_fields' ]
40
39
self .service = service
41
40
self .mission = mission
42
- self .limit = 5000
43
41
44
42
service_dict = {self .service : {'path' : self .service , 'args' : {}}}
45
43
self ._service_api_connection .set_service_params (service_dict , f"{ self .service } /{ self .mission } " )
46
44
47
- def _parse_result (self , response , * , verbose = False ): # Used by the async_to_sync decorator functionality
45
+ def _parse_result (self , response , verbose = False ): # Used by the async_to_sync decorator functionality
48
46
"""
49
47
Parse the results of a `~requests.Response` objects and return an `~astropy.table.Table` of results.
50
48
@@ -55,22 +53,17 @@ def _parse_result(self, response, *, verbose=False): # Used by the async_to_syn
55
53
verbose : bool
56
54
(presently does nothing - there is no output with verbose set to
57
55
True or False)
58
- Default False. Setting to True provides more extensive output.
56
+ Default False. Setting to True provides more extensive output.
59
57
60
58
Returns
61
59
-------
62
60
response : `~astropy.table.Table`
63
61
"""
64
62
65
- results = self ._service_api_connection ._parse_result (response , verbose , data_key = 'results' )
66
- if len (results ) >= self .limit :
67
- warnings .warn ("Maximum results returned, may not include all sources within radius." ,
68
- MaxResultsWarning )
69
-
70
- return results
63
+ return self ._service_api_connection ._parse_result (response , verbose , data_key = 'results' )
71
64
72
65
@class_or_instance
73
- def query_region_async (self , coordinates , * , radius = 3 * u .arcmin , limit = 5000 , offset = 0 , ** kwargs ):
66
+ def query_region_async (self , coordinates , radius = 3 * u .arcmin , ** kwargs ):
74
67
"""
75
68
Given a sky position and radius, returns a list of matching dataset IDs.
76
69
@@ -84,26 +77,17 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs
84
77
The string must be parsable by `~astropy.coordinates.Angle`. The
85
78
appropriate `~astropy.units.Quantity` object from
86
79
`~astropy.units` may also be used. Defaults to 3 arcminutes.
87
- limit : int
88
- Optional and default is 5000.
89
- the maximun number of dataset IDs in the results.
90
- offset : int
91
- Optional and default is 0
92
- the number of records you wish to skip before selecting records.
93
80
**kwargs
94
81
Other mission-specific keyword args.
95
- Any invalid keys are ignored by the API.
96
- All valid key names can be found using `~astroquery.mast.missions.MastMissionsClass.get_column_list`
97
- function.
82
+ These can be found at the following link
83
+ https://mast.stsci.edu/search/docs/#/Hubble%20Search/post_search_hst_api_v0_1_search_post
98
84
For example one can specify the output columns(select_cols) or use other filters(conditions)
99
85
100
86
Returns
101
87
-------
102
88
response : list of `~requests.Response`
103
89
"""
104
90
105
- self .limit = limit
106
-
107
91
# Put coordinates and radius into consistant format
108
92
coordinates = commons .parse_coordinates (coordinates )
109
93
@@ -113,9 +97,7 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs
113
97
# basic params
114
98
params = {'target' : [f"{ coordinates .ra .deg } { coordinates .dec .deg } " ],
115
99
'radius' : radius .arcmin ,
116
- 'radius_units' : 'arcminutes' ,
117
- 'limit' : limit ,
118
- 'offset' : offset }
100
+ 'radius_units' : 'arcminutes' }
119
101
120
102
params ['conditions' ] = []
121
103
# adding additional user specified parameters
@@ -128,47 +110,29 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs
128
110
return self ._service_api_connection .service_request_async (self .service , params , use_json = True )
129
111
130
112
@class_or_instance
131
- def query_criteria_async (self , * , coordinates = None , objectname = None , radius = 3 * u .arcmin ,
132
- limit = 5000 , offset = 0 , select_cols = [], ** criteria ):
113
+ def query_criteria_async (self , ** criteria ):
133
114
"""
134
115
Given a set of search criteria, returns a list of mission metadata.
135
116
136
117
Parameters
137
118
----------
138
- coordinates : str or `~astropy.coordinates` object
139
- The target around which to search. It may be specified as a
140
- string or as the appropriate `~astropy.coordinates` object.
141
- objectname : str
142
- The name of the target around which to search.
143
- radius : str or `~astropy.units.Quantity` object, optional
144
- Default 3 degrees.
145
- The string must be parsable by `~astropy.coordinates.Angle`. The
146
- appropriate `~astropy.units.Quantity` object from
147
- `~astropy.units` may also be used. Defaults to 3 arcminutes.
148
- limit : int
149
- Optional and default is 5000.
150
- the maximun number of dataset IDs in the results.
151
- offset : int
152
- Optional and default is 0.
153
- the number of records you wish to skip before selecting records.
154
- select_cols: list
155
- names of columns that will be included in the astropy table
156
119
**criteria
157
120
Criteria to apply. At least one non-positional criteria must be supplied.
158
- Valid criteria are coordinates, objectname, radius (as in
159
- `~astroquery.mast.missions.MastMissionsClass.query_region` and
160
- `~astroquery.mast.missions.MastMissionsClass.query_object` functions),
121
+ Valid criteria are coordinates, objectname, radius (as in `query_region` and `query_object`),
161
122
and all fields listed in the column documentation for the mission being queried.
162
- Any invalid keys passed in criteria are ignored by the API .
163
- List of all valid fields that can be used to match results on criteria can be retrieved by calling
164
- `~astroquery.mast.missions.MastMissionsClass.get_column_list` function .
123
+ Fields that can be used to match results on criteria. See the TAP schema link below for all field names .
124
+ https://vao.stsci.edu/missionmast/tapservice.aspx/tables
125
+ some common fields for criteria are sci_pep_id, sci_spec_1234 and sci_actual_duration .
165
126
166
127
Returns
167
128
-------
168
129
response : list of `~requests.Response`
169
130
"""
170
131
171
- self .limit = limit
132
+ # Seperating any position info from the rest of the filters
133
+ coordinates = criteria .pop ('coordinates' , None )
134
+ objectname = criteria .pop ('objectname' , None )
135
+ radius = criteria .pop ('radius' , 0.2 * u .deg )
172
136
173
137
if objectname or coordinates :
174
138
coordinates = utils .parse_input_location (coordinates , objectname )
@@ -177,7 +141,7 @@ def query_criteria_async(self, *, coordinates=None, objectname=None, radius=3*u.
177
141
radius = coord .Angle (radius , u .arcmin )
178
142
179
143
# build query
180
- params = {"limit" : self . limit , "offset" : offset , 'select_cols' : select_cols }
144
+ params = {}
181
145
if coordinates :
182
146
params ["target" ] = [f"{ coordinates .ra .deg } { coordinates .dec .deg } " ]
183
147
params ["radius" ] = radius .arcmin
@@ -196,7 +160,7 @@ def query_criteria_async(self, *, coordinates=None, objectname=None, radius=3*u.
196
160
return self ._service_api_connection .service_request_async (self .service , params , use_json = True )
197
161
198
162
@class_or_instance
199
- def query_object_async (self , objectname , * , radius = 3 * u .arcmin , limit = 5000 , offset = 0 , ** kwargs ):
163
+ def query_object_async (self , objectname , radius = 3 * u .arcmin , ** kwargs ):
200
164
"""
201
165
Given an object name, returns a list of matching rows.
202
166
@@ -209,17 +173,10 @@ def query_object_async(self, objectname, *, radius=3*u.arcmin, limit=5000, offse
209
173
The string must be parsable by `~astropy.coordinates.Angle`.
210
174
The appropriate `~astropy.units.Quantity` object from
211
175
`~astropy.units` may also be used. Defaults to 3 arcminutes.
212
- limit : int
213
- Optional and default is 5000.
214
- the maximun number of dataset IDs in the results.
215
- offset : int
216
- Optional and default is 0.
217
- the number of records you wish to skip before selecting records.
218
176
**kwargs
219
177
Mission-specific keyword args.
220
- Any invalid keys are ignored by the API.
221
- All valid keys can be found by calling `~astroquery.mast.missions.MastMissionsClass.get_column_list`
222
- function.
178
+ These can be found in the `service documentation <https://mast.stsci.edu/api/v0/_services.html>`__.
179
+ for specific catalogs. For example one can specify the magtype for an HSC search.
223
180
224
181
Returns
225
182
-------
@@ -228,7 +185,7 @@ def query_object_async(self, objectname, *, radius=3*u.arcmin, limit=5000, offse
228
185
229
186
coordinates = utils .resolve_object (objectname )
230
187
231
- return self .query_region_async (coordinates , radius = radius , limit = limit , offset = offset , ** kwargs )
188
+ return self .query_region_async (coordinates , radius , ** kwargs )
232
189
233
190
@class_or_instance
234
191
def get_column_list (self ):
@@ -237,23 +194,20 @@ def get_column_list(self):
237
194
238
195
Returns
239
196
-------
240
- response : `~astropy.table.Table` that contains columns names, types and their descriptions
197
+ json data that contains columns names and their descriptions
241
198
"""
242
199
243
200
url = f"{ conf .server } /search/util/api/v0.1/column_list?mission={ self .mission } "
244
201
245
202
try :
246
203
results = requests .get (url )
247
204
results = results .json ()
248
- rows = []
249
205
for result in results :
250
206
result .pop ('field_name' )
251
207
result .pop ('queryable' )
252
208
result .pop ('indexed' )
253
209
result .pop ('default_output' )
254
- rows .append ((result ['column_name' ], result ['qual_type' ], result ['description' ]))
255
- data_table = Table (rows = rows , names = ('name' , 'data_type' , 'description' ))
256
- return data_table
210
+ return results
257
211
except Exception :
258
212
raise Exception (f"Error occured while trying to get column list for mission { self .mission } " )
259
213
0 commit comments