Skip to content

Commit 08ff1b8

Browse files
authored
Merge pull request #2995 from esdc-esac-esa-int/ESA_jwst-extend_get_obs_products
get_obs_products method supports product_type parameter as string or list
2 parents 53e636f + bb734e0 commit 08ff1b8

File tree

4 files changed

+62
-7
lines changed

4 files changed

+62
-7
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ gama
3030

3131
- Change URL to https and thus making the module functional again. [#3056]
3232

33+
esa.jwst
34+
^^^^^^^^
35+
36+
- get_obs_products method supports product_type parameter as string or list [#2995]
37+
3338
mpc
3439
^^^
3540

astroquery/esa/jwst/core.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -968,10 +968,11 @@ def get_obs_products(self, *, observation_id=None, cal_level="ALL",
968968
composite products based on level 2 products). To request upper
969969
levels, please use get_related_observations functions first.
970970
Possible values: 'ALL', 3, 2, 1, -1
971-
product_type : str, optional, default None
972-
List only products of the given type. If None, all products are \
973-
listed. Possible values: 'thumbnail', 'preview', 'auxiliary', \
974-
'science'.
971+
product_type : str or list, optional, default None
972+
If the string or at least one element of the list is empty, the value is replaced by None.
973+
With None, all products will be downloaded.
974+
Possible string values: 'thumbnail', 'preview', 'auxiliary', 'science' or 'info'.
975+
Posible list values: any combination of string values.
975976
output_file : str, optional
976977
Output file. If no value is provided, a temporary one is created.
977978
@@ -981,6 +982,8 @@ def get_obs_products(self, *, observation_id=None, cal_level="ALL",
981982
Returns the local path where the product(s) are saved.
982983
"""
983984

985+
if (isinstance(product_type, list) and '' in product_type) or not product_type:
986+
product_type = None
984987
if observation_id is None:
985988
raise ValueError(self.REQUESTED_OBSERVATION_ID)
986989
plane_ids, max_cal_level = self._get_plane_id(observation_id=observation_id)
@@ -997,10 +1000,16 @@ def get_obs_products(self, *, observation_id=None, cal_level="ALL",
9971000
max_cal_level=max_cal_level,
9981001
is_url=True)
9991002
params_dict['planeid'] = plane_ids
1003+
1004+
if type(product_type) is list:
1005+
tap_product_type = ",".join(str(elem) for elem in product_type)
1006+
else:
1007+
tap_product_type = product_type
1008+
10001009
self.__set_additional_parameters(param_dict=params_dict,
10011010
cal_level=cal_level,
10021011
max_cal_level=max_cal_level,
1003-
product_type=product_type)
1012+
product_type=tap_product_type)
10041013
output_file_full_path, output_dir = self.__set_dirs(output_file=output_file,
10051014
observation_id=observation_id)
10061015
# Get file name only

astroquery/esa/jwst/tests/test_jwsttap.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,37 @@ def test_get_obs_products(self):
733733
finally:
734734
shutil.rmtree(output_file_full_path_dir)
735735

736+
# Test product_type paramater with a list
737+
output_file_full_path_dir = os.getcwd() + os.sep + "temp_test_jwsttap_get_obs_products_1"
738+
try:
739+
os.makedirs(output_file_full_path_dir, exist_ok=True)
740+
except OSError as err:
741+
print(f"Creation of the directory {output_file_full_path_dir} failed: {err.strerror}")
742+
raise err
743+
744+
file = data_path('single_product_retrieval.tar')
745+
output_file_full_path = output_file_full_path_dir + os.sep + os.path.basename(file)
746+
shutil.copy(file, output_file_full_path)
747+
parameters['output_file'] = output_file_full_path
748+
749+
expected_files = []
750+
extracted_file_1 = output_file_full_path_dir + os.sep + 'single_product_retrieval_1.fits'
751+
expected_files.append(extracted_file_1)
752+
product_type_as_list = ['science', 'info']
753+
try:
754+
files_returned = (jwst.get_obs_products(
755+
observation_id=observation_id,
756+
cal_level='ALL',
757+
product_type=product_type_as_list,
758+
output_file=output_file_full_path))
759+
parameters['params_dict']['product_type'] = 'science,info'
760+
dummyTapHandler.check_call('load_data', parameters)
761+
self.__check_extracted_files(files_expected=expected_files,
762+
files_returned=files_returned)
763+
finally:
764+
shutil.rmtree(output_file_full_path_dir)
765+
del parameters['params_dict']['product_type']
766+
736767
# Test single file
737768
output_file_full_path_dir = os.getcwd() + os.sep +\
738769
"temp_test_jwsttap_get_obs_products_2"

docs/esa/jwst/jwst.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,24 @@ To download a data product
275275
>>> output_file = Jwst.get_product(artifact_id='6ab73824-6587-4bca-84a8-eb48ac7251be') # doctest: +SKIP
276276
>>> output_file = Jwst.get_product(file_name='jw01166091001_02102_00002_nrca3_cal.fits') # doctest: +SKIP
277277

278+
278279
To download products by observation identifier, it is possible to use the get_obs_products function, with the same parameters
279-
than get_product_list.
280+
than get_product_list, it also supports product_type parameter as string or list. product_type as string:
280281

281282
.. doctest-remote-data::
282283

283284
>>> from astroquery.esa.jwst import Jwst
284285
>>> observation_id = 'jw01122001001_0210r_00001_nrs2'
285-
>>> results = Jwst.get_obs_products(observation_id=observation_id, cal_level=2, product_type='science') # doctest: +SKIP
286+
>>> results = Jwst.get_obs_products(observation_id=observation_id, cal_level=2, product_type='science')
287+
288+
289+
Here product_type as list:
290+
291+
.. doctest-remote-data::
292+
293+
>>> from astroquery.esa.jwst import Jwst
294+
>>> observation_id = 'jw01122001001_0210r_00001_nrs2'
295+
>>> results = Jwst.get_obs_products(observation_id=observation_id, cal_level=2, product_type=['science', 'preview'])
286296

287297
A temporary directory is created with the files and a list of the them is provided.
288298

0 commit comments

Comments
 (0)