Skip to content

Commit b024ff7

Browse files
committed
Adding file_format kwarg to obtain other formats
1 parent 2f3dbcb commit b024ff7

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

astroquery/ipac/ned/core.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ def get_spectra_async(self, object_name, get_query_payload=False,
450450
show_progress=show_progress)
451451
for U in image_urls]
452452

453-
def get_image_list(self, object_name, item='image',
453+
def get_image_list(self, object_name, *, item='image', file_format='fits',
454454
get_query_payload=False):
455455
"""
456456
Helper function that returns a list of urls from which to download
@@ -466,6 +466,10 @@ def get_image_list(self, object_name, item='image',
466466
item : str, optional
467467
Can be either 'image' or 'spectra'. Defaults to 'image'.
468468
Required to decide the right URL to query.
469+
file_format : str, optional
470+
Format of images/spectra to return. Defaults to 'fits'.
471+
Other options available: 'author-ascii', 'NED-ascii', 'VO-table'.
472+
469473
470474
Returns
471475
-------
@@ -483,9 +487,9 @@ def get_image_list(self, object_name, item='image',
483487
url = Ned.SPECTRA_URL if item == 'spectra' else Ned.IMG_DATA_URL
484488
response = self._request("GET", url=url, params=request_payload,
485489
timeout=Ned.TIMEOUT)
486-
return self.extract_image_urls(response.text)
490+
return self.extract_image_urls(response.text, file_format=file_format)
487491

488-
def extract_image_urls(self, html_in):
492+
def extract_image_urls(self, html_in, file_format='fits'):
489493
"""
490494
Helper function that uses regexps to extract the image urls from the
491495
given HTML.
@@ -495,10 +499,25 @@ def extract_image_urls(self, html_in):
495499
html_in : str
496500
source from which the urls are to be extracted
497501
502+
format : str, optional
503+
Format of spectra to return. Defaults to 'fits'.
504+
Other options available: 'author-ascii', 'NED-ascii', 'VO-table'.
505+
498506
"""
499507
base_url = 'http://ned.ipac.caltech.edu'
508+
509+
extensions = {'fits': 'fits.gz',
510+
'author-ascii': 'txt',
511+
'NED-ascii': '_NED.txt',
512+
'VO-table': '_votable.xml'}
513+
514+
names = {'fits': 'FITS',
515+
'author-ascii': 'Author-ASCII',
516+
'NED-ascii': 'NED-ASCII',
517+
'VO-table': 'VOTable'}
518+
500519
pattern = re.compile(
501-
r'<a\s+href\s*?="?\s*?(.+?fits.gz)"?\s*?>\s*?(?:Retrieve|FITS)</a>',
520+
f'<a\s+href\s*?="?\s*?(.+?{extensions[file_format]})"?\s*?>\s*?(?:Retrieve|{names[file_format]})</a>',
502521
re.IGNORECASE)
503522
matched_urls = pattern.findall(html_in)
504523
url_list = [base_url + img_url for img_url in matched_urls]

0 commit comments

Comments
 (0)