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: ClearMap.IO.NPY.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

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 name

The name of this source.

Returns

namestr

Name of this source.

property offset

The offset of the memory map in the file.

Returns

offsetint

Offset of the memeory map in the file.

property order

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

Returns

orderstr

Returns ‘C’ for C contigous and ‘F’ for fortran contigous, None otherwise.

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

Bases: ClearMap.IO.Source.VirtualSource

Virtual memory map source.

as_buffer()[source]
as_real()[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
property name

The name of this source.

Returns

namestr

Name of this source.

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.

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]
read(source, slicing=None, mode=None, **kwargs)[source]

Write data to a memory map.

Arguments

sinkstr, memmap, or Source

The sink to write the data to.

slicingslice specification

Optional slice specification of memmap to read from.

modestr

Optional mode spcification 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.