MemmapData#

class MemmapData(filename, shape, *, dtype=dtype('float32'), mode='r+', order='F', transposed=False, temporary=False, debug=False, _backing=None)#

Bases: object

NumPy-compatible handle for channel-major EEG data stored on disk.

Indexing uses the logical EEG shape and ordinary zero-based NumPy rules. Out-of-range indices raise, and assigning an empty array does not delete. matlab_assign and delete implement EEGLAB @mmo subscript behaviour: growth, empty-assignment deletion, and find on logical masks. transposed=True maps EEGLAB .dat-style storage whose physical axes are (samples, trials, channels) without exposing that layout to callers. Explicit and deep copies share the backing file until a copy is mutated, at which point that handle gets a private temporary file.

Parameters:
  • filename (str | Path)

  • shape (tuple[int, ...])

  • dtype (np.dtype | str)

  • mode (str)

  • order (str)

  • transposed (bool)

  • temporary (bool)

  • debug (bool)

  • _backing (_BackingFile | None)

classmethod empty(shape, *, filename=None, dtype=dtype('float32'), order='F', transposed=False, temporary=None, fill_value=0.0)#

Create a writable disk-backed array initialized to fill_value.

Parameters:
Return type:

MemmapData

classmethod from_array(data, *, filename=None, dtype=dtype('float32'), order='F', transposed=False, temporary=None)#

Write an array to disk and return a logical memory-mapped view.

Parameters:
Return type:

MemmapData

property filename: str#

Return the backing file path as a string.

property path: Path#

Return the backing file path.

property dataFile: str#

Return the backing path using EEGLAB’s mmo field name.

property dimensions: tuple[int, ...]#

Return the logical dimensions using EEGLAB’s mmo field name.

property writable: bool#

Return whether writes are permitted for this handle.

property shape: tuple[int, ...]#

Return the EEG-shaped array dimensions.

property dtype: dtype#

Return the backing file dtype.

property ndim: int#

Return the number of EEG data dimensions.

property size: int#

Return the total sample count.

property T: ndarray#

Return a transposed array view.

flush()#

Flush pending writes to the backing file.

Return type:

None

close()#

Flush and release the backing memory map handle.

Return type:

None

copy(order='C')#

Return an in-memory copy of the mapped data.

Parameters:

order (str)

Return type:

ndarray

mapped_copy()#

Return an independent writable disk-backed copy.

Return type:

MemmapData

resize(shape, *, fill_value=0.0)#

Resize this mapping, retaining the overlapping logical data region.

Resizing writes a private replacement sidecar. The original sidecar is never resized underneath another handle.

Parameters:
Return type:

None

delete(indices, *, axis=None)#

Delete logical indices and replace the sidecar with the smaller data.

axis=None follows column-major linear deletion. Matrix results become row vectors, while column-vector inputs remain columns. Deletion along axis addresses that axis of the full array and does not fold trailing dimensions. A boolean mask is converted with find first: only True positions are removed, and an all-false mask is a no-op.

Parameters:
  • indices (Any)

  • axis (int | None)

Return type:

None

change_file(filename, *, writable=False)#

Move a private mapping, or copy a shared mapping, to filename.

Parameters:
Return type:

None

reshape(*shape, **kwargs)#

Return a reshaped view using NumPy’s reshape semantics.

Parameters:
Return type:

ndarray

astype(*args, **kwargs)#

Return a typed array using NumPy’s astype semantics.

Parameters:
Return type:

ndarray

sum(*args, **kwargs)#

Return NumPy’s sum over the mapped data.

Parameters:
Return type:

Any

mean(*args, **kwargs)#

Return NumPy’s mean over the mapped data.

Parameters:
Return type:

Any

matlab_assign(key, value)#

Assign using EEGLAB @mmo subscript rules.

Numeric indices past the end grow that axis and fill the new samples with zeros. An empty value deletes the indexed entries. A key shorter than the array rank folds trailing dimensions together before that deletion, so two subscripts on a channels-by-samples-by-trials array address channels by samples-times-trials. A boolean mask is converted with find: only True positions are removed, and an all-false mask leaves the mapping unchanged.

With debug=True, a write prints using same copy when it updates the current file, new copy created when copy-on-write replaces it, and new copy created, old deleted when growth or deletion replaces the file. Ordinary [] indexing does not grow, delete, or print.

Parameters:
Return type:

None