Skip to content

Commit 823e49f

Browse files
committed
verbose parameter
1 parent abf87ee commit 823e49f

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ mast
7272
- Added ``return_uri_map`` parameter to ``Observations.get_cloud_uris`` to return a mapping of the input data product URIs
7373
to the returned cloud URIs. [#3314]
7474

75+
- Added ``verbose`` parameter to ``Observations.get_cloud_uris`` to control whether warnings are logged when a product cannot
76+
be found in the cloud. [#3314]
77+
7578

7679
Infrastructure, Utility and Other Changes and Additions
7780
-------------------------------------------------------

astroquery/mast/cloud.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def get_cloud_uri(self, data_product, include_bucket=True, full_url=False):
117117
# Output from ``get_cloud_uri_list`` is always a list even when it's only 1 URI
118118
return uri_list[0]
119119

120-
def get_cloud_uri_list(self, data_products, include_bucket=True, full_url=False):
120+
def get_cloud_uri_list(self, data_products, *, include_bucket=True, full_url=False, verbose=True):
121121
"""
122122
Takes an `~astropy.table.Table` of data products and returns the associated cloud data uris.
123123
@@ -132,6 +132,8 @@ def get_cloud_uri_list(self, data_products, include_bucket=True, full_url=False)
132132
full_url : bool
133133
Default False. Return an HTTP fetchable url instead of a cloud uri.
134134
Must set include_bucket to False to use this option.
135+
verbose : bool
136+
Default True. Whether to issue warnings if a product cannot be found in the cloud.
135137
136138
Returns
137139
-------
@@ -141,7 +143,7 @@ def get_cloud_uri_list(self, data_products, include_bucket=True, full_url=False)
141143
"""
142144
s3_client = self.boto3.client('s3', config=self.config)
143145
data_uris = data_products if isinstance(data_products, list) else data_products['dataURI']
144-
paths = utils.mast_relative_path(data_uris)
146+
paths = utils.mast_relative_path(data_uris, verbose=verbose)
145147
if isinstance(paths, str): # Handle the case where only one product was requested
146148
paths = [paths]
147149

@@ -164,7 +166,8 @@ def get_cloud_uri_list(self, data_products, include_bucket=True, full_url=False)
164166
except self.botocore.exceptions.ClientError as e:
165167
if e.response['Error']['Code'] != "404":
166168
raise
167-
warnings.warn("Unable to locate file {}.".format(path), NoResultsWarning)
169+
if verbose:
170+
warnings.warn("Unable to locate file {}.".format(path), NoResultsWarning)
168171
uri_list.append(None)
169172

170173
return uri_list

astroquery/mast/observations.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,8 @@ def download_products(self, products, *, download_dir=None, flat=False,
874874
return manifest
875875

876876
def get_cloud_uris(self, data_products=None, *, include_bucket=True, full_url=False, pagesize=None, page=None,
877-
mrp_only=False, extension=None, filter_products={}, return_uri_map=False, **criteria):
877+
mrp_only=False, extension=None, filter_products={}, return_uri_map=False, verbose=True,
878+
**criteria):
878879
"""
879880
Given an `~astropy.table.Table` of data products or query criteria and filter parameters,
880881
returns the associated cloud data URIs.
@@ -912,6 +913,8 @@ def get_cloud_uris(self, data_products=None, *, include_bucket=True, full_url=Fa
912913
Default False. If set to True, returns a dictionary mapping the original data product
913914
URIs to their corresponding cloud URIs. This is useful for tracking which products were
914915
successfully converted to cloud URIs.
916+
verbose : bool, optional
917+
Default True. Whether to issue warnings if a product cannot be found in the cloud.
915918
**criteria
916919
Criteria to apply. At least one non-positional criteria must be supplied.
917920
Valid criteria are coordinates, objectname, radius (as in `query_region` and `query_object`),
@@ -972,7 +975,10 @@ def get_cloud_uris(self, data_products=None, *, include_bucket=True, full_url=Fa
972975
data_uris = utils.remove_duplicate_products(data_uris, 'dataURI')
973976

974977
# Get cloud URIS
975-
cloud_uris = self._cloud_connection.get_cloud_uri_list(data_uris, include_bucket, full_url)
978+
cloud_uris = self._cloud_connection.get_cloud_uri_list(data_uris,
979+
include_bucket=include_bucket,
980+
full_url=full_url,
981+
verbose=verbose)
976982

977983
# If return_uri_map is True, create a mapping of dataURIs to cloud URIs
978984
if return_uri_map:

astroquery/mast/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,16 @@ def split_list_into_chunks(input_list, chunk_size):
258258
yield input_list[idx:idx + chunk_size]
259259

260260

261-
def mast_relative_path(mast_uri):
261+
def mast_relative_path(mast_uri, *, verbose=True):
262262
"""
263263
Given one or more MAST dataURI(s), return the associated relative path(s).
264264
265265
Parameters
266266
----------
267267
mast_uri : str, list of str
268268
The MAST uri(s).
269+
verbose : bool, optional
270+
Default True. Whether to issue warnings if the MAST relative path cannot be found for a product.
269271
270272
Returns
271273
-------
@@ -294,7 +296,8 @@ def mast_relative_path(mast_uri):
294296
# so we index for path (index=1)
295297
path = json_response.get(uri)["path"]
296298
if path is None:
297-
warnings.warn(f"Failed to retrieve MAST relative path for {uri}. Skipping...", NoResultsWarning)
299+
if verbose:
300+
warnings.warn(f"Failed to retrieve MAST relative path for {uri}. Skipping...", NoResultsWarning)
298301
elif 'galex' in path:
299302
path = path.lstrip("/mast/")
300303
elif '/ps1/' in path:

0 commit comments

Comments
 (0)