epymorph.data_type
In order to assist with proper data type handling in epymorph, we adopt a set of conventions that somewhat narrow the possibilities for expressing simulation data attributes. This module describes those conventions and provides some utilities for working with them. The goal is to simplify and remove certain categories of errors, like numerical overflow when simulating reasonable numbers of individuals.
ScalarType
module-attribute
Supported scalar value types.
StructType
module-attribute
StructType = tuple[tuple[str, ScalarType], ...]
Supported structured types.
AttributeType
module-attribute
AttributeType = ScalarType | StructType
The allowed type declarations for epymorph attributes.
AttributeValue
module-attribute
AttributeValue = ScalarValue | StructValue
The allowed values types for epymorph attribute values (most notably used as attribute defaults).
ScalarDType
module-attribute
ScalarDType = int64 | float64 | str_ | datetime64
Numpy equivalents to supported scalar values.
AttributeDType
module-attribute
AttributeDType = ScalarDType | StructDType
The allowed numpy dtypes for use in epymorph: these map 1:1 with AttributeType
.
AttributeArray
module-attribute
AttributeArray = NDArray[AttributeDType]
A type describing all supported numpy array forms for attribute data.
CentroidType
module-attribute
CentroidType: AttributeType = (
("longitude", float),
("latitude", float),
)
Structured epymorph type declaration for longitude/latitude coordinates.
CentroidDType
module-attribute
CentroidDType: dtype[void] = dtype_as_np(CentroidType)
The numpy equivalent of CentroidType
(structured dtype for longitude/latitude coordinates).
SimDType
module-attribute
SimDType = int64
This is the numpy datatype that should be used to represent internal simulation data. Where segments of the application maintain compartment and/or event counts, they should take pains to use this type at all times (if possible).
dtype_as_np
dtype_as_np(dtype: AttributeType) -> dtype
Convert a python-style dtype to its numpy-equivalent using epymorph typing conventions.
Parameters:
-
dtype
(AttributeType
) –The attribute type in Python form, e.g.,
int
Returns:
-
dtype
–The numpy equivalent, e.g.,
np.int64
dtype_str
dtype_str(dtype: AttributeType) -> str
Return a human-readable description of the given attribute data type.
Parameters:
-
dtype
(AttributeType
) –The attribute type in Python form, e.g.,
int
Returns:
-
str
–The friendly string representation of the type.
dtype_check
dtype_check(dtype: AttributeType, value: Any) -> bool
Check that a singular Python value conforms to the given attribute data type. This is not intended to check numpy arrays, only scalars and tuples.
Parameters:
-
dtype
(AttributeType
) –The attribute type in Python form, e.g.,
int
-
value
(Any
) –A value to check.
Returns:
-
bool
–True if the values matches the dtype.