alphabase.io.tempmmap

This module allows to create temporary memory-mapped arrays.

Functions:

array(shape, dtype[, tmp_dir_abs_path])

Create a writable temporary memory-mapped array.

clear()

Reset the temporary folder containing temp memory-mapped arrays and create a new one.

create_empty_mmap(shape, dtype[, file_path, ...])

Initialize a new HDF5 file compatible with mmap.

mmap_array_from_path(hdf_file)

reconnect to an exisiting HDF5 file to generate a writable temporary memory-mapped array.

ones(shape, dtype)

Create a writable temporary memory-mapped array filled with ones.

redefine_temp_location(path)

Redefine the location where the temp arrays are written to.

zeros(shape, dtype)

Create a writable temporary memory-mapped array filled with zeros.

alphabase.io.tempmmap.array(shape: tuple, dtype: dtype, tmp_dir_abs_path: str = None) ndarray[source][source]

Create a writable temporary memory-mapped array.

Parameters:
  • shape (tuple) – A tuple with the shape of the array.

  • dtype (type) – The np.dtype of the array.

  • tmp_dir_abs_path (str, optional) – If specified the memory mapped array will be created in this directory. An absolute path is expected. Defaults to None. If not specified the global TEMP_DIR_NAME location will be used.

Returns:

A writable temporary memory-mapped array.

Return type:

type

alphabase.io.tempmmap.clear() str[source][source]

Reset the temporary folder containing temp memory-mapped arrays and create a new one.

WARNING: All existing temp mmapp arrays will be unusable!

Returns:

The name of the new temporary folder.

Return type:

str

alphabase.io.tempmmap.create_empty_mmap(shape: tuple, dtype: dtype, file_path: str = None, overwrite: bool = False, tmp_dir_abs_path: str = None)[source][source]

Initialize a new HDF5 file compatible with mmap. Returns the path to the initialized file. File can be mapped using the mmap_array_from_path function.

Parameters:
  • shape (tuple) – A tuple with the shape of the array.

  • dtype (type) – The np.dtype of the array.

  • file_path (str, optional) – The absolute path to the file that should be created. This includes the file name. Defaults to None. If None a random file name will be generated in the default tempdir location.

  • overwrite (bool , optional) – If True the file will be overwritten if it already exists. Defaults to False.

  • tmp_dir_abs_path (str, optional) – If specified the default tempdir location will be updated to this path. Defaults to None. An absolute path to a directory is expected.

Returns:

path to the newly created file.

Return type:

str

alphabase.io.tempmmap.mmap_array_from_path(hdf_file: str) ndarray[source][source]

reconnect to an exisiting HDF5 file to generate a writable temporary memory-mapped array.

Parameters:

hdf_file (str) – path to the array that should be reconnected to.

Returns:

A writable temporary memory-mapped array.

Return type:

type

alphabase.io.tempmmap.ones(shape: tuple, dtype: dtype) ndarray[source][source]

Create a writable temporary memory-mapped array filled with ones.

Parameters:
  • shape (tuple) – A tuple with the shape of the array.

  • dtype (type) – The np.dtype of the array.

Returns:

A writable temporary memory-mapped array filled with ones.

Return type:

type

alphabase.io.tempmmap.redefine_temp_location(path: str) str[source][source]

Redefine the location where the temp arrays are written to.

Parameters:

path (string)

Returns:

the location of the new temporary directory.

Return type:

str

alphabase.io.tempmmap.zeros(shape: tuple, dtype: dtype) ndarray[source][source]

Create a writable temporary memory-mapped array filled with zeros.

Parameters:
  • shape (tuple) – A tuple with the shape of the array.

  • dtype (type) – The np.dtype of the array.

Returns:

A writable temporary memory-mapped array filled with zeros.

Return type:

type