Skip to content

Commit 4c7b652

Browse files
authored
Merge pull request #2217 from bsipocz/ned_add_fileformat_option
Add file_format option for Ned.get_image_list()
2 parents 1b241d5 + bc6289b commit 4c7b652

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ gaia
2222
- The bug which caused changing the ``MAIN_GAIA_TABLE`` option to have no
2323
effect has been fixed [#2153]
2424

25+
ipac.ned
26+
^^^^^^^^
27+
28+
- Keyword 'file_format' is added to ``get_image_list`` to enable obtaining
29+
links to non-fits file formats, too. [#2217]
30+
2531
vizier
2632
^^^^^^
2733

astroquery/ipac/ned/core.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ def get_spectra_async(self, object_name, get_query_payload=False,
427427
show_progress=True):
428428
"""
429429
Serves the same purpose as `~NedClass.get_spectra` but returns
430-
file-handlers to the remote files rather than downloading them.
430+
file-handlers to the remote fits files rather than downloading them.
431431
432432
Parameters
433433
----------
@@ -443,14 +443,15 @@ def get_spectra_async(self, object_name, get_query_payload=False,
443443
444444
"""
445445
image_urls = self.get_image_list(object_name, item='spectra',
446-
get_query_payload=get_query_payload)
446+
get_query_payload=get_query_payload,
447+
file_format='fits')
447448
if get_query_payload:
448449
return image_urls
449450
return [commons.FileContainer(U, encoding='binary',
450451
show_progress=show_progress)
451452
for U in image_urls]
452453

453-
def get_image_list(self, object_name, item='image',
454+
def get_image_list(self, object_name, *, item='image', file_format='fits',
454455
get_query_payload=False):
455456
"""
456457
Helper function that returns a list of urls from which to download
@@ -466,6 +467,10 @@ def get_image_list(self, object_name, item='image',
466467
item : str, optional
467468
Can be either 'image' or 'spectra'. Defaults to 'image'.
468469
Required to decide the right URL to query.
470+
file_format : str, optional
471+
Format of images/spectra to return. Defaults to 'fits'.
472+
Other options available: 'author-ascii', 'NED-ascii', 'VO-table'.
473+
469474
470475
Returns
471476
-------
@@ -483,9 +488,9 @@ def get_image_list(self, object_name, item='image',
483488
url = Ned.SPECTRA_URL if item == 'spectra' else Ned.IMG_DATA_URL
484489
response = self._request("GET", url=url, params=request_payload,
485490
timeout=Ned.TIMEOUT)
486-
return self.extract_image_urls(response.text)
491+
return self._extract_image_urls(response.text, file_format=file_format)
487492

488-
def extract_image_urls(self, html_in):
493+
def _extract_image_urls(self, html_in, file_format='fits'):
489494
"""
490495
Helper function that uses regexps to extract the image urls from the
491496
given HTML.
@@ -495,10 +500,25 @@ def extract_image_urls(self, html_in):
495500
html_in : str
496501
source from which the urls are to be extracted
497502
503+
format : str, optional
504+
Format of spectra to return. Defaults to 'fits'.
505+
Other options available: 'author-ascii', 'NED-ascii', 'VO-table'.
506+
498507
"""
499508
base_url = 'http://ned.ipac.caltech.edu'
509+
510+
extensions = {'fits': 'fits.gz',
511+
'author-ascii': 'txt',
512+
'NED-ascii': '_NED.txt',
513+
'VO-table': '_votable.xml'}
514+
515+
names = {'fits': 'FITS',
516+
'author-ascii': 'Author-ASCII',
517+
'NED-ascii': 'NED-ASCII',
518+
'VO-table': 'VOTable'}
519+
500520
pattern = re.compile(
501-
r'<a\s+href\s*?="?\s*?(.+?fits.gz)"?\s*?>\s*?(?:Retrieve|FITS)</a>',
521+
f'<a\s+href\s*?="?\s*?(.+?{extensions[file_format]})"?\s*?>\s*?(?:Retrieve|{names[file_format]})</a>',
502522
re.IGNORECASE)
503523
matched_urls = pattern.findall(html_in)
504524
url_list = [base_url + img_url for img_url in matched_urls]

astroquery/ipac/ned/tests/test_ned.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def test_photometry(patch_get):
141141

142142
def test_extract_image_urls():
143143
html_in = open(data_path(DATA_FILES['extract_urls']), 'r').read()
144-
url_list = ned.core.Ned.extract_image_urls(html_in)
144+
url_list = ned.core.Ned._extract_image_urls(html_in)
145145
assert len(url_list) == 5
146146
for url in url_list:
147147
assert url.endswith('fits.gz')

astroquery/ipac/ned/tests/test_ned_remote.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,11 @@ def test_get_object_notes_async(self):
9393
def test_get_object_notes(self):
9494
result = ned.core.Ned.get_table('3c 273', table='object_notes')
9595
assert isinstance(result, Table)
96+
97+
def test_file_format(self):
98+
result_ascii = ned.core.Ned.get_image_list('NGC6060', item='spectra',
99+
file_format='NED-ascii')
100+
result_fits = ned.core.Ned.get_image_list('NGC6060', item='spectra',
101+
file_format='fits')
102+
assert len(result_ascii) == 3
103+
assert len(result_fits) == 1

0 commit comments

Comments
 (0)