Skip to content

Commit e10c47f

Browse files
mhsarmientojespinosaar
authored andcommitted
merge conflicts
1 parent be0938f commit e10c47f

File tree

4 files changed

+98
-38
lines changed

4 files changed

+98
-38
lines changed

CHANGES.rst

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,34 @@
33

44
New Tools and Services
55
----------------------
6+
gaia
7+
^^^^
68

9+
- TAP notifications service is now available for Gaia. If there is notification for the users, e.g planned or unplanned downtimes of the Gaia Archive, etc. [#2376]
710

811
hsa
912
^^^
1013

1114
- New module to access ESA Herschel mission. [#2122]
1215

16+
17+
1318
Service fixes and enhancements
1419
------------------------------
1520

16-
cadc
21+
gaia
1722
^^^^
1823

19-
- Deprecated keywords and ``run_query`` method have been removed. [#2389]
24+
- Method 'load_data' now has the parameter 'valid_data' set to False by default. With this change the epoch photometry service returns all data associated to a given source. [#2376]
2025

2126
casda
2227
^^^^^
2328

2429
- Add the ability to produce 2D and 3D cutouts from ASKAP images and cubes. [#2366]
2530

26-
- Use the standard ``login`` method for authenticating, which supports the system
27-
keyring [#2386]
28-
29-
jplsbdb
30-
^^^^^^^
31-
32-
- Fix a bug for jplsdbd query when the returned physical quantity contains
33-
a unit with exponential. [#2377]
34-
35-
linelists.cdms
36-
^^^^^^^^^^^^^^
37-
38-
- Fix issues with the line name parser and the line data parser; the original
39-
implementation was incomplete and upstream was not fully documented. [#2385, #2411]
40-
4131
Infrastructure, Utility and Other Changes and Additions
4232
-------------------------------------------------------
4333

44-
- New function, ``utils.cleanup_downloads.cleanup_saved_downloads``, is
45-
added to help the testcleanup narrative in narrative documentations. [#2384]
4634

4735

4836
0.4.6 (2022-03-22)

astroquery/gaia/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class Conf(_config.ConfigNamespace):
3939
'MCMC_GSPPHOT',
4040
'MCMC_MSC']
4141

42+
GAIA_MESSAGES = _config.ConfigItem("notification?action=GetNotifications", "Gaia Messages")
43+
4244

4345
conf = Conf()
4446

astroquery/gaia/core.py

Lines changed: 32 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):
@@ -51,7 +52,7 @@ def __init__(self, tap_plus_conn_handler=None,
5152
gaia_data_server='https://gea.esac.esa.int/',
5253
tap_server_context="tap-server",
5354
data_server_context="data-server",
54-
verbose=False):
55+
verbose=False, show_messages=True):
5556
super(GaiaClass, self).__init__(url=gaia_tap_server,
5657
server_context=tap_server_context,
5758
tap_context="tap",
@@ -74,6 +75,10 @@ def __init__(self, tap_plus_conn_handler=None,
7475
else:
7576
self.__gaiadata = datalink_handler
7677

78+
# Enable notifications
79+
if show_messages:
80+
self.get_status_messages()
81+
7782
def login(self, user=None, password=None, credentials_file=None,
7883
verbose=False):
7984
"""Performs a login.
@@ -158,7 +163,7 @@ def logout(self, verbose=False):
158163
except HTTPError as err:
159164
log.error("Error logging out data server")
160165

161-
def load_data(self, ids, data_release=None, data_structure='INDIVIDUAL', retrieval_type="ALL", valid_data=True,
166+
def load_data(self, ids, data_release=None, data_structure='INDIVIDUAL', retrieval_type="ALL", valid_data=False,
162167
band=None, avoid_datatype_check=False, format="votable", output_file=None,
163168
overwrite_output_file=False, verbose=False):
164169
"""Loads the specified table
@@ -185,12 +190,12 @@ def load_data(self, ids, data_release=None, data_structure='INDIVIDUAL', retriev
185190
retrieval type identifier. For GAIA DR2 possible values are ['EPOCH_PHOTOMETRY']
186191
For future GAIA DR3 (Once published), possible values will be ['EPOC_PHOTOMETRY', 'RVS', 'XP_CONTINUOUS',
187192
'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)
193+
valid_data : bool, optional, default False
194+
By default, the epoch photometry service returns all available data, including
195+
data rows where flux is null and/or the rejected_by_photometry flag is set to True.
196+
In order to retrieve only valid data (data rows where flux is not null and/or the
197+
rejected_by_photometry flag is set to False) this request parameter should be included
198+
with valid_data=True.
194199
band : str, optional, default None, valid values: G, BP, RP
195200
By default, the epoch photometry service returns all the
196201
available photometry bands for the requested source.
@@ -911,5 +916,24 @@ def launch_job_async(self, query, name=None, output_file=None,
911916
upload_table_name=upload_table_name,
912917
autorun=autorun)
913918

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

915939
Gaia = GaiaClass()

astroquery/gaia/tests/test_gaiatap.py

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1515
1616
"""
17+
import unittest
1718
import os
1819
from unittest.mock import patch
1920

@@ -39,12 +40,52 @@ def data_path(filename):
3940
return os.path.join(data_dir, filename)
4041

4142

42-
class TestTap:
43+
class TestTap(unittest.TestCase):
44+
45+
def test_show_message(self):
46+
connHandler = DummyConnHandler()
47+
48+
dummy_response = DummyResponse()
49+
dummy_response.set_status_code(200)
50+
dummy_response.set_message("OK")
51+
52+
message_text = "1653401204784D[type: -100,-1]=Gaia dev is under maintenance"
53+
54+
dummy_response.set_data(method='GET',
55+
context=None,
56+
body=message_text,
57+
headers=None)
58+
connHandler.set_default_response(dummy_response)
59+
60+
# show_messages
61+
tableRequest = 'notification?action=GetNotifications'
62+
connHandler.set_response(tableRequest, dummy_response)
63+
64+
tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler)
65+
tap = GaiaClass(connHandler, tapplus, show_messages=True)
4366

4467
def test_query_object(self):
4568
conn_handler = DummyConnHandler()
69+
# Launch response: we use default response because the query contains
70+
# decimals
71+
dummy_response = DummyResponse()
72+
dummy_response.set_status_code(200)
73+
dummy_response.set_message("OK")
74+
75+
message_text = "1653401204784D[type: -100,-1]=Gaia dev is under maintenance"
76+
77+
dummy_response.set_data(method='GET',
78+
context=None,
79+
body=message_text,
80+
headers=None)
81+
conn_handler.set_default_response(dummy_response)
82+
83+
# show_messages
84+
tableRequest = 'notification?action=GetNotifications'
85+
conn_handler.set_response(tableRequest, dummy_response)
86+
4687
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
47-
tap = GaiaClass(conn_handler, tapplus)
88+
tap = GaiaClass(conn_handler, tapplus, show_messages=True)
4889
# Launch response: we use default response because the query contains
4990
# decimals
5091
response_launch_job = DummyResponse()
@@ -125,7 +166,7 @@ def test_query_object(self):
125166
def test_query_object_async(self):
126167
conn_handler = DummyConnHandler()
127168
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
128-
tap = GaiaClass(conn_handler, tapplus)
169+
tap = GaiaClass(conn_handler, tapplus, show_messages=False)
129170
jobid = '12345'
130171
# Launch response
131172
response_launch_job = DummyResponse()
@@ -220,7 +261,7 @@ def test_query_object_async(self):
220261
def test_cone_search_sync(self):
221262
conn_handler = DummyConnHandler()
222263
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
223-
tap = GaiaClass(conn_handler, tapplus)
264+
tap = GaiaClass(conn_handler, tapplus, show_messages=False)
224265
# Launch response: we use default response because the query contains
225266
# decimals
226267
response_launch_job = DummyResponse()
@@ -273,7 +314,7 @@ def test_cone_search_sync(self):
273314
def test_cone_search_async(self):
274315
conn_handler = DummyConnHandler()
275316
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
276-
tap = GaiaClass(conn_handler, tapplus)
317+
tap = GaiaClass(conn_handler, tapplus, show_messages=False)
277318
jobid = '12345'
278319
# Launch response
279320
response_launch_job = DummyResponse()
@@ -380,7 +421,7 @@ def __check_results_column(self, results, column_name, description, unit,
380421

381422
def test_load_data(self):
382423
dummy_handler = DummyTapHandler()
383-
tap = GaiaClass(dummy_handler, dummy_handler)
424+
tap = GaiaClass(dummy_handler, dummy_handler, show_messages=False)
384425

385426
ids = "1,2,3,4"
386427
retrieval_type = "epoch_photometry"
@@ -419,7 +460,7 @@ def test_load_data(self):
419460

420461
def test_get_datalinks(self):
421462
dummy_handler = DummyTapHandler()
422-
tap = GaiaClass(dummy_handler, dummy_handler)
463+
tap = GaiaClass(dummy_handler, dummy_handler, show_messages=False)
423464
ids = ["1", "2", "3", "4"]
424465
verbose = True
425466
parameters = {}
@@ -431,7 +472,7 @@ def test_get_datalinks(self):
431472
def test_xmatch(self):
432473
conn_handler = DummyConnHandler()
433474
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
434-
tap = GaiaClass(conn_handler, tapplus)
475+
tap = GaiaClass(conn_handler, tapplus, show_messages=False)
435476
jobid = '12345'
436477
# Launch response
437478
response_launch_job = DummyResponse()
@@ -579,7 +620,7 @@ def test_xmatch(self):
579620
def test_login(self, mock_login):
580621
conn_handler = DummyConnHandler()
581622
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
582-
tap = GaiaClass(conn_handler, tapplus)
623+
tap = GaiaClass(conn_handler, tapplus, show_messages=False)
583624
tap.login("user", "password")
584625
assert (mock_login.call_count == 2)
585626
mock_login.side_effect = HTTPError("Login error")
@@ -591,7 +632,7 @@ def test_login(self, mock_login):
591632
def test_login_gui(self, mock_login_gui, mock_login):
592633
conn_handler = DummyConnHandler()
593634
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
594-
tap = GaiaClass(conn_handler, tapplus)
635+
tap = GaiaClass(conn_handler, tapplus, show_messages=False)
595636
tap.login_gui()
596637
assert (mock_login_gui.call_count == 1)
597638
mock_login_gui.side_effect = HTTPError("Login error")
@@ -602,9 +643,14 @@ def test_login_gui(self, mock_login_gui, mock_login):
602643
def test_logout(self, mock_logout):
603644
conn_handler = DummyConnHandler()
604645
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
605-
tap = GaiaClass(conn_handler, tapplus)
646+
tap = GaiaClass(conn_handler, tapplus, show_messages=False)
606647
tap.logout()
607648
assert (mock_logout.call_count == 2)
608649
mock_logout.side_effect = HTTPError("Login error")
609650
tap.logout()
610651
assert (mock_logout.call_count == 3)
652+
653+
654+
if __name__ == "__main__":
655+
# import sys;sys.argv = ['', 'Test.testName']
656+
unittest.main()

0 commit comments

Comments
 (0)