# Path: edisgo/network/timeseries.py
# def add_storage_units_timeseries(edisgo_obj, storage_unit_names, **kwargs):
#     """
#     Define storage unit time series for active and reactive power. For more
#     information on required and optional parameters see description of
#     :func:`get_component_timeseries`. The mode initially set within
#     get_component_timeseries is used here to set new timeseries. If a different
#     mode is required, change edisgo_obj.timeseries.mode to the desired mode and
#     provide respective parameters.
# 
#     Parameters
#     ----------
#     edisgo_obj: :class:`~.self.edisgo.EDisGo`
#         The eDisGo model overall container
#     storage_unit_names: str or list of str
#         Names of storage units to add timeseries for. Default None, timeseries
#         for all storage units of edisgo_obj are set then.
# 
#     """
#     # if timeseries have not been set yet, it is not
#     # necessary to add timeseries
#     if not hasattr(edisgo_obj.timeseries, "mode"):
#         logger.debug(
#             "Timeseries have not been set yet. Please call"
#             "get_components_timeseries to create timeseries."
#         )
#         return
#     # turn single name to list
#     if isinstance(storage_unit_names, str):
#         storage_unit_names = [storage_unit_names]
#     # append timeseries of respective mode
#     if edisgo_obj.timeseries.mode:
#         if "worst-case" in edisgo_obj.timeseries.mode:
#             modes = _get_worst_case_modes(edisgo_obj.timeseries.mode)
#             # set random timeindex
#             _worst_case_storage(
#                 edisgo_obj=edisgo_obj,
#                 modes=modes,
#                 storage_names=storage_unit_names,
#             )
#         elif edisgo_obj.timeseries.mode == "manual":
#             storage_units_active_power = kwargs.get(
#                 "storage_units_active_power", None
#             )
#             if storage_units_active_power is not None:
#                 check_timeseries_for_index_and_cols(
#                     edisgo_obj, storage_units_active_power, storage_unit_names
#                 )
#             storage_units_reactive_power = kwargs.get(
#                 "storage_units_reactive_power", None
#             )
#             if storage_units_reactive_power is not None:
#                 check_timeseries_for_index_and_cols(
#                     edisgo_obj,
#                     storage_units_reactive_power,
#                     storage_unit_names,
#                 )
#             _drop_existing_component_timeseries(
#                 edisgo_obj, "storage_units", storage_unit_names
#             )
#             # add new storage timeseries
#             edisgo_obj.timeseries.storage_units_active_power = pd.concat(
#                 [edisgo_obj.timeseries.storage_units_active_power,
#                  storage_units_active_power.loc[:, storage_unit_names]
#                  ],
#                 axis=1
#             )
#             edisgo_obj.timeseries.storage_units_reactive_power = pd.concat(
#                 [edisgo_obj.timeseries.storage_units_reactive_power,
#                  storage_units_reactive_power.loc[:, storage_unit_names]
#                  ],
#                 axis=1
#             )
#         else:
#             raise ValueError(
#                 "{} is not a valid mode.".format(edisgo_obj.timeseries.mode)
#             )
#     else:
#         # create load active and reactive power timeseries
#         _storage_from_timeseries(
#             edisgo_obj=edisgo_obj,
#             name_storage_units=storage_unit_names,
#             ts_active_power=kwargs.get("timeseries_storage_units", None),
#             ts_reactive_power=kwargs.get(
#                 "timeseries_storage_units_reactive_power", None
#             ),
#         )


import numpy as np
import pandas as pd
import logging
from edisgo.network.timeseries import add_storage_units_timeseries

    # ToDo adding timeseries will only work if timeseries.mode is None
    # ToDo @Anya why is for mode manual kwarg called 'storage_units_reactive_power'
    # and for mode None kwarg called 'timeseries_storage_units'
    for st in edisgo.opf_results.storage_units.index:
        storage_cap = edisgo.opf_results.storage_units.at[st, "emax"]
        if (
            storage_cap >= min_storage_size
            and (storage_ts.loc[:, st] > 0.001).any()
        ):
            if not as_load:
                storage = edisgo.topology.add_storage_unit(
                    bus=st, p_nom=storage_cap
                )  # as C-rate is currently always 1
            else:
                storage = edisgo.topology.add_load(
                    load_id=1,
                    bus=st,
                    peak_load=storage_cap,
                    annual_consumption=0.0,
                    sector="storage",
                )
            if timeseries:
                ts_active = storage_ts.loc[:, [st]].rename(
                    columns={st: storage}
                )
                ts_reactive = reactive_power_ts.loc[:, [st]].rename(
                    columns={st: storage}
                )
                if not as_load:

# Path: edisgo/network/timeseries.py
# def add_storage_units_timeseries(edisgo_obj, storage_unit_names, **kwargs):
#     """
#     Define storage unit time series for active and reactive power. For more
#     information on required and optional parameters see description of
#     :func:`get_component_timeseries`. The mode initially set within
#     get_component_timeseries is used here to set new timeseries. If a different
#     mode is required, change edisgo_obj.timeseries.mode to the desired mode and
#     provide respective parameters.
# 
#     Parameters
#     ----------
#     edisgo_obj: :class:`~.self.edisgo.EDisGo`
#         The eDisGo model overall container
#     storage_unit_names: str or list of str
#         Names of storage units to add timeseries for. Default None, timeseries
#         for all storage units of edisgo_obj are set then.
# 
#     """
#     # if timeseries have not been set yet, it is not
#     # necessary to add timeseries
#     if not hasattr(edisgo_obj.timeseries, "mode"):
#         logger.debug(
#             "Timeseries have not been set yet. Please call"
#             "get_components_timeseries to create timeseries."
#         )
#         return
#     # turn single name to list
#     if isinstance(storage_unit_names, str):
#         storage_unit_names = [storage_unit_names]
#     # append timeseries of respective mode
#     if edisgo_obj.timeseries.mode:
#         if "worst-case" in edisgo_obj.timeseries.mode:
#             modes = _get_worst_case_modes(edisgo_obj.timeseries.mode)
#             # set random timeindex
#             _worst_case_storage(
#                 edisgo_obj=edisgo_obj,
#                 modes=modes,
#                 storage_names=storage_unit_names,
#             )
#         elif edisgo_obj.timeseries.mode == "manual":
#             storage_units_active_power = kwargs.get(
#                 "storage_units_active_power", None
#             )
#             if storage_units_active_power is not None:
#                 check_timeseries_for_index_and_cols(
#                     edisgo_obj, storage_units_active_power, storage_unit_names
#                 )
#             storage_units_reactive_power = kwargs.get(
#                 "storage_units_reactive_power", None
#             )
#             if storage_units_reactive_power is not None:
#                 check_timeseries_for_index_and_cols(
#                     edisgo_obj,
#                     storage_units_reactive_power,
#                     storage_unit_names,
#                 )
#             _drop_existing_component_timeseries(
#                 edisgo_obj, "storage_units", storage_unit_names
#             )
#             # add new storage timeseries
#             edisgo_obj.timeseries.storage_units_active_power = pd.concat(
#                 [edisgo_obj.timeseries.storage_units_active_power,
#                  storage_units_active_power.loc[:, storage_unit_names]
#                  ],
#                 axis=1
#             )
#             edisgo_obj.timeseries.storage_units_reactive_power = pd.concat(
#                 [edisgo_obj.timeseries.storage_units_reactive_power,
#                  storage_units_reactive_power.loc[:, storage_unit_names]
#                  ],
#                 axis=1
#             )
#         else:
#             raise ValueError(
#                 "{} is not a valid mode.".format(edisgo_obj.timeseries.mode)
#             )
#     else:
#         # create load active and reactive power timeseries
#         _storage_from_timeseries(
#             edisgo_obj=edisgo_obj,
#             name_storage_units=storage_unit_names,
#             ts_active_power=kwargs.get("timeseries_storage_units", None),
#             ts_reactive_power=kwargs.get(
#                 "timeseries_storage_units_reactive_power", None
#             ),
#         )


# Path: edisgo/opf/results/opf_expand_network.py
import numpy as np
import pandas as pd
import logging
from edisgo.network.timeseries import add_storage_units_timeseries


    # ToDo adding timeseries will only work if timeseries.mode is None
    # ToDo @Anya why is for mode manual kwarg called 'storage_units_reactive_power'
    # and for mode None kwarg called 'timeseries_storage_units'
    for st in edisgo.opf_results.storage_units.index:
        storage_cap = edisgo.opf_results.storage_units.at[st, "emax"]
        if (
            storage_cap >= min_storage_size
            and (storage_ts.loc[:, st] > 0.001).any()
        ):
            if not as_load:
                storage = edisgo.topology.add_storage_unit(
                    bus=st, p_nom=storage_cap
                )  # as C-rate is currently always 1
            else:
                storage = edisgo.topology.add_load(
                    load_id=1,
                    bus=st,
                    peak_load=storage_cap,
                    annual_consumption=0.0,
                    sector="storage",
                )
            if timeseries:
                ts_active = storage_ts.loc[:, [st]].rename(
                    columns={st: storage}
                )
                ts_reactive = reactive_power_ts.loc[:, [st]].rename(
                    columns={st: storage}
                )
                if not as_load:

                    add_storage_units_timeseries(