Skip to content

Commit 1a165c4

Browse files
authored
Merge pull request #3438 from esdc-esac-esa-int/ESA_euclid-EUCLIDSWRQ-215-get_datalinks_metadata
2 parents 8a64491 + 750fcdc commit 1a165c4

File tree

6 files changed

+69
-14
lines changed

6 files changed

+69
-14
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ New Tools and Services
99
API changes
1010
-----------
1111

12+
esa.euclid
13+
^^^^^^^^^^
14+
15+
- Method ``get_datalinks`` has a new argument, ``extra_options``, to customize the results to be got
16+
from the server. Specifically, passing ``'METADATA'`` to this argument will retrieve the extra fields
17+
``datalabs_path``, ``file_name`` and ``hdu_index``. [#3438]
1218

1319

1420
Service fixes and enhancements

astroquery/esa/euclid/core.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,8 +1418,11 @@ def get_spectrum(self, *, source_id, schema='sedm', retrieval_type="ALL", output
14181418

14191419
return files
14201420

1421-
def get_datalinks(self, ids, *, linking_parameter='SOURCE_ID', verbose=False):
1422-
"""Gets datalinks associated to the provided identifiers
1421+
def get_datalinks(self, ids, *, linking_parameter='SOURCE_ID', extra_options=None, verbose=False):
1422+
"""
1423+
Description
1424+
-----------
1425+
Gets datalinks associated to the provided identifiers.
14231426
TAP+ only
14241427
14251428
Parameters
@@ -1428,6 +1431,9 @@ def get_datalinks(self, ids, *, linking_parameter='SOURCE_ID', verbose=False):
14281431
list of identifiers
14291432
linking_parameter : str, optional, default SOURCE_ID, valid values: SOURCE_ID
14301433
By default, all the identifiers are considered as source_id
1434+
extra_options : str, optional, default None, valid values: METADATA
1435+
To let customize the server behaviour, if present.
1436+
If provided with value METADATA, the extra fields datalabs_path, file_name & hdu_index will be retrieved.
14311437
verbose : bool, optional, default 'False'
14321438
flag to display information about the process
14331439
@@ -1437,7 +1443,10 @@ def get_datalinks(self, ids, *, linking_parameter='SOURCE_ID', verbose=False):
14371443
14381444
"""
14391445

1440-
return self.__eucliddata.get_datalinks(ids=ids, linking_parameter=linking_parameter, verbose=verbose)
1446+
return self.__eucliddata.get_datalinks(ids=ids,
1447+
linking_parameter=linking_parameter,
1448+
extra_options=extra_options,
1449+
verbose=verbose)
14411450

14421451
def get_scientific_product_list(self, *, observation_id=None, tile_index=None, category=None, group=None,
14431452
product_type=None, dataset_release='REGREPROC1_R2', verbose=False):

astroquery/esa/euclid/tests/test_euclidtap.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,19 +1220,36 @@ def test_logout(mock_logout):
12201220

12211221

12221222
def test_get_datalinks(monkeypatch):
1223-
def get_datalinks_monkeypatched(self, ids, linking_parameter, verbose):
1223+
def get_datalinks_monkeypatched(self, ids, linking_parameter, extra_options, verbose):
12241224
return Table()
12251225

12261226
# `EuclidClass` is a subclass of `TapPlus`, but it does not inherit
12271227
# `get_datalinks()`, it replaces it with a call to the `get_datalinks()`
1228-
# of its `__gaiadata`.
1228+
# of its `__eucliddata`.
12291229
monkeypatch.setattr(TapPlus, "get_datalinks", get_datalinks_monkeypatched)
12301230
euclid = EuclidClass(show_server_messages=False)
12311231

12321232
result = euclid.get_datalinks(ids=[12345678], verbose=True)
12331233
assert isinstance(result, Table)
12341234

12351235

1236+
def test_get_datalinks_with_metadata(monkeypatch):
1237+
def get_datalinks_monkeypatched(self, ids, linking_parameter, extra_options, verbose):
1238+
table = TapTableMeta()
1239+
table.name = extra_options
1240+
return table
1241+
1242+
# `EuclidClass` is a subclass of `TapPlus`, but it does not inherit
1243+
# `get_datalinks()`, it replaces it with a call to the `get_datalinks()`
1244+
# of its `__eucliddata`.
1245+
monkeypatch.setattr(TapPlus, "get_datalinks", get_datalinks_monkeypatched)
1246+
euclid = EuclidClass(show_server_messages=False)
1247+
1248+
result = euclid.get_datalinks(ids=[12345678], extra_options='METADATA')
1249+
assert isinstance(result, TapTableMeta)
1250+
assert result.name == "METADATA"
1251+
1252+
12361253
@pytest.mark.parametrize("background", [False, True])
12371254
def test_cross_match_basic(monkeypatch, background, cross_match_basic_kwargs, mock_querier_async):
12381255
def load_table_monkeypatched(self, table, verbose):

astroquery/utils/tap/core.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,20 +1247,23 @@ def is_valid_user(self, *, user_id=None, verbose=False):
12471247
print(f"USER response = {user}")
12481248
return user.startswith(f"{user_id}:") and user.count("\\n") == 0
12491249

1250-
def get_datalinks(self, ids, *, linking_parameter=None, verbose=False):
1250+
def get_datalinks(self, ids, *, linking_parameter=None, extra_options=None, verbose=False):
12511251
"""Gets datalinks associated to the provided identifiers
12521252
12531253
Parameters
12541254
----------
12551255
ids : str list, mandatory
1256-
list of identifiers
1256+
List of identifiers
12571257
linking_parameter : str, optional, default SOURCE_ID, valid values: SOURCE_ID, TRANSIT_ID, IMAGE_ID
12581258
By default, all the identifiers are considered as source_id
12591259
SOURCE_ID: the identifiers are considered as source_id
12601260
TRANSIT_ID: the identifiers are considered as transit_id
12611261
IMAGE_ID: the identifiers are considered as sif_observation_id
1262+
extra_options : str, optional, default None, valid values: METADATA
1263+
If present, an extra parameter OPTIONS will be added to the call, to be interpreted by the TAP service
1264+
METADATA: to retrieve extra metadata columns (currently supported by the Euclid archive)
12621265
verbose : bool, optional, default 'False'
1263-
flag to display information about the process
1266+
Flag to display information about the process
12641267
12651268
Returns
12661269
-------
@@ -1282,15 +1285,17 @@ def get_datalinks(self, ids, *, linking_parameter=None, verbose=False):
12821285
if linking_parameter is not None:
12831286
ids_arg = f'{ids_arg}&LINKING_PARAMETER={linking_parameter}'
12841287

1288+
if extra_options is not None:
1289+
ids_arg = f'{ids_arg}&OPTIONS={extra_options}'
1290+
12851291
if verbose:
1286-
print(f"Datalink request: {ids_arg}")
1287-
connHandler = self.__getconnhandler()
1288-
response = connHandler.execute_datalinkpost(subcontext="links",
1289-
data=ids_arg,
1290-
verbose=verbose)
1292+
print(f"Datalink request: ID={ids_arg}")
1293+
1294+
conn_handler = self.__getconnhandler()
1295+
response = conn_handler.execute_datalinkpost(subcontext="links", data=ids_arg, verbose=verbose)
12911296
if verbose:
12921297
print(response.status, response.reason)
1293-
connHandler.check_launch_response_status(response, verbose, 200)
1298+
conn_handler.check_launch_response_status(response, verbose, 200)
12941299
if verbose:
12951300
print("Done.")
12961301
results = utils.read_http_response(response, "votable", use_names_over_ids=self.use_names_over_ids)

astroquery/utils/tap/tests/test_tap.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@ def test_datalink():
635635
responseResultsJob.set_data(method='GET', body=TEST_DATA["job_1.vot"])
636636
req = "links?ID=1,2"
637637
conn_handler.set_response(req, responseResultsJob)
638+
req = "links?ID=1&OPTIONS=METADATA"
639+
conn_handler.set_response(req, responseResultsJob)
638640

639641
# error
640642
responseResultsJob.set_status_code(500)
@@ -651,6 +653,8 @@ def test_datalink():
651653
assert len(results) == 3
652654
results = tap.get_datalinks(['1', '2'])
653655
assert len(results) == 3
656+
results = tap.get_datalinks(1, extra_options='METADATA', verbose=True)
657+
assert len(results) == 3
654658

655659

656660
def test_get_new_column_values_for_update():

docs/esa/euclid/euclid.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,20 @@ To find out the resources associated with a given source:
12161216
sedm 2707008224650763513 SOURCE_ID https://eas.esac.esa.int/sas-dd/data?ID=sedm+2707008224650763513&RETRIEVAL_TYPE=SPECTRA_BGS #this Spectra Blue Source --
12171217

12181218

1219+
This method also provides a way to get the extra columns datalabs_path, file_name & hdu_index in the call:
1220+
1221+
.. Skipping authentication requiring examples
1222+
.. doctest-skip::
1223+
1224+
>>> from astroquery.esa.euclid import Euclid
1225+
>>> Euclid.login()
1226+
>>> result = Euclid.get_datalinks(ids=2707008224650763513, extra_options='METADATA')
1227+
>>> print(result)
1228+
ID linking_parameter access_url ... file_name hdu_index
1229+
...
1230+
------------------------ ----------------- ------------------------------------------------------------------------------------------- ... ------------------------------------------------------------- ---------
1231+
sedm 2707008224650763513 SOURCE_ID https://eas.esac.esa.int/sas-dd/data?ID=sedm+2707008224650763513&RETRIEVAL_TYPE=SPECTRA_RGS ... EUC_SIR_W-COMBSPEC_102158586_2024-11-05T16:05:44.880543Z.fits 1602
1232+
sedm 2707008224650763513 SOURCE_ID https://eas.esac.esa.int/sas-dd/data?ID=sedm+2707008224650763513&RETRIEVAL_TYPE=SPECTRA_BGS ... EUC_SIR_W-COMBSPEC_102158586_2024-11-05T16:05:44.880543Z.fits 1602
12191233

12201234

12211235
The query below retrieves a random sample of Euclid sources having spectra.

0 commit comments

Comments
 (0)