@@ -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 ]
0 commit comments