Skip to content

Commit e23cecb

Browse files
committed
address review comments
1 parent 9344740 commit e23cecb

File tree

4 files changed

+96
-85
lines changed

4 files changed

+96
-85
lines changed

astroquery/heasarc/core.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def _get_default_columns(self, catalog_name):
9999
]
100100
meta.sort('value')
101101
defaults = meta['par']
102-
return defaults
102+
return list(defaults)
103103

104104
def get_default_radius(self, catalog_name):
105105
"""Get a mission-appropriate default radius for a catalog
@@ -118,10 +118,10 @@ def get_default_radius(self, catalog_name):
118118
(self._meta['table'] == catalog_name)
119119
& (self._meta['par'] == '')
120120
]
121-
radius = np.double(meta['value'][0]) * u.arcmin
121+
radius = np.float32(meta['value'][0]) * u.arcmin
122122
return radius
123123

124-
def set_session(self, session):
124+
def _set_session(self, session):
125125
"""Set requests.Session to use when querying the data
126126
127127
Parameters
@@ -424,8 +424,8 @@ def query_region(self, position=None, catalog=None, radius=None, *,
424424
response = self.query_tap(query=adql, maxrec=maxrec)
425425

426426
# save the response in case we want to use it later
427-
self._query_result = response
428-
self._catalog_name = catalog
427+
self._last_result = response
428+
self._last_catalog_name = catalog
429429

430430
table = response.to_table()
431431
if add_offset:
@@ -484,13 +484,13 @@ def locate_data(self, query_result=None, catalog_name=None):
484484
"""
485485
if query_result is None:
486486
if (
487-
not hasattr(self, '_query_result')
488-
or self._query_result is None
487+
not hasattr(self, '_last_result')
488+
or self._last_result is None
489489
):
490490
raise ValueError('query_result is None, and none '
491491
'found from a previous search')
492492
else:
493-
query_result = self._query_result
493+
query_result = self._last_result
494494

495495
if not isinstance(query_result, Table):
496496
raise TypeError('query_result need to be an astropy.table.Table')
@@ -502,7 +502,7 @@ def locate_data(self, query_result=None, catalog_name=None):
502502
'query_region or a subset.')
503503

504504
if catalog_name is None:
505-
catalog_name = self._catalog_name
505+
catalog_name = self._last_catalog_name
506506
if not (
507507
isinstance(catalog_name, str)
508508
and catalog_name in self.tap.tables.keys()
@@ -661,10 +661,10 @@ def _download_heasarc(self, links, location='.'):
661661
}
662662

663663
# get local_filepath name
664-
local_filepath = f'{location}/xamin.tar'
664+
local_filepath = f'{location}/heasarc-data.tar'
665665
iname = 1
666666
while os.path.exists(local_filepath):
667-
local_filepath = f'{location}/xamin.{iname}.tar'
667+
local_filepath = f'{location}/heasarc-data.{iname}.tar'
668668
iname += 1
669669

670670
log.info(f'Downloading to {local_filepath} ...')

astroquery/heasarc/tests/test_heasarc.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from astropy.table import Table
99
import astropy.units as u
1010

11-
from astroquery.heasarc import Heasarc
11+
from astroquery.heasarc import Heasarc, HeasarcClass
1212
from astroquery.exceptions import InvalidQueryError
1313

1414
try:
@@ -199,6 +199,8 @@ def test_no_catalog():
199199

200200

201201
def test_tap_def():
202+
# Use a new HeasarcClass object
203+
Heasarc = HeasarcClass()
202204
assert Heasarc._tap is None
203205
Heasarc.tap
204206
assert Heasarc._tap is not None
@@ -208,6 +210,8 @@ def test_meta_def():
208210
class MockResult:
209211
def to_table(self):
210212
return Table({'value': ['1.5', '1.2', '-0.3']})
213+
# Use a new HeasarcClass object
214+
Heasarc = HeasarcClass()
211215
assert Heasarc._meta_info is None
212216
with patch('astroquery.heasarc.core.HeasarcClass.query_tap') as mock_query_tap:
213217
mock_query_tap.return_value = MockResult()
@@ -216,18 +220,22 @@ def to_table(self):
216220

217221

218222
def test__get_default_columns(mock_meta):
223+
# Use a new HeasarcClass object
224+
Heasarc = HeasarcClass()
219225
cols = Heasarc._get_default_columns('tab1')
220226
assert list(cols) == ['p1', 'p3']
221227

222228

223229
def test__get_default_radius(mock_meta):
230+
# Use a new HeasarcClass object
231+
Heasarc = HeasarcClass()
224232
radius = Heasarc.get_default_radius('tab1')
225233
assert radius.value == 3.0
226234

227235

228-
def test_set_session():
236+
def test__set_session():
229237
with pytest.raises(ValueError):
230-
Heasarc.set_session('not session object')
238+
Heasarc._set_session('not session object')
231239

232240

233241
def test__list_catalogs(mock_tap):

astroquery/heasarc/tests/test_heasarc_remote.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22

33
import os
4-
import shutil
54
import pytest
5+
import tempfile
66
import astropy.units as u
77
from astropy.table import Table
88
from astropy.coordinates import SkyCoord
@@ -83,6 +83,7 @@ def test_query_region_cone(self, coordinates):
8383
spatial="cone",
8484
columns="*",
8585
radius=1 * u.arcmin,
86+
add_offset=True
8687
)
8788
assert isinstance(result, Table)
8889
assert len(result) == 3
@@ -95,11 +96,12 @@ def test_query_columns_radius(self):
9596
"""
9697
result = Heasarc.query_region(
9798
"NGC 4151", catalog="suzamaster", columns="ra,dec,obsid",
98-
radius=10 * u.arcmin
99+
radius=10 * u.arcmin,
100+
add_offset=True
99101
)
100102
assert len(result) == 4
101103
# assert only selected columns are returned
102-
assert result.colnames == ["ra", "dec", "obsid", "search_offset_"]
104+
assert result.colnames == ["ra", "dec", "obsid", "search_offset"]
103105

104106
def test_query_region_box(self):
105107
result = Heasarc.query_region(
@@ -196,9 +198,9 @@ def test_download_data__heasarc_file(self):
196198
f"data/archive/{filename}")
197199
]
198200
})
199-
Heasarc.download_data(tab, host="heasarc", location=".")
200-
assert os.path.exists(filename)
201-
os.remove(filename)
201+
with tempfile.TemporaryDirectory() as tmpdir:
202+
Heasarc.download_data(tab, host="heasarc", location=tmpdir)
203+
assert os.path.exists(f'{tmpdir}/{filename}')
202204

203205
def test_download_data__heasarc_folder(self):
204206
tab = Table({
@@ -207,21 +209,22 @@ def test_download_data__heasarc_folder(self):
207209
"AO10/P91129/91129-01-68-00A/stdprod")
208210
]
209211
})
210-
Heasarc.download_data(tab, host="heasarc", location=".")
211-
assert os.path.exists("stdprod")
212-
assert os.path.exists("stdprod/FHed_1791a7b9-1791a931.gz")
213-
assert os.path.exists("stdprod/FHee_1791a7b9-1791a92f.gz")
214-
assert os.path.exists("stdprod/FHef_1791a7b9-1791a92f.gz")
215-
shutil.rmtree("stdprod")
212+
with tempfile.TemporaryDirectory() as tmpdir:
213+
Heasarc.download_data(tab, host="heasarc", location=tmpdir)
214+
assert os.path.exists(f"{tmpdir}/stdprod")
215+
assert os.path.exists(f"{tmpdir}/stdprod/FHed_1791a7b9-1791a931.gz")
216+
assert os.path.exists(f"{tmpdir}/stdprod/FHee_1791a7b9-1791a92f.gz")
217+
assert os.path.exists(f"{tmpdir}/stdprod/FHef_1791a7b9-1791a92f.gz")
216218

217219
def test_download_data__s3_file(self):
218220
filename = "00README"
219221
tab = Table(
220222
{"aws": [f"s3://nasa-heasarc/rxte/data/archive/{filename}"]}
221223
)
222-
Heasarc.download_data(tab, host="aws", location=".")
223-
assert os.path.exists(filename)
224-
os.remove(filename)
224+
with tempfile.TemporaryDirectory() as tmpdir:
225+
Heasarc.enable_cloud(provider='aws', profile=None)
226+
Heasarc.download_data(tab, host="aws", location=tmpdir)
227+
assert os.path.exists(f'{tmpdir}/{filename}')
225228

226229
@pytest.mark.parametrize("slash", ["", "/"])
227230
def test_download_data__s3_folder(self, slash):
@@ -233,12 +236,13 @@ def test_download_data__s3_folder(self, slash):
233236
]
234237
}
235238
)
236-
Heasarc.download_data(tab, host="aws", location=".")
237-
assert os.path.exists("stdprod")
238-
assert os.path.exists("stdprod/FHed_1791a7b9-1791a931.gz")
239-
assert os.path.exists("stdprod/FHee_1791a7b9-1791a92f.gz")
240-
assert os.path.exists("stdprod/FHef_1791a7b9-1791a92f.gz")
241-
shutil.rmtree("stdprod")
239+
with tempfile.TemporaryDirectory() as tmpdir:
240+
Heasarc.enable_cloud(provider='aws', profile=None)
241+
Heasarc.download_data(tab, host="aws", location=tmpdir)
242+
assert os.path.exists(f"{tmpdir}/stdprod")
243+
assert os.path.exists(f"{tmpdir}/stdprod/FHed_1791a7b9-1791a931.gz")
244+
assert os.path.exists(f"{tmpdir}/stdprod/FHee_1791a7b9-1791a92f.gz")
245+
assert os.path.exists(f"{tmpdir}/stdprod/FHef_1791a7b9-1791a92f.gz")
242246

243247
def test_query_mission_columns(self):
244248
with pytest.warns(AstropyDeprecationWarning):

0 commit comments

Comments
 (0)