ImpactItem#

class qsdsan.ImpactItem(ID='', functional_unit='', price=0.0, source=None, **indicator_CFs)#

A class for calculation of environmental impacts.

Parameters:
  • ID (str) – ID of the impact item.

  • functional_unit (str) – Functional unit of the impact item.

  • price (float) – Price of the item per functional unit.

  • source (ImpactItem) – If provided, all attributions and properties of this impact item will be copied from the provided source.

  • indicator_CFs (kwargs) – Impact indicators and their characterization factors (CFs), can be in the form of str=float or str=(float, unit).

Tip

ImpactItem should be used for environmental impacts associated with construction and transportation. For impacts associated with streams (e.g., chemicals, wastes, emissions), use StreamImpactItem instead.

Examples

Firstly make impact indicators.

>>> import qsdsan as qs
>>> GWP = qs.ImpactIndicator('GlobalWarming', alias='GWP', unit='kg CO2-eq')
>>> FEC = qs.ImpactIndicator('FossilEnergyConsumption', alias='FEC', unit='MJ')

We can make impact items in different ways (numbers are made up).

>>> Steel = qs.ImpactItem('Steel', 'kg', GWP=2.55)
>>> Steel.show()
ImpactItem      : Steel [per kg]
Price           : None USD
ImpactIndicators:
                           Characterization factors
GlobalWarming (kg CO2-eq)                      2.55
>>> # Unit will be automatically converted to match the unit of the impact indicator
>>> Electricity = qs.ImpactItem('Electricity', functional_unit='kWh',
...                             GWP=(480, 'g CO2-eq'), FEC=(5926, 'kJ'))
>>> Electricity.show()
ImpactItem      : Electricity [per kWh]
Price           : None USD
ImpactIndicators:
                              Characterization factors
GlobalWarming (kg CO2-eq)                         0.48
FossilEnergyConsumption (MJ)                      5.93
>>> # Note that 5.93 appearing instead of 5.926 is for nicer print
>>> Electricity.CFs
{'GlobalWarming': 0.48, 'FossilEnergyConsumption': 5.926}
>>> # Get all impact items
>>> qs.ImpactItem.get_all_items()
{'Steel': <ImpactItem: Steel>, 'Electricity': <ImpactItem: Electricity>}

You can make copies of impact items and choose to link to the source or not.

>>> Steel2 = Steel.copy('Steel2', set_as_source=True)
>>> Steel2.CFs['GlobalWarming']
2.55
>>> Steel3 = Steel.copy('Steel3', set_as_source=False)
>>> Steel3.CFs['GlobalWarming']
2.55
>>> # Once linked, CFs of the copy will update with the source
>>> Steel.CFs['GlobalWarming'] = 2
>>> Steel.CFs['GlobalWarming']
2
>>> Steel2.CFs['GlobalWarming']
2
>>> Steel3.CFs['GlobalWarming']
2.55
>>> # Update the copy won't update the source
>>> Steel2.CFs['GlobalWarming'] = 5
>>> Steel.CFs['GlobalWarming']
2
>>> Steel2.CFs['GlobalWarming']
2

Manage the registry.

>>> qs.ImpactItem.get_all_items()
{'Steel': <ImpactItem: Steel>,
 'Electricity': <ImpactItem: Electricity>,
 'Steel2': <ImpactItem: Steel2>,
 'Steel3': <ImpactItem: Steel3>}
>>> Steel2.deregister()
The impact item "Steel2" has been removed from the registry.
>>> qs.ImpactItem.get_all_items()
{'Steel': <ImpactItem: Steel>,
 'Electricity': <ImpactItem: Electricity>,
 'Steel3': <ImpactItem: Steel3>}
>>> Steel2.register()
The impact item "Steel2" has been added to the registry.
>>> qs.ImpactItem.get_all_items()
{'Steel': <ImpactItem: Steel>,
 'Electricity': <ImpactItem: Electricity>,
 'Steel3': <ImpactItem: Steel3>,
 'Steel2': <ImpactItem: Steel2>}
>>> qs.ImpactItem.clear_registry()
All impact items have been removed from the registry.
>>> qs.ImpactItem.get_all_items()
{}
>>> # Clear all registries for testing purpose
>>> from qsdsan.utils import clear_lca_registries
>>> clear_lca_registries()
property CFs#

[dict] Characterization factors of this item for different impact indicators.

property ID#

Unique identification (str). If set as ‘’, it will choose a default ID.

add_indicator(indicator, CF_value, CF_unit='')#

Add an indicator with characterization factor values.

Parameters:
  • indicator (obj or str) – ImpactIndicator or its ID.

  • CF_value (float) – Characterization factor of the indicator.

  • CF_unit (str) – Unit of the characterization factor value.

classmethod clear_registry(print_msg=True)#

Remove all existing impact items from the registry.

copy(new_ID='', set_as_source=False)#

Return a new ImpactItem object with the same settings.

Parameters:
  • new_ID (str) – ID of the new impact item.

  • set_as_source (bool) – Whether to set the original impact item as the source.

Examples

>>> import qsdsan as qs
>>> GWP = qs.ImpactIndicator('GlobalWarming', alias='GWP', unit='kg CO2-eq')
>>> Steel = qs.ImpactItem('Steel', 'kg', GWP=2.55)
>>> Steel.show()
ImpactItem      : Steel [per kg]
Price           : None USD
ImpactIndicators:
                           Characterization factors
GlobalWarming (kg CO2-eq)                      2.55
>>> Steel_cp = Steel.copy(set_as_source=True)
>>> Steel_cp.show()
ImpactItem      : item1 [per kg]
Source          : Steel
Price           : None USD
ImpactIndicators:
                           Characterization factors
GlobalWarming (kg CO2-eq)                      2.55
>>> Steel_cp.source is Steel
True
deregister(print_msg=True)#

Remove this impact item from the registry.

property functional_unit#

[str] Functional unit of this item.

classmethod get_all_items()#

Get all impact items.

classmethod get_item(ID)#

Get an item by its ID.

property indicators#

[tuple] Impact indicators associated with this item.

classmethod load_from_file(path_or_dict, index_col=None)#

Load impact items from an Excel file or a pandas.DataFrame.

This Excel should have multiple sheets:

  • The “info” sheet should have three columns: “ID” (e.g., Cement) “functional_unit” (e.g., kg), and “kind” (“ImpactItem” or “StreamImpactItem”) of different impact items.

  • The remaining sheets should contain characterization factors of impact indicators.

    • Name of the sheet should be the ID (e.g., GlobalWarming) or alias (e.g., GWP) of the indicator.

    • Each sheet should have at least two columns: “unit” (e.g., kg CO2-eq) and “expected” (values) of the CF.

    • You can also have additional columns to be used for other purpose (e.g., uncertainty analysis).

Note

This function is just one way to batch-load impact items, you can always write your own function that fits your datasheet format, as long as it provides all the information to construct new impact items.

Parameters:
  • path_or_dict (str or dict of pandas.DataFrame) – A dict of DataFrame or complete path of the datasheet in xls/xlsx.

  • index_col (None or int) – Index column of the pandas.DataFrame.

Tip

Refer to the Bwaise system in the Exposan repository for a sample file.

classmethod load_items_from_excel(path_or_dict, index_col=None)#

Same as load_from_file(), has been deprecated.

property price#

Price of this item per functional unit.

register(print_msg=True)#

Add this impact item to the registry.

property registered#

[bool] If this impact item is registered in the record.

remove_indicator(indicator)#

Remove an indicator from this impact item.

Parameters:

indicator (str or ImpactIndicator) – ImpactIndicator or its ID.

show()#

Show basic information of this impact item.

property source#

[ImpactItem] If provided, all attributions and properties of this impact item will be copied from the provided source. ID of the impact item can be provided instead of the object.

StreamImpactItem#

class qsdsan.StreamImpactItem(ID='', linked_stream=None, functional_unit='kg', source=None, flow_getter=None, **indicator_CFs)#

A class for calculation of environmental impacts associated with streams (e.g., chemical inputs, emissions).

Parameters:
  • ID (str) – ID of the item. If no ID is provided but its linked_stream is provided, the ID will be set as ID of the linked_stream with a suffix ‘_item’

  • linked_stream (SanStream) – The associated SanStream for environmental impact calculation.

  • functional_unit (str) – Functional unit of the impact item. The default is ‘kg’.

  • source (StreamImpactItem) – If provided, all attributions and properties of this StreamImpactItem will be copied from the provided source.

  • flow_getter (callable|float|int) – If none specified, default to SanStream.F_mass.

  • indicator_CFs (kwargs) – ImpactIndicators and their characterization factors (CFs).

Tip

For environmental impacts associated with construction and transportation, use ImpactItem instead.

Examples

Refer to ImpactItem for general features. Below is about the additional features for StreamImpactItem.

Assume we want to account for the global warming potential for methane:

>>> # Make impact indicators
>>> import qsdsan as qs
>>> GWP = qs.ImpactIndicator('GlobalWarming', alias='GWP', unit='kg CO2-eq')
>>> FEC = qs.ImpactIndicator('FossilEnergyConsumption', alias='FEC', unit='MJ')
>>> # Make an stream impact item
>>> methane_item = qs.StreamImpactItem('methane_item', GWP=28)
>>> methane_item.show()
StreamImpactItem: methane_item [per kg]
Linked to       : None
Price           : None USD
ImpactIndicators:
                           Characterization factors
GlobalWarming (kg CO2-eq)                        28
>>> # Make a stream and link the stream to the impact item
>>> cmps = qs.utils.create_example_components()
>>> qs.set_thermo(cmps)
>>> methane = qs.SanStream('methane', Methane=1, units='kg/hr',
...                        stream_impact_item=methane_item)
>>> methane_item.show()
StreamImpactItem: methane_item [per kg]
Linked to       : methane
Price           : None USD
ImpactIndicators:
                           Characterization factors
GlobalWarming (kg CO2-eq)                        28

We can make copies of the impact item, and link it to the original one.

>>> methane2 = methane.copy('methane2')
>>> methane_item2 = methane_item.copy('methane_item2', stream=methane2,
...                                   set_as_source=True)
>>> methane_item2.CFs['GlobalWarming']
28
>>> methane_item.CFs['GlobalWarming'] = 1
>>> methane_item2.CFs['GlobalWarming']
1

We can also add or remove impact indicators.

>>> methane_item.remove_indicator('GlobalWarming')
The impact indicator "GlobalWarming" has been removed.
>>> methane_item2.show()
StreamImpactItem: methane_item2 [per kg]
Linked to       : methane2
Source          : methane_item
Price           : None USD
ImpactIndicators:
 None
>>> methane_item.add_indicator('GlobalWarming', 28)
>>> methane_item2.show()
StreamImpactItem: methane_item2 [per kg]
Linked to       : methane2
Source          : methane_item
Price           : None USD
ImpactIndicators:
                           Characterization factors
GlobalWarming (kg CO2-eq)                        28
property ID#

[str] ID of the item. If no ID is provided but its linked_stream is provided, the ID will be set as ID of the linked_stream with a suffix ‘_item’.

copy(new_ID='', stream=None, set_as_source=False)#

Return a new StreamImpactItem object with the same settings.

Parameters:
  • new_ID (str) – ID of the new stream impact item.

  • stream (SanStream) – Linked stream to the copy.

  • set_as_source (bool) – Whether to set the original impact item as the source.

property flow_getter#

[callable] A function taking a SanStream object and returns the flow [functional unit/hr] for impact calculation. If None specified, default to SanStream.F_mass.

property linked_stream#

[SanStream] The associated SanStream for environmental impact calculation, can be set by either the SanStream object or its ID.

property price#

[float] Price of the linked stream.

show()#

Show basic information about this StreamImpactItem object.

property source#

[StreamImpactItem] If provided, all attributions and properties of this StreamImpactItem will be copied from the provided source. ID of the impact item can be provided instead of the object.

Note

Since the price is copied from the price of the linked_stream, it can be different from the source.