def get_costs(self, t_subset=None):

        def _factor(var, t_subset_slice):
            """Return the fraction of var within t_subset. Used to
               calculate the correct fraction of operational costs."""
            if 'c' in var.coords:
                sum_dims = ('c', 't')
            else:
                sum_dims = ('t')

            return (var[dict(t=t_subset_slice)].sum(dim=sum_dims)
                    / var.sum(dim=sum_dims)).fillna(0)

        if t_subset is None:
            t_subset_slice = slice(None)
        else:
            t_subset_slice = t_subset

        # len_adjust is the fraction of construction and fixed costs
        # that is accrued to the chosen t_subset. NB: construction and fixed
        # operation costs are calculated for a whole year
        len_adjust = (sum(self.data.time_res_series.iloc[t_subset_slice])
                      / sum(self.data.time_res_series))

        # Adjust for the fact that fixed costs accrue over a smaller length
        # of time as per len_adjust
        cost = self.get_var('cost_con') + self.get_var('cost_op_fixed')
        cost = cost * len_adjust

        # Get variable costs
        cost_var = self.get_var('cost_op_var')
        cost_fuel = self.get_var('cost_op_fuel')
        cost_rb = self.get_var('cost_op_rb')

        # Adjust for the fact that variable costs are only accrued over
        # the t_subset period
        if t_subset is not None:
            es_prod = self.get_var('es_prod')
            # Broadcast multiplication along cost classes
            cost_var = cost_var * _factor(es_prod, t_subset_slice)
            rs = self.get_var('rs')
            cost_fuel = cost_fuel * _factor(rs, t_subset_slice)
            try:
                rbs = self.get_var('rbs')
                # NB: we do .fillna(0) because the rbs var will only
                # be defined for techs that actually use rbs, so
                # we'd get NaN costs for all other techs, which would
                # propagate through to making final costs NaN too
                cost_rb = cost_rb * _factor(rbs, t_subset_slice).fillna(0)
            except exceptions.ModelError:
                pass  # If rbs doesn't exist in the data, ModelError is raised,
                # and we simply move on...

        cost = cost + cost_var + cost_fuel + cost_rb
        return cost
Get costs.
dataset/ETHPy150Open calliope-project/calliope/calliope/core.py/Model.get_costs