epymorph.data_shape
Utility classes to verify the shape of data as numpy arrays whose dimensions can be relative to the simulation context, and to adapt equivalent shapes.
Dimensions
Bases: Protocol
A class to store the lengths of dimensions which are supported by DataShapes. It is possible to create Dimensions instances which contain a subset of the available dimensions, for cases where the other dimensions aren't known and aren't needed.
of
staticmethod
of(
*,
T: int | None = None,
N: int | None = None,
C: int | None = None,
E: int | None = None,
) -> Dimensions
PartialDimensions
PartialDimensions(
*,
T: int | None = None,
N: int | None = None,
C: int | None = None,
E: int | None = None,
)
Bases: Dimensions
A Dimensions instance where some dimensions are unknown. If code accesses an unknown dimension, a DimensionError is raised.
CompleteDimensions
Bases: Dimensions
A Dimensions instance where all dimensions are known.
DataShape
Bases: ABC
Description of a data attribute's shape relative to a simulation context.
to_tuple
abstractmethod
to_tuple(dim: Dimensions) -> tuple[int, ...]
Returns a tuple with the lengths of the dimensions in this shape. If an axis is of indeterminate length, that axis is represented as -1.
matches
abstractmethod
matches(dim: Dimensions, value: NDArray) -> bool
Does the given value match this shape expression?
adapt
abstractmethod
adapt(
dim: Dimensions, value: NDArray[DataT]
) -> NDArray[DataT]
Adapt the given value to this shape; raise ValueError if we can't.
Scalar
dataclass
Bases: DataShape
A scalar value.
to_tuple
to_tuple(dim: Dimensions) -> tuple[int, ...]
Returns a tuple with the lengths of the dimensions in this shape. If an axis is of indeterminate length, that axis is represented as -1.
matches
matches(dim: Dimensions, value: NDArray) -> bool
Does the given value match this shape expression?
adapt
adapt(
dim: Dimensions, value: NDArray[DataT]
) -> NDArray[DataT]
Adapt the given value to this shape; raise ValueError if we can't.
Time
dataclass
Bases: DataShape
An array of at least size T (the number of simulation days).
to_tuple
to_tuple(dim: Dimensions) -> tuple[int, ...]
Returns a tuple with the lengths of the dimensions in this shape. If an axis is of indeterminate length, that axis is represented as -1.
matches
matches(dim: Dimensions, value: NDArray) -> bool
Does the given value match this shape expression?
adapt
adapt(
dim: Dimensions, value: NDArray[DataT]
) -> NDArray[DataT]
Adapt the given value to this shape; raise ValueError if we can't.
Node
dataclass
Bases: DataShape
An array of size N (the number of simulation nodes).
to_tuple
to_tuple(dim: Dimensions) -> tuple[int, ...]
Returns a tuple with the lengths of the dimensions in this shape. If an axis is of indeterminate length, that axis is represented as -1.
matches
matches(dim: Dimensions, value: NDArray) -> bool
Does the given value match this shape expression?
adapt
adapt(
dim: Dimensions, value: NDArray[DataT]
) -> NDArray[DataT]
Adapt the given value to this shape; raise ValueError if we can't.
NodeAndNode
dataclass
Bases: DataShape
An array of size NxN.
to_tuple
to_tuple(dim: Dimensions) -> tuple[int, ...]
Returns a tuple with the lengths of the dimensions in this shape. If an axis is of indeterminate length, that axis is represented as -1.
matches
matches(dim: Dimensions, value: NDArray) -> bool
Does the given value match this shape expression?
adapt
adapt(
dim: Dimensions, value: NDArray[DataT]
) -> NDArray[DataT]
Adapt the given value to this shape; raise ValueError if we can't.
NodeAndCompartment
dataclass
Bases: DataShape
An array of size NxC.
to_tuple
to_tuple(dim: Dimensions) -> tuple[int, ...]
Returns a tuple with the lengths of the dimensions in this shape. If an axis is of indeterminate length, that axis is represented as -1.
matches
matches(dim: Dimensions, value: NDArray) -> bool
Does the given value match this shape expression?
adapt
adapt(
dim: Dimensions, value: NDArray[DataT]
) -> NDArray[DataT]
Adapt the given value to this shape; raise ValueError if we can't.
TimeAndNode
dataclass
Bases: DataShape
An array of size at-least-T by exactly-N.
to_tuple
to_tuple(dim: Dimensions) -> tuple[int, ...]
Returns a tuple with the lengths of the dimensions in this shape. If an axis is of indeterminate length, that axis is represented as -1.
matches
matches(dim: Dimensions, value: NDArray) -> bool
Does the given value match this shape expression?
adapt
adapt(
dim: Dimensions, value: NDArray[DataT]
) -> NDArray[DataT]
Adapt the given value to this shape; raise ValueError if we can't.
NodeAndArbitrary
dataclass
Bases: DataShape
An array of size exactly-N by any dimension.
to_tuple
to_tuple(dim: Dimensions) -> tuple[int, ...]
Returns a tuple with the lengths of the dimensions in this shape. If an axis is of indeterminate length, that axis is represented as -1.
matches
matches(dim: Dimensions, value: NDArray) -> bool
Does the given value match this shape expression?
adapt
adapt(
dim: Dimensions, value: NDArray[DataT]
) -> NDArray[DataT]
Adapt the given value to this shape; raise ValueError if we can't.
ArbitraryAndNode
dataclass
Bases: DataShape
An array of size any dimension by exactly-N.
to_tuple
to_tuple(dim: Dimensions) -> tuple[int, ...]
Returns a tuple with the lengths of the dimensions in this shape. If an axis is of indeterminate length, that axis is represented as -1.
matches
matches(dim: Dimensions, value: NDArray) -> bool
Does the given value match this shape expression?
adapt
adapt(
dim: Dimensions, value: NDArray[DataT]
) -> NDArray[DataT]
Adapt the given value to this shape; raise ValueError if we can't.
Shapes
dataclass
Static instances for all available shapes.
DataShapeMatcher
DataShapeMatcher(
shape: DataShape,
dim: Dimensions,
*,
exact: bool = False,
)