**Hi, my name is riyan, im quite new in pypsa. i made my own network consist of Medium and Low voltage in Indonesia to check the loading of transformer and line, but also checking the voltage on the end of radial network. i already succeded build pypsa network, an also i’m running pypsa network.lpf() everything fine. and when i try to do network.pf() for non linear power flow , with one generator slack. and MV and LV network.
it give me error like this, can you explain it why or how to solve it:
**
`**KeyError** Traceback (most recent call last)
File ~anaconda3envsdissertationLibsite-packagespandascoreindexesbase.py:3805, in Index.get_loc(self, key)
3804 try:
-> 3805 return self._engine.get_loc(casted_key)
3806 except KeyError as err:
File index.pyx:167, in pandas._libs.index.IndexEngine.get_loc()
File index.pyx:196, in pandas._libs.index.IndexEngine.get_loc()
File pandas\_libs\hashtable_class_helper.pxi:7081, in pandas._libs.hashtable.PyObjectHashTable.get_item()
File pandas\_libs\hashtable_class_helper.pxi:7089, in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: None
The above exception was the direct cause of the following exception:
---
File ~anaconda3envsdissertationLibsite-packagespypsapf.py:263, in network_pf(network, snapshots, skip_pre, x_tol, use_seed, distribute_slack, slack_weights)
216 def network_pf(
217 network,
218 snapshots=None,
(...)
223 slack_weights="p_set",
224 ):
225 """
226 Full non-linear power flow for generic network.
227
(...)
260 iteration error for each snapshot (rows) and sub_network (columns)
261 """
--> 263 return _network_prepare_and_run_pf(
264 network,
265 snapshots,
266 skip_pre,
267 linear=False,
268 x_tol=x_tol,
269 use_seed=use_seed,
270 distribute_slack=distribute_slack,
271 slack_weights=slack_weights,
272 )
File ~anaconda3envsdissertationLibsite-packagespypsapf.py:192, in _network_prepare_and_run_pf(network, snapshots, skip_pre, linear, distribute_slack, slack_weights, **kwargs)
183 sub_network_pf_fun(
184 sub_network, snapshots=snapshots, skip_pre=True, **kwargs
185 )
187 elif len(sub_network.buses()) <= 1:
188 (
189 itdf[sub_network.name],
190 difdf[sub_network.name],
191 cnvdf[sub_network.name],
--> 192 ) = sub_network_pf_singlebus(
193 sub_network,
194 snapshots=snapshots,
195 skip_pre=True,
196 distribute_slack=distribute_slack,
197 slack_weights=sn_slack_weights,
198 )
199 else:
200 (
201 itdf[sub_network.name],
202 difdf[sub_network.name],
(...)
210 **kwargs,
211 )
File ~anaconda3envsdissertationLibsite-packagespypsapf.py:411, in sub_network_pf_singlebus(sub_network, snapshots, skip_pre, distribute_slack, slack_weights, linear)
405 network.generators_t.p.loc[
406 snapshots, group.index
407 ] += bus_generator_shares.multiply(
408 -network.buses_t.p.loc[snapshots, bus], axis=0
409 )
410 else:
--> 411 network.generators_t.p.loc[
412 snapshots, sub_network.slack_generator
413 ] -= network.buses_t.p.loc[snapshots, sub_network.slack_bus]
415 network.generators_t.q.loc[
416 snapshots, sub_network.slack_generator
417 ] -= network.buses_t.q.loc[snapshots, sub_network.slack_bus]
419 network.buses_t.p.loc[snapshots, sub_network.slack_bus] = 0.0
File ~anaconda3envsdissertationLibsite-packagespandascoreindexing.py:1184, in _LocationIndexer.__getitem__(self, key)
1182 if self._is_scalar_access(key):
1183 return self.obj._get_value(*key, takeable=self._takeable)
-> 1184 return self._getitem_tuple(key)
1185 else:
1186 # we by definition only have the 0th axis
1187 axis = self.axis or 0
File ~anaconda3envsdissertationLibsite-packagespandascoreindexing.py:1368, in _LocIndexer._getitem_tuple(self, tup)
1366 with suppress(IndexingError):
1367 tup = self._expand_ellipsis(tup)
-> 1368 return self._getitem_lowerdim(tup)
1370 # no multi-index, so validate all of the indexers
1371 tup = self._validate_tuple_indexer(tup)
File ~anaconda3envsdissertationLibsite-packagespandascoreindexing.py:1065, in _LocationIndexer._getitem_lowerdim(self, tup)
1061 for i, key in enumerate(tup):
1062 if is_label_like(key):
1063 # We don't need to check for tuples here because those are
1064 # caught by the _is_nested_tuple_indexer check above.
-> 1065 section = self._getitem_axis(key, axis=i)
1067 # We should never have a scalar section here, because
1068 # _getitem_lowerdim is only called after a check for
1069 # is_scalar_access, which that would be.
1070 if section.ndim == self.ndim:
1071 # we're in the middle of slicing through a MultiIndex
1072 # revise the key wrt to `section` by inserting an _NS
File ~anaconda3envsdissertationLibsite-packagespandascoreindexing.py:1431, in _LocIndexer._getitem_axis(self, key, axis)
1429 # fall thru to straight lookup
1430 self._validate_key(key, axis)
-> 1431 return self._get_label(key, axis=axis)
File ~anaconda3envsdissertationLibsite-packagespandascoreindexing.py:1381, in _LocIndexer._get_label(self, label, axis)
1379 def _get_label(self, label, axis: AxisInt):
1380 # GH#5567 this will fail if the label is not present in the axis.
-> 1381 return self.obj.xs(label, axis=axis)
File ~anaconda3envsdissertationLibsite-packagespandascoregeneric.py:4287, in NDFrame.xs(self, key, axis, level, drop_level)
4285 if axis == 1:
4286 if drop_level:
-> 4287 return self[key]
4288 index = self.columns
4289 else:
File ~anaconda3envsdissertationLibsite-packagespandascoreframe.py:4102, in DataFrame.__getitem__(self, key)
4100 if self.columns.nlevels > 1:
4101 return self._getitem_multilevel(key)
-> 4102 indexer = self.columns.get_loc(key)
4103 if is_integer(indexer):
4104 indexer = [indexer]
File ~anaconda3envsdissertationLibsite-packagespandascoreindexesbase.py:3812, in Index.get_loc(self, key)
3807 if isinstance(casted_key, slice) or (
3808 isinstance(casted_key, abc.Iterable)
3809 and any(isinstance(x, slice) for x in casted_key)
3810 ):
3811 raise InvalidIndexError(key)
-> 3812 raise KeyError(key) from err
3813 except TypeError:
3814 # If we have a listlike key, _check_indexing_error will raise
3815 # InvalidIndexError. Otherwise we fall through and re-raise
3816 # the TypeError.
3817 self._check_indexing_error(key)
KeyError:None
can you help me solve this or tell me why its happen? seems like pyspa can not detect the slack bus or slack generator, while i already define generator control as 'Slack'. it still gives me 'None' key error. it works really well if i only use network.lpf() but when i use non linear network.pf() it keeps giving me error
````
riyan pramudito is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.