dopo.lca ======== .. py:module:: dopo.lca .. autoapi-nested-parse:: Generates and saves Life Cycle Assessment (LCA) scores plots for various sectors. The module computes LCA scores for activities and methods. Attributes ---------- .. autoapisummary:: dopo.lca.bc_version Functions --------- .. autoapisummary:: dopo.lca._agg_small_inputs dopo.lca._compare_activities_multiple_methods dopo.lca.compare_activities_by_grouped_leaves dopo.lca.find_leaves dopo.lca.sector_lca_scores Module Contents --------------- .. py:function:: _agg_small_inputs(dataframe, cutoff=0.01) Aggregates small inputs in a DataFrame into an "other" input category. This function calculates the sum of scores for each group of activities and then calculates the percentage for each row. Rows with less than the specified cutoff percentage are labeled as "Other". The function then groups the DataFrame by the same columns and 'input' to aggregate scores. :param dataframe: A DataFrame containing LCA scores for activities. :type dataframe: pandas DataFrame :param cutoff: A threshold value for summarizing inputs below or equal to this value in an "other" column. :type cutoff: float, optional :return: A DataFrame with aggregated scores. :rtype: pandas DataFrame .. py:function:: _compare_activities_multiple_methods(activities: list, methods: list, output_format: str = 'pandas', mode: str = 'absolute', cutoff: float = 0.01, cache=None) -> pandas.DataFrame Compares a list of activities using multiple LCA methods and stores the results in a dictionary of DataFrames. This function generates comparison results for each method in `methods`, formats them into DataFrames, and organizes them in a dictionary where the keys are method-specific names derived from the `identifier` and method details. Each DataFrame contains total scores and input contributions, with columns ordered and indexed appropriately. :param activities: A list of activities to compare. :type activities: list :param methods: A list of methods to use for comparison. :type methods: list :param output_format: The format of the output DataFrame. :type output_format: str, optional :param mode: The mode of the comparison. :type mode: str, optional :return: A pandas DataFrame containing LCA scores. :rtype: pd.DataFrame .. py:function:: compare_activities_by_grouped_leaves(activities, lcia_method, mode='relative', max_level=4, cutoff=0.0075, output_format='list', str_length=50, cache=None) Compare activities by the impact of their different inputs, aggregated by the product classification of those inputs. Args: activities: list of ``Activity`` instances. lcia_method: tuple. LCIA method to use when traversing supply chain graph. mode: str. If "relative" (default), results are returned as a fraction of total input. Otherwise, results are absolute impact per input exchange. max_level: int. Maximum level in supply chain to examine. cutoff: float. Fraction of total impact to cutoff supply chain graph traversal at. output_format: str. See below. str_length; int. If ``output_format`` is ``html``, this controls how many characters each column label can have. Raises: ValueError: ``activities`` is malformed. Returns: Depends on ``output_format``: * ``list``: Tuple of ``(column labels, data)`` * ``html``: HTML string that will print nicely in Jupyter notebooks. * ``pandas``: a pandas ``DataFrame``. .. py:function:: find_leaves(activity, lcia_method, results=None, lca_obj=None, amount=1, total_score=None, level=0, max_level=3, cutoff=0.025, cache=None, activities_to_exclude_from_cache=None) Traverse the supply chain of an activity to find leaves - places where the impact of that component falls below a threshold value. Returns a list of ``(impact of this activity, amount consumed, Activity instance)`` tuples. .. py:function:: sector_lca_scores(sectors, methods, cutoff=0.01) -> dict Generates LCA score tables for each sector's activity list, including total scores and CPC input contributions. This function calculates LCA scores for activities within each sector using methods specified in the `method_dict`. Inputs below or equal to the `cutoff` value are summarized in an "other" column. :param sectors: A dictionary where keys are sector names and values are lists of activities. :type sectors: dict :param methods: A list of methods to use for LCA calculations. :type methods: list :param cutoff: A threshold value for summarizing inputs below or equal to this value in an "other" column. :type cutoff: float, optional :return: A dictionary where each key is a sector name and each value is a DataFrame containing LCA scores. :rtype: dict .. py:data:: bc_version