Skip to content

Commit b78fc97

Browse files
davidgltbsipocz
authored andcommitted
Include warning in get_datalabs_path method for ehst when the data volume is not mounted in DataLabs
1 parent 0002370 commit b78fc97

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

astroquery/esa/hubble/core.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,17 +1027,37 @@ def get_datalabs_path(self, filename, default_volume=None):
10271027
if job is None:
10281028
return None
10291029

1030+
query2 = f"select observation_id from ehst.artifact where file_name = '{filename}'"
1031+
job2 = self.query_tap(query=query2)
1032+
if job2 is None:
1033+
return None
1034+
1035+
observation_id = job2["observation_id"][0]
1036+
query3 = f"select instrument_name from ehst.observation where observation_id = '{observation_id}'"
1037+
job3 = self.query_tap(query=query3)
1038+
if job3 is None:
1039+
return None
1040+
1041+
instrument_name = job3["instrument_name"][0]
1042+
10301043
# Output example for path: /hstdata/hstdata_i/i/b4x/04, or hstdata_i/i/b4x/04 for path_parsed
10311044
path = self._get_decoded_string(string=job["file_path"][0])
10321045
path_parsed = path.split("hstdata/", 1)[1]
10331046

10341047
# Automatic fill: convert /hstdata/hstdata_i/i/b4x/04 to /data/user/hub_hstdata_i/i/b4x/04
10351048
if default_volume is None:
1036-
return "/data/user/hub_" + path_parsed + "/" + filename
1037-
1049+
full_path = "/data/user/hub_" + path_parsed + "/" + filename
1050+
file_exists = os.path.exists(full_path)
1051+
10381052
# Use the path provided by the user: convert /hstdata/hstdata_i/i/b4x/04 to /data/user/myPath/i/b4x/04
1039-
path_parsed = path_parsed.split("/", 1)[1]
1040-
return "/data/user/" + default_volume + "/" + path_parsed + "/" + filename
1053+
else:
1054+
path_parsed = path_parsed.split("/", 1)[1]
1055+
full_path = "/data/user/" + default_volume + "/" + path_parsed + "/" + filename
1056+
file_exists = os.path.exists(full_path)
1057+
1058+
if not file_exists:
1059+
print(f"File '{filename}' is not accessible. Please ensure the '{instrument_name}' volume is mounted in your ESA Datalabs instance.")
1060+
return full_path
10411061

10421062

10431063
ESAHubble = ESAHubbleClass()

0 commit comments

Comments
 (0)