material_balance
material_balance ¤
MaterialBalanceEvents ¤
MaterialBalanceEvents(
dataframe: DataFrame,
input_uuids: list[str],
output_uuids: list[str],
*,
event_uuid: str = "eng:material_balance",
value_column: str = "value_double",
time_column: str = "systime",
time_weighted: bool = True,
missing_as_zero: bool = False
)
Bases: Base
Engineering: Material / Energy Balance
Check whether inputs and outputs balance (mass, energy, flow) per time window. The most fundamental daily engineering check for any process.
Methods: - balance_check: Per-window sum(inputs) vs sum(outputs). - imbalance_trend: Track whether imbalance is growing or shrinking. - detect_balance_exceedance: Sustained imbalance events. - contribution_breakdown: Each signal's share of total input/output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
Long-format input data. |
required |
input_uuids
|
list[str]
|
Signals flowing into the balance boundary. |
required |
output_uuids
|
list[str]
|
Signals flowing out of it. |
required |
event_uuid
|
str
|
UUID assigned to generated events. |
'eng:material_balance'
|
value_column
|
str
|
Column holding the flow values. |
'value_double'
|
time_column
|
str
|
Timestamp column. |
'systime'
|
time_weighted
|
bool
|
|
True
|
missing_as_zero
|
bool
|
|
False
|
balance_check ¤
balance_check(
window: str = "1h", tolerance_pct: float = 5.0
) -> pd.DataFrame
Per-window balance check: sum(inputs) vs sum(outputs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
str
|
Resample window. |
'1h'
|
tolerance_pct
|
float
|
Maximum acceptable imbalance percentage. |
5.0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: start, end, duration_seconds, |
DataFrame
|
total_input, total_output, imbalance, imbalance_pct, balanced. |
DataFrame
|
|
imbalance_trend ¤
imbalance_trend(window: str = '1h') -> pd.DataFrame
Track whether imbalance is growing, shrinking, or stable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
str
|
Resample window passed to :meth: |
'1h'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: start, end, duration_seconds, |
DataFrame
|
imbalance_pct, rolling_avg_imbalance, trend_direction. |
DataFrame
|
|
detect_balance_exceedance ¤
detect_balance_exceedance(
window: str = "1h",
tolerance_pct: float = 5.0,
min_duration: str = "2h",
) -> pd.DataFrame
Detect sustained imbalance events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
str
|
Resample window passed to :meth: |
'1h'
|
tolerance_pct
|
float
|
Maximum acceptable imbalance percentage per window. |
5.0
|
min_duration
|
str
|
Minimum length of a run of consecutive unbalanced windows to report it as an event (pandas offset string). Windows whose totals are NaN (missing data) end a run. |
'2h'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: start, end, duration_seconds, uuid, |
DataFrame
|
source_uuid (input and output uuids, comma-joined), is_delta, |
DataFrame
|
avg_imbalance_pct, max_imbalance_pct, likely_cause. |
contribution_breakdown ¤
contribution_breakdown(window: str = '1h') -> pd.DataFrame
Each signal's contribution to total input/output per window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
str
|
Resample window (pandas offset string). |
'1h'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: start, end, duration_seconds, uuid, |
DataFrame
|
source_uuid, role, value, pct_of_total. |
DataFrame
|
|
DataFrame
|
is |
DataFrame
|
Canonical twin columns: |
DataFrame
|
holds the same values as the deprecated column right before it, which is |
DataFrame
|
removed in the next major release. |