Skip to content

Commit 91d160f

Browse files
authored
Merge pull request #3073 from esdc-esac-esa-int/ESA_jwst-new_astroquery_method_to_get_all_products_by_program_id
Method to get all products by program id (proposal id)
2 parents 2a27dff + 2019702 commit 91d160f

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ esa.jwst
3535

3636
- get_obs_products method supports product_type parameter as string or list [#2995]
3737

38+
- Add download_files_from_program method to get all products by program id [#3073]
39+
3840
mpc
3941
^^^
4042

astroquery/esa/jwst/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class Conf(_config.ConfigNamespace):
4545
"Name of Dec parameter "
4646
"in table")
4747

48+
JWST_ARCHIVE_TABLE = _config.ConfigItem("jwst.archive", "JWST archive table")
49+
4850

4951
conf = Conf()
5052

astroquery/esa/jwst/core.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,40 @@ def get_obs_products(self, *, observation_id=None, cal_level="ALL",
10351035

10361036
return files
10371037

1038+
def download_files_from_program(self, proposal_id, *, product_type=None, verbose=False):
1039+
"""Get JWST products given its proposal ID.
1040+
1041+
Parameters
1042+
----------
1043+
proposal_id : int, mandatory
1044+
Program or Proposal ID associated to the observations.
1045+
product_type : str or list, optional, default None
1046+
If the string or at least one element of the list is empty,
1047+
the value is replaced by None.
1048+
With None, all products will be downloaded.
1049+
Possible string values: 'thumbnail', 'preview', 'auxiliary', 'science' or 'info'.
1050+
Posible list values: any combination of string values.
1051+
verbose : bool, optional, default 'False'
1052+
flag to display information about the process
1053+
1054+
Returns
1055+
-------
1056+
allobs : list
1057+
Returns the observationsid included into the proposal_id.
1058+
"""
1059+
1060+
query = (f"SELECT observationid "
1061+
f"FROM {str(conf.JWST_ARCHIVE_TABLE)} "
1062+
f"WHERE proposal_id='{str(proposal_id)}'")
1063+
if verbose:
1064+
print(query)
1065+
job = self.__jwsttap.launch_job_async(query=query, verbose=verbose)
1066+
allobs = set(JwstClass.get_decoded_string(job.get_results()['observationid']))
1067+
for oid in allobs:
1068+
log.info(f"Downloading products for Observation ID: {oid}")
1069+
self.get_obs_products(observation_id=oid, product_type=product_type)
1070+
return list(allobs)
1071+
10381072
def __check_file_number(self, output_dir, output_file_name,
10391073
output_file_full_path, files):
10401074
num_files_in_dir = len(os.listdir(output_dir))

astroquery/esa/jwst/tests/test_jwsttap.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,13 @@ def test_get_products_list_error(self):
684684
jwst.get_product_list(observation_id=observation_id, product_type='test')
685685
assert "product_type must be one of" in err.value.args[0]
686686

687+
def test_download_files_from_program(self):
688+
dummyTapHandler = DummyTapHandler()
689+
jwst = JwstClass(tap_plus_handler=dummyTapHandler, data_handler=dummyTapHandler, show_messages=False)
690+
with pytest.raises(TypeError) as err:
691+
jwst.download_files_from_program()
692+
assert "missing 1 required positional argument: 'proposal_id'" in err.value.args[0]
693+
687694
def test_get_obs_products(self):
688695
dummyTapHandler = DummyTapHandler()
689696
jwst = JwstClass(tap_plus_handler=dummyTapHandler, data_handler=dummyTapHandler, show_messages=False)

docs/esa/jwst/jwst.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ than get_product_list, it also supports product_type parameter as string or list
289289
Here product_type as list:
290290

291291
.. doctest-remote-data::
292-
292+
293293
>>> from astroquery.esa.jwst import Jwst
294294
>>> observation_id = 'jw01122001001_0210r_00001_nrs2'
295295
>>> results = Jwst.get_obs_products(observation_id=observation_id, cal_level=2, product_type=['science', 'preview'])
@@ -326,6 +326,18 @@ Using the observation ID as input parameter, this function will retrieve the obs
326326
'jw02739001001_02105_00002_nrcblong',
327327
'jw02739001001_02105_00003_nrcalong']
328328
329+
To query the data products associated with a certain Proposal ID and filtered by product_type.
330+
331+
.. doctest-remote-data::
332+
333+
>>> from astroquery.esa.jwst import Jwst
334+
>>> observation_list = Jwst.download_files_from_program(proposal_id='6651', product_type='preview') # doctest: +IGNORE_OUTPUT
335+
INFO: Query finished. [astroquery.utils.tap.core]
336+
INFO: Downloading products for Observation ID: jw06651001001_05201_00001_nis [astroquery.esa.jwst.core]
337+
INFO: Downloading products for Observation ID: jw06651002001_05201_00001_nis [astroquery.esa.jwst.core]
338+
>>> print(observation_list) # doctest: +IGNORE_OUTPUT
339+
['jw06651001001_05201_00001_nis', 'jw06651002001_05201_00001_nis']
340+
329341
330342
1.5 Getting public tables
331343
~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)