From b78fc97c17d5fb8bbf67ca9413364beae12ce03e Mon Sep 17 00:00:00 2001 From: David Gonzalez Date: Mon, 1 Jul 2024 11:06:44 +0200 Subject: [PATCH 1/4] Include warning in get_datalabs_path method for ehst when the data volume is not mounted in DataLabs --- astroquery/esa/hubble/core.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/astroquery/esa/hubble/core.py b/astroquery/esa/hubble/core.py index e0bdaea927..da19939b32 100644 --- a/astroquery/esa/hubble/core.py +++ b/astroquery/esa/hubble/core.py @@ -1027,17 +1027,37 @@ def get_datalabs_path(self, filename, default_volume=None): if job is None: return None + query2 = f"select observation_id from ehst.artifact where file_name = '{filename}'" + job2 = self.query_tap(query=query2) + if job2 is None: + return None + + observation_id = job2["observation_id"][0] + query3 = f"select instrument_name from ehst.observation where observation_id = '{observation_id}'" + job3 = self.query_tap(query=query3) + if job3 is None: + return None + + instrument_name = job3["instrument_name"][0] + # Output example for path: /hstdata/hstdata_i/i/b4x/04, or hstdata_i/i/b4x/04 for path_parsed path = self._get_decoded_string(string=job["file_path"][0]) path_parsed = path.split("hstdata/", 1)[1] # Automatic fill: convert /hstdata/hstdata_i/i/b4x/04 to /data/user/hub_hstdata_i/i/b4x/04 if default_volume is None: - return "/data/user/hub_" + path_parsed + "/" + filename - + full_path = "/data/user/hub_" + path_parsed + "/" + filename + file_exists = os.path.exists(full_path) + # Use the path provided by the user: convert /hstdata/hstdata_i/i/b4x/04 to /data/user/myPath/i/b4x/04 - path_parsed = path_parsed.split("/", 1)[1] - return "/data/user/" + default_volume + "/" + path_parsed + "/" + filename + else: + path_parsed = path_parsed.split("/", 1)[1] + full_path = "/data/user/" + default_volume + "/" + path_parsed + "/" + filename + file_exists = os.path.exists(full_path) + + if not file_exists: + print(f"File '{filename}' is not accessible. Please ensure the '{instrument_name}' volume is mounted in your ESA Datalabs instance.") + return full_path ESAHubble = ESAHubbleClass() From 0ed7fe6d347e4c5b31b799cf15967522ca8fd7f1 Mon Sep 17 00:00:00 2001 From: David Gonzalez Date: Mon, 1 Jul 2024 11:38:33 +0200 Subject: [PATCH 2/4] Add PR number in CHANGES.rst Align to PEP8 --- CHANGES.rst | 5 +++++ astroquery/esa/hubble/core.py | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index d3ae861374..24f059866d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -15,6 +15,11 @@ alma - Added support for frequency_resolution in KHz [#3035] +ehst +^^^^ + +- Include warning in get_datalabs_path method for ehst when the data volume is not mounted in DataLabs [#3059] + gama ^^^^ diff --git a/astroquery/esa/hubble/core.py b/astroquery/esa/hubble/core.py index da19939b32..3018b8d3dc 100644 --- a/astroquery/esa/hubble/core.py +++ b/astroquery/esa/hubble/core.py @@ -1031,13 +1031,13 @@ def get_datalabs_path(self, filename, default_volume=None): job2 = self.query_tap(query=query2) if job2 is None: return None - + observation_id = job2["observation_id"][0] query3 = f"select instrument_name from ehst.observation where observation_id = '{observation_id}'" job3 = self.query_tap(query=query3) if job3 is None: return None - + instrument_name = job3["instrument_name"][0] # Output example for path: /hstdata/hstdata_i/i/b4x/04, or hstdata_i/i/b4x/04 for path_parsed @@ -1048,15 +1048,16 @@ def get_datalabs_path(self, filename, default_volume=None): if default_volume is None: full_path = "/data/user/hub_" + path_parsed + "/" + filename file_exists = os.path.exists(full_path) - + # Use the path provided by the user: convert /hstdata/hstdata_i/i/b4x/04 to /data/user/myPath/i/b4x/04 else: path_parsed = path_parsed.split("/", 1)[1] full_path = "/data/user/" + default_volume + "/" + path_parsed + "/" + filename file_exists = os.path.exists(full_path) - + if not file_exists: - print(f"File '{filename}' is not accessible. Please ensure the '{instrument_name}' volume is mounted in your ESA Datalabs instance.") + print(f"File '{filename}' is not accessible. Please ensure the '{instrument_name}' " \ + "volume is mounted in your ESA Datalabs instance.") return full_path From 18d1c4432a4f5264106547ae96b0a0493c1bad80 Mon Sep 17 00:00:00 2001 From: David Gonzalez Date: Tue, 2 Jul 2024 10:40:37 +0200 Subject: [PATCH 3/4] fix PEP8 backslash recommendation --- astroquery/esa/hubble/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astroquery/esa/hubble/core.py b/astroquery/esa/hubble/core.py index 3018b8d3dc..0e2a1a560f 100644 --- a/astroquery/esa/hubble/core.py +++ b/astroquery/esa/hubble/core.py @@ -1056,7 +1056,7 @@ def get_datalabs_path(self, filename, default_volume=None): file_exists = os.path.exists(full_path) if not file_exists: - print(f"File '{filename}' is not accessible. Please ensure the '{instrument_name}' " \ + print(f"File '{filename}' is not accessible. Please ensure the '{instrument_name}' " "volume is mounted in your ESA Datalabs instance.") return full_path From 0b6a0163f032f64ddfeffda2828fcdbdca3e5c4a Mon Sep 17 00:00:00 2001 From: David Gonzalez Date: Fri, 5 Jul 2024 12:59:55 +0200 Subject: [PATCH 4/4] replace print by warnings.warn to show an user warning --- astroquery/esa/hubble/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/astroquery/esa/hubble/core.py b/astroquery/esa/hubble/core.py index 0e2a1a560f..cae9050401 100644 --- a/astroquery/esa/hubble/core.py +++ b/astroquery/esa/hubble/core.py @@ -1056,8 +1056,8 @@ def get_datalabs_path(self, filename, default_volume=None): file_exists = os.path.exists(full_path) if not file_exists: - print(f"File '{filename}' is not accessible. Please ensure the '{instrument_name}' " - "volume is mounted in your ESA Datalabs instance.") + warnings.warn(f"File {filename} is not accessible. Please ensure the {instrument_name} " + "volume is mounted in your ESA Datalabs instance.") return full_path