You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using Astropy tables to cross match some galaxy catalogues and running in to memory issues on a university HPC. I wonder if there is any way to gain access to the memory mapping feature available with the general astropy.io.fits module. I like astropy.table because it is easy to display in notebooks but may have to stop using it because of memory issues. I may have to rewrite code to tile the sky for memory reasons anyway but wondered if there was an easy way to prevent astropy from loading the whole table into memory.
I'm not sure, I am going to try using astropy.io.fits instead of astropy.Table so I can see if opening fits files with memmap=True reduces the memory used. I wonder if anyone knows if astropy.Table inherits from astropy.io.fits and therefore if it defaults to memmap=True anyway.
@pllim - yes astropy Table does not support memory mapping, and indeed reading a FITS extension as a Table requires putting the whole thing in to memory.
I can imagine a relatively simple extension to the FITS connect code to allow reading in only a subset of the rows into a table.
So currently Table will put the whole table in to memory, but it should be possible to add optional arguments to specify a list of columns to include or exclude, to read only a few columns (as include_names and exclude_names for io.ascii). Thanks to memmap and using .field() to read to columns data, it should help reduce the memory usage I guess ?
I think this could be an important issue for making astropy competitive with stilts which is extremely memory efficient, particularly as future surveys promise to create larger and larger quantities of data. I plan to spend some effort on tiling the sky to deal with this issue but think it may be a long term project unless astropy does not aspire to handle 'big data'. I watch with interest. Thank you everyone for your help I guess it is sensible to close the topic now.
It should indeed be possible to have table columns be views on (parts of) the underlying fits table. It may not need more than adding and propagating a copy argument.
@saimn At the hardware level, mmap only works for starting at an offset and then extending for size bytes. There is no way to reduce the memory size, other than specifying chunks and then repeatedly processing these chunks in a loop.
Activity
pllim commentedon Aug 30, 2017
Will #6458 solve your problem?
raphaelshirley commentedon Aug 31, 2017
I'm not sure, I am going to try using astropy.io.fits instead of astropy.Table so I can see if opening fits files with memmap=True reduces the memory used. I wonder if anyone knows if astropy.Table inherits from astropy.io.fits and therefore if it defaults to memmap=True anyway.
pllim commentedon Aug 31, 2017
#3958 -- Looks like you cannot pass
memmapdirectly toTableyet.#1380 --
memmapmight not work in some modes.pllim commentedon Aug 31, 2017
The actual code that reads FITS into Table is in https://github.com/astropy/astropy/blob/master/astropy/io/fits/connect.py . While it is true that FITS reader defaults to
memmap=True, the part where FITS data is parsed into a Table would require the entire table to be read into memory (maybe @taldcroft can confirm). So it is possible to only load one extension at a time, but you cannot load only part of the same extension.p.s. Please correct me if I am wrong!
taldcroft commentedon Aug 31, 2017
@pllim - yes astropy Table does not support memory mapping, and indeed reading a FITS extension as a Table requires putting the whole thing in to memory.
I can imagine a relatively simple extension to the FITS connect code to allow reading in only a subset of the rows into a table.
@pllim - as a side note, is the default for
memmapTrue? The docs say it isNone, but they don't indicate what that implies. http://astropy.readthedocs.io/en/latest/io/fits/api/files.html#astropy.io.fits.openpllim commentedon Aug 31, 2017
The logic is in https://github.com/astropy/astropy/blob/master/astropy/io/fits/file.py . I followed a few branches of the logic and seems to me default is
Truefor "normal" cases? Feel free to double check.I also opened a file locally and checked for my use case:
saimn commentedon Aug 31, 2017
memmapis True by default, since PyFITS 3.1. It isNonein thefits.opensignature because there is also a config item and it allows to check if it is explicitly set toTrue(https://github.com/astropy/astropy/blob/astropy/io/fits/hdu/hdulist.py#L141)saimn commentedon Aug 31, 2017
So currently
Tablewill put the whole table in to memory, but it should be possible to add optional arguments to specify a list of columns to include or exclude, to read only a few columns (asinclude_namesandexclude_namesforio.ascii). Thanks to memmap and using.field()to read to columns data, it should help reduce the memory usage I guess ?raphaelshirley commentedon Sep 1, 2017
I think this could be an important issue for making astropy competitive with stilts which is extremely memory efficient, particularly as future surveys promise to create larger and larger quantities of data. I plan to spend some effort on tiling the sky to deal with this issue but think it may be a long term project unless astropy does not aspire to handle 'big data'. I watch with interest. Thank you everyone for your help I guess it is sensible to close the topic now.
embray commentedon Oct 12, 2017
I'm not clear on why
Tablewouldn't take advantage of this. Can't it load a column from a FITS table without making a copy?astrofrog commentedon Oct 12, 2017
I have the same question as @embray - why can't we support memory mapping?
mhvk commentedon Oct 14, 2017
It should indeed be possible to have table columns be views on (parts of) the underlying fits table. It may not need more than adding and propagating a
copyargument.manodeep commentedon May 1, 2018
@saimn At the hardware level,
mmaponly works for starting at anoffsetand then extending forsizebytes. There is no way to reduce the memory size, other than specifyingchunksand then repeatedly processing thesechunksin a loop.pllim commentedon Feb 20, 2019
So, did #6821 fix this?
saimn commentedon Feb 20, 2019
Probably, since it is now possible to use memmap with
Table.read.