Skip to content

Commit 391ecaa

Browse files
committed
Revert "updates to missions_mast search API astroquery interface"
This reverts commit e0a6a4d.
1 parent e0a6a4d commit 391ecaa

File tree

5 files changed

+865
-888
lines changed

5 files changed

+865
-888
lines changed

astroquery/mast/missions.py

Lines changed: 26 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
"""
88

99
import requests
10-
import warnings
1110

12-
from astropy.table import Table
1311
import astropy.units as u
1412
import astropy.coordinates as coord
1513

1614
from astroquery.utils import commons, async_to_sync
1715
from astroquery.utils.class_or_instance import class_or_instance
18-
from astroquery.exceptions import InvalidQueryError, MaxResultsWarning
16+
from astroquery.exceptions import InvalidQueryError
1917

2018
from astroquery.mast import utils
2119
from astroquery.mast.core import MastQueryWithLogin
@@ -29,7 +27,8 @@
2927
class MastMissionsClass(MastQueryWithLogin):
3028
"""
3129
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.
3332
"""
3433

3534
def __init__(self, *, mission='hst', service='search'):
@@ -39,12 +38,11 @@ def __init__(self, *, mission='hst', service='search'):
3938
'skip_count', 'user_fields']
4039
self.service = service
4140
self.mission = mission
42-
self.limit = 5000
4341

4442
service_dict = {self.service: {'path': self.service, 'args': {}}}
4543
self._service_api_connection.set_service_params(service_dict, f"{self.service}/{self.mission}")
4644

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
4846
"""
4947
Parse the results of a `~requests.Response` objects and return an `~astropy.table.Table` of results.
5048
@@ -55,22 +53,17 @@ def _parse_result(self, response, *, verbose=False): # Used by the async_to_syn
5553
verbose : bool
5654
(presently does nothing - there is no output with verbose set to
5755
True or False)
58-
Default False. Setting to True provides more extensive output.
56+
Default False. Setting to True provides more extensive output.
5957
6058
Returns
6159
-------
6260
response : `~astropy.table.Table`
6361
"""
6462

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')
7164

7265
@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):
7467
"""
7568
Given a sky position and radius, returns a list of matching dataset IDs.
7669
@@ -84,26 +77,17 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs
8477
The string must be parsable by `~astropy.coordinates.Angle`. The
8578
appropriate `~astropy.units.Quantity` object from
8679
`~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.
9380
**kwargs
9481
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
9884
For example one can specify the output columns(select_cols) or use other filters(conditions)
9985
10086
Returns
10187
-------
10288
response : list of `~requests.Response`
10389
"""
10490

105-
self.limit = limit
106-
10791
# Put coordinates and radius into consistant format
10892
coordinates = commons.parse_coordinates(coordinates)
10993

@@ -113,9 +97,7 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs
11397
# basic params
11498
params = {'target': [f"{coordinates.ra.deg} {coordinates.dec.deg}"],
11599
'radius': radius.arcmin,
116-
'radius_units': 'arcminutes',
117-
'limit': limit,
118-
'offset': offset}
100+
'radius_units': 'arcminutes'}
119101

120102
params['conditions'] = []
121103
# adding additional user specified parameters
@@ -128,47 +110,29 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs
128110
return self._service_api_connection.service_request_async(self.service, params, use_json=True)
129111

130112
@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):
133114
"""
134115
Given a set of search criteria, returns a list of mission metadata.
135116
136117
Parameters
137118
----------
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
156119
**criteria
157120
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`),
161122
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.
165126
166127
Returns
167128
-------
168129
response : list of `~requests.Response`
169130
"""
170131

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)
172136

173137
if objectname or coordinates:
174138
coordinates = utils.parse_input_location(coordinates, objectname)
@@ -177,7 +141,7 @@ def query_criteria_async(self, *, coordinates=None, objectname=None, radius=3*u.
177141
radius = coord.Angle(radius, u.arcmin)
178142

179143
# build query
180-
params = {"limit": self.limit, "offset": offset, 'select_cols': select_cols}
144+
params = {}
181145
if coordinates:
182146
params["target"] = [f"{coordinates.ra.deg} {coordinates.dec.deg}"]
183147
params["radius"] = radius.arcmin
@@ -196,7 +160,7 @@ def query_criteria_async(self, *, coordinates=None, objectname=None, radius=3*u.
196160
return self._service_api_connection.service_request_async(self.service, params, use_json=True)
197161

198162
@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):
200164
"""
201165
Given an object name, returns a list of matching rows.
202166
@@ -209,17 +173,10 @@ def query_object_async(self, objectname, *, radius=3*u.arcmin, limit=5000, offse
209173
The string must be parsable by `~astropy.coordinates.Angle`.
210174
The appropriate `~astropy.units.Quantity` object from
211175
`~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.
218176
**kwargs
219177
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.
223180
224181
Returns
225182
-------
@@ -228,7 +185,7 @@ def query_object_async(self, objectname, *, radius=3*u.arcmin, limit=5000, offse
228185

229186
coordinates = utils.resolve_object(objectname)
230187

231-
return self.query_region_async(coordinates, radius=radius, limit=limit, offset=offset, **kwargs)
188+
return self.query_region_async(coordinates, radius, **kwargs)
232189

233190
@class_or_instance
234191
def get_column_list(self):
@@ -237,23 +194,20 @@ def get_column_list(self):
237194
238195
Returns
239196
-------
240-
response : `~astropy.table.Table` that contains columns names, types and their descriptions
197+
json data that contains columns names and their descriptions
241198
"""
242199

243200
url = f"{conf.server}/search/util/api/v0.1/column_list?mission={self.mission}"
244201

245202
try:
246203
results = requests.get(url)
247204
results = results.json()
248-
rows = []
249205
for result in results:
250206
result.pop('field_name')
251207
result.pop('queryable')
252208
result.pop('indexed')
253209
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
257211
except Exception:
258212
raise Exception(f"Error occured while trying to get column list for mission {self.mission}")
259213

astroquery/mast/services.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _json_to_table(json_obj, data_key='data'):
3131
3232
Parameters
3333
----------
34-
json_obj : data array or list of dictionaries
34+
json_obj : dict
3535
A MAST microservice response JSON object (python dictionary)
3636
data_key : str
3737
string that contains the key name in json_obj that stores the data rows
@@ -50,7 +50,6 @@ def _json_to_table(json_obj, data_key='data'):
5050

5151
# for each item in info, store the type and column name
5252
# for each item in info, type has to be converted from DB data types (SQL server in most cases)
53-
# from missions_mast search service such as varchar, integer, float, boolean etc
5453
# to corresponding numpy type
5554
for idx, col, col_type, ignore_value in \
5655
[(idx, x['name'], x[type_key].lower(), None) for idx, x in enumerate(json_obj['info'])]:
@@ -79,7 +78,6 @@ def _json_to_table(json_obj, data_key='data'):
7978
# Step through data array of values
8079
col_data = np.array([x[idx] for x in json_obj[data_key]], dtype=object)
8180
except KeyError:
82-
# it's not a data array, fall back to using column name as it is array of dictionaries
8381
col_data = np.array([x[col] for x in json_obj[data_key]], dtype=object)
8482
if ignore_value is not None:
8583
col_data[np.where(np.equal(col_data, None))] = ignore_value

astroquery/mast/tests/data/mission_incorrect_results.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,5 @@
131131
}
132132
]
133133
},
134-
"totalResults": 3
134+
"totalResults": 3,
135135
}

astroquery/mast/tests/test_mast.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22

3-
import json
43
import os
54
import re
65
from shutil import copyfile
@@ -13,7 +12,6 @@
1312

1413
import astropy.units as u
1514

16-
from astroquery.mast.services import _json_to_table
1715
from astroquery.utils.mocks import MockResponse
1816
from astroquery.exceptions import InvalidQueryError, InputWarning
1917

@@ -260,7 +258,6 @@ def test_missions_query_criteria_async_with_missing_results(patch_post):
260258
obs_type,
261259
aec,
262260
aperture])
263-
table = _json_to_table(json.loads(responses), 'results')
264261

265262

266263
###################

0 commit comments

Comments
 (0)