Skip to content

Commit 0d9a0ce

Browse files
author
Marin Visscher
committed
Enable substitution exchanges for functional_sqlite
1 parent 9d4ba9d commit 0d9a0ce

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

bw_functional/database.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ def technosphere(nodes, exchanges):
266266
"""
267267
consumption = Build.consumption(nodes, exchanges)
268268
production = Build.production(nodes, exchanges)
269-
return pd.concat([consumption, production])
269+
substitution = Build.substitution(nodes, exchanges)
270+
return pd.concat([consumption, production, substitution])
270271

271272
@staticmethod
272273
def biosphere(nodes, exchanges):
@@ -300,6 +301,22 @@ def consumption(nodes, exchanges):
300301
x["flip"] = True
301302
return x[["row", "col", "amount", "flip"] + UNCERTAINTY_FIELDS]
302303

304+
@staticmethod
305+
def substitution(nodes, exchanges):
306+
"""
307+
Constructs the consumption flows by allocating technosphere exchanges.
308+
309+
Args:
310+
nodes (pd.DataFrame): The dataframe containing node data.
311+
exchanges (pd.DataFrame): The dataframe containing exchange data.
312+
313+
Returns:
314+
pd.DataFrame: A dataframe containing allocated consumption flows with additional metadata.
315+
"""
316+
x = Build.allocated(nodes, exchanges, ["substitution"])
317+
x["flip"] = False
318+
return x[["row", "col", "amount", "flip"] + UNCERTAINTY_FIELDS]
319+
303320
@staticmethod
304321
def production(nodes, exchanges):
305322
"""
@@ -389,7 +406,7 @@ def allocate_distributions(df: pd.DataFrame) -> pd.DataFrame:
389406
# Distributions that use the standard method
390407
standard = [sa.NormalUncertainty.id, sa.UniformUncertainty.id, sa.TriangularUncertainty.id,
391408
sa.WeibullUncertainty.id, sa.GammaUncertainty.id, sa.GeneralizedExtremeValueUncertainty.id,
392-
sa.UndefinedUncertainty, sa.NoUncertainty]
409+
sa.UndefinedUncertainty.id, sa.NoUncertainty.id]
393410
# Lognormal uncertainty
394411
ln = [sa.LognormalUncertainty.id]
395412

0 commit comments

Comments
 (0)