Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESASky handle eROSITA downloads #3111

Merged
merged 2 commits into from
Oct 1, 2024
Merged
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
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ mast
- Present users with an error rather than a warning when nonexistent query criteria are used in ``mast.Observations.query_criteria``
and ``mast.Catalogs.query_criteria``. [#3084]

- Support for case-insensitive criteria keyword arguments in ``mast.Observations.query_criteria`` and
- Support for case-insensitive criteria keyword arguments in ``mast.Observations.query_criteria`` and
``mast.Catalogs.query_criteria``. [#3087]

- Added function ``mast.Observations.get_unique_product_list`` to return the unique data products associated with
Expand Down Expand Up @@ -802,6 +802,8 @@ esa.esasky

- Added Solar System Object functionality. [#2106]

- Added support for eROSITA downloads. [#3111]

ipac
^^^^

Expand Down
14 changes: 12 additions & 2 deletions astroquery/esasky/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ESASkyClass(BaseQuery):
__TAP_DEC_COLUMN_STRING = "tapDecColumn"
__METADATA_STRING = "metadata"
__PRODUCT_URL_STRING = "product_url"
__EROSITA_PRODUCT_URL_STRING = "prod_url"
__ACCESS_URL_STRING = "access_url"
__USE_INTERSECT_STRING = "useIntersectPolygonInsteadOfContainsPoint"
__ZERO_ARCMIN_STRING = "0 arcmin"
Expand Down Expand Up @@ -1464,6 +1465,8 @@ def _get_maps_for_mission(self, maps_table, mission, download_dir, cache, json,
url_key = self.__PRODUCT_URL_STRING
if url_key == "" and self.__ACCESS_URL_STRING in maps_table.keys():
url_key = self.__ACCESS_URL_STRING
if url_key == "" and mission == 'EROSITA':
url_key = self.__EROSITA_PRODUCT_URL_STRING
if url_key == "" or mission == "ALMA":
log.info(mission + " does not yet support downloading of fits files")
return maps
Expand Down Expand Up @@ -1520,13 +1523,20 @@ def _get_maps_for_mission(self, maps_table, mission, download_dir, cache, json,

response.raise_for_status()

if ('Content-Type' in response.headers
and response.headers['Content-Type'] == 'application/zip'):
if response.headers.get('Content-Type') == 'application/zip':
with ZipFile(file=BytesIO(response.content)) as zip:
for info in zip.infolist():
if self._ends_with_fits_like_extentsion(info.filename):
maps.append(self._open_fits(
zip.extract(info.filename, path=mission_directory), verbose=verbose))
elif response.headers.get('Content-Type') == 'application/x-gzip':
with esatar.open(name='dummy', mode='r', fileobj=BytesIO(response.content)) as tar:
for file in tar.getmembers():
if self._ends_with_fits_like_extentsion(file.name):
file.name = os.path.basename(file.name)
tar.extract(file, path=mission_directory)
maps.append(self._open_fits(
Path(mission_directory, file.name), verbose=verbose))
else:
file_name = self._extract_file_name_from_response_header(response.headers)
if file_name == "":
Expand Down
9 changes: 9 additions & 0 deletions astroquery/esasky/tests/test_esasky_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ def test_esasky_get_images(self, tmp_path, mission):
for hdu_list in result[mission.upper()]:
hdu_list.close()

@pytest.mark.bigdata
def test_esasky_get_images_for_erosita(self, tmp_path):
mission = 'eROSITA'
result = ESASky.get_images(position="67.84 -61.44", missions=mission, download_dir=tmp_path)
assert tmp_path.stat().st_size

for hdu_list in result[mission.upper()]:
hdu_list.close()

@pytest.mark.bigdata
@pytest.mark.parametrize('mission, position',
zip(['JWST-MID-IR', 'JWST-NEAR-IR'],
Expand Down