Python Life Cycle Inventory Analysis

The PyLCIA module links to the DES material model through the DES interface code. The DES interface preprocesses the incoming materials dataframe and prepares it for the LCA calculations. The interface calls on five main subcomponents of the pyLCIA module. It calls the concrete life cycle inventory updater to check for glass fiber materials in the incoming stream. If yes, it creates a modified cement coprocessing inventory based on the amount of glass fiber present in the incoming stream. This modified inventory is then used for LCA calculations. It calls the insitu_emission module to calculation insitu emissions. The foreground system for the study has direct emissions. To calculation those emissions, these systems are required to be scaled up based on their usage and then direct emissions derived using the scaling variables. These calculations are done using a modified LCA approach using a static inventory with just just product flows. It calls the pylca_opt_foreground module to calculate the first set of LCA calculations only for the foreground activities. All input flows to the foreground system from the background life cycle inventory are derived based on the scale up or scale down of these processes. This module also preprocesses the inventory and allows replacement of electricity production with dynamic grid mixes from electricity capacity expansion models. It call the pylca_opt_background module to perform the major LCA calculations of the background inventory. The final demand to the background LCI is obtained from the pylca_opt_foreground module. This module calculates the complete cradle to gate life cycle emissions for the foreground processes. The final module used by PyLCIA is the pylca_celavi_background_postprocess which has two main functions. It combines background and foreground emissions to complete our system boundary for the life cyle analysis. Finally, it converts emissions to impact factors and prepares the results to be sent to DES for final processing and visualization.

ReEDS Data Importer

class celavi.reeds_importer.ReedsImporter(reeds_imported_filename, reeds_output_filename)

The ReedsImporter class

  • Provides an object which stores the files names required for modifying ReEDS output datasets for compatibility with pyLCIA.

  • Calls the data manipulation methods.

Parameters
  • reeds_imported_filename (str) – Name of the manually edited ReEDS input file.

  • reeds_output_filename (str) – Name of the final pyLCIA compatible electricity grid mix file.

__init__(reeds_imported_filename, reeds_output_filename)

Store the filenames required for ReEDS data manipulation.

Parameters
  • reeds_imported_filename (str) – Name of the manually edited ReEDS input file

  • reeds_output_filename (str) – Name of the final pylcia compatible electricity grid mix file.

state_level_reeds_importer()

Store filenames and performs ReEDS data manipulation at the state electricity grid mix level.

national_level_reeds_importer()

Stores filenames and performs ReEDS data manipulation at the national electricity grid mix level.

Discrete Event Simulation Interface

class des_interface.PylcaCelavi(lcia_des_filename, shortcutlca_filename, intermediate_demand_filename, dynamic_lci_filename, electricity_grid_spatial_level, static_lci_filename, uslci_tech_filename, uslci_emission_filename, uslci_process_filename, stock_filename, emissions_lci_filename, traci_lci_filename, use_shortcut_lca_calculations, verbose, substitution_rate, run=0)
__init__(lcia_des_filename, shortcutlca_filename, intermediate_demand_filename, dynamic_lci_filename, electricity_grid_spatial_level, static_lci_filename, uslci_tech_filename, uslci_emission_filename, uslci_process_filename, stock_filename, emissions_lci_filename, traci_lci_filename, use_shortcut_lca_calculations, verbose, substitution_rate, run=0)

Stores filenames in self and deletes old interface file if it exists.

Parameters
  • lcia_des_filename (str) – Path to file that stores calculated impacts for passing back to the discrete event simulation.

  • shortcutlca_filename (str) – Path to file where previously calculated impacts are stored. This file can be used instead of re-calculating impacts from the inventory.

  • intermediate_demand_filename (str) – Path to file that stores the final demand vector every time the LCIA calculations are run. For debugging purposes only.

  • dynamic_lci_filename (str) – Path to the LCI dataset which changes with time.

  • electricity_grid_spatial_level (str) – Specification of grid spatial level used for lca calculations. Must be “state” or “national”.

  • static_lci_filename (str) – Path to the LCI dataset which does not change with time.

  • uslci_filename (str) – Path to the U.S. LCI dataset pickle file.

  • stock_filename (str) – Filename for storage pickle variable.

  • emissions_lci_filename (str) – Filename for emissions inventory.

  • traci_lci_filename (str) – Filename for TRACI 2.0 characterization factor dataset.

  • use_shortcut_lca_calculations (Boolean) – Boolean flag for using previously calculating impact data or running the optimization code to re-calculate impacts.

  • verbose (int) – 0 to suppress detailed print statements 1 to allow print statements

  • substitution_rate (Dict) – Dictionary of material name: substitution rates for materials displaced by the circular component.

  • run (int) – Model run. Defaults to zero.

lca_performance_improvement(df, state, electricity_grid_spatial_level)

This function is used to bypass pylca celavi calculations It reads emission factor data from previous runs stored in a file and performs lca faster.

The stored file needs to be reset after any significant update to data.

Parameters
  • df (pandas.DataFrame) –

    Material flow and process information provided by the DES. Columns:

    • year: int

      Model year.

    • stage: str

      Activity in the system

    • material: str

      Material flowing through the particular system activity

    • state: str

      Optional state identifier. Required only if electricity_grid_spatial_level is “state”.

    • route_id: str

      UUID for the route along which transportation occurs. None for non-transportation activities.

  • state (str) – State identifier. Currently not used

  • electricity_grid_spatial_level (str) – Specification of grid spatial level used for lca calculations. Must be “state” or “national”.

Returns

  • pandas.DataFrame, pandas.DataFrame – Emission results using the shortcut calculations and another dataframe with the flows that do not have any emission results. Columns:

    • year: int

      Model year.

    • stage: str

      Supply chain stage.

    • material: str

      Material being processed.

    • state: str

      State in which process exists.

    • route_id: str

      UUID of transportation route.

  • pandas.DataFrame – Pollutant flows from the shortcut LCA file, or an empty DataFrame if the shortcut file doesn’t exist. Columns:

    • flow name: str

      Pollutant name.

    • flow unit: str

      Unit of pollutant flow.

    • flow quantity: float

      Pollutant flow quantity.

    • year: int

      Model year.

    • facility_id: int

      Facility ID.

    • stage: str

      Supply chain stage.

    • state: str

      State where facility is located.

    • material: str

      Material being processed.

    • route_id: str

      UUID of transportation route.

pylca_run_main(df, verbose=0)

This function runs the individual pylca celavi functions for performing LCA relevant calculations.

Parameters

df (pandas.DataFrame) – Material flows from DES.

Returns

res_df – LCIA results (also appends to csv file)

Columns:
  • year: int

  • facility_id: int

  • material: str

  • route_id: str

  • state: str

  • stage: str

  • impacts: str

  • impact: float

Return type

pd.DataFrame

Insitu Emission Calculations

insitu_emission.preprocessing(year, df_emission)

This function preprocesses the emissions database for foregound system before calculation. It creates a product only database for technology matrix construction. Removes any dummy flows from the database.

Parameters
  • year (str) – year of LCA calculation

  • df_emission (pandas dataframe) – emission inventory

Returns

  • product_df (pandas dataframe) – An inventory with only product flows for creating the technology product matrix

  • df_with_all_other_flows (pandas dataframe) – inventory with no product flows

insitu_emission.solver(tech_matrix, F, process, df_with_all_other_flows)

This function houses the calculator to solve Xs = F for calculating insitu emissions. Solves the Xs=F equation. Solves the scaling vector.

Parameters
  • tech_matrix (numpy matrix) – technology matrix from the products inventory

  • F (numpy array) – Final demand vector

  • process (list) – list of processes in the emissions inventory

  • df_with_all_other_flows (pandas dataFrame) – lca inventory with no product flows

Returns

results_total – emissions as a dataframe after performing insitu emissions calculations These are insitu mass pollutant flows calculated for demand of material by foreground processes.

Columns:
  • product: str

  • unit: str

  • value: float

Return type

pandas dataframe

insitu_emission.electricity_corrector_before20(df)

This function is used to replace pre 2020 electricity flows in the emissions inventory with the base electricity mix flow in the USLCI inventory Electricity, at Grid, US, 2010’

Parameters

df (pd.DataFrame) – Background process inventory. Columns are derived from the background LCI database being used.

Returns

df – process inventory with electricity flows before 2020 converted to the base electricity mix flow in USLCI.

Return type

pd.DataFrame

insitu_emission.runner_insitu(tech_matrix, F, yr, i, j, k, state, final_demand_scaler, process, df_with_all_other_flows)

Runs the solver function for the insitu emissions and creates foreground emissions data frame in proper format.

Parameters
  • matrix (tech) – technology matrix built from the emissions inventory.

  • F (final demand series vector) – final demand of the foreground system

  • yr (int) – Model year

  • i (int) – facility ID

  • j (str) – Name of supply chain stage

  • k (str) – Name of material

  • state (str) – State where the facility is located.

  • final_demand_scaler (int) – Integer for scaling final demand and avoiding badly scaled matrix calculations.

  • process (list) – List of processes included in the technology matrix

  • df_with_all_other_flows (pd.DataFrame) – Dataframe with flows in the inventory which do not have a production process.

Returns

res – Emission results in the form of a dataframe. Columns:

  • product: str

  • unit: str

  • value: float

  • year: int

  • facility_id: int

  • stage: str

  • material: str

  • route_id: int

  • state: str

Return type

pandas dataframe

insitu_emission.model_celavi_lci_insitu(f_d, yr, fac_id, stage, material, state, df_emissions, verbose)

Creates a product only technology matrix for scaling vector calculations. Runs the solver to perform insitu emissions calculations. Conforms emission results to a dataframe. Performs column checks and renames columns . Returns the emissions dataframe.

Parameters
  • f_d (pandas dataframe) – Dataframe from DES

  • yr (int) – Model year.

  • fac_id (int) – Facility ID of facility being evaluated

  • stage (str) – Supply chain stage.

  • material (str) – material being evaluated

  • df_emission (pandas dataframe) – Emissons inventory

Returns

res – Insitu emissions dataframe with modified column names after checking column number. Columns:

  • flow name: str

  • flow unit: str

  • flow quantity: float

  • year: int

  • facility_id: int

  • stage: str

  • material: str

  • route_id: int

  • state: str

Return type

pandas dataframe

Concrete Inventory Editor

concrete_life_cycle_inventory_editor.concrete_life_cycle_inventory_updater(d_f, yr, k, stage, static_filename, stock_filename, emissions_filename, substitution_rate)

Modify a static concrete production inventory based on availability of ground blade material at the cement processing stage.

If blade material is not available, a stock variable is created to keep track of the amount of material available for use in cement co-processing in later years.

Parameters
  • d_f (pandas.DataFrame) – Material flow, stage and facility information from the DES interface.

  • yr (int) – Model year.

  • k (str) – Material being processed.

  • stage (str) – Supply chain stage.

  • static_filename (str) – Filename for the static concrete production inventory.

  • stock_filename (str) – Filename for the material stock variable (pickled).

  • emissons_filename (str) – Filename for concrete production emissions inventory.

  • substitution_rate (Dict) – Dictionary of substitution rates for materials displaced by the ground blade material.

Returns

  • df_static (pd.DataFrame) – updated static inventory with changes due to concrete demand and GFRP availability.

  • df_emissions (pd.DataFrame) – emissions inventory

Background Inventory Optimization

pylca_opt_background.model_celavi_lci_background(f_d, yr, fac_id, stage, material, route_id, state, uslci_tech_filename, uslci_emission_filename, uslci_process_filename, verbose)

Creates the technology matrix for the background system inventory and the final demand vector based on input data. Performs necessary checks before and after the LCA calculations.

Checks performed 1. Final demand to the background LCA system by the foreground system is not zero. If zero returns empty dataframe and simulation continues without breaking code. 2. Checks the LCA solver returned a proper dataframe. If empty dataframe is returned, it attaches column names to the dataframe and code continues without breaking.

Parameters
  • f_d (pandas.DataFrame) – Dataframe from DES interface containing material flow information

  • yr (int) – Model year

  • fac_id (int) – Facility id

  • stage (str) – Supply chain stage

  • material (str) – Material being processed

  • route_id (str) – Unique identifier for transportation route.

  • state (str) – State in which LCA calculations are taking place.

  • uslci_tech_filename (str) – Filename for the USLCI technology matrix. It contains the technology matrix from USLCI.

  • uslci_process_filename (str) – Filename for the USLCI process list matrix. It contains the list of processes in the USLCI.

  • uslci_emission_filename (str) – Filename for the USLCI emissions list matrix. It contains the list of emissions from acttivities in the background process inventory.

  • verbose (int) – Toggles level of progress reporting provided by this method. Defaults to 0 (no reporting).

Returns

res2 – Life cycle emissions from the background LCA calculation in the form of a dataframe with modified column names and supplemental information after performing calculation checks. These are mass pollutant flows calculated from USLCI for demand of material at a certain stage and from a facility. Columns:

  • product: str

  • unit: str

  • value: float

  • year: int

  • facility_id: int

  • stage: str

  • material: str

  • route_id: int

  • state: str

Return type

pd.DataFrame

Please note: model_celavi_lci_background has functions defined within it that are not accessible to the autodoc.

Foreground Inventory Optimization

pylca_opt_foreground.preprocessing(year, state, df_static, dynamic_lci_filename, electricity_grid_spatial_level)

This function preprocesses the foreground process inventory before the LCA calculation. It joins the dynamic LCA inventory with the static LCA inventory. Removes dummy processes with no output from the inventory.

Parameters
  • year (str) – Model year.

  • state (str) – State in which calculations are taking place.

  • df_static (pd.DataFrame) – Static foreground LCI.

  • dynamic_lci_filename (str) – Dynamic foreground LCI.

Returns

  • process_df (pd.DataFrame) – cleaned process inventory merged with dynamic data

  • df_with_all_other_flows (pd.DataFrame) – inventory with no product flows

    Columns:
    • flow name: str

    • flow unit: str

    • flow quantity: float

    • year: int

    • facility_id: int

    • stage: str

    • material: str

    • route_id: int

    • state: str

pylca_opt_foreground.solver(tech_matrix, F, process, df_with_all_other_flows)

This function solves Xs = F where X is the tech matrix for the foreground process inventory. Solves the Xs=F equation. Solves the scaling vector.

Parameters
  • tech_matrix (numpy matrix) – technology matrix from the foreground process inventory

  • F (vector) – Final demand vector

  • process (list) – List of process names corresponding to the scaling vector s.

  • df_with_all_other_flows (pd.DataFrame) – Foreground inventory with no product flows.

Returns

results_total – LCA results for foreground system in the form of a dataframe after performing LCA calculations This method calculates the outputs required from the background processes to operate the foreground processes. No emission flows are included in this calculation.

Columns:
  • product: str

  • unit: str

  • value: float

Return type

pd.DataFrame

pylca_opt_foreground.electricity_corrector_before20(df)

This function is used to replace pre 2020 electricity flows in the foreground inventory with the base electricity mix flow from the background USLCI inventory “Electricity, at Grid, US, 2010”

Parameters

df (pd.DataFrame) – Foreground inventory.

Returns

df – process inventory with electricity flows before 2020 converted to the base electricity mix flow in the background LCA inventory. Columns:

  • flow name: str

  • flow unit: str

  • flow quantity: float

  • year: int

  • facility_id: int

  • stage: str

  • material: str

  • route_id: int

  • state: str

Return type

pd.DataFrame

pylca_opt_foreground.lca_runner_foreground(tech_matrix, F, yr, i, j, k, route_id, state, final_demand_scaler, process, df_with_all_other_flows, intermediate_demand_filename, verbose)

Calls the LCA solver function for the foreground inventory and arranges and stores the results in a pandas dataframe.

Parameters
  • matrix (tech) – technology matrix built from the foreground process inventory.

  • F (final demand series vector) – final demand of the LCA problem

  • yr (int) – year of analysis

  • i (int) – facility ID

  • j (str) – stage

  • k (str) – material

  • route_id (str) – UUID identifying the transportation route

  • state (str) – state in which LCA calculations are taking place

  • final_demand_scaler (int) – scaling variable number to ease calculation

  • process (list) – list of processes included in the technology matrix

  • df_with_all_other_flows (pd.DataFrame) – Dataframe with flows in the inventory which do not have a production process.

Returns

res – Returns the demand of materials by the foreground system to the background system in a properly arranged dataframe with all supplemental information.

Columns:
  • product: str

  • unit: str

  • value: float

  • year: int

  • facility_id: int

  • stage: str

  • material: str

  • route_id: int

  • state: str

Return type

pd.DataFrame

Background Emissions Postprocessing

pylca_celavi_background_postprocess.postprocessing(final_res, insitu, verbose)

This function is used for post processing of final results dataframe It adds the insitu foreground emissions with the background emissions.

Parameters
  • final_res (pandas.DataFrame) – Background pollutant flow quantities.

  • insitu (pandas.DataFrame) – Insitu pollutant flow quantities.

  • verbose (int) – Controls the level of progress reporting from this method.

Returns

final_res – Combined total emissions dataframe with individual pollutant information

Columns:
  • flow name: str

  • flow unit: str

  • year: int

  • facility_id: int

  • stage: str

  • material: str

  • route_id: int

  • state: str

  • flow quantity: float

Return type

pd.DataFrame

pylca_celavi_background_postprocess.impact_calculations(final_res, traci_lci_filename)

This function is used for life cycle impact analysis post processing of final results dataframe It converts mass flow of pollutants to environmental impacts based on TRACI 2.1 characterization method

Parameters
  • final_res (pandas dataframe) – Emissions dataframe with foreground and background emissions

  • traci_lci_filename (str) – name of the traci characerization file

Returns

df_lcia – dataframe wih LCIA impact results

Columns:
  • facility_id: int

  • material: str

  • route_id: int

  • state: str

  • stage: str

  • impacts: str

  • impact: float

Return type

pd.DataFrame