linopy.piecewise.Slopes

linopy.piecewise.Slopes#

class linopy.piecewise.Slopes(values, y0=0.0, align='pieces', dim=None)#

Per-piece slopes + initial y-value, deferred until an x grid is known.

Used as the second element of a tuple in add_piecewise_formulation(). When any Slopes tuple is present, exactly one other tuple must carry explicit breakpoints — that tuple’s values are the x grid against which all Slopes are integrated:

m.add_piecewise_formulation(
    (power, [0, 30, 60, 100]),               # the x grid
    (fuel,  Slopes([1.2, 1.4, 1.7], y0=0)),  # integrated against power
)

With two or more non-Slopes tuples there is no canonical x axis, and the call raises ValueError. Resolve the Slopes explicitly via to_breakpoints() in that case, or for any standalone use:

bp = Slopes([1.2, 1.4, 1.7], y0=0).to_breakpoints([0, 30, 60, 100])
Parameters:
  • values (BreaksLike) – Per-piece slopes. 1D for shared breakpoints; 2D (DataFrame / dict / DataArray with entity dim) for per-entity slopes.

  • y0 (float, dict, pd.Series, or DataArray, default 0.0) – y-value at the first breakpoint. Scalar broadcasts to all entities; dict/Series/DataArray provides per-entity values.

  • align ({"pieces", "leading"}, default "pieces") – Alignment of values relative to the x grid.

    • "pieces": len(values) == len(x_points) - 1; values[i] is the slope between x[i] and x[i+1].

    • "leading": len(values) == len(x_points); values[0] must be NaN and is dropped, values[i] for i>=1 is the slope between x[i-1] and x[i]. Useful when a marginal value is tabulated alongside each breakpoint with the first row’s marginal undefined.

  • dim (str, optional) – Entity dimension name. Required when values is a pd.DataFrame or dict.

Warns:

EvolvingAPIWarningSlopes is part of the newly-added piecewise API. Its constructor signature and dispatch semantics may be refined. Silence with warnings.filterwarnings("ignore", category=linopy.EvolvingAPIWarning).

__init__(values, y0=0.0, align='pieces', dim=None)#

Methods

__init__(values[, y0, align, dim])

to_breakpoints(x_points)

Resolve to a breakpoint xarray.DataArray, given an x grid.

Attributes

values

y0

align

dim