Skip to content

Commit c761ff5

Browse files
authored
Merge pull request #3249 from esdc-esac-esa-int/ESA_euclid_EUCLIDPCR-1914_new_datalink_retrieval_type
EUCLID : include new datalink retrieval types 'SPECTRA_BGS' and 'SPECTRA_RGS'
2 parents bc5e6f8 + c5b7a81 commit c761ff5

File tree

5 files changed

+63
-32
lines changed

5 files changed

+63
-32
lines changed

astroquery/esa/euclid/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class Conf(_config.ConfigNamespace):
6969

7070
SCHEMAS = ['sedm']
7171

72+
VALID_DATALINK_RETRIEVAL_TYPES = ['SPECTRA_BGS', 'SPECTRA_RGS']
73+
7274

7375
conf = Conf()
7476

astroquery/esa/euclid/core.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class EuclidClass(TapPlus):
3939
"""
4040
ROW_LIMIT = conf.ROW_LIMIT
4141

42+
__VALID_DATALINK_RETRIEVAL_TYPES = conf.VALID_DATALINK_RETRIEVAL_TYPES
43+
4244
def __init__(self, *, tap_plus_conn_handler=None, datalink_handler=None, cutout_handler=None, environment='PDR',
4345
verbose=False, show_server_messages=True):
4446

@@ -456,6 +458,7 @@ def login(self, *, user=None, password=None, credentials_file=None, verbose=Fals
456458
"""
457459
try:
458460
log.info("Login to Euclid TAP server")
461+
log.info(f"Euclid TAP server url: {self._TapPlus__getconnhandler().get_host_url()}")
459462
super().login(user=user, password=password, credentials_file=credentials_file, verbose=verbose)
460463
except HTTPError as err:
461464
log.error('Error logging in TAP server: %s' % (str(err)))
@@ -466,8 +469,10 @@ def login(self, *, user=None, password=None, credentials_file=None, verbose=Fals
466469

467470
try:
468471
log.info("Login to Euclid data service")
472+
log.info(f"Euclid data server url: {self.__eucliddata._TapPlus__getconnhandler().get_host_url()}")
469473
self.__eucliddata.login(user=tap_user, password=tap_password, verbose=verbose)
470474
log.info("Login to Euclid cutout service")
475+
log.info(f"Euclid cutout server url: {self.__euclidcutout._TapPlus__getconnhandler().get_host_url()}")
471476
self.__euclidcutout.login(user=tap_user, password=tap_password, verbose=verbose)
472477
except HTTPError as err:
473478
log.error('Error logging in data or cutout services: %s' % (str(err)))
@@ -487,6 +492,7 @@ def login_gui(self, verbose=False):
487492
"""
488493
try:
489494
log.info("Login to Euclid TAP server")
495+
log.info(f"Euclid TAP server url: {self._TapPlus__getconnhandler().get_host_url()}")
490496
TapPlus.login_gui(self, verbose=verbose)
491497
except HTTPError as err:
492498
log.error('Error logging in TAP server: %s' % (str(err)))
@@ -497,6 +503,7 @@ def login_gui(self, verbose=False):
497503

498504
try:
499505
log.info("Login to Euclid data server")
506+
log.info(f"Euclid data server url: {self.__eucliddata._TapPlus__getconnhandler().get_host_url()}")
500507
self.__eucliddata.login(user=tap_user, password=tap_password, verbose=verbose)
501508
except HTTPError as err:
502509
log.error('Error logging in data server: %s' % (str(err)))
@@ -505,6 +512,7 @@ def login_gui(self, verbose=False):
505512

506513
try:
507514
log.info("Login to Euclid cutout server")
515+
log.info(f"Euclid cutout server url: {self.__euclidcutout._TapPlus__getconnhandler().get_host_url()}")
508516
self.__euclidcutout.login(user=tap_user, password=tap_password, verbose=verbose)
509517
except HTTPError as err:
510518
log.error('Error logging in cutout server: %s' % (str(err)))
@@ -1145,7 +1153,7 @@ def get_cutout(self, *, file_path=None, instrument=None, id=None, coordinate, ra
11451153

11461154
return files
11471155

1148-
def get_spectrum(self, *, source_id, schema='sedm', output_file=None, verbose=False):
1156+
def get_spectrum(self, *, source_id, schema='sedm', retrieval_type="ALL", output_file=None, verbose=False):
11491157
"""
11501158
Description
11511159
-----------
@@ -1161,6 +1169,9 @@ def get_spectrum(self, *, source_id, schema='sedm', output_file=None, verbose=Fa
11611169
source id for the spectrum
11621170
schema : str, mandatory, default 'sedm'
11631171
the data release, 'sedm'
1172+
retrieval_type : str, optional, default 'ALL' to retrieve all data from the list of sources
1173+
retrieval type identifier. Possible values are: 'SPECTRA_BGS' for the blue spectrum and 'SPECTRA_RGS' for
1174+
the red one.
11641175
output_file : str, optional
11651176
output file name. If no value is provided, a temporary one is created with the name
11661177
"<working directory>/temp_<%Y%m%d_%H%M%S>/<source_id>.fits"
@@ -1175,9 +1186,19 @@ def get_spectrum(self, *, source_id, schema='sedm', output_file=None, verbose=Fa
11751186
if source_id is None or schema is None:
11761187
raise ValueError(self.__ERROR_MSG_REQUESTED_GENERIC)
11771188

1178-
params_dict = {'TAPCLIENT': 'ASTROQUERY', 'RETRIEVAL_TYPE': 'SPECTRA'}
1189+
rt = str(retrieval_type).upper()
1190+
if rt != 'ALL' and rt not in self.__VALID_DATALINK_RETRIEVAL_TYPES:
1191+
raise ValueError(f"Invalid argument value for 'retrieval_type'. Found {retrieval_type}, "
1192+
f"expected: 'ALL' or any of {self.__VALID_DATALINK_RETRIEVAL_TYPES}")
1193+
1194+
params_dict = {}
1195+
11791196
id_value = """{schema} {source_id}""".format(**{'schema': schema, 'source_id': source_id})
11801197
params_dict['ID'] = id_value
1198+
params_dict['SCHEMA'] = schema
1199+
params_dict['RETRIEVAL_TYPE'] = str(retrieval_type)
1200+
params_dict['USE_ZIP_ALWAYS'] = 'true'
1201+
params_dict['TAPCLIENT'] = 'ASTROQUERY'
11811202

11821203
fits_file = source_id + '.fits'
11831204
output_file_full_path, output_dir = self.__set_dirs(output_file=output_file, observation_id=fits_file)

astroquery/esa/euclid/tests/test_euclidtap.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,11 +746,9 @@ def test_get_product_exceptions():
746746

747747
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, show_server_messages=False)
748748

749-
with pytest.raises(ValueError) as exc_info:
749+
with pytest.raises(ValueError, match="'file_name' and 'product_id' are both None"):
750750
tap.get_product(file_name=None, product_id=None, output_file=None)
751751

752-
str(exc_info.value).startswith("'file_name' and 'product_id' are both None")
753-
754752

755753
@patch.object(TapPlus, 'load_data')
756754
def test_get_product_exceptions_2(mock_load_data, caplog):
@@ -1083,6 +1081,10 @@ def test_get_spectrum_exceptions():
10831081
tap.get_spectrum(source_id='2417660845403252054', schema=None, output_file=None)
10841082

10851083
assert str(exc_info.value).startswith('Missing required argument')
1084+
with pytest.raises(ValueError, match=(
1085+
"Invalid argument value for 'retrieval_type'. Found hola, expected: 'ALL' or any of \\['SPECTRA_BGS', "
1086+
"'SPECTRA_RGS'\\]")):
1087+
tap.get_spectrum(retrieval_type='hola', source_id='2417660845403252054', schema='schema', output_file=None)
10861088

10871089

10881090
@patch.object(TapPlus, 'login')

astroquery/utils/tap/conn/tests/DummyConnHandler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,6 @@ def execute_table_tool(self, data,
152152

153153
def execute_secure(self, subcontext=None, data=None, verbose=False):
154154
return self.__execute_post(subcontext=subcontext, data=data, verbose=verbose)
155+
156+
def get_host_url(self):
157+
return "my fake object"

docs/esa/euclid/euclid.rst

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,47 +1187,50 @@ The query below retrieves a random sample of Euclid sources having spectra.
11871187
.. doctest-skip::
11881188

11891189
>>> from astroquery.esa.euclid import Euclid
1190-
>>> query = f"SELECT TOP 2000 * FROM catalogue.phz_photo_z"
1190+
>>> query = f"SELECT TOP 2000 * FROM catalogue.spectra_source"
11911191
>>> job = Euclid.launch_job_async(query)
11921192
>>> results = job.get_results()
11931193
>>> print(f'Table size (rows): {len(results)}')
11941194
Table size (rows): 2000
11951195
>>> print(results)
1196-
alt_tom_bin_id basic_download_data_oid best_chi2 bias_id flag_som_alt_tomobin ... phz_weight pos_tom_bin_id to_be_published tom_bin_id
1197-
-------------- ----------------------- ------------------ ------- -------------------- ... ---------------------- -------------- --------------- ----------
1198-
-1 24244 13.634156774112924 650116 0.0 ... 0.0 -1 1 -1
1199-
7 23184 9.45719634132798 470000 0.0 ... 0.0 9 1 9
1200-
4 24219 9.03551275610211 650109 0.0 ... 0.0 5 1 5
1201-
4 24217 11.377904580545868 680010 0.0 ... 0.0 5 1 5
1202-
7 23149 9.820783165150553 710144 0.0 ... 0.0 9 1 9
1203-
2 23754 11.087106621642459 670072 1.0 ... 1.0276379182726198e-41 2 1 2
1204-
-1 23810 8.64268146392629 490134 0.0 ... 0.0 -1 1 -1
1205-
2 23146 45.67227559471531 180123 1.0 ... 0.0 1 1 1
1206-
9 23863 8.025249522871265 240067 0.0 ... 0.0 11 1 11
1207-
... ... ... ... ... ... ... ... ... ...
1208-
7 23149 10.460809793799836 140091 0.0 ... 0.0 9 1 9
1209-
-1 24048 30.025366533693905 740121 0.0 ... 0.0 -1 1 -1
1210-
7 23146 22.22414007557969 650021 0.0 ... 0.0 9 1 9
1211-
-1 23159 8.39209205469723 550128 0.0 ... 0.0 -1 1 -1
1212-
7 24244 10.528557338331286 380060 0.0 ... 0.0 9 1 9
1213-
4 23150 9.109943087443972 730149 0.0 ... 0.0 5 1 5
1214-
-1 24219 8.77864379928032 670062 0.0 ... 8.832217943512524e-67 -1 1 -1
1215-
-1 24217 11.956472846691256 70029 0.0 ... 0.0 -1 1 -1
1216-
4 23149 9.201836975705545 600058 1.0 ... 1.0 5 1 5
1217-
6 23754 8.934832487262709 440041 1.0 ... 0.9950650845505895 7 1 7
1218-
5 23146 15.085673491841636 390028 1.0 ... 0.0 7 1 7
1219-
5 23159 11.356825209088221 111 0.0 ... 0.0 7 1 7
1196+
combined_spectra_fk combined_spectra_product_fk datalabs_path dec_obj dith_num file_name ... hdu_index ra_obj source_id spectra_source_oid to_be_published
1197+
------------------- --------------------------- ----------------------------------- ----------------- -------- ------------------------------------------------------------- ... --------- ---------------- ------------------- ------------------ ---------------
1198+
161 6170 /data/euclid_q1/Q1_R1/SIR/102159190 66.2272115578693 3 EUC_SIR_W-COMBSPEC_102159190_2024-11-05T16:27:45.906227Z.fits ... 355 267.261146414289 2672611464662272115 66161 1
1199+
161 6170 /data/euclid_q1/Q1_R1/SIR/102159190 66.230432248046 4 EUC_SIR_W-COMBSPEC_102159190_2024-11-05T16:27:45.906227Z.fits ... 557 267.319331443563 2673193314662304322 66179 1
1200+
161 6170 /data/euclid_q1/Q1_R1/SIR/102159190 66.2259968885041 4 EUC_SIR_W-COMBSPEC_102159190_2024-11-05T16:27:45.906227Z.fits ... 679 267.39974379438 2673997437662259968 66185 1
1201+
161 6170 /data/euclid_q1/Q1_R1/SIR/102159190 66.2258832168495 4 EUC_SIR_W-COMBSPEC_102159190_2024-11-05T16:27:45.906227Z.fits ... 1132 267.610835873887 2676108358662258832 66216 1
1202+
161 6170 /data/euclid_q1/Q1_R1/SIR/102159190 66.2267511367135 4 EUC_SIR_W-COMBSPEC_102159190_2024-11-05T16:27:45.906227Z.fits ... 1561 267.82310164423 2678231016662267511 66245 1
1203+
161 6170 /data/euclid_q1/Q1_R1/SIR/102159190 66.2306295177874 4 EUC_SIR_W-COMBSPEC_102159190_2024-11-05T16:27:45.906227Z.fits ... 1608 267.840533186228 2678405331662306295 66249 1
1204+
161 6170 /data/euclid_q1/Q1_R1/SIR/102159190 66.2258188827905 4 EUC_SIR_W-COMBSPEC_102159190_2024-11-05T16:27:45.906227Z.fits ... 1672 267.868196199085 2678681961662258188 66254 1
1205+
161 6170 /data/euclid_q1/Q1_R1/SIR/102159190 66.2302887578947 3 EUC_SIR_W-COMBSPEC_102159190_2024-11-05T16:27:45.906227Z.fits ... 2121 268.121362468449 2681213624662302887 66283 1
1206+
161 6168 /data/euclid_q1/Q1_R1/SIR/102159190 66.2180692869346 3 EUC_SIR_W-COMBSPEC_102159190_2024-11-05T16:27:08.615108Z.fits ... 320 267.232306764858 2672323067662180692 65811 1
1207+
161 6168 /data/euclid_q1/Q1_R1/SIR/102159190 66.2163449302499 4 EUC_SIR_W-COMBSPEC_102159190_2024-11-05T16:27:08.615108Z.fits ... 678 267.390646814535 2673906468662163449 65836 1
1208+
161 6168 /data/euclid_q1/Q1_R1/SIR/102159190 66.2177524156252 4 EUC_SIR_W-COMBSPEC_102159190_2024-11-05T16:27:08.615108Z.fits ... 787 267.444077136233 2674440771662177524 65843 1
1209+
... ... ... ... ... ... ... ... ... ... ... ...
1210+
180 7517 /data/euclid_q1/Q1_R1/SIR/102042287 -29.5639947358353 2 EUC_SIR_W-COMBSPEC_102042287_2024-11-05T17:42:15.562399Z.fits ... 58 54.5720898250079 -545720898295639947 264701 1
1211+
161 6203 /data/euclid_q1/Q1_R1/SIR/102159190 66.2431257852549 2 EUC_SIR_W-COMBSPEC_102159190_2024-11-05T16:34:19.265698Z.fits ... 88 267.227375121186 2672273751662431257 67437 1
12201212
Length = 2000 rows
1213+
>>> print("source ids:")
1214+
>>> print(results['source_id'])
1215+
<Column name='source_id' dtype='int64' length=200>
1216+
2672611464662272115
1217+
2673193314662304322
1218+
2673997437662259968
1219+
2676108358662258832
1220+
...
1221+
2671568248661962869
1222+
2673081407661969815
1223+
2673195636661993590
12211224

12221225

12231226
The following example shows how to retrieve the DataLink products (1D Spectra) associated with the previous sources (IDs).
12241227

12251228
.. Skipping authentication requiring examples
12261229
.. doctest-skip::
12271230

1228-
>>> files = Euclid.get_spectrum(source_id='2675005060662306333')
1231+
>>> files = Euclid.get_spectrum(retrieval_type='SPECTRA_BGS', source_id='2675005060662306333')
12291232
>>> from astropy.io import fits
1230-
>>> print(fits.info(files[0]))
1233+
>>> print(fits.info(files[0])) # doctest: +IGNORE_OUTPUT
12311234
Filename: /home/astroquery/temp_20250225_204959/2675005060662306333.fits
12321235
No. Name Ver Type Cards Dimensions Format
12331236
0 PRIMARY 1 PrimaryHDU 4 ()

0 commit comments

Comments
 (0)