How to use the calliope.backend.pyomo.util.loc_tech_is_in function in calliope

To help you get started, we’ve selected a few calliope examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github calliope-project / calliope / calliope / backend / pyomo / constraints / piecewise.py View on Github external
if step != last_timestep:
        return backend_model.cost_var[cost, loc_tech, step] == 0

    if (po.value(cost_om_prod) != 'nan' and cost_om_prod is not None):
        slope, intercept = (float(i) for i in po.value(cost_om_prod).split('::'))
        cost_prod = (
            slope * sum(
                backend_model.timestep_weights[timestep] * backend_model.carrier_prod[loc_tech_carrier, timestep]
                # TODO: remove monthwise step hardcoding
                for timestep in backend_model.timesteps if timestep.month == step.month
            ) + intercept * backend_model.purchased[loc_tech]
        )
    else:
        cost_prod = None

    if loc_tech_is_in(backend_model, loc_tech, 'loc_techs_supply_plus') and po.value(cost_om_con) != 'nan' and cost_om_con is not None:
        slope, intercept = (float(i) for i in po.value(cost_om_prod).split('::'))
        cost_con = (
            slope * sum(
                backend_model.timestep_weights[timestep] * backend_model.resource_con[loc_tech, timestep]
                # TODO: remove monthwise step hardcoding
                for timestep in backend_model.timesteps if timestep.month == step.month
            ) + intercept * backend_model.purchased[loc_tech]
        )

    elif loc_tech_is_in(backend_model, loc_tech, 'loc_techs_supply') and po.value(cost_om_con) != 'nan' and cost_om_con is not None:
        slope, intercept = (float(i) for i in po.value(cost_om_prod).split('::'))
        # TODO: add in a check for energy_eff == 0, as this will create an infinite value
        cost_con = (
            slope * sum(
                backend_model.timestep_weights[timestep] *
                (backend_model.carrier_prod[loc_tech_carrier, timestep] /
github calliope-project / calliope / calliope / backend / pyomo / constraints / milp.py View on Github external
]
        multiplier = 1

    max_systemwide = get_param(backend_model, 'units_max_systemwide', tech)
    equals_systemwide = get_param(backend_model, 'units_equals_systemwide', tech)

    if np.isinf(po.value(max_systemwide)) and not equals_systemwide:
        return po.Constraint.NoConstraint
    elif equals_systemwide and np.isinf(po.value(equals_systemwide)):
        raise ValueError(
            'Cannot use inf for energy_cap_equals_systemwide for tech `{}`'.format(tech)
        )

    sum_expr_units = sum(
        backend_model.units[loc_tech] for loc_tech in all_loc_techs
        if loc_tech_is_in(backend_model, loc_tech, 'loc_techs_milp')
    )
    sum_expr_purchase = sum(
        backend_model.purchased[loc_tech] for loc_tech in all_loc_techs
        if loc_tech_is_in(backend_model, loc_tech, 'loc_techs_purchase')
    )

    if equals_systemwide:
        return sum_expr_units + sum_expr_purchase == equals_systemwide * multiplier
    else:
        return sum_expr_units + sum_expr_purchase <= max_systemwide * multiplier
github calliope-project / calliope / calliope / backend / pyomo / constraints / costs.py View on Github external
loc_tech_carrier = model_data_dict['data']['lookup_loc_techs'][loc_tech]

    if po.value(cost_om_prod):
        cost_prod = cost_om_prod * weight * backend_model.carrier_prod[loc_tech_carrier, timestep]
    else:
        cost_prod = 0

    if loc_tech_is_in(backend_model, loc_tech, 'loc_techs_supply_plus') and cost_om_con:
        cost_con = cost_om_con * weight * backend_model.resource_con[loc_tech, timestep]
    elif loc_tech_is_in(backend_model, loc_tech, 'loc_techs_supply') and cost_om_con:
        energy_eff = get_param(backend_model, 'energy_eff', (loc_tech, timestep))
        if po.value(energy_eff) > 0:  # in case energy_eff is zero, to avoid an infinite value
            cost_con = cost_om_con * weight * (backend_model.carrier_prod[loc_tech_carrier, timestep] / energy_eff)
        else:
            cost_con = 0
    elif loc_tech_is_in(backend_model, loc_tech, 'loc_techs_demand') and cost_om_con:
        cost_con = cost_om_con * weight * (-1) * backend_model.carrier_con[loc_tech_carrier, timestep]
    else:
        cost_con = 0

    backend_model.cost_var_rhs[cost, loc_tech, timestep].expr = cost_prod + cost_con
    return (backend_model.cost_var[cost, loc_tech, timestep] ==
            backend_model.cost_var_rhs[cost, loc_tech, timestep])
github calliope-project / calliope / calliope / backend / pyomo / constraints / milp.py View on Github external
.. math::

            \\boldsymbol{cost_{investment}}(cost, loc::tech) += \\boldsymbol{units}(loc::tech)
            \\times cost_{purchase}(cost, loc::tech) * timestep_{weight} * depreciation
            \\quad \\forall cost \\in costs, \\forall loc::tech \\in loc::techs_{cost_{investment}, milp}
    """
    model_data_dict = backend_model.__calliope_model_data
    ts_weight = get_timestep_weight(backend_model)
    depreciation_rate = model_data_dict['data']['cost_depreciation_rate'][(cost, loc_tech)]

    cost_purchase = get_param(backend_model, 'cost_purchase', (cost, loc_tech))
    cost_of_purchase = (
        backend_model.units[loc_tech] * cost_purchase * ts_weight * depreciation_rate
    )

    if loc_tech_is_in(backend_model, loc_tech, 'loc_techs_transmission'):
        cost_of_purchase = cost_of_purchase / 2

    backend_model.cost_investment_rhs[cost, loc_tech].expr += cost_of_purchase

    return None
github calliope-project / calliope / calliope / backend / pyomo / constraints / costs.py View on Github external
def cost_constraint_rule(backend_model, cost, loc_tech):
    """
    Combine investment and time varying costs into one cost per technology.

    .. container:: scrolling-wrapper

        .. math::

            \\boldsymbol{cost}(cost, loc::tech) = \\boldsymbol{cost_{investment}}(cost, loc::tech)
            + \\sum_{timestep \\in timesteps} \\boldsymbol{cost_{var}}(cost, loc::tech, timestep)

    """
    run_config = backend_model.__calliope_run_config

    # FIXME: remove check for operate from constraint files, avoid investment costs more intelligently?
    if loc_tech_is_in(backend_model, loc_tech, 'loc_techs_investment_cost') and run_config['mode'] != 'operate':
        cost_investment = backend_model.cost_investment[cost, loc_tech]
    else:
        cost_investment = 0

    if loc_tech_is_in(backend_model, loc_tech, 'loc_techs_om_cost'):
        cost_var = sum(backend_model.cost_var[cost, loc_tech, timestep]
                       for timestep in backend_model.timesteps)
    else:
        cost_var = 0

    return (
        backend_model.cost[cost, loc_tech] == cost_investment + cost_var
    )
github calliope-project / calliope / calliope / backend / pyomo / constraints / costs.py View on Github external
def _get_investment_cost(capacity_decision_variable, calliope_set):
        """
        Conditionally add investment costs, if the relevant set of technologies
        exists. Both inputs are strings.
        """
        if loc_tech_is_in(backend_model, loc_tech, calliope_set):
            _cost = (getattr(backend_model, capacity_decision_variable)[loc_tech] *
                get_param(backend_model, 'cost_' + capacity_decision_variable, (cost, loc_tech)))
            return _cost
        else:
            return 0
github calliope-project / calliope / calliope / backend / pyomo / constraints / costs.py View on Github external
"""
    model_data_dict = backend_model.__calliope_model_data

    cost_om_prod = get_param(backend_model, 'cost_om_prod', (cost, loc_tech, timestep))
    cost_om_con = get_param(backend_model, 'cost_om_con', (cost, loc_tech, timestep))
    weight = backend_model.timestep_weights[timestep]

    loc_tech_carrier = model_data_dict['data']['lookup_loc_techs'][loc_tech]

    if po.value(cost_om_prod):
        cost_prod = cost_om_prod * weight * backend_model.carrier_prod[loc_tech_carrier, timestep]
    else:
        cost_prod = 0

    if loc_tech_is_in(backend_model, loc_tech, 'loc_techs_supply_plus') and cost_om_con:
        cost_con = cost_om_con * weight * backend_model.resource_con[loc_tech, timestep]
    elif loc_tech_is_in(backend_model, loc_tech, 'loc_techs_supply') and cost_om_con:
        energy_eff = get_param(backend_model, 'energy_eff', (loc_tech, timestep))
        if po.value(energy_eff) > 0:  # in case energy_eff is zero, to avoid an infinite value
            cost_con = cost_om_con * weight * (backend_model.carrier_prod[loc_tech_carrier, timestep] / energy_eff)
        else:
            cost_con = 0
    elif loc_tech_is_in(backend_model, loc_tech, 'loc_techs_demand') and cost_om_con:
        cost_con = cost_om_con * weight * (-1) * backend_model.carrier_con[loc_tech_carrier, timestep]
    else:
        cost_con = 0

    backend_model.cost_var_rhs[cost, loc_tech, timestep].expr = cost_prod + cost_con
    return (backend_model.cost_var[cost, loc_tech, timestep] ==
            backend_model.cost_var_rhs[cost, loc_tech, timestep])
github calliope-project / calliope / calliope / backend / pyomo / constraints / costs.py View on Github external
cost_resource_area = _get_investment_cost('resource_area', 'loc_techs_area')

    cost_om_annual_investment_fraction = get_param(backend_model, 'cost_om_annual_investment_fraction', (cost, loc_tech))
    cost_om_annual = get_param(backend_model, 'cost_om_annual', (cost, loc_tech))

    ts_weight = get_timestep_weight(backend_model)
    depreciation_rate = model_data_dict['data']['cost_depreciation_rate'].get((cost, loc_tech), 0)

    cost_con = (
        depreciation_rate * ts_weight *
        (cost_energy_cap + cost_storage_cap + cost_resource_cap +
         cost_resource_area)
    )

    # Transmission technologies exist at two locations, thus their cost is divided by 2
    if loc_tech_is_in(backend_model, loc_tech, 'loc_techs_transmission'):
            cost_con = cost_con / 2

    cost_fractional_om = cost_om_annual_investment_fraction * cost_con
    cost_fixed_om = cost_om_annual * backend_model.energy_cap[loc_tech] * ts_weight

    backend_model.cost_investment_rhs[cost, loc_tech].expr = (
        cost_fractional_om + cost_fixed_om + cost_con
    )

    return (
        backend_model.cost_investment[cost, loc_tech] ==
        backend_model.cost_investment_rhs[cost, loc_tech]
    )
github calliope-project / calliope / calliope / backend / pyomo / constraints / costs.py View on Github external
model_data_dict = backend_model.__calliope_model_data

    cost_om_prod = get_param(backend_model, 'cost_om_prod', (cost, loc_tech, timestep))
    cost_om_con = get_param(backend_model, 'cost_om_con', (cost, loc_tech, timestep))
    weight = backend_model.timestep_weights[timestep]

    loc_tech_carrier = model_data_dict['data']['lookup_loc_techs'][loc_tech]

    if po.value(cost_om_prod):
        cost_prod = cost_om_prod * weight * backend_model.carrier_prod[loc_tech_carrier, timestep]
    else:
        cost_prod = 0

    if loc_tech_is_in(backend_model, loc_tech, 'loc_techs_supply_plus') and cost_om_con:
        cost_con = cost_om_con * weight * backend_model.resource_con[loc_tech, timestep]
    elif loc_tech_is_in(backend_model, loc_tech, 'loc_techs_supply') and cost_om_con:
        energy_eff = get_param(backend_model, 'energy_eff', (loc_tech, timestep))
        if po.value(energy_eff) > 0:  # in case energy_eff is zero, to avoid an infinite value
            cost_con = cost_om_con * weight * (backend_model.carrier_prod[loc_tech_carrier, timestep] / energy_eff)
        else:
            cost_con = 0
    elif loc_tech_is_in(backend_model, loc_tech, 'loc_techs_demand') and cost_om_con:
        cost_con = cost_om_con * weight * (-1) * backend_model.carrier_con[loc_tech_carrier, timestep]
    else:
        cost_con = 0

    backend_model.cost_var_rhs[cost, loc_tech, timestep].expr = cost_prod + cost_con
    return (backend_model.cost_var[cost, loc_tech, timestep] ==
            backend_model.cost_var_rhs[cost, loc_tech, timestep])