Dataset¶
technoeconomics.data
¶
Data access: lazy, serialisable datasets resolved to scalars or series.
Constant
dataclass
¶
A single fixed value.
Attributes:
Dataset
dataclass
¶
Bases: ABC
Base for all datasets: a lazy, serialisable handle for one value.
The type parameter T is the resolved value's type -- float for a scalar
dataset, pandas.Series for a series. Concrete datasets are frozen dataclasses
subclassing Dataset[float] or Dataset[pd.Series] and implementing compute.
(De)serialisation is declared once, on the [ScalarDataset][technoeconomics.data.ScalarDataset]
/ [SeriesDataset][technoeconomics.data.SeriesDataset] aliases, via the class-name-tagged
codec from technoeconomics.serialise; a concrete dataset therefore stays a plain
pydantic-free @dataclass.
compute
abstractmethod
¶
resolve
¶
Return this dataset's value over snapshots, memoised when cache is set.
The resolution entry point, wrapping the author's
compute:
resolve_datasets calls it. When cache
is True the value is keyed by (self, snapshots) -- a frozen dataset with
hashable fields is its own key -- and computed once even under concurrent resolves;
otherwise compute runs every time.
Parameters:
-
snapshots(DatetimeIndex) –The horizon the value is aligned to.
Returns:
-
T–The computed value. A cached value is shared by reference, so callers must treat
-
T–it as read-only (resolution copies it into a component rather than mutating it).
Source code in src/technoeconomics/data/base.py
Sinusoidal
dataclass
¶
Sinusoidal(mean: Param[float, Magnitude], amplitude: Param[float, Magnitude], period: Param[float, Gt(0), Unit('h')] = 24.0, phase: Param[float, Unit('h')] = 0.0)
Bases: Dataset[Series]
A sine wave over the snapshots -- a stand-in for daily/seasonal shapes.
The value at time t is mean + amplitude * sin(2*pi * (h - phase) /
period), where h is the number of hours since the first snapshot.
Attributes:
-
mean(Param[float, Magnitude]) –Baseline the wave oscillates around. A magnitude: its unit and bounds come from the field holding this dataset.
-
amplitude(Param[float, Magnitude]) –Peak deviation from
mean. A magnitude, likemean. -
period(Param[float, Gt(0), Unit('h')]) –Oscillation period in hours (e.g.
24daily,8760yearly). -
phase(Param[float, Unit('h')]) –Horizontal shift in hours.
compute
¶
Return the sine wave sampled at snapshots.
Source code in src/technoeconomics/data/sources.py
resolve_datasets
¶
Return copies of objs with every Dataset field replaced by its value.
Parameters:
-
objs(Iterable[C]) –Dataclass instances (typically components) to resolve.
-
snapshots(DatetimeIndex) –The horizon series values are aligned to.
Returns:
-
list[C]–New instances with concrete values in place of datasets; instances with no
-
list[C]–dataset fields are returned as is.
Source code in src/technoeconomics/data/base.py
base
¶
Core data-access contract: the Dataset type and dataset resolution.
Dataset
dataclass
¶
Bases: ABC
Base for all datasets: a lazy, serialisable handle for one value.
The type parameter T is the resolved value's type -- float for a scalar
dataset, pandas.Series for a series. Concrete datasets are frozen dataclasses
subclassing Dataset[float] or Dataset[pd.Series] and implementing compute.
(De)serialisation is declared once, on the [ScalarDataset][technoeconomics.data.ScalarDataset]
/ [SeriesDataset][technoeconomics.data.SeriesDataset] aliases, via the class-name-tagged
codec from technoeconomics.serialise; a concrete dataset therefore stays a plain
pydantic-free @dataclass.
compute
abstractmethod
¶
resolve
¶
Return this dataset's value over snapshots, memoised when cache is set.
The resolution entry point, wrapping the author's
compute:
resolve_datasets calls it. When cache
is True the value is keyed by (self, snapshots) -- a frozen dataset with
hashable fields is its own key -- and computed once even under concurrent resolves;
otherwise compute runs every time.
Parameters:
-
snapshots(DatetimeIndex) –The horizon the value is aligned to.
Returns:
-
T–The computed value. A cached value is shared by reference, so callers must treat
-
T–it as read-only (resolution copies it into a component rather than mutating it).
Source code in src/technoeconomics/data/base.py
ResultCache
¶
Process-wide single-flight memoiser: one factory call per key, shared by racers.
A dataset resolved concurrently across the solve worker threads must compute once, not
once per thread. The first caller to miss stores a Future under the key and runs the
factory; callers arriving while it is in flight find that Future and block on its
result. The lock guards only the TTLCache bookkeeping -- which is not thread-safe, and
mutates even on a read here to refresh the idle timer -- while the factory runs unlocked,
so a slow compute never blocks a hit or an unrelated key.
Parameters:
-
maxsize(int, default:_MAXSIZE) –Distinct keys retained before the least-recently-used is evicted.
-
ttl(float, default:_TTL_SECONDS) –Seconds a key survives untouched (each hit resets the timer).
Source code in src/technoeconomics/data/base.py
get_or_make
¶
Return the value for key, computing it via factory on a miss.
Parameters:
-
key(Hashable) –A hashable key that fully determines the value.
-
factory(Callable[[], T]) –Produces the value on a miss; called at most once per in-flight key.
Returns:
-
T–The value for
key, freshly computed or replayed from an in-flight or earlier -
T–call. A
factorythat raises propagates to every waiter and is not cached, so a -
T–later call retries.
Source code in src/technoeconomics/data/base.py
resolve_datasets
¶
Return copies of objs with every Dataset field replaced by its value.
Parameters:
-
objs(Iterable[C]) –Dataclass instances (typically components) to resolve.
-
snapshots(DatetimeIndex) –The horizon series values are aligned to.
Returns:
-
list[C]–New instances with concrete values in place of datasets; instances with no
-
list[C]–dataset fields are returned as is.
Source code in src/technoeconomics/data/base.py
sources
¶
Concrete datasets.
Constant
dataclass
¶
A single fixed value.
Attributes:
Sinusoidal
dataclass
¶
Sinusoidal(mean: Param[float, Magnitude], amplitude: Param[float, Magnitude], period: Param[float, Gt(0), Unit('h')] = 24.0, phase: Param[float, Unit('h')] = 0.0)
Bases: Dataset[Series]
A sine wave over the snapshots -- a stand-in for daily/seasonal shapes.
The value at time t is mean + amplitude * sin(2*pi * (h - phase) /
period), where h is the number of hours since the first snapshot.
Attributes:
-
mean(Param[float, Magnitude]) –Baseline the wave oscillates around. A magnitude: its unit and bounds come from the field holding this dataset.
-
amplitude(Param[float, Magnitude]) –Peak deviation from
mean. A magnitude, likemean. -
period(Param[float, Gt(0), Unit('h')]) –Oscillation period in hours (e.g.
24daily,8760yearly). -
phase(Param[float, Unit('h')]) –Horizontal shift in hours.
compute
¶
Return the sine wave sampled at snapshots.