Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if index is None:
index = get_free_id(net["load"])
if index in net["load"].index:
raise UserWarning("A load with the id %s already exists" % index)
# store dtypes
dtypes = net.load.dtypes
net.load.loc[index, ["name", "bus", "p_mw", "const_z_percent", "const_i_percent", "scaling",
"q_mvar", "sn_mva", "in_service", "type"]] = \
[name, bus, p_mw, const_z_percent, const_i_percent, scaling, q_mvar, sn_mva,
bool(in_service), type]
# and preserve dtypes
_preserve_dtypes(net.load, dtypes)
if not isnan(min_p_mw):
if "min_p_mw" not in net.load.columns:
net.load.loc[:, "min_p_mw"] = pd.Series()
net.load.loc[index, "min_p_mw"] = float(min_p_mw)
if not isnan(max_p_mw):
if "max_p_mw" not in net.load.columns:
net.load.loc[:, "max_p_mw"] = pd.Series()
net.load.loc[index, "max_p_mw"] = float(max_p_mw)
if not isnan(min_q_mvar):
if "min_q_mvar" not in net.load.columns:
net.load.loc[:, "min_q_mvar"] = pd.Series()
if index is None:
index = get_free_id(net.xward)
if index in net["xward"].index:
raise UserWarning("An extended ward equivalent with index %s already exists" % index)
# store dtypes
dtypes = net.xward.dtypes
net.xward.loc[index, ["bus", "ps_mw", "qs_mvar", "pz_mw", "qz_mvar", "r_ohm", "x_ohm", "vm_pu",
"name", "in_service"]] = \
[bus, ps_mw, qs_mvar, pz_mw, qz_mvar, r_ohm, x_ohm, vm_pu, name, in_service]
# and preserve dtypes
_preserve_dtypes(net.xward, dtypes)
return index
else:
raise UserWarning("Unknown element type")
if index is None:
index = get_free_id(net["switch"])
if index in net["switch"].index:
raise UserWarning("A switch with index %s already exists" % index)
# store dtypes
dtypes = net.switch.dtypes
net.switch.loc[index, ["bus", "element", "et", "closed", "type", "name", "z_ohm"]] = \
[bus, element, et, closed, type, name, z_ohm]
# and preserve dtypes
_preserve_dtypes(net.switch, dtypes)
return index
index = get_free_id(net["shunt"])
if index in net["shunt"].index:
raise UserWarning("A shunt with index %s already exists" % index)
if vn_kv is None:
vn_kv = net.bus.vn_kv.at[bus]
# store dtypes
dtypes = net.shunt.dtypes
net.shunt.loc[index, ["bus", "name", "p_mw", "q_mvar", "vn_kv", "step", "max_step",
"in_service"]] = [bus, name, p_mw, q_mvar, vn_kv, step, max_step,
in_service]
# and preserve dtypes
_preserve_dtypes(net.shunt, dtypes)
return index
if index is None:
index = get_free_id(net["storage"])
if index in net["storage"].index:
raise UserWarning("A storage with the id %s already exists" % index)
# store dtypes
dtypes = net.storage.dtypes
net.storage.loc[index, ["name", "bus", "p_mw", "q_mvar", "sn_mva", "scaling",
"soc_percent", "min_e_mwh", "max_e_mwh", "in_service", "type"]] = \
[name, bus, p_mw, q_mvar, sn_mva, scaling,
soc_percent, min_e_mwh, max_e_mwh, bool(in_service), type]
# and preserve dtypes
_preserve_dtypes(net.storage, dtypes)
# check for OPF parameters and add columns to network table
if not isnan(min_p_mw):
if "min_p_mw" not in net.storage.columns:
net.storage.loc[:, "min_p_mw"] = pd.Series()
net.storage.loc[index, "min_p_mw"] = float(min_p_mw)
if not isnan(max_p_mw):
if "max_p_mw" not in net.storage.columns:
net.storage.loc[:, "max_p_mw"] = pd.Series()
net.storage.loc[index, "max_p_mw"] = float(max_p_mw)
if not isnan(min_q_mvar):
if "min_q_mvar" not in net.storage.columns:
if index in self.net.controller.index.values:
# check if controller is being recreated from json and just add the instance
c = self.net.controller.controller.at[index]
if isinstance(c, dict):
self.net.controller.at[index, 'controller'] = self
return index
raise UserWarning("A controller with index %s already exists" % index)
if drop_same_existing_ctrl:
drop_same_type_existing_controllers(self.net, type(self), index=index, **kwargs)
else:
log_same_type_existing_controllers(self.net, type(self), index=index, **kwargs)
dtypes = self.net.controller.dtypes
columns = ['controller', 'in_service', 'order', 'level', 'recycle']
self.net.controller.loc[index, columns] = self, in_service, order, level, recycle
_preserve_dtypes(self.net.controller, dtypes)
return index
if index is None:
index = get_free_id(net["sgen"])
if index in net["sgen"].index:
raise UserWarning("A static generator with the id %s already exists" % index)
# store dtypes
dtypes = net.sgen.dtypes
net.sgen.loc[index, ["name", "bus", "p_mw", "scaling",
"q_mvar", "sn_mva", "in_service", "type",
"current_source"]] = \
[name, bus, p_mw, scaling, q_mvar, sn_mva, bool(in_service), type, current_source]
# and preserve dtypes
_preserve_dtypes(net.sgen, dtypes)
if not isnan(min_p_mw):
if "min_p_mw" not in net.sgen.columns:
net.sgen.loc[:, "min_p_mw"] = pd.Series()
net.sgen.loc[index, "min_p_mw"] = float(min_p_mw)
if not isnan(max_p_mw):
if "max_p_mw" not in net.sgen.columns:
net.sgen.loc[:, "max_p_mw"] = pd.Series()
net.sgen.loc[index, "max_p_mw"] = float(max_p_mw)
if not isnan(min_q_mvar):
if "min_q_mvar" not in net.sgen.columns:
net.sgen.loc[:, "min_q_mvar"] = pd.Series()
net.trafo3w.loc[index, ["lv_bus", "mv_bus", "hv_bus", "vn_hv_kv", "vn_mv_kv", "vn_lv_kv",
"sn_hv_mva", "sn_mv_mva", "sn_lv_mva", "vk_hv_percent",
"vk_mv_percent", "vk_lv_percent", "vkr_hv_percent",
"vkr_mv_percent", "vkr_lv_percent", "pfe_kw", "i0_percent",
"shift_mv_degree", "shift_lv_degree", "tap_side", "tap_step_percent",
"tap_step_degree", "tap_pos", "tap_neutral", "tap_max", "tap_min", "in_service",
"name", "std_type", "tap_at_star_point"]] = \
[lv_bus, mv_bus, hv_bus, vn_hv_kv, vn_mv_kv, vn_lv_kv,
sn_hv_mva, sn_mv_mva, sn_lv_mva, vk_hv_percent, vk_mv_percent,
vk_lv_percent, vkr_hv_percent, vkr_mv_percent, vkr_lv_percent,
pfe_kw, i0_percent, shift_mv_degree, shift_lv_degree,
tap_side, tap_step_percent, tap_step_degree, tap_pos, tap_neutral, tap_max,
tap_min, bool(in_service), name, None, tap_at_star_point]
# and preserve dtypes
_preserve_dtypes(net.trafo3w, dtypes)
if not isnan(max_loading_percent):
if "max_loading_percent" not in net.trafo3w.columns:
net.trafo3w.loc[:, "max_loading_percent"] = pd.Series()
net.trafo3w.loc[index, "max_loading_percent"] = float(max_loading_percent)
return index
net["line"] = net["line"].append(dd, sort=False)
else:
# prior to pandas 0.23 there was no explicit parameter (instead it was standard behavior)
net["line"] = net["line"].append(dd)
if hasattr(max_loading_percent, "__iter__"):
if "max_loading_percent" not in net.line.columns:
net.line["max_loading_percent"] = pd.Series(index=net.line.index)
net.line.loc[index, "max_loading_percent"] = [0 if isnan(ml) else float(ml) for ml in max_loading_percent]
else:
if not isnan(max_loading_percent):
if "max_loading_percent" not in net.line.columns:
net.line["max_loading_percent"] = pd.Series(index=net.line.index)
net.line.loc[index, "max_loading_percent"] = max_loading_percent
_preserve_dtypes(net.line, dtypes)
if geodata is not None:
dtypes = net.line_geodata.dtypes
df = pd.DataFrame(index=index, columns=net.line_geodata.columns)
# works with single or multiple lists of coordinates
if len(geodata[0]) == 2 and not hasattr(geodata[0][0], "__iter__"):
# geodata is a single list of coordinates
df["coords"] = [geodata] * len(index)
else:
# geodata is multiple lists of coordinates
df["coords"] = geodata
if version.parse(pd.__version__) >= version.parse("0.23"):
net.line_geodata = net.line_geodata.append(df, sort=False)
else:
# prior to pandas 0.23 there was no explicit parameter (instead it was standard behavior)