Utility Types in MatNWB

Note

Documentation for “untyped” types will be added soon

“Untyped” Utility types are tools which allow for both flexibility as well as limiting certain constraints that are imposed by the NWB schema. These types are commonly stored in the +types/+untyped/ package directories in your MatNWB installation.

Sets and Anons

The Set (types.untyped.Set or Constrained Sets) is used to capture a dynamic number of particular NWB-typed objects. They may contain certain type constraints on what types are allowable to be set. Set keys and values can be set and retrieved using their set and get methods:

value = someSet.get('key name');
someSet.set('key name', value);

Note

Sets also borrow containers.Map’s keys and values methods to retrieve cell arrays of either.

The Anon type (types.untyped.Anon) can be understood as a Set type with only a single key-value entry. This rarer type is only used for cases where the name for the stored object can be set by the user. Anon types may also hold NWB type constraints like Set.

DataStubs and DataPipes

When working with NWB files, datasets can be very large (gigabytes or more). Loading all this data into memory at once would be impractical or impossible. MatNWB uses two types to handle on-disk data efficiently: DataStubs and DataPipes.

DataStubs (Read only)

A DataStub (types.untyped.DataStub) represents a read-only reference to data stored in an NWB file. When you read an NWB file, non-scalar and multi-dimensional datasets are automatically represented as DataStubs rather than loaded into memory.

https://github.com/NeurodataWithoutBorders/nwb-overview/blob/main/docs/source/img/matnwb_datastub.png?raw=true

Key characteristics:

  • Lazy loading: Data remains on disk until you explicitly access it

  • Memory efficient: Only the portions you request are loaded

  • MATLAB-style indexing: Access data using familiar syntax like dataStub(1:100, :)

  • Read-only: Cannot be used to modify or write data

You’ll encounter DataStubs whenever you read existing NWB files containing non-scalar or multi-dimensional datasets.

DataPipes (read and write)

A DataPipe (types.untyped.DataPipe) extends the concept of lazy data access to support writing as well as reading. While DataStubs are created automatically when reading files, you create DataPipes explicitly when writing data.

Key characteristics:

  • Bidirectional: Supports both reading and writing operations

  • Incremental writing: Stream data to disk in chunks rather than all at once

  • Compression support: Apply HDF5 compression and chunking strategies

  • Write optimization: Configure how data is stored on disk for better performance

DataPipes solve the problem of writing datasets that are too large to fit in memory, or when you want fine-grained control over how data is stored in the HDF5 file.

See also