def init_time_series(net, time_steps, continue_on_divergence=False, verbose=True, **kwargs): """ inits the time series calculation creates the dict ts_variables, which includes necessary variables for the time series / control function INPUT: **net** - The pandapower format network **time_steps** (list or tuple, None) - time_steps to calculate as list or tuple (start, stop) if None, all time steps from provided data source are simulated OPTIONAL: **continue_on_divergence** (bool, False) - If True time series calculation continues in case of errors. **verbose** (bool, True) - prints progress bar or logger debug messages """ time_steps = init_time_steps(net, time_steps, **kwargs) ts_variables = dict() init_default_outputwriter(net, time_steps, **kwargs) level, order = get_controller_order(net) # get run function run = kwargs.get("run", pp.runpp) recycle_options = False if hasattr(run, "__name__") and run.__name__ == "runpp": # use faster runpp options if possible recycle_options = get_recycle_settings(net, **kwargs) init_output_writer(net, time_steps) # True at default. Initial power flow is calculated before each control step (some controllers need inits) ts_variables["initial_powerflow"] = check_for_initial_powerflow(order) # order of controller (controllers are called in a for loop.) ts_variables["controller_order"] = order # run function to be called in run_control - default is pp.runpp, but can be runopf or whatever you like ts_variables["run"] = run # recycle options, which define what can be recycled ts_variables["recycle_options"] = recycle_options # time steps to be calculated (list or range) ts_variables["time_steps"] = time_steps # If True, a diverged power flow is ignored and the next step is calculated ts_variables["continue_on_divergence"] = continue_on_divergence # print settings ts_variables["verbose"] = verbose if logger.level is not 10 and verbose: # simple progress bar print_progress_bar(0, len(time_steps), prefix='Progress:', suffix='Complete', length=50) return ts_variables
def test_multiple_levels(net): TrafoController(net, 0, side="lv", trafotype="2W", level=1, tol=1e-6, in_service=True) Controller(net, gid=2, level=[1, 2]) Controller(net, gid=2, level=[1, 2]) level, order = get_controller_order(net, net.controller) # three levels with unspecific controller order => in order of appearance # assert order == [[0, 1], [1,2]] assert len(order) == 2 assert order[0][0][0].index == 0 assert order[0][1][0].index == 1 assert order[1][0][0].index == 1 assert order[1][1][0].index == 2 assert level == [1, 2] pp.runpp(net, run_control=True)
def test_level_in_service(net): c1 = DummyController(net) c2 = DummyController(net, level=1) c3 = DummyController(net, level=1, order=-1) c4 = DummyController(net, level=1, order=-2, in_service=False) net.controller.at[0, 'in_service'] = False pp.runpp(net, run_control=True) assert not c1.applied assert c2.applied assert c3.applied assert not c4.applied level, order = get_controller_order(net) assert len(level) == 2 assert len(order[0]) == 0 assert len(order[1]) == 2 assert order[1][0] == c3 and order[1][1] == c2
def get_controller_order_multinet(multinet): """ Defining the controller order per level. Takes the order and level columns from net.controller. If levels are specified, the levels and orders are executed in ascending order. :param multinet: multinet with multinet controllers, net distinct controllers and several pandapipes/pandapower nets :type multinet: pandapipes.Multinet :return: nested list of tuples given the correct order of the controllers, respectively for each level :rtype: list """ net_list = [] controller_list = [] if hasattr(multinet, "controller") and len( multinet.controller[multinet.controller.in_service]) != 0: # if no controllers are in the net, we have no levels and no order lists multinets = [multinet] * len(multinet.controller) net_list += multinets controller_list += [multinet.controller] for net_name in multinet['nets'].keys(): net = multinet['nets'][net_name] if not (hasattr(net, 'controller') and len(net.controller[net.controller.in_service]) != 0): # if no controllers are in the net, we have no levels and no order lists continue nets = [net] * len(net.controller) net_list += nets controller_list += [net.controller] controller_list = pd.concat(controller_list).reset_index(drop=True) if not controller_list.size: # if no controllers are in the net, we have no levels and no order lists return [0], [[]] else: return get_controller_order(net_list, controller_list)
def init_time_series_ppipe(net, time_steps, output_writer=None, continue_on_divergence=False, verbose=True, **kwargs): """ Inits the time series calculation. Creates the dict ts_variables, which includes necessary variables for the time series / control function. :param net: The pandapipes format network :type net: pandapipesNet :param time_steps: time_steps to calculate as list or tuple (start, stop) if None, all time steps from provided data source are simulated :type time_steps: list or tuple :param output_writer: A predefined output writer. If None the a default one is created with get_default_output_writer() :type output_writer: ?, default None :param continue_on_divergence: If True time series calculation continues in case of errors. :type continue_on_divergence: bool, default False :param verbose: prints progess bar or logger debug messages :type verbose: bool, default True :param kwargs: :type kwargs: :return: :rtype: """ time_steps = init_time_steps_ppipe(net, time_steps, **kwargs) ts_variables = dict() output_writer = init_outputwriter_ppipe(net, time_steps, output_writer) level, order = get_controller_order(net) # use faster runpp if timeseries possible run, recycle_class = get_run_function(**kwargs) # True at default. Initial power flow is calculated before each control step # (some controllers need inits) ts_variables["initial_pipeflow"] = check_for_initial_pipeflow(order) ts_variables["initial_powerflow"] = ts_variables["initial_pipeflow"] # order of controller (controllers are called in a for loop.) ts_variables["controller_order"] = order # run function to be called in run_control - default is pp.runpp, but can be runopf or whatever # you like ts_variables["run"] = run # recycle class function, which stores some NR variables. Only used if recycle == True ts_variables["recycle_class"] = recycle_class # output writer, which logs information during the time series simulation ts_variables["output_writer"] = output_writer # time steps to be calculated (list or range) ts_variables["time_steps"] = time_steps # If True, a diverged power flow is ignored and the next step is calculated ts_variables["continue_on_divergence"] = continue_on_divergence if logger.level is not 10 and verbose: # simple progress bar print_progress_bar(0, len(time_steps), prefix='Progress:', suffix='Complete', length=50) if "recycle" in kwargs: kwargs.pop("recycle") return ts_variables, kwargs