Skip to content

Commit 1e3eb77

Browse files
authored
Merge pull request #3437 from esdc-esac-esa-int/ESA_ehst-improvements-datalabs
2 parents 6fbdff1 + 779cca2 commit 1e3eb77

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ API changes
1414
Service fixes and enhancements
1515
------------------------------
1616

17+
esa.hubble
18+
^^^^^^^^^^
19+
20+
- Update ``get_datalabs_path`` method so an alternative path is checked if the
21+
file is not in Datalabs yet [#3437]
1722

1823

1924
Infrastructure, Utility and Other Changes and Additions

astroquery/esa/hubble/core.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ def parse_messages_response(self, response):
937937
for line in response.iter_lines():
938938
string_message = line.decode("utf-8")
939939
string_messages.append(string_message[string_message.index('=') + 1:])
940-
print(string_messages[len(string_messages)-1])
940+
print(string_messages[len(string_messages) - 1])
941941
return string_messages
942942

943943
def get_columns(self, table_name, *, only_names=True, verbose=False):
@@ -1031,20 +1031,23 @@ def get_datalabs_path(self, filename, default_volume=None):
10311031
path = self._get_decoded_string(string=job["file_path"][0])
10321032
path_parsed = path.split("hstdata/", 1)[1]
10331033

1034-
# Automatic fill: convert /hstdata/hstdata_i/i/b4x/04 to /data/user/hub_hstdata_i/i/b4x/04
1035-
if default_volume is None:
1036-
full_path = "/data/user/hub_" + path_parsed + "/" + filename
1037-
file_exists = os.path.exists(full_path)
1034+
for datalabs_path in ["/data/user/", "/data/"]:
1035+
# Automatic fill: convert /hstdata/hstdata_i/i/b4x/04 to <datalabs_path>/hub_hstdata_i/i/b4x/04
1036+
if default_volume is None:
1037+
full_path = datalabs_path + "hub_" + path_parsed + "/" + filename
1038+
1039+
# Use the path provided by the user: convert /hstdata/hstdata_i/i/b4x/04 to <datalabs_path>/myPath/i/b4x/04
1040+
else:
1041+
trimmed_path = path_parsed.split("/", 1)[1]
1042+
full_path = datalabs_path + default_volume + "/" + trimmed_path + "/" + filename
10381043

1039-
# Use the path provided by the user: convert /hstdata/hstdata_i/i/b4x/04 to /data/user/myPath/i/b4x/04
1040-
else:
1041-
path_parsed = path_parsed.split("/", 1)[1]
1042-
full_path = "/data/user/" + default_volume + "/" + path_parsed + "/" + filename
10431044
file_exists = os.path.exists(full_path)
10441045

1045-
if not file_exists:
1046-
warnings.warn(f"File {filename} is not accessible. Please ensure the {instrument_name} "
1047-
"volume is mounted in your ESA Datalabs instance.")
1046+
if file_exists:
1047+
return full_path
1048+
1049+
warnings.warn(f"File {filename} is not accessible. Please ensure the {instrument_name} "
1050+
"volume is mounted in your ESA Datalabs instance.")
10481051
return full_path
10491052

10501053

astroquery/esa/hubble/tests/test_esa_hubble.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,17 +770,20 @@ def test_get_datalabs_path(self, mock_get_decoded_string, mock_query_tap):
770770
{"observation_id": ["obs123"]}, # Second query result
771771
{"instrument_name": ["instrumentXYZ"]} # Third query result
772772
]
773-
mock_query_tap.side_effect = values + values
773+
mock_query_tap.side_effect = values * 3
774774
# Set up the return value for the _get_decoded_string method
775775
mock_get_decoded_string.return_value = "/hstdata/hstdata_i/i/b4x/04"
776776
# Set up the return value for os.path.exists
777-
mock_exists.return_value = True
777+
mock_exists.side_effect = [True, False, True, True]
778778
# Example usage
779779
filename = "ib4x04ivq_flt.jpg"
780780
default_volume = None
781781
full_path = ehst.get_datalabs_path(filename=filename, default_volume=default_volume)
782782
assert full_path == "/data/user/hub_hstdata_i/i/b4x/04/ib4x04ivq_flt.jpg"
783783

784+
full_path = ehst.get_datalabs_path(filename=filename, default_volume=default_volume)
785+
assert full_path == "/data/hub_hstdata_i/i/b4x/04/ib4x04ivq_flt.jpg"
786+
784787
# Test with default_volume provided
785788
default_volume = "myPath"
786789

astroquery/esa/hubble/tests/test_esa_hubble_remote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ def test_get_datalabs_path_image(self, recwarn):
136136
result = esa_hubble.get_datalabs_path(filename='ib4x04ivq_flt.jpg', default_volume=None)
137137
assert len(recwarn) == 1
138138
assert "ib4x04ivq_flt.jpg" in str(recwarn[0].message)
139-
assert result == '/data/user/hub_hstdata_i/i/b4x/04/ib4x04ivq_flt.jpg'
139+
assert result == '/data/hub_hstdata_i/i/b4x/04/ib4x04ivq_flt.jpg'
140140

141141
def test_get_datalabs_path_fits(self, recwarn):
142142
result = esa_hubble.get_datalabs_path(filename='ib4x04ivq_flt.fits', default_volume=None)
143143
assert len(recwarn) == 1
144144
assert "ib4x04ivq_flt.fits" in str(recwarn[0].message)
145-
assert result == '/data/user/hub_hstdata_i/i/b4x/04/ib4x04ivq_flt.fits.gz'
145+
assert result == '/data/hub_hstdata_i/i/b4x/04/ib4x04ivq_flt.fits.gz'

0 commit comments

Comments
 (0)