Skip to content

Commit 9328685

Browse files
committed
fix-3269: add support for rows in heasarc.download_data
1 parent 469aea4 commit 9328685

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

astroquery/heasarc/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import tarfile
77
import warnings
88
import numpy as np
9-
from astropy.table import Table
9+
from astropy.table import Table, Row
1010
from astropy import coordinates
1111
from astropy import units as u
1212
from astropy.utils.decorators import deprecated, deprecated_renamed_argument
@@ -582,7 +582,7 @@ def download_data(self, links, host='heasarc', location='.'):
582582
583583
Parameters
584584
----------
585-
links : `astropy.table.Table`
585+
links : `astropy.table.Table` or `astropy.table.Row`
586586
The result from locate_data
587587
host : str
588588
The data host. The options are: heasarc (default), sciserver, aws.
@@ -603,6 +603,9 @@ def download_data(self, links, host='heasarc', location='.'):
603603
if len(links) == 0:
604604
raise ValueError('Input links table is empty')
605605

606+
if isinstance(links, Row):
607+
links = links.table[[links.index]]
608+
606609
if host not in ['heasarc', 'sciserver', 'aws']:
607610
raise ValueError('host has to be one of heasarc, sciserver, aws')
608611

astroquery/heasarc/tests/test_heasarc.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,25 @@ def test_download_data__outside_sciserver():
332332
)
333333

334334

335+
def test_download_data__table_row():
336+
with tempfile.TemporaryDirectory() as tmpdir:
337+
datadir = f'{tmpdir}/data'
338+
downloaddir = f'{tmpdir}/download'
339+
os.makedirs(datadir, exist_ok=True)
340+
with open(f'{datadir}/file.txt', 'w') as fp:
341+
fp.write('data')
342+
# include both a file and a directory
343+
tab = Table({'sciserver': [f'{tmpdir}/data/file.txt', f'{tmpdir}/data']})
344+
# The patch is to avoid the test that we are on sciserver
345+
with patch('os.path.exists') as exists:
346+
exists.return_value = True
347+
Heasarc.download_data(tab[0], host="sciserver", location=downloaddir)
348+
Heasarc.download_data(tab[1], host="sciserver", location=downloaddir)
349+
assert os.path.exists(f'{downloaddir}/file.txt')
350+
assert os.path.exists(f'{downloaddir}/data')
351+
assert os.path.exists(f'{downloaddir}/data/file.txt')
352+
353+
335354
# S3 mock tests
336355
s3_bucket = "nasa-heasarc"
337356
s3_key1 = "some/location/file1.txt"

docs/heasarc/heasarc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ The first gives the url to the data from the main heasarc server. The second giv
201201
the local path to the data on Sciserver. The last gives the S3 URI to the data in the cloud.
202202
You can specify where the data are to be downloaded using the ``location`` parameter.
203203

204-
To download the data, you can pass ``links`` table to `~astroquery.heasarc.HeasarcClass.download_data`,
204+
To download the data, you can pass ``links`` table (or row) to `~astroquery.heasarc.HeasarcClass.download_data`,
205205
specifying from where you want the data to be fetched by specifying the ``host`` parameter. By default,
206206
the data is fetched from the main HEASARC servers.
207207
The recommendation is to use different hosts depending on where your code is running:

0 commit comments

Comments
 (0)