ccpem/mrcfile

accessing specific slice from a memmap

martinschorb opened this issue · 2 comments

Hi,

we are often dealing with tiled montage maps of grid squares stored as a stack of montages/mosaics in a single MRC file. These can than easily go into several GB of file size.

I now like to extract only single slices for processing and was looking into the memmaps to do this efficiently.

I tried
mm._open_memmap(dtype='int16',shape=(mm.header.nx,mm.header.ny,mm.header.nz))
giving me a 'NoneType' object back.

How do I access data blocks properly? I could get it directly with _read_data but to get there I would need to specify the exact byte offset. What is the proper wrapper to do it?

Thanks a lot,
Martin

OK,

I just found calling dataon a memmap returns a np.memmap. I guess I wouold then just extract my slices using indeces there...

Glad to hear you found the answer! There's a section in the usage guide about using memmap files which will give you a bit more information: https://mrcfile.readthedocs.io/en/latest/usage_guide.html#memory-mapped-files

mrcfile uses the standard Python convention that the "public" API uses normal names while "internal" methods start with a leading underscore. In general you should be able to do everything you need without calling things like _open_memmap(). (Though it is a useful feature of Python that you can dig into the internals when you really need to!)