diff --git a/CHANGES.rst b/CHANGES.rst index 9e7b133ee8..2953d907f5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -30,6 +30,11 @@ gama - Change URL to https and thus making the module functional again. [#3056] +esa.jwst +^^^^^^^^ + +- get_obs_products method supports product_type parameter as string or list [#2995] + mpc ^^^ diff --git a/astroquery/esa/jwst/core.py b/astroquery/esa/jwst/core.py index 8a1db48bdf..45293e2995 100644 --- a/astroquery/esa/jwst/core.py +++ b/astroquery/esa/jwst/core.py @@ -968,10 +968,11 @@ def get_obs_products(self, *, observation_id=None, cal_level="ALL", composite products based on level 2 products). To request upper levels, please use get_related_observations functions first. Possible values: 'ALL', 3, 2, 1, -1 - product_type : str, optional, default None - List only products of the given type. If None, all products are \ - listed. Possible values: 'thumbnail', 'preview', 'auxiliary', \ - 'science'. + product_type : str or list, optional, default None + If the string or at least one element of the list is empty, the value is replaced by None. + With None, all products will be downloaded. + Possible string values: 'thumbnail', 'preview', 'auxiliary', 'science' or 'info'. + Posible list values: any combination of string values. output_file : str, optional Output file. If no value is provided, a temporary one is created. @@ -981,6 +982,8 @@ def get_obs_products(self, *, observation_id=None, cal_level="ALL", Returns the local path where the product(s) are saved. """ + if (isinstance(product_type, list) and '' in product_type) or not product_type: + product_type = None if observation_id is None: raise ValueError(self.REQUESTED_OBSERVATION_ID) 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", max_cal_level=max_cal_level, is_url=True) params_dict['planeid'] = plane_ids + + if type(product_type) is list: + tap_product_type = ",".join(str(elem) for elem in product_type) + else: + tap_product_type = product_type + self.__set_additional_parameters(param_dict=params_dict, cal_level=cal_level, max_cal_level=max_cal_level, - product_type=product_type) + product_type=tap_product_type) output_file_full_path, output_dir = self.__set_dirs(output_file=output_file, observation_id=observation_id) # Get file name only diff --git a/astroquery/esa/jwst/tests/test_jwsttap.py b/astroquery/esa/jwst/tests/test_jwsttap.py index dfb99935a6..15f8605f8a 100644 --- a/astroquery/esa/jwst/tests/test_jwsttap.py +++ b/astroquery/esa/jwst/tests/test_jwsttap.py @@ -733,6 +733,37 @@ def test_get_obs_products(self): finally: shutil.rmtree(output_file_full_path_dir) + # Test product_type paramater with a list + output_file_full_path_dir = os.getcwd() + os.sep + "temp_test_jwsttap_get_obs_products_1" + try: + os.makedirs(output_file_full_path_dir, exist_ok=True) + except OSError as err: + print(f"Creation of the directory {output_file_full_path_dir} failed: {err.strerror}") + raise err + + file = data_path('single_product_retrieval.tar') + output_file_full_path = output_file_full_path_dir + os.sep + os.path.basename(file) + shutil.copy(file, output_file_full_path) + parameters['output_file'] = output_file_full_path + + expected_files = [] + extracted_file_1 = output_file_full_path_dir + os.sep + 'single_product_retrieval_1.fits' + expected_files.append(extracted_file_1) + product_type_as_list = ['science', 'info'] + try: + files_returned = (jwst.get_obs_products( + observation_id=observation_id, + cal_level='ALL', + product_type=product_type_as_list, + output_file=output_file_full_path)) + parameters['params_dict']['product_type'] = 'science,info' + dummyTapHandler.check_call('load_data', parameters) + self.__check_extracted_files(files_expected=expected_files, + files_returned=files_returned) + finally: + shutil.rmtree(output_file_full_path_dir) + del parameters['params_dict']['product_type'] + # Test single file output_file_full_path_dir = os.getcwd() + os.sep +\ "temp_test_jwsttap_get_obs_products_2" diff --git a/docs/esa/jwst/jwst.rst b/docs/esa/jwst/jwst.rst index 8cd59f85f5..f0429aa652 100644 --- a/docs/esa/jwst/jwst.rst +++ b/docs/esa/jwst/jwst.rst @@ -275,14 +275,24 @@ To download a data product >>> output_file = Jwst.get_product(artifact_id='6ab73824-6587-4bca-84a8-eb48ac7251be') # doctest: +SKIP >>> output_file = Jwst.get_product(file_name='jw01166091001_02102_00002_nrca3_cal.fits') # doctest: +SKIP + To download products by observation identifier, it is possible to use the get_obs_products function, with the same parameters -than get_product_list. +than get_product_list, it also supports product_type parameter as string or list. product_type as string: .. doctest-remote-data:: >>> from astroquery.esa.jwst import Jwst >>> observation_id = 'jw01122001001_0210r_00001_nrs2' - >>> results = Jwst.get_obs_products(observation_id=observation_id, cal_level=2, product_type='science') # doctest: +SKIP + >>> results = Jwst.get_obs_products(observation_id=observation_id, cal_level=2, product_type='science') + + +Here product_type as list: + +.. doctest-remote-data:: + + >>> from astroquery.esa.jwst import Jwst + >>> observation_id = 'jw01122001001_0210r_00001_nrs2' + >>> results = Jwst.get_obs_products(observation_id=observation_id, cal_level=2, product_type=['science', 'preview']) A temporary directory is created with the files and a list of the them is provided.