Axis¶
axis
¶
Runtime axis types and helpers.
Axis(name, kind, size, labels=None, values=None, domain=None, spacing=None)
dataclass
¶
Resolved Runtime Axis.
Describe one named axis after configuration has been validated and converted into runtime metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
IdentifierString
|
Stable axis name used by systems and parameters. |
kind |
Literal['continuous', 'categorical']
|
Whether the axis is continuous or categorical. |
size |
int
|
Number of positions along the axis. |
labels |
tuple[str, ...] | None
|
Optional labels for categorical axes. |
values |
tuple[int, ...] | None
|
Optional integer values associated with categorical labels. |
domain |
tuple[float, float] | None
|
Closed numeric domain for continuous axes. |
spacing |
Literal['linear', 'log'] | None
|
Spacing rule for continuous axes. |
Notes
Continuous axes intentionally support both point-style and bin-style
calculations. The same axis can expose representative points via
points() and intervals via bins(), so systems and parameters can use
whichever view is appropriate without introducing incompatible axis
definitions.
bin_edges()
¶
Continuous Bin Edges.
Partition a continuous axis domain into size bins.
Returns:
| Type | Description |
|---|---|
tuple[float, ...]
|
The bin-edge coordinates with length |
Notes
Linear axes use np.linspace(lower, upper, size + 1). Log axes use
np.geomspace(lower, upper, size + 1).
Examples:
>>> from flepimop2.axis import Axis
>>> axis = Axis(
... name="time",
... kind="continuous",
... size=4,
... domain=(0.0, 8.0),
... spacing="linear",
... )
>>> axis.bin_edges()
(0.0, 2.0, 4.0, 6.0, 8.0)
Source code in src/flepimop2/axis.py
bins()
¶
Continuous Bin Intervals.
Return half-open-style interval metadata for each continuous bin.
Returns:
| Type | Description |
|---|---|
tuple[tuple[float, float], ...]
|
A tuple of |
Examples:
>>> from flepimop2.axis import Axis
>>> axis = Axis(
... name="time",
... kind="continuous",
... size=2,
... domain=(0.0, 4.0),
... spacing="linear",
... )
>>> axis.bins()
((0.0, 2.0), (2.0, 4.0))
Source code in src/flepimop2/axis.py
from_model(name, model)
classmethod
¶
Build an Axis from a configuration model.
Returns:
| Type | Description |
|---|---|
Axis
|
The resolved runtime axis. |
Source code in src/flepimop2/axis.py
points()
¶
Representative Continuous Points.
Return one representative point for each continuous bin.
Returns:
| Type | Description |
|---|---|
tuple[float, ...]
|
A tuple of representative point coordinates with length |
Notes
Points are the centroids of the bins returned by Axis.bins, arithmetic midpoints for linear spacing and geometric means for log spacing.
Examples:
>>> from pprint import pp
>>> from flepimop2.axis import Axis
>>> Axis(
... name="time",
... kind="continuous",
... size=4,
... domain=(0.0, 8.0),
... spacing="linear",
... ).points()
(1.0, 3.0, 5.0, 7.0)
>>> pp(
... Axis(
... name="time",
... kind="continuous",
... size=4,
... domain=(1e-9, 1e-3),
... spacing="log",
... ).points()
... )
(5.623413251903491e-09,
1.7782794100389227e-07,
5.623413251903491e-06,
0.0001778279410038923)
Source code in src/flepimop2/axis.py
AxisCollection(axes=None)
¶
Bases: Mapping[IdentifierString, Axis]
Runtime Axis Collection.
Store resolved axes and provide lookup and named-shape helpers for systems, parameters, and engines.
Notes
AxisCollection is the runtime entry point for working with named axes.
Systems typically use it to resolve requested parameter shapes, while
parameter modules use it to interpret declared axis names and inspect
axis metadata such as labels or bin edges.
Examples:
>>> from flepimop2.axis import AxisCollection
>>> axes = AxisCollection.from_config({
... "age": {
... "kind": "categorical",
... "labels": ["age0_17", "age18_64", "age65_plus"],
... },
... "time": {
... "kind": "continuous",
... "domain": (0.0, 12.0),
... "size": 4,
... },
... })
>>> axes.size("age")
3
>>> axes["age"].labels
('age0_17', 'age18_64', 'age65_plus')
>>> axes["time"].bin_edges()
(0.0, 3.0, 6.0, 9.0, 12.0)
>>> axes.resolve_shape(("age", "time")).sizes
(3, 4)
>>> axes.resolve_shape(("region",))
Traceback (most recent call last):
...
KeyError: "Unknown axis names requested: ('region',)."
Initialize the collection with an optional axis mapping.
Source code in src/flepimop2/axis.py
__getitem__(key)
¶
__iter__()
¶
Iterate over axis names in the collection.
Returns:
| Type | Description |
|---|---|
Iterator[IdentifierString]
|
An iterator over axis names. |
__len__()
¶
from_config(config)
classmethod
¶
Construct a runtime axis collection from configuration data.
Returns:
| Type | Description |
|---|---|
AxisCollection
|
The resolved runtime axis collection. |
Source code in src/flepimop2/axis.py
get(name, /, default=None)
¶
Return a named axis, optionally providing a default.
Returns:
| Type | Description |
|---|---|
Axis | T | None
|
The resolved axis, or the provided default when missing. |
Source code in src/flepimop2/axis.py
resolve_shape(axis_names)
¶
Resolve a tuple of axis names into concrete dimension sizes.
Returns:
| Type | Description |
|---|---|
ResolvedShape
|
The resolved named shape. |
Source code in src/flepimop2/axis.py
size(name)
¶
ResolvedShape(axis_names=(), sizes=())
dataclass
¶
A named runtime shape resolved against a concrete axis collection.
__post_init__()
¶
Validate the number of axis names and sizes match.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> from flepimop2.axis import ResolvedShape
>>> ResolvedShape(axis_names=("age", "time"), sizes=(3, 4))
ResolvedShape(axis_names=('age', 'time'), sizes=(3, 4))
>>> ResolvedShape(axis_names=("age",), sizes=(3, 4))
Traceback (most recent call last):
...
ValueError: ResolvedShape axis_names and sizes must have matching lengths; got 1 names and 2 sizes.