# Path: calliope/preprocess/util.py
# def get_all_carriers(config, direction="both"):
# def flatten_list(unflattened_list):
# def split_loc_techs_transmission(transmission_string):
# def get_systemwide_constraints(tech_config):
# def vincenty(coord1, coord2):
#     U1 = np.arctan((1 - f) * np.tan(np.radians(coord1[0])))
#     U2 = np.arctan((1 - f) * np.tan(np.radians(coord2[0])))
#     L = np.radians(coord2[1] - coord1[1])
#         C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha))
#     A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)))
#     B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)))
#     D = b * A * (sigma - deltaSigma)
# 
# Path: calliope/preprocess/checks.py
# DEFAULTS = AttrDict.from_yaml(
#     os.path.join(os.path.dirname(calliope.__file__), "config", "defaults.yaml")
# )
# POSSIBLE_COSTS = [i for i in DEFAULTS.techs.default_tech.costs.default_cost.keys()]
# def check_overrides(config_model, override):
# def check_initial(config_model):
# def _check_tech_final(
#     model_run, tech_id, tech_config, loc_id, model_warnings, errors, comments
# ):
# def check_final(model_run):
# def check_model_data(model_data):
# 
# Path: calliope/exceptions.py
# def _formatwarning(message, category, filename, lineno, line=None):
# def warn(message, _class=ModelWarning):
# def print_warnings_and_raise_errors(warnings=None, errors=None):
# class ModelError(Exception):
# class BackendError(Exception):
# class ModelWarning(Warning):
# class BackendWarning(Warning):


from itertools import product
from calliope.preprocess.util import constraint_exists, concat_iterable
from calliope.preprocess import checks
from calliope import exceptions
import numpy as np
    ----------
    model_run : AttrDict
    """

    sets = model_run.sets
    # From here on, everything is a `key=value` pair within a dictionary

    constraint_sets = dict()
    # energy_balance.py
    constraint_sets["loc_carriers_system_balance_constraint"] = sets.loc_carriers
    constraint_sets[
        "loc_techs_balance_supply_constraint"
    ] = sets.loc_techs_finite_resource_supply
    constraint_sets[
        "loc_techs_balance_demand_constraint"
    ] = sets.loc_techs_finite_resource_demand
    constraint_sets[
        "loc_techs_resource_availability_supply_plus_constraint"
    ] = sets.loc_techs_finite_resource_supply_plus
    constraint_sets[
        "loc_techs_balance_transmission_constraint"
    ] = sets.loc_techs_transmission
    constraint_sets[
        "loc_techs_balance_supply_plus_constraint"
    ] = sets.loc_techs_supply_plus
    constraint_sets["loc_techs_balance_storage_constraint"] = sets.loc_techs_storage
    if model_run.run.cyclic_storage is True:
        constraint_sets["loc_techs_storage_initial_constraint"] = [
            i
            for i in sets.loc_techs_store

# Path: calliope/preprocess/util.py
# def get_all_carriers(config, direction="both"):
# def flatten_list(unflattened_list):
# def split_loc_techs_transmission(transmission_string):
# def get_systemwide_constraints(tech_config):
# def vincenty(coord1, coord2):
#     U1 = np.arctan((1 - f) * np.tan(np.radians(coord1[0])))
#     U2 = np.arctan((1 - f) * np.tan(np.radians(coord2[0])))
#     L = np.radians(coord2[1] - coord1[1])
#         C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha))
#     A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)))
#     B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)))
#     D = b * A * (sigma - deltaSigma)
# 
# Path: calliope/preprocess/checks.py
# DEFAULTS = AttrDict.from_yaml(
#     os.path.join(os.path.dirname(calliope.__file__), "config", "defaults.yaml")
# )
# POSSIBLE_COSTS = [i for i in DEFAULTS.techs.default_tech.costs.default_cost.keys()]
# def check_overrides(config_model, override):
# def check_initial(config_model):
# def _check_tech_final(
#     model_run, tech_id, tech_config, loc_id, model_warnings, errors, comments
# ):
# def check_final(model_run):
# def check_model_data(model_data):
# 
# Path: calliope/exceptions.py
# def _formatwarning(message, category, filename, lineno, line=None):
# def warn(message, _class=ModelWarning):
# def print_warnings_and_raise_errors(warnings=None, errors=None):
# class ModelError(Exception):
# class BackendError(Exception):
# class ModelWarning(Warning):
# class BackendWarning(Warning):


# Path: calliope/preprocess/constraint_sets.py
from itertools import product
from calliope.preprocess.util import constraint_exists, concat_iterable
from calliope.preprocess import checks
from calliope import exceptions
import numpy as np

    ----------
    model_run : AttrDict
    """

    sets = model_run.sets
    # From here on, everything is a `key=value` pair within a dictionary

    constraint_sets = dict()
    # energy_balance.py
    constraint_sets["loc_carriers_system_balance_constraint"] = sets.loc_carriers
    constraint_sets[
        "loc_techs_balance_supply_constraint"
    ] = sets.loc_techs_finite_resource_supply
    constraint_sets[
        "loc_techs_balance_demand_constraint"
    ] = sets.loc_techs_finite_resource_demand
    constraint_sets[
        "loc_techs_resource_availability_supply_plus_constraint"
    ] = sets.loc_techs_finite_resource_supply_plus
    constraint_sets[
        "loc_techs_balance_transmission_constraint"
    ] = sets.loc_techs_transmission
    constraint_sets[
        "loc_techs_balance_supply_plus_constraint"
    ] = sets.loc_techs_supply_plus
    constraint_sets["loc_techs_balance_storage_constraint"] = sets.loc_techs_storage
    if model_run.run.cyclic_storage is True:
        constraint_sets["loc_techs_storage_initial_constraint"] = [
            i
            for i in sets.loc_techs_store

            if constraint_exists(model_run, i, "constraints.storage_initial")