Skip to content

Commit 1bd73f9

Browse files
committed
add new get_product_impact as generalized method for LCA
1 parent 70685c0 commit 1bd73f9

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

biosteam/_system.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3787,14 +3787,45 @@ def get_net_impact(self, key, displace=True):
37873787
+ self.get_net_utility_impact(key, displace=displace)
37883788
)
37893789

3790-
def get_property_allocated_impact(self, key, name, basis, ignored=None, products=None):
3790+
def get_product_impact(self,
3791+
product, key, allocation_method,
3792+
basis, ignored=None, products=None
3793+
):
3794+
if product == 'electricity':
3795+
power_utility = self.power_utility
3796+
if allocation_method == 'displacement':
3797+
return self.get_net_impact(key) / (power_utility.get_property(basis + '/hr') * self.operating_hours)
3798+
elif allocation_method == 'energy':
3799+
return self.get_property_allocated_impact(key, allocation_method, basis, ignored, products)
3800+
else:
3801+
raise ValueError(f"allocation method for 'electricity' must be either 'energy' or 'displacement', not {allocation_method!r}")
3802+
elif isinstance(product, Stream):
3803+
if allocation_method == 'displacement':
3804+
return self.get_net_impact(key) / (product.get_total_flow(basis + '/hr') * self.operating_hours)
3805+
else:
3806+
property_allocated_impact = self.get_property_allocated_impact(key, allocation_method, None, ignored, products)
3807+
return (
3808+
property_allocated_impact
3809+
* self.get_property(product, allocation_method)
3810+
/ (product.get_total_flow(basis + '/hr') * self.operating_hours)
3811+
)
3812+
else:
3813+
raise ValueError("product must be a stream object or 'electricity'")
3814+
3815+
def get_property_allocated_impact(self, key, name, basis=None, ignored=None, products=None):
37913816
if ignored is None: ignored = frozenset()
37923817
total_property = 0.
37933818
heat_utilities = self.heat_utilities
37943819
power_utility = self.power_utility
37953820
operating_hours = self.operating_hours
37963821
units = None if basis is None else basis + '/hr'
3797-
if name in bst.allocation_properties: name += '-allocation'
3822+
if name in bst.allocation_properties:
3823+
name += '-allocation'
3824+
else:
3825+
raise ValueError(
3826+
f'allocation method {name!r} not registered in bst.settings.allocation_methods; '
3827+
'to define a new allocation method use the bst.settings.define_allocation_property method'
3828+
)
37983829
if hasattr(bst.PowerUtility, name):
37993830
if power_utility.rate < 0.:
38003831
total_property += power_utility.get_property(name, units) * operating_hours

0 commit comments

Comments
 (0)