# Path: calliope/core/util/tools.py
# def get_from_dict(data_dict, map_list):
# def apply_to_dict(data_dict, map_list, func, args):
#     def __init__(self, func):
#     def __get__(self, obj, objtype=None):
#     def __call__(self, *args, **kw):
# def relative_path(base_path_file, path):
# def load_function(source):
# def plugin_load(name, builtin_module):
# class memoize_instancemethod(object):
# 
# 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):


import logging
import re
import numpy as np
import pandas as pd
import xarray as xr
import pyomo.core as po
from pandas.api.types import is_numeric_dtype
from calliope.core.util.tools import memoize
from calliope import exceptions
    from a carrier_tier, return the primary tier (of `in`, `out`) and
    corresponding decision variable (`carrier_con` and `carrier_prod`, respectively)
    """
    if "out" in tier:
        return "out", backend_model.carrier_prod
    elif "in" in tier:
        return "in", backend_model.carrier_con


def get_var(backend_model, var, dims=None, sparse=False, expr=False):
    """
    Return output for variable `var` as a pandas.Series (1d),
    pandas.Dataframe (2d), or xarray.DataArray (3d and higher).

    Parameters
    ----------
    var : variable name as string, e.g. 'resource'
    dims : list, optional
        indices as strings, e.g. ('loc_techs', 'timesteps');
        if not given, they are auto-detected
    sparse : bool, optional; default = False
        If extracting Pyomo Param data, the output sparse array includes inputs
        the user left as NaN replaced with the default value for that Param.
    expr : bool, optional
        If True, treat var as a pyomo expression, which requires calculating
        the result of the expression before translating into nd data structure
    """
    try:
        var_container = getattr(backend_model, var)
    except AttributeError:

# Path: calliope/core/util/tools.py
# def get_from_dict(data_dict, map_list):
# def apply_to_dict(data_dict, map_list, func, args):
#     def __init__(self, func):
#     def __get__(self, obj, objtype=None):
#     def __call__(self, *args, **kw):
# def relative_path(base_path_file, path):
# def load_function(source):
# def plugin_load(name, builtin_module):
# class memoize_instancemethod(object):
# 
# 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/backend/pyomo/util.py
import logging
import re
import numpy as np
import pandas as pd
import xarray as xr
import pyomo.core as po
from pandas.api.types import is_numeric_dtype
from calliope.core.util.tools import memoize
from calliope import exceptions

    from a carrier_tier, return the primary tier (of `in`, `out`) and
    corresponding decision variable (`carrier_con` and `carrier_prod`, respectively)
    """
    if "out" in tier:
        return "out", backend_model.carrier_prod
    elif "in" in tier:
        return "in", backend_model.carrier_con


def get_var(backend_model, var, dims=None, sparse=False, expr=False):
    """
    Return output for variable `var` as a pandas.Series (1d),
    pandas.Dataframe (2d), or xarray.DataArray (3d and higher).

    Parameters
    ----------
    var : variable name as string, e.g. 'resource'
    dims : list, optional
        indices as strings, e.g. ('loc_techs', 'timesteps');
        if not given, they are auto-detected
    sparse : bool, optional; default = False
        If extracting Pyomo Param data, the output sparse array includes inputs
        the user left as NaN replaced with the default value for that Param.
    expr : bool, optional
        If True, treat var as a pyomo expression, which requires calculating
        the result of the expression before translating into nd data structure
    """
    try:
        var_container = getattr(backend_model, var)
    except AttributeError:

        raise exceptions.BackendError("Variable {} inexistent.".format(var))