Ejemplo n.º 1
0
    def _combine_s1_s2(self, target: IDataProviderTarget):
        """
        Check if there is an S2 target that matches this target exactly (if this is a S1 target) and combine them into one target.

        :param target: The input target
        :return: The combined target (or the original if no combining was required)
        """
        if target.scope == EScope.S1 and not pd.isnull(
                target.base_year_ghg_s1):
            matches = [
                t for t in self.s2_targets
                if t.company_id == target.company_id and t.base_year == target.
                base_year and t.start_year == target.start_year and t.end_year
                == target.end_year and t.target_type == target.target_type
                and t.intensity_metric == target.intensity_metric
            ]
            if len(matches) > 0:
                matches.sort(key=lambda t: t.coverage_s2, reverse=True)
                s2 = matches[0]
                combined_coverage = (target.coverage_s1 * target.base_year_ghg_s1 +
                                     s2.coverage_s2 * s2.base_year_ghg_s2) / \
                                    (target.base_year_ghg_s1 + s2.base_year_ghg_s2)
                target.reduction_ambition = target.reduction_ambition * target.coverage_s1 * target.base_year_ghg_s1 + \
                                            s2.reduction_ambition * s2.coverage_s1 * s2.base_year_ghg_s2 / \
                                            (target.base_year_ghg_s1 + s2.base_year_ghg_s1) / combined_coverage
                target.coverage_s1 = combined_coverage
                target.coverage_s2 = combined_coverage
                # We don't need to delete the S2 target as it'll be definition have a lower coverage than the combined
                # target, therefore it won't be picked for our 9-box grid
        return target
Ejemplo n.º 2
0
    def _convert_s1_s2(self, target: IDataProviderTarget):
        """
        Convert a S1 or S2 target into a S1+S2 target.

        :param target: The input target
        :return: The converted target (or the original if no conversion was required)
        """
        # In both cases the base_year_ghg s1 + s2 should not be zero
        if target.base_year_ghg_s1 + target.base_year_ghg_s2 != 0:
            if target.scope == EScope.S1:
                coverage = target.coverage_s1 * target.base_year_ghg_s1 / (
                    target.base_year_ghg_s1 + target.base_year_ghg_s2)
                target.coverage_s1 = coverage
                target.coverage_s2 = coverage
                target.scope = EScope.S1S2
            elif target.scope == EScope.S2:
                coverage = target.coverage_s2 * target.base_year_ghg_s2 / (
                    target.base_year_ghg_s1 + target.base_year_ghg_s2)
                target.coverage_s1 = coverage
                target.coverage_s2 = coverage
                target.scope = EScope.S1S2
        return target