dopo.database_comparison

Module for LCA Database Comparison and Excel Plotting

Provides functions to compare LCA scores between databases and visualize results in Excel. It uses brightway2 for LCA calculations and openpyxl for Excel operations.

Functions

_add_sector_marker(df, sector)

Adds a 'sector' column to the DataFrame for labeling and plotting purposes, and reorders columns

_barchart_compare_db_xcl(filename, index_positions, ...)

Generates bar charts comparing relative changes from multiple Excel worksheets,

_categorize_sheets_by_sector_comparison(file_path)

Categorizes Excel sheets by sector based on their names from a given file.

_lca_scores_compare(database_dict, method_dict)

Compare Life Cycle Assessment (LCA) scores across different sectors and methods.

_relative_changes_db(database_dict_eco, ...)

Computes relative changes in LCA scores between two databases (ecoinvent and premise), adds

_relative_changes_df(database_dict_eco, ...)

Compute relative changes in Life Cycle Assessment (LCA) scores between two databases (ecoinvent and premise)

database_comparison_plots(database_dict_ecoinvent, ...)

Generate comparison plots of Life Cycle Assessment (LCA) scores between two databases and save

Module Contents

dopo.database_comparison._add_sector_marker(df, sector)[source]

Adds a ‘sector’ column to the DataFrame for labeling and plotting purposes, and reorders columns to place ‘sector’ after ‘product’ if it exists.

Args:

df (pd.DataFrame): DataFrame to modify. sector (str): Sector name to add as a marker.

Returns:

pd.DataFrame: DataFrame with the added ‘sector’ column and reordered columns.

dopo.database_comparison._barchart_compare_db_xcl(filename, index_positions, current_row_stacked_bar)[source]

Generates bar charts comparing relative changes from multiple Excel worksheets, organizes them by sector, and saves the charts to new sheets in the same Excel file.

Args:

filename (str): Path to the Excel file containing the data. index_positions (dict): Dictionary with the positions of relevant columns for each sheet. current_row_stacked_bar (int): Initial row position for placing stacked bar charts.

Returns:

None. Saves the charts directly into the Excel file.

dopo.database_comparison._categorize_sheets_by_sector_comparison(file_path)[source]

Categorizes Excel sheets by sector based on their names from a given file.

Args:

file_path (str): Path to the Excel file.

Returns:

dict: A dictionary where each key is a sector and each value is a list of sheet names corresponding to that sector.

dopo.database_comparison._lca_scores_compare(database_dict, method_dict)[source]

Compare Life Cycle Assessment (LCA) scores across different sectors and methods.

Args:
database_dict (dict): Dictionary where each key is a sector name and each value is a dictionary

containing activities of that sector.

method_dict (dict): Dictionary where each key is a method identifier and each value is a dictionary

containing method details such as ‘method name’, ‘short name’, and ‘unit’.

Returns:

dict: A nested dictionary where each key is a sector name, and each value is a dictionary containing DataFrames for each method with total LCA scores related information for all activities.

dopo.database_comparison._relative_changes_db(database_dict_eco, database_dict_premise, method_dict, excel_file)[source]

Computes relative changes in LCA scores between two databases (ecoinvent and premise), adds sector markers, and writes the results to an Excel file. Also returns the column positions for plotting.

Args:

database_dict_eco (dict): Dictionary of sectors with activities for the ecoinvent database. database_dict_premise (dict): Dictionary of sectors with activities for the premise database. method_dict (dict): Dictionary of methods with their details such as ‘method name’, ‘short name’, and ‘unit’. excel_file (str): Path to the Excel file where results are to be saved.

Returns:

dict: Dictionary containing the positions of specific columns for each sector and method comparison.

dopo.database_comparison._relative_changes_df(database_dict_eco, database_dict_premise, method_dict)[source]

Compute relative changes in Life Cycle Assessment (LCA) scores between two databases (ecoinvent and premise) across different sectors and methods.

Args:

database_dict_eco (dict): Dictionary of sectors with activities for the ecoinvent database. database_dict_premise (dict): Dictionary of sectors with activities for the premise database. method_dict (dict): Dictionary of methods with their details such as ‘method name’, ‘short name’, and ‘unit’.

Returns:

dict: A nested dictionary where each key is a sector name, and each value is a dictionary containing DataFrames for each method with relative changes in LCA scores and related information.

dopo.database_comparison.database_comparison_plots(database_dict_ecoinvent, database_dict_premise, method_dict, excel_file, current_row)[source]

Generate comparison plots of Life Cycle Assessment (LCA) scores between two databases and save them to an Excel file.

This function compares LCA scores between two different databases (e.g., ecoinvent and premise) using the given impact assessment methods. It generates a bar chart showing the relative changes between the databases and saves the results to an Excel file.

Args:
database_dict_ecoinvent (dict): A dictionary representing the first LCA database (e.g.,

ecoinvent).

database_dict_premise (dict): A dictionary representing the second LCA database (e.g.,

premise).

method_dict (dict): A dictionary where keys are method names or IDs and values are

corresponding method data.

excel_file (str): The name of the Excel file where the comparison plots will be saved. current_row (int): The last row in the Excel sheet occupied by stacked bar plot. The

comparison charts will be inserted below.

Returns:

None

The function performs the following steps: 1. Calculates the relative changes in LCA scores between the two databases using the provided

methods.

  1. Saves the results to the specified Excel file.

  2. Generates a bar chart that visually compares the LCA scores between the two databases and

    appends it to the Excel file.

Note:
  • The function relies on helper functions such as relative_changes_db to calculate the

    relative changes between databases and barchart_compare_db_xcl to generate and save the bar chart.