Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_obs_products method supports product_type parameter as string or list #2995

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ New Tools and Services
Service fixes and enhancements
------------------------------

esa.jwst
^^^^^^^^

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

mpc
^^^

Expand Down
19 changes: 14 additions & 5 deletions astroquery/esa/jwst/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,10 +965,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
List only products of the given type. If None, empty or an element
of the list is empty, all products are listed.
Possible values: 'thumbnail', 'preview', 'auxiliary',
'science', 'info', ['science', 'preview']...
output_file : str, optional
Output file. If no value is provided, a temporary one is created.

Expand All @@ -978,6 +979,8 @@ def get_obs_products(self, *, observation_id=None, cal_level="ALL",
Returns the local path where the product(s) are saved.
"""

if (type(product_type) is 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)
Expand All @@ -994,10 +997,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
Expand Down
14 changes: 12 additions & 2 deletions docs/esa/jwst/jwst.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down