snnlab.viz.contracts
Complete declared API of the contracts module, with signatures, data fields, validation and source.
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.
| Symbol | Kind |
|---|---|
| RecordingError | class |
| Recording | class |
RecordingError
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
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:
| Field | Annotation | Default | Meaning |
|---|---|---|---|
dt_ms | float | required | Simulation timestep in milliseconds. |
signals | Mapping[str, np.ndarray] | required | Stored member of this data contract; see the class docstring and serialization methods. |
metadata | Mapping[str, Any] | field(default_factory=dict) | Stored member of this data contract; see the class docstring and serialization methods. |
source | Path | None | None | Stored 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
Decorators: property.
def Recording.steps(self) -> intReturn 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
Decorators: property.
def Recording.duration_ms(self) -> floatReturn annotation: float.
Return expressions (branch-dependent; names refer to the linked implementation):
self.steps * self.dt_msImplementation
def duration_ms(self) -> float:
return self.steps * self.dt_msRecording.require
def Recording.require(self, *names: str) -> tuple[np.ndarray, ...]| Parameter | Annotation | Default | Meaning |
|---|---|---|---|
*names | str | variadic | Defined 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)