Skip to content

Commit 4d19e0d

Browse files
authored
Merge pull request #2168 from jaymedina/mast-get-cloud-uri-update
`astroquery.mast.Observations` get_cloud_uri(s) update
2 parents 9862845 + 5b6d5b1 commit 4d19e0d

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

astroquery/mast/observations.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,8 @@ def get_cloud_uris(self, data_products, include_bucket=True, full_url=False):
753753
"""
754754

755755
if self._cloud_connection is None:
756-
raise AttributeError("Must enable s3 dataset before attempting to query the s3 information")
756+
raise RemoteServiceError('Please enable anonymous cloud access by calling `enable_cloud_dataset` method. '
757+
'See MAST Labs documentation for an example: https://mast-labs.stsci.io/#example-data-access-with-astroquery-observations')
757758

758759
return self._cloud_connection.get_cloud_uri_list(data_products, include_bucket, full_url)
759760

@@ -784,8 +785,10 @@ def get_cloud_uri(self, data_product, include_bucket=True, full_url=False):
784785
"""
785786

786787
if self._cloud_connection is None:
787-
raise AttributeError("Must enable s3 dataset before attempting to query the s3 information")
788+
raise RemoteServiceError('Please enable anonymous cloud access by calling `enable_cloud_dataset` method. '
789+
'See MAST Labs documentation for an example: https://mast-labs.stsci.io/#example-data-access-with-astroquery-observations')
788790

791+
# Query for product URIs
789792
return self._cloud_connection.get_cloud_uri(data_product, include_bucket, full_url)
790793

791794

astroquery/mast/tests/test_mast_remote.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,38 @@ def test_observations_download_file(self, tmpdir):
295295
result = mast.Observations.download_file(uri)
296296
assert result == ('COMPLETE', None, None)
297297

298+
def test_get_cloud_uri(self):
299+
test_obs_id = '25568122'
300+
301+
# get a product list
302+
product = mast.Observations.get_product_list(test_obs_id)[24]
303+
304+
assert len(product) > 0, f'No product found for OBSID {test_obs_id}. Unable to move forward with getting URIs from the cloud.'
305+
306+
# enable access to public AWS S3 bucket
307+
mast.Observations.enable_cloud_dataset()
308+
309+
# get uri
310+
uri = mast.Observations.get_cloud_uri(product)
311+
312+
assert len(uri) > 0, f'Product for OBSID {test_obs_id} was not found in the cloud.'
313+
314+
def test_get_cloud_uris(self):
315+
test_obs_id = '25568122'
316+
317+
# get a product list
318+
products = mast.Observations.get_product_list(test_obs_id)[24:]
319+
320+
assert len(products) > 0, f'No products found for OBSID {test_obs_id}. Unable to move forward with getting URIs from the cloud.'
321+
322+
# enable access to public AWS S3 bucket
323+
mast.Observations.enable_cloud_dataset()
324+
325+
# get uris
326+
uris = mast.Observations.get_cloud_uris(products)
327+
328+
assert len(uris) > 0, f'Products for OBSID {test_obs_id} were not found in the cloud.'
329+
298330
######################
299331
# CatalogClass tests #
300332
######################

0 commit comments

Comments
 (0)