ams.core.service#

Routine services — operations and transformations on routine arrays.

Service selection guide#

Pick a service by what you need; subclass ROperationService only if none of the existing ones fits.

Need

Use

Wrap a precomputed ndarray

ValueService

Apply f(u.v, **args)

NumOp (workhorse)

Apply f(u.v, u2.v, ...)

NumOpDual (e.g. multiply)

Repeat u across columns

NumHstack (broadcast)

Pick gen subset by indexer

VarSelect

Sum into zones / areas

ZonalSum

Ramp difference matrix

RampSub

Shape-only reduction matrix

inline (e.g. np.ones((1, u.n)))

Zonal load scaling

LoadScale (load-status aware)

UC min on/off duration

MinDur (UC routines only)

Notes#

  • The expand_dims=axis kwarg on NumOp covers the NumExpandDim use case. NumExpandDim is deprecated in v1.3.0 and slated for removal in v1.4.0 — use NumOp directly. VarReduction is likewise deprecated (no production users); inline the reduction matrix instead.

  • MinDur inherits from NumOpDual for parameter plumbing only; the inherited fun/rfun machinery is unused.

  • .v caching: subclasses recompute fresh on every access — there is no framework-level cache. Only ValueService returns a stored value. Memoize at the routine level if a tight loop is hitting .v repeatedly.

File layout#

  1. Bases (RBaseService, ROperationService)

  2. Static storage (ValueService)

  3. Generic single-input ops (NumOp, NumHstack)

  4. Generic dual-input ops (NumOpDual)

  5. Subset / aggregation (VarSelect, ZonalSum)

  6. Reduction / difference (RampSub, VarReduction)

  7. Domain-specific (LoadScale, MinDur)

  8. Deprecated, slated for removal in v1.4.0 (NumExpandDim, VarReduction)

Classes

LoadScale(u, sd[, name, tex_name, unit, ...])

Retrieve zonal load by scaling nodal load using the specified load scale factor.

MinDur(u, u2[, name, tex_name, unit, info, ...])

Build the coefficient matrix for minimum online/offline constraints used in UC.

NumExpandDim(u[, axis, args, name, ...])

Expand the dimensions of the input array along a specified axis using NumPy's np.expand_dims(u.v, axis=axis).

NumHstack(u, ref[, args, name, tex_name, ...])

Repeat an array along the second axis nc times or the length of reference array, using NumPy's hstack function, where nc is the column number of the reference array, np.hstack([u.v[:, np.newaxis] * ref.shape[1]], **kwargs).

NumOp(u, fun[, args, name, tex_name, unit, ...])

Perform an operation on a numerical array using the function fun(u.v, **args).

NumOpDual(u, u2, fun[, args, name, ...])

Performan an operation on two numerical arrays using the function fun(u.v, u2.v, **args).

RBaseService([name, tex_name, unit, info, ...])

Base class for services that are used in a routine.

ROperationService(u[, name, tex_name, unit, ...])

Base calss for operational services used in routine.

RampSub(u[, name, tex_name, unit, info, ...])

Build a substraction matrix for a 2D variable in the shape (nr, nr-1), where nr is the rows of the input.

ValueService(name, value[, tex_name, unit, ...])

Service to store given numeric values.

VarReduction(u, fun[, name, tex_name, unit, ...])

A numerical matrix to reduce a 2D variable to 1D, np.fun(shape=(1, u.n)).

VarSelect(u, indexer[, gamma, name, ...])

A numerical matrix to select a subset of a 2D variable, u.v[:, idx].

ZonalSum(u, zone[, name, tex_name, unit, ...])

Build zonal sum matrix for a vector in the shape of collection model, Area or Zone.