6
6
This module contains various methods for querying MAST observations.
7
7
"""
8
8
9
-
10
9
import warnings
11
10
import json
12
11
import time
38
37
from . import conf , utils
39
38
from .core import MastQueryWithLogin
40
39
41
-
42
40
__all__ = ['Observations' , 'ObservationsClass' ,
43
41
'MastClass' , 'Mast' ]
44
42
@@ -51,6 +49,13 @@ class ObservationsClass(MastQueryWithLogin):
51
49
Class for querying MAST observational data.
52
50
"""
53
51
52
+ # Calling static class variables
53
+ _caom_all = 'Mast.Caom.All'
54
+ _caom_cone = 'Mast.Caom.Cone'
55
+ _caom_filtered_position = 'Mast.Caom.Filtered.Position'
56
+ _caom_filtered = 'Mast.Caom.Filtered'
57
+ _caom_products = 'Mast.Caom.Products'
58
+
54
59
def _parse_result (self , responses , verbose = False ): # Used by the async_to_sync decorator functionality
55
60
"""
56
61
Parse the results of a list of `~requests.Response` objects and returns an `~astropy.table.Table` of results.
@@ -82,7 +87,7 @@ def list_missions(self):
82
87
"""
83
88
84
89
# getting all the histogram information
85
- service = "Mast.Caom.All"
90
+ service = self . _caom_all
86
91
params = {}
87
92
response = self ._portal_api_connection .service_request_async (service , params , format = 'extjs' )
88
93
json_response = response [0 ].json ()
@@ -112,9 +117,9 @@ def get_metadata(self, query_type):
112
117
"""
113
118
114
119
if query_type .lower () == "observations" :
115
- colconf_name = "Mast.Caom.Cone"
120
+ colconf_name = self . _caom_cone
116
121
elif query_type .lower () == "products" :
117
- colconf_name = "Mast.Caom.Products"
122
+ colconf_name = self . _caom_products
118
123
else :
119
124
raise InvalidQueryError ("Unknown query type." )
120
125
@@ -152,14 +157,14 @@ def _parse_caom_criteria(self, **criteria):
152
157
153
158
# Build the mashup filter object and store it in the correct service_name entry
154
159
if coordinates or objectname :
155
- mashup_filters = self ._portal_api_connection .build_filter_set ("Mast.Caom.Cone" ,
156
- "Mast.Caom.Filtered.Position" ,
157
- ** criteria )
160
+ mashup_filters = self ._portal_api_connection .build_filter_set (self . _caom_cone ,
161
+ self . _caom_filtered_position ,
162
+ ** criteria )
158
163
coordinates = utils .parse_input_location (coordinates , objectname )
159
164
else :
160
- mashup_filters = self ._portal_api_connection .build_filter_set ("Mast.Caom.Cone" ,
161
- "Mast.Caom.Filtered" ,
162
- ** criteria )
165
+ mashup_filters = self ._portal_api_connection .build_filter_set (self . _caom_cone ,
166
+ self . _caom_filtered ,
167
+ ** criteria )
163
168
164
169
# handle position info (if any)
165
170
position = None
@@ -168,7 +173,7 @@ def _parse_caom_criteria(self, **criteria):
168
173
# if radius is just a number we assume degrees
169
174
radius = coord .Angle (radius , u .deg )
170
175
171
- # build the coordinates string needed by Mast.Caom.Filtered.Position
176
+ # build the coordinates string needed by ObservationsClass._caom_filtered_position
172
177
position = ', ' .join ([str (x ) for x in (coordinates .ra .deg , coordinates .dec .deg , radius .deg )])
173
178
174
179
return position , mashup_filters
@@ -209,7 +214,7 @@ def query_region_async(self, coordinates, radius=0.2*u.deg, pagesize=None, page=
209
214
# if radius is just a number we assume degrees
210
215
radius = coord .Angle (radius , u .deg )
211
216
212
- service = 'Mast.Caom.Cone'
217
+ service = self . _caom_cone
213
218
params = {'ra' : coordinates .ra .deg ,
214
219
'dec' : coordinates .dec .deg ,
215
220
'radius' : radius .deg }
@@ -286,12 +291,12 @@ def query_criteria_async(self, pagesize=None, page=None, **criteria):
286
291
raise InvalidQueryError ("At least one non-positional criterion must be supplied." )
287
292
288
293
if position :
289
- service = "Mast.Caom.Filtered.Position"
294
+ service = self . _caom_filtered_position
290
295
params = {"columns" : "*" ,
291
296
"filters" : mashup_filters ,
292
297
"position" : position }
293
298
else :
294
- service = "Mast.Caom.Filtered"
299
+ service = self . _caom_filtered
295
300
params = {"columns" : "*" ,
296
301
"filters" : mashup_filters }
297
302
@@ -322,7 +327,7 @@ def query_region_count(self, coordinates, radius=0.2*u.deg, pagesize=None, page=
322
327
response : int
323
328
"""
324
329
325
- # build the coordinates string needed by Mast.Caom.Filtered.Position
330
+ # build the coordinates string needed by ObservationsClass._caom_filtered_position
326
331
coordinates = commons .parse_coordinates (coordinates )
327
332
328
333
# if radius is just a number we assume degrees
@@ -331,7 +336,7 @@ def query_region_count(self, coordinates, radius=0.2*u.deg, pagesize=None, page=
331
336
# turn coordinates into the format
332
337
position = ', ' .join ([str (x ) for x in (coordinates .ra .deg , coordinates .dec .deg , radius .deg )])
333
338
334
- service = "Mast.Caom.Filtered.Position"
339
+ service = self . _caom_filtered_position
335
340
params = {"columns" : "COUNT_BIG(*)" ,
336
341
"filters" : [],
337
342
"position" : position }
@@ -399,12 +404,12 @@ def query_criteria_count(self, pagesize=None, page=None, **criteria):
399
404
400
405
# send query
401
406
if position :
402
- service = "Mast.Caom.Filtered.Position"
407
+ service = self . _caom_filtered_position
403
408
params = {"columns" : "COUNT_BIG(*)" ,
404
409
"filters" : mashup_filters ,
405
410
"position" : position }
406
411
else :
407
- service = "Mast.Caom.Filtered"
412
+ service = self . _caom_filtered
408
413
params = {"columns" : "COUNT_BIG(*)" ,
409
414
"filters" : mashup_filters }
410
415
@@ -440,7 +445,7 @@ def get_product_list_async(self, observations):
440
445
if len (observations ) == 0 :
441
446
raise InvalidQueryError ("Observation list is empty, no associated products." )
442
447
443
- service = 'Mast.Caom.Products'
448
+ service = self . _caom_products
444
449
params = {'obsid' : ',' .join (observations )}
445
450
446
451
return self ._portal_api_connection .service_request_async (service , params )
0 commit comments