Hi,
Pyfits.open() supports memmap for reading FITS files (and this is the
default). However, you'll still need to have the memory to write the array.
I seriously doubt that this is a memory exhaustion problem. Your initial
14 2Kx2K images in int16 occupy only 112 Mb, so unless your computer is
really old, this is not the issue...
Looking in your initial code it seems the problem is that you're
appending arrays to a list and then converting to an array again before
writing. This is very inefficient.
In your last example you hit the limit at 156 images, which is 1248 Mb
-- a much more plausible value for a RAM limit. Given that you still hit
a limit, I would say that the memmap is not being useful. It is still
having to copy the full datacube in memory when you do the write. If the
memmap was working properly, there would be no limit.
For simplicity and future reference I suggest doing away with the memmap
in this case and just do something like:
dataTmp = numpy.empty((N, 2048, 2048), dtype='int16')
for i, fname in enumerate(files):
dataTmp[i] = pyfits.getdata(fname)
pyfits.writeto("results.fits", clobber=True)
del dataTmp
As others mentioned, large FITS datacubes are not a good idea. I much
prefer having several extensions for different images. Also, if you have
a datacube with more than 2Gb, people with 32-bit systems won't be able
to read them.
For a true memory-independent solution to your problem, I would be
tempted to do what you call 'binary hacking'. It wouldn't be very hard
because a fits file is essentially an ascii header with the binary data.
I suspect it would take less than 20 lines of python code to implement
something like that, write the header and then use memmap for the binary
part.
Cheers,
Tiago
> --
> You received this message because you are subscribed to the Google
> Groups "SunPy" group.
> To view this discussion on the web visit
>
https://groups.google.com/d/msg/sunpy/-/niibICWsU44J.