MMP#

Interface to numpy memmaps

Note

For image processing we use [x,y,z] order of arrays. To speed up access to z-planes memmaps are created in Fortran order by default.

class Source(location=None, shape=None, dtype=None, order=None, array=None, mode=None, name=None)[source]#

Bases: Source

Memory mapped array source.

as_buffer()[source]#
as_virtual()[source]#

Return virtual source without array data to pass in parallel processing.

Returns

sourceSource class

The source class without array data.

property array#

The underlying data array.

Returns

arrayarray or np.ndarray

The underlying data array of this source.

property dtype#

The data type of the source.

Returns

dtypedtype

The data type of the source.

property location#

The location where the data of the source is stored.

Returns

locationstr or None

Returns the location of the data source or None if this source lives in memory only.

property mode#
property offset#

The offset of the memory map in the file.

Returns

offsetint

Offset of the memory map in the file.

property order#

The order of how the data is stored in the source.

Returns

orderstr

Returns ‘C’ for C contiguous and ‘F’ for Fortran contiguous, None otherwise.

class VirtualSource(source=None, shape=None, dtype=None, order=None, name=None, mode=None)[source]#

Bases: VirtualSource

Virtual memory map source.

as_real()[source]#

Default: reopen from location with mode. Override in modules that need extra constructor args.

property array#
create(location=None, shape=None, dtype=None, order=None, mode=None, array=None, as_source=True, **kwargs)[source]#

Create a memory map.

Arguments

locationstr

The filename of the memory mapped array.

shapetuple or None

The shape of the memory map to create.

dtypedtype

The data type of the memory map.

order‘C’, ‘F’, or None

The contiguous order of the memmap.

mode‘r’, ‘w’, ‘w+’, None

The mode to open the memory map.

arrayarray, Source or None

Optional source with data to fill the memory map with.

as_sourcebool

If True, return as Source class.

Returns

memmapnp.memmap

The memory map.

Note

By default memmaps are initialized as Fortran contiguous if order is None.

edit(source, **kwargs)[source]#

Open an existing memmap for in-place modification.

header_size(filename)[source]#

Return the offset of a header in a memmaped file.

Arguments

filenamestr

Filename of the npy fie.

Returns

offsetint

The offest due to the header.

is_memmap(source)[source]#
open_ro(source, **kwargs)[source]#

Open a source strictly read-only for metadata queries.

read(source, slicing=None, mode=None, **kwargs)[source]#

Read data from a memory mapped source.

Arguments

sourcestr, memmap, or Source

The source to read the data from.

slicingslice specification

Optional slice specification of memmap to read from.

modestr

Optional mode specification of how to open the memmap.

Returns

sourceSource

The read memmap source.

write(sink, data, slicing=None, **kwargs)[source]#

Write data to a memory map.

Arguments

sinkstr, memmap, or Source

The sink to write the data to.

dataarray

The data to write int the sink.

slicingslice specification or None

Optional slice specification of an existing memmap to write to.

Returns

sinkstr, memmap, or Source

The sink.