Io¶
btorch.io
¶
I/O utilities for serializing and loading simulation data.
This module provides helpers for converting between PyTorch tensors, nested dictionaries, and persistent storage formats (xarray/Zarr). Key features include:
- Sparse array encoding for efficient spike storage
- Dimension-aware serialization with flexible (time, batch, neuron) grouping
- Automatic handling of partial recordings on neuron subsets
- Compression and chunking for large datasets
- Option dataclasses:
DimLayout,SparseOptions,ZarrStoreOptions
Main entry points
memories_to_xarray: Convert nested dict to xr.Datasetxarray_to_memories: Restore nested dict from xr.Datasetsave_memories_to_xarray: Save dict directly to Zarrload_memories_from_xarray: Load dict from Zarr store
Attributes¶
__all__ = ['DimLayout', 'SparseOptions', 'ZarrStoreOptions', 'from_spike_sparse', 'load_memories_from_xarray', 'memories_to_xarray', 'save_memories_to_xarray', 'to_sparse_repr', 'xarray_to_memories']
module-attribute
¶
Classes¶
DimLayout
dataclass
¶
Dimension layout of a memories dictionary.
Attributes:
| Name | Type | Description |
|---|---|---|
dim_counts |
tuple[int, ...] | None
|
Number of physical dimensions per logical group in
|
dim_names |
tuple[str, ...]
|
Logical group names, in array order. |
hint_field |
str | None
|
Flattened (dot-separated) field name used as the shape template for dimension inference. |
strict_dims |
bool
|
If True, every variable must match the global dimension structure exactly. If False, lower-rank arrays (e.g. parameters) are allowed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in btorch/io/serialization.py
SparseOptions
dataclass
¶
Sparse COO encoding policy for spike arrays.
Attributes:
| Name | Type | Description |
|---|---|---|
spike_suffix |
str
|
Substring (case-insensitive) identifying spike arrays. |
spike_dtype |
Any
|
Dtype dense spike arrays are cast to when sparse-encoded. |
sparse_threshold |
float
|
Encode sparsely when |
force_sparse |
bool | tuple[str, ...]
|
True to force sparse encoding of all spike arrays, or the flattened variable names to force. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in btorch/io/serialization.py
ZarrStoreOptions
dataclass
¶
Compression, chunking and overwrite policy of a Zarr store.
Attributes:
| Name | Type | Description |
|---|---|---|
compression_level |
int
|
Zstd compression level (1-9, higher is smaller). |
chunks |
dict[str, int] | None
|
Chunk size per dimension, e.g. |
overwrite |
bool
|
If True overwrite an existing store, else fail if it exists. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in btorch/io/serialization.py
Functions:¶
from_spike_sparse(ds, var_name, return_sparse_2d=False)
¶
Reconstruct a dense or scipy sparse array from btorch sparse encoding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset containing the sparse-encoded variable. |
required |
var_name
|
str
|
Name of the sparse marker variable (the scalar with attrs). |
required |
return_sparse_2d
|
bool
|
If True and the original was 2D, return a scipy coo_array instead of dense numpy. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray | coo_array
|
A tuple of (array, used_variable_names). The array is either dense |
set[str]
|
numpy or scipy sparse (if 2D and requested). used_variable_names |
tuple[ndarray | coo_array, set[str]]
|
contains all dataset keys consumed during reconstruction. |
Shape semantics
- Output array has shape from
original_shapeattrs - Dense output: numpy array of original dtype
- Sparse output (2D only): scipy.sparse.coo_array
Source code in btorch/io/serialization.py
load_memories_from_xarray(path, dask=False, return_sparse_2d=False)
¶
Load a nested dictionary from a Zarr store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the Zarr store. |
required |
dask
|
bool
|
If True, return Dask-backed arrays (lazy loading). If False, load into memory immediately. |
False
|
return_sparse_2d
|
bool
|
If True, return 2D arrays as scipy sparse coo_array. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Nested dictionary with restored structure. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If |
Source code in btorch/io/serialization.py
memories_to_xarray(memories, layout=None, *, neuron_ids=None, partial_map=None, sparse=None)
¶
Convert a nested dictionary of simulation results into an xr.Dataset.
This function flattens a nested dictionary (e.g., from a simulation run containing spike trains, voltages, and synaptic states) and converts it into an xarray Dataset with consistent dimension naming and optional sparse encoding for spike arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memories
|
dict[str, Any]
|
Nested dictionary of arrays/tensors. Keys become variable names (dot-separated for nested dicts). |
required |
layout
|
DimLayout | None
|
Dimension counts/names, shape hint and strictness (see
:class: |
None
|
neuron_ids
|
Any | None
|
Optional neuron identifiers for |
None
|
partial_map
|
dict[str, Any] | None
|
Dict of |
None
|
sparse
|
SparseOptions | None
|
Sparse spike encoding policy (see :class: |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
xr.Dataset with all variables, coordinates, and sparse encodings. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a |
ImportError
|
If |
Example
memories = { ... "spike": torch.randn(100, 32, 128) > 0, # (T, B, N) ... "v": torch.randn(100, 32, 128), ... } ds = memories_to_xarray(memories, DimLayout(dim_counts=(1, 1, 1))) ds # Dataset with dims (time: 100, batch: 32, neuron: 128)
Source code in btorch/io/serialization.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |
save_memories_to_xarray(memories, path, layout=None, *, neuron_ids=None, partial_map=None, sparse=None, store=None)
¶
Save a nested dictionary to a Zarr store via xarray.
Convenience wrapper that converts the dictionary to a Dataset and saves with compression and optional chunking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memories
|
dict[str, Any]
|
Nested dictionary of arrays/tensors to save. |
required |
path
|
str | Path
|
Path to the output Zarr store. |
required |
layout
|
DimLayout | None
|
Dimension layout (see :class: |
None
|
neuron_ids
|
Any | None
|
Optional neuron identifiers. |
None
|
partial_map
|
dict[str, Any] | None
|
Partial recording indices for subset fields. |
None
|
sparse
|
SparseOptions | None
|
Sparse spike encoding policy (see :class: |
None
|
store
|
ZarrStoreOptions | None
|
Zarr compression, chunking and overwrite policy (see
:class: |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If |
ValueError
|
Propagated from :func: |
Exception
|
With |
Source code in btorch/io/serialization.py
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 | |
to_sparse_repr(val, var_dims, var_name)
¶
Convert a dense or sparse array to sparse COO representation for storage.
Supports arbitrary dtypes (float, int, bool). Only non-zero entries are stored. The returned dictionary contains index arrays per dimension and a data array, suitable for constructing an xr.Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
ndarray | spmatrix | sparray
|
Array to encode. Can be dense numpy or scipy sparse. |
required |
var_dims
|
Sequence[str]
|
Physical dimension names for this variable (e.g., ["time", "batch", "neuron"]). |
required |
var_name
|
str
|
Base name for the variable (used to name output keys). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary mapping variable names to (dims, data) tuples or xr.DataArray |
dict[str, Any]
|
coords. Keys include:
- |
Shape semantics
- Input array with shape
(*var_dims)andnnznon-zeros - Output index arrays: each has shape
(nnz,) - Output data array: shape
(nnz,), dtype preserved from input
Source code in btorch/io/serialization.py
xarray_to_memories(ds, return_sparse_2d=False)
¶
Convert an xr.Dataset back to a nested dictionary.
Reconstructs the original nested dictionary structure from a Dataset
created by memories_to_xarray. Handles sparse-encoded variables
automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset to convert (typically loaded from Zarr). |
required |
return_sparse_2d
|
bool
|
If True, return 2D arrays as scipy sparse coo_array instead of dense numpy. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Nested dictionary with restored variable names and structure. |
Example
ds = xr.open_zarr("simulation.zarr") memories = xarray_to_memories(ds) memories["spike"].shape # (T, B, N) or scipy sparse
Source code in btorch/io/serialization.py
btorch.io.serialization
¶
Serialization helpers for converting simulation data to xarray/Zarr format.
This module handles conversion of nested dictionaries (typically containing simulation "memories" like spike trains, voltages, and synaptic states) into xarray Datasets for storage and analysis.
Sparse Encoding Semantics¶
Arrays are encoded in sparse COO format when beneficial. For a variable
named spikes with shape (T, B, N) and nnz non-zero entries:
spikes: scalar marker with attrs{"_btorch_sparse": True, ...}spikes_idx_time: indices along time dim, shape(nnz,)spikes_idx_batch: indices along batch dim, shape(nnz,)spikes_idx_neuron: indices along neuron dim, shape(nnz,)spikes_data: actual values, shape(nnz,)
The sparse dimension is named _btorch_sparse_idx_{var_name} to avoid
collisions. Original dtype and shape are preserved in the marker attrs.
Shape Conventions¶
Dimension groups are specified via :class:DimLayout: dim_names (default:
("time", "batch", "neuron")) and dim_counts (how many physical
dimensions each logical group spans). For example:
dim_counts=(1, 1, 2)withdim_names=("time", "batch", "neuron")produces physical dims["time", "batch", "neuron_0", "neuron_1"]- A tensor of shape
(100, 32, 64, 64)would map as(time=100, batch=32, neuron_0=64, neuron_1=64)
Partial recordings (only a subset of neurons recorded) are expanded to full size by filling missing entries with NaN (float) or 0 (integer/bool).
Classes¶
DimLayout
dataclass
¶
Dimension layout of a memories dictionary.
Attributes:
| Name | Type | Description |
|---|---|---|
dim_counts |
tuple[int, ...] | None
|
Number of physical dimensions per logical group in
|
dim_names |
tuple[str, ...]
|
Logical group names, in array order. |
hint_field |
str | None
|
Flattened (dot-separated) field name used as the shape template for dimension inference. |
strict_dims |
bool
|
If True, every variable must match the global dimension structure exactly. If False, lower-rank arrays (e.g. parameters) are allowed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in btorch/io/serialization.py
SparseOptions
dataclass
¶
Sparse COO encoding policy for spike arrays.
Attributes:
| Name | Type | Description |
|---|---|---|
spike_suffix |
str
|
Substring (case-insensitive) identifying spike arrays. |
spike_dtype |
Any
|
Dtype dense spike arrays are cast to when sparse-encoded. |
sparse_threshold |
float
|
Encode sparsely when |
force_sparse |
bool | tuple[str, ...]
|
True to force sparse encoding of all spike arrays, or the flattened variable names to force. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in btorch/io/serialization.py
ZarrStoreOptions
dataclass
¶
Compression, chunking and overwrite policy of a Zarr store.
Attributes:
| Name | Type | Description |
|---|---|---|
compression_level |
int
|
Zstd compression level (1-9, higher is smaller). |
chunks |
dict[str, int] | None
|
Chunk size per dimension, e.g. |
overwrite |
bool
|
If True overwrite an existing store, else fail if it exists. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in btorch/io/serialization.py
Functions:¶
_encode_variable(var_name, val, var_dims, sparse)
¶
Return the dataset entries for one variable (dense or sparse COO).
Source code in btorch/io/serialization.py
_expand_dim_names(dim_names, dim_counts)
¶
Expand logical dimension groups into physical names.
Examples:
- ("time", "neuron"), (1, 2) -> ["time", "neuron_0", "neuron_1"]
- ("time", "batch"), (1, 1) -> ["time", "batch"]
Source code in btorch/io/serialization.py
_expand_partial(val, indices, var_name, neuron_group_dims, dim_registry)
¶
Expand a partially recorded variable to the full neuron size.
Contract: val holds only the recorded neurons along its trailing neuron
dims and indices locates them in the full population. 1D indices
address the flattened neuron dims; val must then still carry one
trailing axis per neuron dim whose sizes multiply to len(indices)
(e.g. (T, B, 1, k) for two neuron dims). The leading (time/batch) shape is kept;
the neuron dims are expanded to the size registered in dim_registry
(known from neuron_ids) and unrecorded entries are filled with NaN
(0 for non-float dtypes).
Raises:
| Type | Description |
|---|---|
ValueError
|
If no neuron dims are defined or their full size is unknown. |
Source code in btorch/io/serialization.py
_infer_dim_counts(val, neuron_ids, dim_names=('time', 'batch', 'neuron'))
¶
Infer dim_counts (T, B, N) from a representative array by its rank.
This is a heuristic (rank 3 -> T, B, N; rank 2 -> T, N; rank 1 -> N); pass
dim_counts or hint_field explicitly when it is ambiguous. Ranks
above 3 fall back to (1, 1, 1) and leave the extra trailing axes to the
private-dimension logic of :func:memories_to_xarray.
Returns:
| Type | Description |
|---|---|
tuple[int, int, int]
|
Tuple of (time_dims, batch_dims, neuron_dims) counts. |
Source code in btorch/io/serialization.py
_resolve_var_dims(var_name, val, all_mapped_dims, dim_registry, hint_field, strict_dims)
¶
Name the dimensions of one variable and register their sizes.
Alignment contract: core dims (e.g. T, B, N) are a fixed prefix of every
array; extra trailing dims (e.g. a synapse state of shape (T, B, N, 2)) get
private names; lower-rank arrays are right-aligned to the core dims. A size
that conflicts with an already registered dim is an error when
hint_field is given, otherwise that axis gets a private name.
dim_registry is updated in place.
Raises:
| Type | Description |
|---|---|
ValueError
|
On a size conflict with |
Source code in btorch/io/serialization.py
_root_id_entry(neuron_group_dims, dim_registry, neuron_ids)
¶
Build the root_id variable, or None if the neuron size is unknown.
Without neuron_ids the ids default to arange.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in btorch/io/serialization.py
_validate_and_infer_dims(flat_data, dim_names, dim_counts, hint_field, neuron_ids)
¶
Determine global dimension structure (dim_counts) and physical names.
Counts come from dim_counts if given, else from the hint_field
array, else from the first variable; an empty flat_data gives
(1, 1, 1).
Returns:
| Type | Description |
|---|---|
tuple[Sequence[int], list[str], list[str]]
|
Tuple of (dim_counts, all_mapped_dims, neuron_group_dims). |
Source code in btorch/io/serialization.py
from_spike_sparse(ds, var_name, return_sparse_2d=False)
¶
Reconstruct a dense or scipy sparse array from btorch sparse encoding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset containing the sparse-encoded variable. |
required |
var_name
|
str
|
Name of the sparse marker variable (the scalar with attrs). |
required |
return_sparse_2d
|
bool
|
If True and the original was 2D, return a scipy coo_array instead of dense numpy. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray | coo_array
|
A tuple of (array, used_variable_names). The array is either dense |
set[str]
|
numpy or scipy sparse (if 2D and requested). used_variable_names |
tuple[ndarray | coo_array, set[str]]
|
contains all dataset keys consumed during reconstruction. |
Shape semantics
- Output array has shape from
original_shapeattrs - Dense output: numpy array of original dtype
- Sparse output (2D only): scipy.sparse.coo_array
Source code in btorch/io/serialization.py
load_memories_from_xarray(path, dask=False, return_sparse_2d=False)
¶
Load a nested dictionary from a Zarr store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the Zarr store. |
required |
dask
|
bool
|
If True, return Dask-backed arrays (lazy loading). If False, load into memory immediately. |
False
|
return_sparse_2d
|
bool
|
If True, return 2D arrays as scipy sparse coo_array. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Nested dictionary with restored structure. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If |
Source code in btorch/io/serialization.py
memories_to_xarray(memories, layout=None, *, neuron_ids=None, partial_map=None, sparse=None)
¶
Convert a nested dictionary of simulation results into an xr.Dataset.
This function flattens a nested dictionary (e.g., from a simulation run containing spike trains, voltages, and synaptic states) and converts it into an xarray Dataset with consistent dimension naming and optional sparse encoding for spike arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memories
|
dict[str, Any]
|
Nested dictionary of arrays/tensors. Keys become variable names (dot-separated for nested dicts). |
required |
layout
|
DimLayout | None
|
Dimension counts/names, shape hint and strictness (see
:class: |
None
|
neuron_ids
|
Any | None
|
Optional neuron identifiers for |
None
|
partial_map
|
dict[str, Any] | None
|
Dict of |
None
|
sparse
|
SparseOptions | None
|
Sparse spike encoding policy (see :class: |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
xr.Dataset with all variables, coordinates, and sparse encodings. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a |
ImportError
|
If |
Example
memories = { ... "spike": torch.randn(100, 32, 128) > 0, # (T, B, N) ... "v": torch.randn(100, 32, 128), ... } ds = memories_to_xarray(memories, DimLayout(dim_counts=(1, 1, 1))) ds # Dataset with dims (time: 100, batch: 32, neuron: 128)
Source code in btorch/io/serialization.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |
require(module_name, extra, purpose=None)
¶
Import an optional dependency, or raise ImportError with an install hint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_name
|
str
|
Dotted module path to import (e.g. |
required |
extra
|
str
|
Name of the btorch extra that provides the module (e.g. |
required |
purpose
|
str | None
|
Optional short description of the feature needing the module. |
None
|
Returns:
| Type | Description |
|---|---|
ModuleType
|
The imported module. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the module is not installed. |
Source code in btorch/utils/_optional.py
save_memories_to_xarray(memories, path, layout=None, *, neuron_ids=None, partial_map=None, sparse=None, store=None)
¶
Save a nested dictionary to a Zarr store via xarray.
Convenience wrapper that converts the dictionary to a Dataset and saves with compression and optional chunking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memories
|
dict[str, Any]
|
Nested dictionary of arrays/tensors to save. |
required |
path
|
str | Path
|
Path to the output Zarr store. |
required |
layout
|
DimLayout | None
|
Dimension layout (see :class: |
None
|
neuron_ids
|
Any | None
|
Optional neuron identifiers. |
None
|
partial_map
|
dict[str, Any] | None
|
Partial recording indices for subset fields. |
None
|
sparse
|
SparseOptions | None
|
Sparse spike encoding policy (see :class: |
None
|
store
|
ZarrStoreOptions | None
|
Zarr compression, chunking and overwrite policy (see
:class: |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If |
ValueError
|
Propagated from :func: |
Exception
|
With |
Source code in btorch/io/serialization.py
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 | |
to_numpy_or_sparse(data)
¶
Convert to a dense NumPy array, keeping sparse data sparse.
Unlike :func:to_numpy, SciPy sparse inputs pass through unchanged and
sparse torch tensors become SciPy COO arrays instead of failing, and NumPy
scalars are returned as they are. Objects exposing .numpy() (other
tensor-likes) are converted through it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
|
required |
Returns:
| Type | Description |
|---|---|
ndarray | generic | spmatrix | sparray
|
Dense |
Source code in btorch/utils/array.py
to_sparse_repr(val, var_dims, var_name)
¶
Convert a dense or sparse array to sparse COO representation for storage.
Supports arbitrary dtypes (float, int, bool). Only non-zero entries are stored. The returned dictionary contains index arrays per dimension and a data array, suitable for constructing an xr.Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
ndarray | spmatrix | sparray
|
Array to encode. Can be dense numpy or scipy sparse. |
required |
var_dims
|
Sequence[str]
|
Physical dimension names for this variable (e.g., ["time", "batch", "neuron"]). |
required |
var_name
|
str
|
Base name for the variable (used to name output keys). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary mapping variable names to (dims, data) tuples or xr.DataArray |
dict[str, Any]
|
coords. Keys include:
- |
Shape semantics
- Input array with shape
(*var_dims)andnnznon-zeros - Output index arrays: each has shape
(nnz,) - Output data array: shape
(nnz,), dtype preserved from input
Source code in btorch/io/serialization.py
xarray_to_memories(ds, return_sparse_2d=False)
¶
Convert an xr.Dataset back to a nested dictionary.
Reconstructs the original nested dictionary structure from a Dataset
created by memories_to_xarray. Handles sparse-encoded variables
automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset to convert (typically loaded from Zarr). |
required |
return_sparse_2d
|
bool
|
If True, return 2D arrays as scipy sparse coo_array instead of dense numpy. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Nested dictionary with restored variable names and structure. |
Example
ds = xr.open_zarr("simulation.zarr") memories = xarray_to_memories(ds) memories["spike"].shape # (T, B, N) or scipy sparse