Skip to content

Commit

Permalink
Merge branch 'develop' into cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jkupka authored Jan 7, 2021
2 parents 6b6e2d5 + a945fba commit 0dc5f5f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 28 deletions.
17 changes: 6 additions & 11 deletions pandapower/control/basic_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,19 @@ def __init__(self, net, in_service=True, order=0, level=0, index=None, recycle=F
drop_same_existing_ctrl=False, initial_run=True, overwrite=False,
matching_params=None, **kwargs):
super().__init__()
self.recycle = recycle
self.initial_run = initial_run
self.matching_params = dict() if matching_params is None else matching_params
# add oneself to net, creating the ['controller'] DataFrame, if necessary
if index is None:
index = get_free_id(net.controller)
self.index = index
self.add_controller_to_net(net=net, in_service=in_service, order=order,
self.add_controller_to_net(net=net, in_service=in_service, initial_run=initial_run, order=order,
level=level, index=index, recycle=recycle,
drop_same_existing_ctrl=drop_same_existing_ctrl,
overwrite=overwrite, matching_params=matching_params, **kwargs)

def __repr__(self):
rep = "This " + self.__class__.__name__ + " has the following parameters: \n"

for member in ["index", "json_excludes", "recycle"]:
for member in ["index", "json_excludes"]:
rep += ("\n" + member + ": ").ljust(20)
d = locals()
exec('value = self.' + member, d)
Expand All @@ -67,7 +64,7 @@ def __setstate__(self, state):
self.__dict__.update(state)


def add_controller_to_net(self, net, in_service, order, level, index, recycle,
def add_controller_to_net(self, net, in_service, initial_run, order, level, index, recycle,
drop_same_existing_ctrl, overwrite, **kwargs):
"""
adds the controller to net['controller'] dataframe.
Expand All @@ -92,10 +89,8 @@ def add_controller_to_net(self, net, in_service, order, level, index, recycle,
# use base class method to raise an error if the object is in DF and overwrite = False
super().add_to_net(net=net, element='controller', index=index, overwrite=overwrite)

columns = ['object', 'in_service', 'recycle']
net.controller.loc[index,columns] = self, in_service, recycle
net.controller['order'][index] = order
net.controller['level'][index]= level
columns = ['object', 'in_service', 'order', 'level', 'initial_run', 'recycle']
net.controller.loc[index,columns] = self, in_service, order, level, initial_run, recycle

_preserve_dtypes(net.controller, dtypes)

Expand All @@ -108,7 +103,7 @@ def time_step(self, net, time):
"""
pass

def set_recycle(self):
def set_recycle(self, net):
"""
Checks the recyclability of this controller and changes the recyclability of the control handler if
necessary. With this a faster time series calculation can be achieved since not everything must be
Expand Down
11 changes: 5 additions & 6 deletions pandapower/control/controller/const_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def __init__(self, net, element, variable, element_index, profile_name=None, dat
logger.error("Parameter set_q_from_cosphi deprecated!")
raise ValueError
self.applied = False
self.initial_run = initial_run
# write functions faster, depending on type of self.element_index
if isinstance(self.element_index, int):
# use .at if element_index is integer for speedup
Expand All @@ -91,15 +90,15 @@ def __init__(self, net, element, variable, element_index, profile_name=None, dat
else:
# use common .loc
self.write = "loc"
self.set_recycle()
self.set_recycle(net)

def set_recycle(self):
def set_recycle(self, net):
allowed_elements = ["load", "sgen", "storage", "gen", "ext_grid", "trafo", "trafo3w",
"line"]
if self.recycle is False or self.element not in allowed_elements:
if net.controller.at[self.index, 'recycle'] is False or self.element not in allowed_elements:
# if recycle is set to False by the user when creating the controller it is deactivated
# or when const control controls an element which is not able to be recycled
self.recycle = False
net.controller.at[self.index, 'recycle'] = False
return
# these variables determine what is re-calculated during a time series run
recycle = dict(trafo=False, gen=False, bus_pq=False)
Expand All @@ -113,7 +112,7 @@ def set_recycle(self):
recycle["trafo"] = True
# recycle is either the dict what should be recycled
# or False if the element + variable combination is not supported
self.recycle = recycle if any(list(recycle.values())) else False
net.controller.at[self.index, 'recycle'] = recycle if any(list(recycle.values())) else False

def write_to_net(self, net):
"""
Expand Down
10 changes: 5 additions & 5 deletions pandapower/control/controller/trafo_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,18 @@ def __init__(self, net, tid, side, tol, in_service, trafotype, level=0, order=0,
self.tid))
if net[self.trafotable].at[self.tid, "tap_step_percent"] < 0:
self.tap_side_coeff *= -1
self.set_recycle()
self.set_recycle(net)

def set_recycle(self):
def set_recycle(self, net):
allowed_elements = ["2W", "3W"]
if self.recycle is False or self.trafotype not in allowed_elements:
if net.controller.at[self.index, 'recycle'] is False or self.trafotype not in allowed_elements:
# if recycle is set to False by the user when creating the controller it is deactivated or when
# const control controls an element which is not able to be recycled
self.recycle = False
net.controller.at[self.index, 'recycle'] = False
return
# these variables determine what is re-calculated during a time series run
recycle = dict(trafo=True, gen=False, bus_pq=False)
self.recycle = recycle
net.controller.at[self.index, 'recycle'] = recycle

def timestep(self, net):
self.tap_pos = net[self.trafotable].at[self.tid, "tap_pos"]
Expand Down
12 changes: 9 additions & 3 deletions pandapower/control/run_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,18 @@ def check_for_initial_run(controller_order):
return True

for levelorder in controller_order:
for ctrl, _ in levelorder:
for ctrl, net in levelorder:
if hasattr(ctrl, 'initial_powerflow'):
ctrl.initial_run = ctrl.initial_powerflow
net.controller.at[ctrl.index, 'initial_run']= ctrl.initial_powerflow
logger.warning("initial_powerflow is deprecated. Instead of defining initial_powerflow "
"please define initial_run in the future.")
if ctrl.initial_run:
del ctrl.initial_powerflow
elif hasattr(ctrl, 'initial_run'):
net.controller.at[ctrl.index, 'initial_run']= ctrl.initial_run
logger.warning("initial_run as attribute is deprecated. initial_run is now part of the "
"net.controller DataFrame")
del ctrl.initial_run
if net.controller.at[ctrl.index, 'initial_run']:
return True
return False

Expand Down
7 changes: 7 additions & 0 deletions pandapower/convert_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ def _add_missing_columns(net):
if "name" not in net.measurement:
net.measurement.insert(0, "name", None)

if "initial_run" not in net.controller:
net.controller.insert(4, 'initial_run', False)
for _, ctrl in net.controller.iterrows():
if hasattr(ctrl['object'], 'initial_run'):
net.controller.at[ctrl.name, 'initial_run'] = ctrl['object'].initial_run
else:
net.controller.at[ctrl.name, 'initial_run'] = ctrl['object'].initial_powerflow

def _update_trafo_type_parameter_names(net):
for element in ('trafo', 'trafo3w'):
Expand Down
1 change: 1 addition & 0 deletions pandapower/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def create_empty_network(name="", f_hz=50., sn_mva=1, add_stdtypes=True):
('in_service', "bool"),
('order', "float64"),
('level', dtype(object)),
('initial_run', "bool"),
("recycle", "bool"),
],
# geodata
Expand Down
4 changes: 1 addition & 3 deletions pandapower/timeseries/run_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _check_controller_recyclability(net):

for idx in net.controller.index:
# todo: write to controller data frame recycle column instead of using self.recycle of controller instance
ctrl_recycle = net.controller.at[idx, "object"].recycle
ctrl_recycle = net.controller.at[idx, "recycle"]
if not isinstance(ctrl_recycle, dict):
# if one controller has a wrong recycle configuration it is deactived
recycle = False
Expand Down Expand Up @@ -250,8 +250,6 @@ def init_time_series(net, time_steps, continue_on_divergence=False, verbose=True

time_steps = init_time_steps(net, time_steps, **kwargs)

ts_variables = dict()

init_default_outputwriter(net, time_steps, **kwargs)
# get run function
run = kwargs.pop("run", pp.runpp)
Expand Down

0 comments on commit 0dc5f5f

Please sign in to comment.