Skip to content

Commit 12de14d

Browse files
Jorge Fernandez HernandezJorge Fernandez Hernandez
Jorge Fernandez Hernandez
authored and
Jorge Fernandez Hernandez
committed
EUCLIDPCR-1914 new datalink retrieval type 'SPECTRA_BGS', 'SPECTRA_RGS'
1 parent b744eeb commit 12de14d

File tree

5 files changed

+61
-28
lines changed

5 files changed

+61
-28
lines changed

astroquery/esa/euclid/__init__.py

+2
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

+20-2
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)))
@@ -1145,7 +1150,7 @@ def get_cutout(self, *, file_path=None, instrument=None, id=None, coordinate, ra
11451150

11461151
return files
11471152

1148-
def get_spectrum(self, *, source_id, schema='sedm', output_file=None, verbose=False):
1153+
def get_spectrum(self, *, source_id, schema='sedm', retrieval_type="ALL", output_file=None, verbose=False):
11491154
"""
11501155
Description
11511156
-----------
@@ -1161,6 +1166,9 @@ def get_spectrum(self, *, source_id, schema='sedm', output_file=None, verbose=Fa
11611166
source id for the spectrum
11621167
schema : str, mandatory, default 'sedm'
11631168
the data release, 'sedm'
1169+
retrieval_type : str, optional, default 'ALL' to retrieve all data from the list of sources
1170+
retrieval type identifier. Possible values are: 'SPECTRA_BGS' for the blue spectrum and 'SPECTRA_RGS' for
1171+
the red one.
11641172
output_file : str, optional
11651173
output file name. If no value is provided, a temporary one is created with the name
11661174
"<working directory>/temp_<%Y%m%d_%H%M%S>/<source_id>.fits"
@@ -1175,9 +1183,19 @@ def get_spectrum(self, *, source_id, schema='sedm', output_file=None, verbose=Fa
11751183
if source_id is None or schema is None:
11761184
raise ValueError(self.__ERROR_MSG_REQUESTED_GENERIC)
11771185

1178-
params_dict = {'TAPCLIENT': 'ASTROQUERY', 'RETRIEVAL_TYPE': 'SPECTRA'}
1186+
rt = str(retrieval_type).upper()
1187+
if rt != 'ALL' and rt not in self.__VALID_DATALINK_RETRIEVAL_TYPES:
1188+
raise ValueError(f"Invalid mandatory argument 'retrieval_type'. Found {retrieval_type}, "
1189+
f"expected: 'ALL' or any of {self.__VALID_DATALINK_RETRIEVAL_TYPES}")
1190+
1191+
params_dict = {}
1192+
11791193
id_value = """{schema} {source_id}""".format(**{'schema': schema, 'source_id': source_id})
11801194
params_dict['ID'] = id_value
1195+
params_dict['SCHEMA'] = schema
1196+
params_dict['RETRIEVAL_TYPE'] = str(retrieval_type)
1197+
params_dict['USE_ZIP_ALWAYS'] = 'true'
1198+
params_dict['TAPCLIENT'] = 'ASTROQUERY'
11811199

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

astroquery/esa/euclid/tests/test_euclidtap.py

+7
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,13 @@ def test_get_spectrum_exceptions():
10841084

10851085
assert str(exc_info.value).startswith('Missing required argument')
10861086

1087+
with pytest.raises(Exception) as exc_info:
1088+
tap.get_spectrum(retrieval_type='hola', source_id='2417660845403252054', schema='schema', output_file=None)
1089+
1090+
assert str(exc_info.value).startswith(
1091+
"Invalid mandatory argument 'retrieval_type'. Found hola, expected: 'ALL' or any of ['SPECTRA_BGS', "
1092+
"'SPECTRA_RGS']")
1093+
10871094

10881095
@patch.object(TapPlus, 'login')
10891096
def test_login(mock_login):

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

+3
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

+29-26
Original file line numberDiff line numberDiff line change
@@ -1187,45 +1187,48 @@ 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
12301233
>>> print(fits.info(files[0]))
12311234
Filename: /home/astroquery/temp_20250225_204959/2675005060662306333.fits

0 commit comments

Comments
 (0)