Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ API changes
Service fixes and enhancements
------------------------------

esa.hubble
^^^^^^^^^^

- Update ``get_datalabs_path`` method so an alternative path is checked if the
file is not in Datalabs yet [#3437]


Infrastructure, Utility and Other Changes and Additions
Expand Down
27 changes: 15 additions & 12 deletions astroquery/esa/hubble/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ def parse_messages_response(self, response):
for line in response.iter_lines():
string_message = line.decode("utf-8")
string_messages.append(string_message[string_message.index('=') + 1:])
print(string_messages[len(string_messages)-1])
print(string_messages[len(string_messages) - 1])
return string_messages

def get_columns(self, table_name, *, only_names=True, verbose=False):
Expand Down Expand Up @@ -1031,20 +1031,23 @@ def get_datalabs_path(self, filename, default_volume=None):
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:
full_path = "/data/user/hub_" + path_parsed + "/" + filename
file_exists = os.path.exists(full_path)
for datalabs_path in ["/data/user/", "/data/"]:
# Automatic fill: convert /hstdata/hstdata_i/i/b4x/04 to <datalabs_path>/hub_hstdata_i/i/b4x/04
if default_volume is None:
full_path = datalabs_path + "hub_" + path_parsed + "/" + filename

# Use the path provided by the user: convert /hstdata/hstdata_i/i/b4x/04 to <datalabs_path>/myPath/i/b4x/04
else:
trimmed_path = path_parsed.split("/", 1)[1]
full_path = datalabs_path + default_volume + "/" + trimmed_path + "/" + filename

# 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:
warnings.warn(f"File {filename} is not accessible. Please ensure the {instrument_name} "
"volume is mounted in your ESA Datalabs instance.")
if file_exists:
return full_path

warnings.warn(f"File {filename} is not accessible. Please ensure the {instrument_name} "
"volume is mounted in your ESA Datalabs instance.")
return full_path


Expand Down
7 changes: 5 additions & 2 deletions astroquery/esa/hubble/tests/test_esa_hubble.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,17 +770,20 @@ def test_get_datalabs_path(self, mock_get_decoded_string, mock_query_tap):
{"observation_id": ["obs123"]}, # Second query result
{"instrument_name": ["instrumentXYZ"]} # Third query result
]
mock_query_tap.side_effect = values + values
mock_query_tap.side_effect = values * 3
# Set up the return value for the _get_decoded_string method
mock_get_decoded_string.return_value = "/hstdata/hstdata_i/i/b4x/04"
# Set up the return value for os.path.exists
mock_exists.return_value = True
mock_exists.side_effect = [True, False, True, True]
# Example usage
filename = "ib4x04ivq_flt.jpg"
default_volume = None
full_path = ehst.get_datalabs_path(filename=filename, default_volume=default_volume)
assert full_path == "/data/user/hub_hstdata_i/i/b4x/04/ib4x04ivq_flt.jpg"

full_path = ehst.get_datalabs_path(filename=filename, default_volume=default_volume)
assert full_path == "/data/hub_hstdata_i/i/b4x/04/ib4x04ivq_flt.jpg"

# Test with default_volume provided
default_volume = "myPath"

Expand Down
Loading