# 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/time/clustering.py
# def _stack_data(data, dates, times):
# def reshape_for_clustering(data, loc_techs=None, variables=None):
# def get_mean_from_clusters(data, clusters, timesteps_per_day):
# def find_nearest_vector_index(array, value, metric="rmse"):
# def get_closest_days_from_clusters(data, mean_data, clusters, daily_timesteps):
# def _timesteps_from_daily_index(idx, daily_timesteps):
# def map_clusters_to_data(
#     data, clusters, how, daily_timesteps, storage_inter_cluster=True
# ):
# def get_clusters(
#     data,
#     func,
#     timesteps_per_day,
#     tech=None,
#     timesteps=None,
#     k=None,
#     variables=None,
#     **kwargs,
# ):
# def hartigan_n_clusters(X, threshold=10):
#     def _H_rule(inertia, inertia_plus_one, n_clusters, len_input):
#     X = np.nan_to_num(reshaped_data, nan=0.0, posinf=0.0, neginf=0.0)
#     X = reshape_for_clustering(data, tech, variables)
#     HK = threshold + 1
#         HK = _H_rule(inertia, inertia_plus_one, n_clusters, len_input)


import logging
import datetime
import numpy as np
import pandas as pd
import xarray as xr
from calliope import exceptions
from calliope.time import clustering
"""
Copyright (C) since 2013 Calliope contributors listed in AUTHORS.
Licensed under the Apache 2.0 License (see LICENSE file).

funcs.py
~~~~~~~~

Functions to process time series data.

"""




logger = logging.getLogger(__name__)


def get_daily_timesteps(data, check_uniformity=False):
    daily_timesteps = [
        data.timestep_resolution.loc[i].values
        for i in np.unique(data.timesteps.to_index().strftime("%Y-%m-%d"))
    ]

    if check_uniformity:
        if not np.all(daily_timesteps == daily_timesteps[0]):

# 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/time/clustering.py
# def _stack_data(data, dates, times):
# def reshape_for_clustering(data, loc_techs=None, variables=None):
# def get_mean_from_clusters(data, clusters, timesteps_per_day):
# def find_nearest_vector_index(array, value, metric="rmse"):
# def get_closest_days_from_clusters(data, mean_data, clusters, daily_timesteps):
# def _timesteps_from_daily_index(idx, daily_timesteps):
# def map_clusters_to_data(
#     data, clusters, how, daily_timesteps, storage_inter_cluster=True
# ):
# def get_clusters(
#     data,
#     func,
#     timesteps_per_day,
#     tech=None,
#     timesteps=None,
#     k=None,
#     variables=None,
#     **kwargs,
# ):
# def hartigan_n_clusters(X, threshold=10):
#     def _H_rule(inertia, inertia_plus_one, n_clusters, len_input):
#     X = np.nan_to_num(reshaped_data, nan=0.0, posinf=0.0, neginf=0.0)
#     X = reshape_for_clustering(data, tech, variables)
#     HK = threshold + 1
#         HK = _H_rule(inertia, inertia_plus_one, n_clusters, len_input)


# Path: calliope/time/funcs.py
import logging
import datetime
import numpy as np
import pandas as pd
import xarray as xr
from calliope import exceptions
from calliope.time import clustering

"""
Copyright (C) since 2013 Calliope contributors listed in AUTHORS.
Licensed under the Apache 2.0 License (see LICENSE file).

funcs.py
~~~~~~~~

Functions to process time series data.

"""




logger = logging.getLogger(__name__)


def get_daily_timesteps(data, check_uniformity=False):
    daily_timesteps = [
        data.timestep_resolution.loc[i].values
        for i in np.unique(data.timesteps.to_index().strftime("%Y-%m-%d"))
    ]

    if check_uniformity:
        if not np.all(daily_timesteps == daily_timesteps[0]):

            raise exceptions.ModelError(