snnlab
API referencesnnlab.viz

snnlab.viz.contracts

Complete declared API of the contracts module, with signatures, data fields, validation and source.

Back to viz reference

Renderer-neutral retained evidence. All time-varying signal arrays must share a leading time axis, and dt_ms must be positive and finite. A Recording is not an instruction to rerun a simulation or replace absent evidence.

The signatures, defaults, fields, docstrings and implementation excerpts below are generated from the Python source. Annotations are shown as declared; unannotated means the source supplies no type annotation. These pages document callable surfaces, including legacy support utilities, without promising backend support for every declaration.

SymbolKind
RecordingErrorclass
Recordingclass

RecordingError

View source

Source docstring:

Raised when an input cannot support truthful rendering.

Bases: ValueError. Inherited third-party framework APIs follow their owning library.

Complete class implementation
class RecordingError(ValueError):
    """Raised when an input cannot support truthful rendering."""

Recording

View source

Source docstring:

An open-ended, renderer-neutral view of one time-series recording.

Class decorators: dataclass(frozen=True).

Dataclass constructor parameters. Factory defaults are shown as field declarations; omit these arguments to create fresh values per instance:

Recording(dt_ms: float, signals: Mapping[str, np.ndarray], metadata: Mapping[str, Any] = field(default_factory=dict), source: Path | None = None)

Declared fields, including fields inherited from local data classes:

FieldAnnotationDefaultMeaning
dt_msfloatrequiredSimulation timestep in milliseconds.
signalsMapping[str, np.ndarray]requiredStored member of this data contract; see the class docstring and serialization methods.
metadataMapping[str, Any]field(default_factory=dict)Stored member of this data contract; see the class docstring and serialization methods.
sourcePath | NoneNoneStored member of this data contract; see the class docstring and serialization methods.

Constructor/initialization exception expressions:

Explicit exception expression
RecordingError('dt_ms must be finite and positive')
RecordingError('recording contains no time-varying signals')
RecordingError(f'time-varying signals disagree on length: {sorted(lengths)}')

Recording.steps

View source

Decorators: property.

def Recording.steps(self) -> int

Return annotation: int.

Return expressions (branch-dependent; names refer to the linked implementation):

next((np.asarray(value).shape[0] for value in self.signals.values() if np.asarray(value).ndim))
Implementation
def steps(self) -> int:
        return next(
            np.asarray(value).shape[0]
            for value in self.signals.values()
            if np.asarray(value).ndim
        )

Recording.duration_ms

View source

Decorators: property.

def Recording.duration_ms(self) -> float

Return annotation: float.

Return expressions (branch-dependent; names refer to the linked implementation):

self.steps * self.dt_ms
Implementation
def duration_ms(self) -> float:
        return self.steps * self.dt_ms

Recording.require

View source

def Recording.require(self, *names: str) -> tuple[np.ndarray, ...]
ParameterAnnotationDefaultMeaning
*namesstrvariadicDefined by the source contract and implementation below.

Return annotation: tuple[np.ndarray, ...].

Return expressions (branch-dependent; names refer to the linked implementation):

tuple((np.asarray(self.signals[name]) for name in names))

Explicit exceptions in this implementation; called helpers may raise additional errors:

Explicit exception expression
RecordingError('recording lacks required signals: ' + ', '.join(missing))
Implementation
def require(self, *names: str) -> tuple[np.ndarray, ...]:
        missing = [name for name in names if name not in self.signals]
        if missing:
            raise RecordingError(
                "recording lacks required signals: " + ", ".join(missing)
            )
        return tuple(np.asarray(self.signals[name]) for name in names)
Complete class implementation
class Recording:
    """An open-ended, renderer-neutral view of one time-series recording."""

    dt_ms: float
    signals: Mapping[str, np.ndarray]
    metadata: Mapping[str, Any] = field(default_factory=dict)
    source: Path | None = None

    def __post_init__(self) -> None:
        if not np.isfinite(self.dt_ms) or self.dt_ms <= 0:
            raise RecordingError("dt_ms must be finite and positive")
        lengths = {
            np.asarray(value).shape[0]
            for value in self.signals.values()
            if np.asarray(value).ndim
        }
        if not lengths:
            raise RecordingError("recording contains no time-varying signals")
        if len(lengths) != 1:
            raise RecordingError(
                f"time-varying signals disagree on length: {sorted(lengths)}"
            )

    @property
    def steps(self) -> int:
        return next(
            np.asarray(value).shape[0]
            for value in self.signals.values()
            if np.asarray(value).ndim
        )

    @property
    def duration_ms(self) -> float:
        return self.steps * self.dt_ms

    def require(self, *names: str) -> tuple[np.ndarray, ...]:
        missing = [name for name in names if name not in self.signals]
        if missing:
            raise RecordingError(
                "recording lacks required signals: " + ", ".join(missing)
            )
        return tuple(np.asarray(self.signals[name]) for name in names)

On this page