mescal.impact_assessment ======================== .. py:module:: mescal.impact_assessment Attributes ---------- .. autoapisummary:: mescal.impact_assessment.ca mescal.impact_assessment.calculation_setups Classes ------- .. autoapisummary:: mescal.impact_assessment.MultiLCA Functions --------- .. autoapisummary:: mescal.impact_assessment._add_virtual_technosphere_flow mescal.impact_assessment._aggregate_direct_emissions_activities mescal.impact_assessment._is_empty mescal.impact_assessment.compute_impact_scores mescal.impact_assessment.compute_territorial_impact_scores mescal.impact_assessment.validation_direct_carbon_emissions Module Contents --------------- .. py:class:: MultiLCA(cs_name: str, contribution_analysis: str, limit: int or float, limit_type: str, req_technosphere: bool, log_config=None) Bases: :py:obj:`object` Adaptation of the `MultiLCA` class from the `bw2calc` package in order to perform contribution analysis. Wrapper class for performing LCA calculations with many functional units and LCIA methods. Needs to be passed a ``calculation_setup`` name. This class does not subclass the `LCA` class, and performs all calculations upon instantiation. Initialization creates `self.results`, which is a NumPy array of LCA scores, with rows of functional units and columns of LCIA methods. Ordering is the same as in the `calculation_setup`. Initialize the MultiLCA_with_contribution_analysis class. :param cs_name: name of the calculation setup to use :param contribution_analysis: if 'emissions', the function will return the contribution analysis of top elementary flows. If 'processes', the function will return the contribution analysis of top processes. If 'both', it will return both. :param limit: number of values to return (if limit_type is 'number'), or percentage cutoff (if limit_type is 'percent') :param limit_type: contribution analysis limit type, can be 'percent' or 'number' :param req_technosphere: if True, the function will compute the requirements for technosphere flows :param log_config: log configuration for the LCA calculation .. py:property:: all Get all possible databases by merging all functional units .. py:attribute:: contribution_analysis .. py:attribute:: func_units .. py:attribute:: lca .. py:attribute:: limit .. py:attribute:: limit_type .. py:attribute:: method_matrices :value: [] .. py:attribute:: methods .. py:attribute:: results .. py:function:: _add_virtual_technosphere_flow(act: dict, exc_act: dict, amount: float) -> dict Add a technosphere exchange to an activity :param act: activity to which the exchange is added :param exc_act: activity of the exchange :param amount: amount of the exchange :return: the activity with the new exchange .. py:function:: _aggregate_direct_emissions_activities(self, esm_db: mescal.database.Database, direct_emissions_db: list[dict], activities_subject_to_double_counting: pandas.DataFrame) -> mescal.database.Database Aggregate the activities subject to double counting for the same ESM technology :param esm_db: ESM database :param direct_emissions_db: direct emissions ESM database before aggregation :param activities_subject_to_double_counting: dataframe of activities subject to double counting :return: aggregated direct emissions ESM database .. py:function:: _is_empty(self, row: pandas.Series) -> float Fill empty cells with the ESM value if the technology is not in the technology compositions file :param row: row of the lifetime dataframe :return: lifetime value .. py:function:: compute_impact_scores(self, methods: list[str], specific_lcia_categories: list[str] = None, specific_lcia_abbrev: list[str] = None, impact_abbrev: pandas.DataFrame = None, assessment_type: str = 'esm', overwrite: bool = True, contribution_analysis: str = None, contribution_analysis_limit_type: str = 'number', contribution_analysis_limit: float or int = 5, req_technosphere: bool = False) -> tuple[pandas.DataFrame, pandas.DataFrame | None, pandas.DataFrame | None] Compute the impact scores of the technologies and resources :param methods: list of life-cycle impact assessment methods for which LCA scores are computed :param specific_lcia_categories: restrict the impact assessment to specific LCIA categories :param specific_lcia_abbrev: restrict the impact assessment to specific LCIA categories identified by their abbreviation in the impact_abbrev file :param impact_abbrev: dataframe containing the impact categories abbreviations :param assessment_type: type of assessment, can be 'esm' for the computation of the energy system life-cycle impacts, or 'direct emissions' for the computation of direct emissions only :param overwrite: only relevant if assessment_type is 'direct emissions', if True, the direct emissions database will be overwritten if it exists :param contribution_analysis: if 'emissions', the function will return the contribution analysis of top elementary flows. If 'processes', the function will return the contribution analysis of top processes. If 'both', it will return both. :param contribution_analysis_limit_type: contribution analysis limit type, can be 'percent' or 'number'. Default is 'percent'. :param contribution_analysis_limit: number of values to return (if limit_type is 'number'), or percentage cutoff (if limit_type is 'percent'). Default is 0.01. :param req_technosphere: if True, the function will compute the requirements for technosphere flows. :return: impact scores dataframe of the technologies and resources for all selected impact categories, contribution analysis dataframe (None if contribution_analysis is None), and technosphere flows requirements dataframe (None if req_technosphere is False). .. py:function:: compute_territorial_impact_scores(self, df_contrib_processes: pandas.DataFrame) -> pandas.DataFrame Compute the territorial and abroad impact scores from the contribution analysis of processes. :param df_contrib_processes: dataframe of the contribution analysis of processes :return: territorial and abroad impact scores dataframe .. py:function:: validation_direct_carbon_emissions(self, R_direct: pandas.DataFrame, lcia_method_carbon_emissions: str, carbon_flow_in_esm: str or list[str], esm_results: pandas.DataFrame = None, return_df: bool = False, save_df: bool = True) -> tuple[pd.DataFrame, pd.DataFrame | None] or None Returns a dataframe comparing the direct carbon emissions obtained from the LCIA phase (direct emissions module) and direct carbon emissions from the ESM. Please make sure that carbon emissions are expressed with the same physical unit, e.g., kg CO2-eq., in the ESM and LCIA method (while functional units, e.g., kWh, are automatically converted to ESM units). :param R_direct: dataframe containing the direct carbon emissions from the LCIA phase :param lcia_method_carbon_emissions: name of the LCIA method for carbon emissions in brightway :param carbon_flow_in_esm: names(s) of the carbon flow(s) in the ESM :param esm_results: dataframe containing the annual production of each technology in the ESM. It must contain the columns 'Name' and 'Production', and it can possibly contain the 'Run' and 'Year' columns too. If provided, the system's direct emissions will be compared. :param return_df: if True, the function will return the dataframe :param save_df: if True, the function will save the dataframe to a csv file named direct_carbon_emissions_differences and a file named direct_carbon_emissions_differences_system (if esm_results is provided) in self.results_path_file :return: dataframe comparing the direct carbon emissions from the LCIA phase and the ESM if return_df is True .. py:data:: ca .. py:data:: calculation_setups :value: None .. py:method:: _get_impact_categories(methods: list[str]) -> list[str] :staticmethod: Get all impact categories from a list of methods :param methods: list of LCIA methods :return: list of impact categories in the LCIA methods