Exemple #1
0
    def test_read_file_like_object(self):
        """Test reading a FITS file from a file-like object."""

        filelike = BytesIO()
        with open(self.data('test0.fits'), 'rb') as f:
            filelike.write(f.read())
        filelike.seek(0)
        with ignore_warnings():
            assert len(fits.open(filelike)) == 5
Exemple #2
0
    def test_read_file_like_object(self):
        """Test reading a FITS file from a file-like object."""

        filelike = BytesIO()
        with open(self.data("test0.fits"), "rb") as f:
            filelike.write(f.read())
        filelike.seek(0)
        with ignore_warnings():
            assert_equal(len(pyfits.open(filelike)), 5)
Exemple #3
0
 def hdulist(self):
     self._file.seek(self._datLoc)
     fileobj = BytesIO()
     # Read the data into a BytesIO--reading directly from the file
     # won't work (at least for gzipped files) due to problems deep
     # within the gzip module that make it difficult to read gzip files
     # embedded in another file
     fileobj.write(self._file.read(self.size))
     fileobj.seek(0)
     if self._header['COMPRESS']:
         fileobj = gzip.GzipFile(fileobj=fileobj)
     return HDUList.fromfile(fileobj, mode='readonly')
Exemple #4
0
    def test_streaming_hdu_write_file_like(self):
        """Test streaming an HDU to an open file-like object."""

        arr = np.zeros((5, 5), dtype=np.int32)
        # The file-like object underlying a StreamingHDU must be in binary mode
        sf = BytesIO()
        shdu = self._make_streaming_hdu(sf)
        shdu.write(arr)
        assert shdu.writecomplete
        assert shdu.size == 100

        sf.seek(0)
        hdul = fits.open(sf)
        assert len(hdul) == 1
        assert (hdul[0].data == arr).all()
Exemple #5
0
    def test_update_filelike(self):
        """Test opening a file-like object in update mode and resizing the
        HDU.
        """

        sf = BytesIO()
        arr = np.zeros((100, 100))
        hdu = pyfits.PrimaryHDU(data=arr)
        hdu.writeto(sf)

        sf.seek(0)
        arr = np.zeros((200, 200))
        hdul = pyfits.open(sf, mode='update')
        hdul[0].data = arr
        hdul.flush()

        sf.seek(0)
        hdul = pyfits.open(sf)
        assert_equal(len(hdul), 1)
        assert_true((hdul[0].data == arr).all())