Skip to content

Commit cbe6d20

Browse files
authored
Merge pull request #2376 from esdc-esac-esa-int/gaia-astroquery-1.1
Gaia astroquery 1.1
2 parents 9526b6f + fc8d45b commit cbe6d20

File tree

3 files changed

+100
-18
lines changed

3 files changed

+100
-18
lines changed

CHANGES.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44
New Tools and Services
55
----------------------
66

7+
gaia
8+
^^^^
9+
10+
- TAP notifications service is now available for Gaia. If there is notification for the users,
11+
for example planned or our unplanned downtimes of the archive, etc. The notification
12+
will be also visible when accessing the archive through Astroquery. [#2376]
713

814
hsa
915
^^^
1016

1117
- New module to access ESA Herschel mission. [#2122]
1218

19+
1320
Service fixes and enhancements
1421
------------------------------
1522

@@ -49,6 +56,13 @@ oac
4956
- Fix bug in parsing events that contain html tags (e.g. in their alias
5057
field). [#2423]
5158

59+
gaia
60+
^^^^
61+
62+
- Method 'load_data' now has the parameter 'valid_data' set to False by default.
63+
With this change the epoch photometry service returns all data associated
64+
to a given source. [#2376]
65+
5266

5367
Infrastructure, Utility and Other Changes and Additions
5468
-------------------------------------------------------

astroquery/gaia/core.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from astropy import units as u
3434
import warnings
3535
from astroquery.exceptions import InputWarning
36+
from collections.abc import Iterable
3637

3738

3839
class GaiaClass(TapPlus):
@@ -44,14 +45,15 @@ class GaiaClass(TapPlus):
4445
MAIN_GAIA_TABLE_DEC = conf.MAIN_GAIA_TABLE_DEC
4546
ROW_LIMIT = conf.ROW_LIMIT
4647
VALID_DATALINK_RETRIEVAL_TYPES = conf.VALID_DATALINK_RETRIEVAL_TYPES
48+
GAIA_MESSAGES = "notification?action=GetNotifications"
4749

4850
def __init__(self, tap_plus_conn_handler=None,
4951
datalink_handler=None,
5052
gaia_tap_server='https://gea.esac.esa.int/',
5153
gaia_data_server='https://gea.esac.esa.int/',
5254
tap_server_context="tap-server",
5355
data_server_context="data-server",
54-
verbose=False):
56+
verbose=False, show_server_messages=True):
5557
super(GaiaClass, self).__init__(url=gaia_tap_server,
5658
server_context=tap_server_context,
5759
tap_context="tap",
@@ -74,6 +76,10 @@ def __init__(self, tap_plus_conn_handler=None,
7476
else:
7577
self.__gaiadata = datalink_handler
7678

79+
# Enable notifications
80+
if show_server_messages:
81+
self.get_status_messages()
82+
7783
def login(self, user=None, password=None, credentials_file=None,
7884
verbose=False):
7985
"""Performs a login.
@@ -158,7 +164,7 @@ def logout(self, verbose=False):
158164
except HTTPError as err:
159165
log.error("Error logging out data server")
160166

161-
def load_data(self, ids, data_release=None, data_structure='INDIVIDUAL', retrieval_type="ALL", valid_data=True,
167+
def load_data(self, ids, data_release=None, data_structure='INDIVIDUAL', retrieval_type="ALL", valid_data=False,
162168
band=None, avoid_datatype_check=False, format="votable", output_file=None,
163169
overwrite_output_file=False, verbose=False):
164170
"""Loads the specified table
@@ -185,12 +191,12 @@ def load_data(self, ids, data_release=None, data_structure='INDIVIDUAL', retriev
185191
retrieval type identifier. For GAIA DR2 possible values are ['EPOCH_PHOTOMETRY']
186192
For future GAIA DR3 (Once published), possible values will be ['EPOC_PHOTOMETRY', 'RVS', 'XP_CONTINUOUS',
187193
'XP_SAMPLED', 'MCMC_GSPPHOT' or 'MCMC_MSC']
188-
valid_data : bool, optional, default True
189-
By default, the epoch photometry service returns only valid data,
190-
that is, all data rows where flux is not null and
191-
rejected_by_photometry flag is not true. In order to retrieve
192-
all data associated to a given source without this filter,
193-
this request parameter should be included (valid_data=False)
194+
valid_data : bool, optional, default False
195+
By default, the epoch photometry service returns all available data, including
196+
data rows where flux is null and/or the rejected_by_photometry flag is set to True.
197+
In order to retrieve only valid data (data rows where flux is not null and/or the
198+
rejected_by_photometry flag is set to False) this request parameter should be included
199+
with valid_data=True.
194200
band : str, optional, default None, valid values: G, BP, RP
195201
By default, the epoch photometry service returns all the
196202
available photometry bands for the requested source.
@@ -911,5 +917,27 @@ def launch_job_async(self, query, name=None, output_file=None,
911917
upload_table_name=upload_table_name,
912918
autorun=autorun)
913919

920+
def get_status_messages(self):
921+
"""Retrieve the messages to inform users about
922+
the status of Gaia TAP
923+
"""
924+
try:
925+
subContext = self.GAIA_MESSAGES
926+
connHandler = self._TapPlus__getconnhandler()
927+
response = connHandler.execute_tapget(subContext, False)
928+
if response.status == 200:
929+
if isinstance(response, Iterable):
930+
for line in response:
931+
932+
try:
933+
print(line.decode("utf-8").split('=', 1)[1])
934+
except ValueError as e:
935+
print(e)
936+
except IndexError:
937+
print("Archive down for maintenance")
938+
939+
except OSError:
940+
print("Status messages could not be retrieved")
941+
914942

915943
Gaia = GaiaClass()

astroquery/gaia/tests/test_gaiatap.py

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,50 @@ def data_path(filename):
4141

4242
class TestTap:
4343

44+
def test_show_message(self):
45+
connHandler = DummyConnHandler()
46+
47+
dummy_response = DummyResponse()
48+
dummy_response.set_status_code(200)
49+
dummy_response.set_message("OK")
50+
51+
message_text = "1653401204784D[type: -100,-1]=Gaia dev is under maintenance"
52+
53+
dummy_response.set_data(method='GET',
54+
context=None,
55+
body=message_text,
56+
headers=None)
57+
connHandler.set_default_response(dummy_response)
58+
59+
# show_server_messages
60+
tableRequest = 'notification?action=GetNotifications'
61+
connHandler.set_response(tableRequest, dummy_response)
62+
63+
tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler)
64+
tap = GaiaClass(connHandler, tapplus, show_server_messages=True)
65+
4466
def test_query_object(self):
4567
conn_handler = DummyConnHandler()
68+
# Launch response: we use default response because the query contains
69+
# decimals
70+
dummy_response = DummyResponse()
71+
dummy_response.set_status_code(200)
72+
dummy_response.set_message("OK")
73+
74+
message_text = "1653401204784D[type: -100,-1]=Gaia dev is under maintenance"
75+
76+
dummy_response.set_data(method='GET',
77+
context=None,
78+
body=message_text,
79+
headers=None)
80+
conn_handler.set_default_response(dummy_response)
81+
82+
# show_server_messages
83+
tableRequest = 'notification?action=GetNotifications'
84+
conn_handler.set_response(tableRequest, dummy_response)
85+
4686
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
47-
tap = GaiaClass(conn_handler, tapplus)
87+
tap = GaiaClass(conn_handler, tapplus, show_server_messages=True)
4888
# Launch response: we use default response because the query contains
4989
# decimals
5090
response_launch_job = DummyResponse()
@@ -125,7 +165,7 @@ def test_query_object(self):
125165
def test_query_object_async(self):
126166
conn_handler = DummyConnHandler()
127167
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
128-
tap = GaiaClass(conn_handler, tapplus)
168+
tap = GaiaClass(conn_handler, tapplus, show_server_messages=False)
129169
jobid = '12345'
130170
# Launch response
131171
response_launch_job = DummyResponse()
@@ -220,7 +260,7 @@ def test_query_object_async(self):
220260
def test_cone_search_sync(self):
221261
conn_handler = DummyConnHandler()
222262
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
223-
tap = GaiaClass(conn_handler, tapplus)
263+
tap = GaiaClass(conn_handler, tapplus, show_server_messages=False)
224264
# Launch response: we use default response because the query contains
225265
# decimals
226266
response_launch_job = DummyResponse()
@@ -273,7 +313,7 @@ def test_cone_search_sync(self):
273313
def test_cone_search_async(self):
274314
conn_handler = DummyConnHandler()
275315
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
276-
tap = GaiaClass(conn_handler, tapplus)
316+
tap = GaiaClass(conn_handler, tapplus, show_server_messages=False)
277317
jobid = '12345'
278318
# Launch response
279319
response_launch_job = DummyResponse()
@@ -380,7 +420,7 @@ def __check_results_column(self, results, column_name, description, unit,
380420

381421
def test_load_data(self):
382422
dummy_handler = DummyTapHandler()
383-
tap = GaiaClass(dummy_handler, dummy_handler)
423+
tap = GaiaClass(dummy_handler, dummy_handler, show_server_messages=False)
384424

385425
ids = "1,2,3,4"
386426
retrieval_type = "epoch_photometry"
@@ -419,7 +459,7 @@ def test_load_data(self):
419459

420460
def test_get_datalinks(self):
421461
dummy_handler = DummyTapHandler()
422-
tap = GaiaClass(dummy_handler, dummy_handler)
462+
tap = GaiaClass(dummy_handler, dummy_handler, show_server_messages=False)
423463
ids = ["1", "2", "3", "4"]
424464
verbose = True
425465
parameters = {}
@@ -431,7 +471,7 @@ def test_get_datalinks(self):
431471
def test_xmatch(self):
432472
conn_handler = DummyConnHandler()
433473
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
434-
tap = GaiaClass(conn_handler, tapplus)
474+
tap = GaiaClass(conn_handler, tapplus, show_server_messages=False)
435475
jobid = '12345'
436476
# Launch response
437477
response_launch_job = DummyResponse()
@@ -579,7 +619,7 @@ def test_xmatch(self):
579619
def test_login(self, mock_login):
580620
conn_handler = DummyConnHandler()
581621
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
582-
tap = GaiaClass(conn_handler, tapplus)
622+
tap = GaiaClass(conn_handler, tapplus, show_server_messages=False)
583623
tap.login("user", "password")
584624
assert (mock_login.call_count == 2)
585625
mock_login.side_effect = HTTPError("Login error")
@@ -591,7 +631,7 @@ def test_login(self, mock_login):
591631
def test_login_gui(self, mock_login_gui, mock_login):
592632
conn_handler = DummyConnHandler()
593633
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
594-
tap = GaiaClass(conn_handler, tapplus)
634+
tap = GaiaClass(conn_handler, tapplus, show_server_messages=False)
595635
tap.login_gui()
596636
assert (mock_login_gui.call_count == 1)
597637
mock_login_gui.side_effect = HTTPError("Login error")
@@ -602,7 +642,7 @@ def test_login_gui(self, mock_login_gui, mock_login):
602642
def test_logout(self, mock_logout):
603643
conn_handler = DummyConnHandler()
604644
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
605-
tap = GaiaClass(conn_handler, tapplus)
645+
tap = GaiaClass(conn_handler, tapplus, show_server_messages=False)
606646
tap.logout()
607647
assert (mock_logout.call_count == 2)
608648
mock_logout.side_effect = HTTPError("Login error")

0 commit comments

Comments
 (0)