我試圖打開一個大的IDL產生的擬合數據立方體(159,2,4096,4096):發生Python的開幕大擬合數據緩衝區大小錯誤
In [37]: hdulist = fits.open('/randpath/randname1.fits')
In [38]: hdulist.info()
Filename: /randpath/randname1.fits
No. Name Type Cards Dimensions Format
0 PRIMARY PrimaryHDU 11 (159, 2, 4096, 4096) float32
In [39]: scidata = hdulist[0].data
以下錯誤:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-39-d492d4e07eb1> in <module>()
----> 1 scidata = hdulist[0].data
/opt/local/anaconda/anaconda-2.2.0/lib/python2.7/site-packages/astropy/utils/decorators.py in __get__(self, obj, owner)
513 return obj.__dict__[self._key]
514 except KeyError:
--> 515 val = self.fget(obj)
516 obj.__dict__[self._key] = val
517 return val
/opt/local/anaconda/anaconda-2.2.0/lib/python2.7/site-packages/astropy/io/fits/hdu/image.py in data(self)
206 return
207
--> 208 data = self._get_scaled_image_data(self._data_offset, self.shape)
209 self._update_header_scale_info(data.dtype)
210
/opt/local/anaconda/anaconda-2.2.0/lib/python2.7/site-packages/astropy/io/fits/hdu/image.py in _get_scaled_image_data(self, offset, shape)
619 code = BITPIX2DTYPE[self._orig_bitpix]
620
--> 621 raw_data = self._get_raw_data(shape, code, offset)
622 raw_data.dtype = raw_data.dtype.newbyteorder('>')
623
/opt/local/anaconda/anaconda-2.2.0/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py in _get_raw_data(self, shape, code, offset)
566 offset=offset)
567 elif self._file:
--> 568 return self._file.readarray(offset=offset, dtype=code, shape=shape)
569 else:
570 return None
/opt/local/anaconda/anaconda-2.2.0/lib/python2.7/site-packages/astropy/io/fits/file.py in readarray(self, size, offset, dtype, shape)
272
273 return np.ndarray(shape=shape, dtype=dtype, offset=offset,
--> 274 buffer=self._mmap)
275 else:
276 count = reduce(lambda x, y: x * y, shape)
TypeError: buffer is too small for requested array
的平均陣列(2,4096,4096)效果很好:
In [40]: hdulist2 = fits.open('/randpath/randname1avg.fits')
In [41]: hdulist2.info()
Filename: /randpath/randname1avg.fits
No. Name Type Cards Dimensions Format
0 PRIMARY PrimaryHDU 10 (2, 4096, 4096) float32
In [42]: scidata2 = hdulist2[0].data
任何想法?由於某種原因,尺寸似乎很重要。 MATLAB無法打開第一個適合文件:
Warning: Seek failed, 'Offset is bad - after end-of-file or last character written.'. File may be an
invalid FITS file or corrupt. Output structure may not contain complete file information.
> In fitsinfo>skipHduData (line 721)
In fitsinfo (line 226)
In fitsread (line 99)
Error using fitsiolib
CFITSIO library error (108): error reading from FITS file
Error in matlab.io.fits.readImg (line 85)
imgdata = fitsiolib('read_subset',fptr,fpixel,lpixel,inc);
Error in fitsread>read_image_hdu (line 438)
data = fits.readImg(fptr);
Error in fitsread (line 125)
data = read_image_hdu(info,1,raw,pixelRegion);
IDL可以,原因不明。運行astropy.io工作流程時,陣列大小是否有限制?可以毫無問題地生成相同大小的隨機矩陣。我目前正在研究一臺256 GB內存的機器,因此內存不應該扮演角色,應該如何?感謝所有的幫助!
更新:第一次hdulist被加載的Python實際上給出了一些更有用的錯誤消息:
警告:文件可能已被截斷:實際的文件長度(4160755136)比預期的大小(21340624320)[小astropy.io.fits.file] 事實上,文件大小隻有3.9 GB,與預期的大約20 GB相反。我必須仔細檢查(對IDL沒有多少經驗),但由於某種原因,它(writefits)無法正確創建適合文件。
更新2:問題已解決。 IDL 6.2(安裝在機器上的舊版本)顯然不能處理太大的文件,IDL 8.3(這也是安裝的)可以。不知道爲什麼。
快速搜索主要錯誤消息「TypeError:緩衝區對於請求的數組來說太小」表示當文件損壞時可能會彈出此錯誤;當它太大時不是本身(儘管在這些情況下誤導性的,錯誤信息)。 MATLAB似乎也這麼認爲:FITS文件已損壞。看看你是否可以在另一個FITS閱讀器中打開它(例如,'fv',如果你有它),或者嘗試使用['fitsverify'](https://heasarc.gsfc.nasa.gov/docs/software/ftools/fitsverify /)工具。但是,將文件寫入磁盤時,實際上它聽起來像是IDL搞砸了。也許試試另一種格式,例如HDF5? – Evert
「文件大小僅爲3.9 GB,與預期的〜20 GB相反」:只是喊出32位(指針大小)限制。 – Evert