def download_hdulist(self, uri, **kwargs):
        """
        Downloads a FITS image as a HDUList.

        Args:
          uri: The URI of the FITS image to download.
          kwargs: optional arguments to pass to the vos client.
            For example, passing view="cutout" and cutout=[1] will result
            in a cutout of extension 1 from the FITS image specified by the
            URI.

        Returns:
          hdulist: astropy.io.fits.hdu.hdulist.HDUList
            The requests FITS image as an Astropy HDUList object
            (http://docs.astropy.org/en/latest/io/fits/api/hdulists.html).
        """

        logger.debug(str(kwargs))
        hdulist = None
        try:
            vobj = storage.vofile(uri, **kwargs)
            try:
                fobj = cStringIO.StringIO(vobj.read())
                fobj.seek(0)
                hdulist = fits.open(fobj)
            except Exception as e:
                sys.stderr.write("ERROR: {}\n".format(str(e)))
                sys.stderr.write("While loading {} {}\n".format(uri, kwargs))
                pass
            finally:
                vobj.close()
        except Exception as e:
            sys.stderr.write(str(e)+"\n")
            sys.stderr.write("While opening connection to {}.\n".format(uri))
            sys.stderr.write("Sending back FLAT instead, too keep display happy.")
            hdulist = self.download_hdulist('vos:OSSOS/dbimages/calibrators/13AQ05_r_flat.fits', **kwargs)
        return hdulist
def download_hdulist ( self , uri , ** kwargs ) : logger . debug ( str ( kwargs ) ) hdulist = None try : vobj = storage . vofile ( uri , ** kwargs ) try : fobj = cStringIO . StringIO ( vobj . read ( ) ) fobj . seek ( 0 ) hdulist = fits . open ( fobj ) except Exception as e : sys . stderr . write ( "ERROR: {}\n" . format ( str ( e ) ) ) sys . stderr . write ( "While loading {} {}\n" . format ( uri , kwargs ) ) pass finally : vobj . close ( ) except Exception as e : sys . stderr . write ( str ( e ) + "\n" ) sys . stderr . write ( "While opening connection to {}.\n" . format ( uri ) ) sys . stderr . write ( "Sending back FLAT instead, too keep display happy." ) hdulist = self . download_hdulist ( 'vos:OSSOS/dbimages/calibrators/13AQ05_r_flat.fits' , ** kwargs ) return hdulist
Downloads a FITS image as a HDUList.

        Args:
          uri: The URI of the FITS image to download.
          kwargs: optional arguments to pass to the vos client.
            For example, passing view="cutout" and cutout=[1] will result
            in a cutout of extension 1 from the FITS image specified by the
            URI.

        Returns:
          hdulist: astropy.io.fits.hdu.hdulist.HDUList
            The requests FITS image as an Astropy HDUList object
            (http://docs.astropy.org/en/latest/io/fits/api/hdulists.html).