I’m trying to load into memory a few 2 000 FITS using astropy.io.fits
:
def readfits(filename):
with fits.open(filename) as ft:
# the fits contain a single HDU
data = ft[0].data
return data
data_sci = []
for i in range(2000):
data_sci.append(readfits("filename_{}.fits".format(i)))
However, when reaching the 1015th file, OSError: [Errno 24] Too many open
files
is raised.
I have the same issue with:
def readfits(filename):
ft = fits.open(filename) as ft:
data = ft[0].data
ft.close()
return data
I suspect that astropy.io.fits
does not properly close the file. Is there a
way I can force the files to be closed?
del
. I simply replaced the linedata = ft[0].data
withdata = ft[0].data.copy()
instead. – Percept