From 8d87d8416ec86ad4385abc0eba45cf1c12c4d551 Mon Sep 17 00:00:00 2001 From: Jennifer Medina Date: Tue, 11 Jul 2023 14:35:18 -0400 Subject: [PATCH] Adapting changes to support GALEX cloud products. Error handling updates. --- astroquery/mast/cloud.py | 14 +++++++------- astroquery/mast/utils.py | 11 ++++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/astroquery/mast/cloud.py b/astroquery/mast/cloud.py index ae4e836279..57a8456910 100644 --- a/astroquery/mast/cloud.py +++ b/astroquery/mast/cloud.py @@ -14,7 +14,7 @@ from astropy.utils.console import ProgressBarOrSpinner from astropy.utils.exceptions import AstropyDeprecationWarning -from ..exceptions import NoResultsWarning +from ..exceptions import NoResultsWarning, InvalidQueryError from . import utils @@ -110,7 +110,12 @@ def get_cloud_uri(self, data_product, include_bucket=True, full_url=False): """ uri_list = self.get_cloud_uri_list(data_product, include_bucket=include_bucket, full_url=full_url) - return uri_list[0] + + # Making sure we got at least 1 URI from the query above. + if len(uri_list) == 0: + raise InvalidQueryError("No products found on the cloud for this query.") + else: + return uri_list[0] def get_cloud_uri_list(self, data_products, include_bucket=True, full_url=False): """ @@ -142,14 +147,9 @@ def get_cloud_uri_list(self, data_products, include_bucket=True, full_url=False) uri_list = [] for path in paths: - if path is None: uri_list.append(None) - elif 'galex' in path: - path = path.lstrip("/mast/") else: - path = path.lstrip("/") - try: # Use `head_object` to verify that the product is available on S3 (not all products are) s3_client.head_object(Bucket=self.pubdata_bucket, Key=path) diff --git a/astroquery/mast/utils.py b/astroquery/mast/utils.py index 617665742b..f184ec8f0f 100644 --- a/astroquery/mast/utils.py +++ b/astroquery/mast/utils.py @@ -182,7 +182,12 @@ def mast_relative_path(mast_uri): {"uri": chunk}) json_response = response.json() for uri in chunk: - result.append(json_response.get(uri[1])["path"]) + path = json_response.get(uri[1])["path"] + if 'galex' in path: + path = path.lstrip("/mast/") + else: + path = path.lstrip("/") + result.append(path) # If the input was a single URI string, we return a single string if isinstance(mast_uri, str): @@ -195,3 +200,7 @@ def _split_list_into_chunks(input_list, chunk_size): """Helper function for `mast_relative_path`.""" for idx in range(0, len(input_list), chunk_size): yield input_list[idx:idx + chunk_size] + + +def mast_path_strip(path, mission): + """Helper function to"""