Skip to content

Commit

Permalink
retry with a new table
Browse files Browse the repository at this point in the history
Signed-off-by: Hugo KULESZA <hugo.kulesza@rte-france.com>
  • Loading branch information
HugoKulesza committed Sep 2, 2024
1 parent 518a30b commit a6a2dd0
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -609,18 +609,6 @@ static NetworkDataframeMapper danglingLines() {
.booleans("paired", DanglingLine::isPaired)
.booleans("fictitious", Identifiable::isFictitious, Identifiable::setFictitious, false)
.strings("tie_line_id", dl -> dl.getTieLine().map(Identifiable::getId).orElse(""))
.doubles("min_p", (dl, context) -> perUnitPQ(context, Optional.ofNullable(dl.getGeneration()).map(DanglingLine.Generation::getMinP).orElse(NaN)),
(dl, minP, context) -> Optional.ofNullable(dl.getGeneration()).ifPresent(gen -> gen.setMinP(unPerUnitPQ(context, minP))), false)
.doubles("max_p", (dl, context) -> perUnitPQ(context, Optional.ofNullable(dl.getGeneration()).map(DanglingLine.Generation::getMaxP).orElse(NaN)),
(dl, maxP, context) -> Optional.ofNullable(dl.getGeneration()).ifPresent(gen -> gen.setMaxP(unPerUnitPQ(context, maxP))), false)
.doubles("target_p", (dl, context) -> perUnitPQ(context, Optional.ofNullable(dl.getGeneration()).map(DanglingLine.Generation::getTargetP).orElse(NaN)),
(dl, targetP, context) -> Optional.ofNullable(dl.getGeneration()).ifPresent(gen -> gen.setTargetP(unPerUnitPQ(context, targetP))), false)
.doubles("target_q", (dl, context) -> perUnitPQ(context, Optional.ofNullable(dl.getGeneration()).map(DanglingLine.Generation::getTargetQ).orElse(NaN)),
(dl, targetQ, context) -> Optional.ofNullable(dl.getGeneration()).ifPresent(gen -> gen.setTargetQ(unPerUnitPQ(context, targetQ))), false)
.doubles("target_v", (dl, context) -> perUnitV(context, Optional.ofNullable(dl.getGeneration()).map(DanglingLine.Generation::getTargetV).orElse(NaN), dl.getTerminal()),
(dl, targetV, context) -> Optional.ofNullable(dl.getGeneration()).ifPresent(gen -> gen.setTargetV(unPerUnitV(context, targetV, dl.getTerminal()))), false)
.booleans("voltage_regulator_on", dl -> Optional.ofNullable(dl.getGeneration()).map(DanglingLine.Generation::isVoltageRegulationOn).orElse(false),
(dl, voltageRegulatorOn) -> Optional.ofNullable(dl.getGeneration()).ifPresent(gen -> gen.setVoltageRegulationOn(voltageRegulatorOn)), false)
.addProperties()
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,11 @@ Optional<DanglingLineAdder> createAdder(Network network, int row, boolean throwE
applyIfPresent(g, row, adder::setG);
applyIfPresent(b, row, adder::setB);
applyIfPresent(pairingKey, row, adder::setPairingKey);
addGenerationIfPresent(adder, row);
return Optional.of(adder);
} else {
return Optional.empty();
}
}

private void addGenerationIfPresent(DanglingLineAdder adder, int row) {
if (minP == null && maxP == null && targetV == null && targetP == null && targetQ == null
&& voltageRegulatorOn == null) {
return;
}
DanglingLineAdder.GenerationAdder genAdder = adder.newGeneration();
applyIfPresent(minP, row, genAdder::setMinP);
applyIfPresent(maxP, row, genAdder::setMaxP);
applyIfPresent(targetP, row, genAdder::setTargetP);
applyIfPresent(targetQ, row, genAdder::setTargetQ);
applyIfPresent(targetV, row, genAdder::setTargetV);
applyBooleanIfPresent(voltageRegulatorOn, row, genAdder::setVoltageRegulationOn);
genAdder.add();
}
}

@Override
Expand Down
1 change: 1 addition & 0 deletions pypowsybl/_pypowsybl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class ElementType:
BUS_FROM_BUS_BREAKER_VIEW: ClassVar[ElementType] = ...
BUSBAR_SECTION: ClassVar[ElementType] = ...
DANGLING_LINE: ClassVar[ElementType] = ...
DANGLING_LINE_GENERATION: ClassVar[ElementType] = ...
TIE_LINE: ClassVar[ElementType] = ...
GENERATOR: ClassVar[ElementType] = ...
HVDC_LINE: ClassVar[ElementType] = ...
Expand Down
68 changes: 62 additions & 6 deletions pypowsybl/network/impl/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,12 +1236,6 @@ def get_dangling_lines(self, all_attributes: bool = False, attributes: List[str]
- **ucte-xnode-code**: deprecated for pairing key.
- **paired**: if the dangling line is paired with a tie line
- **tie_line_id**: the ID of the tie line if the dangling line is paired
- **min_p** (optional): Minimum active power output of the dangling line's generation part
- **max_p** (optional): Maximum active power output of the dangling line's generation part
- **target_p** (optional): Active power target of the generation part
- **target_q** (optional): Reactive power target of the generation part
- **target_v** (optional): Voltage target of the generation part
- **voltage_regulator_on** (optional): ``True`` if the generation part regulates voltage
This dataframe is indexed by the id of the dangling lines
Expand Down Expand Up @@ -1291,6 +1285,35 @@ def get_dangling_lines(self, all_attributes: bool = False, attributes: List[str]
"""
return self.get_elements(ElementType.DANGLING_LINE, all_attributes, attributes, **kwargs)

def get_dangling_lines_generation(self, all_attributes: bool = False, attributes: List[str] = None,
**kwargs: ArrayLike):
r"""
Get a dataframe of the optional generation part of dangling lines.
Args:
all_attributes: flag for including all attributes in the dataframe, default is false
attributes: attributes to include in the dataframe. The 2 parameters are mutually exclusive.
If no parameter is specified, the dataframe will include the default attributes.
kwargs: the data to be selected, as named arguments.
Returns:
A dataframe of the generation part of the network dangling lines.
Notes:
The resulting dataframe, depending on the parameters, will include the following columns:
- **dangling_line_id**: The ID of the dangling line
- **target_p**:
- **voltage_regulator_on**:
- **target_q**:
- **target_v**:
- **min_p**:
- **max_p**:
This dataframe is indexed by the id of the dangling lines to which the generation part is attached
"""
return self.get_elements(ElementType.DANGLING_LINE_GENERATION, all_attributes, attributes, **kwargs)

def get_tie_lines(self, all_attributes: bool = False, attributes: List[str] = None,
**kwargs: ArrayLike) -> DataFrame:
r"""
Expand Down Expand Up @@ -3775,6 +3798,39 @@ def create_dangling_lines(self, df: DataFrame = None, **kwargs: ArrayLike) -> No
kwargs.pop(ucte_xnode_code_str)
return self._create_elements(ElementType.DANGLING_LINE, [df], **kwargs)

def create_dangling_line_generation_parts(self, df: Dataframe = None, **kwargs: ArrayLike):
"""
Creates the generation part of already created dangling lines.
Args:
df: Attributes as a dataframe.
kwargs: Attributes as keyword arguments.
Notes:
Data may be provided as a dataframe or as keyword arguments.
In the latter case, all arguments must have the same length.
Valid attributes are:
- **dangling_line_id**: the identifier of the already existing dangling line
- **target_p**:
- **voltage_regulator_on**:
- **target_q**:
- **target_v**:
- **min_p**:
- **max_p**:
Examples:
Using keyword arguments:
.. code-block:: python
network.create_dangling_line_generation_parts(id='BAT-1', voltage_level_id='VL1', bus_id='B1',
p0=10, q0=3, r=0, x=5, g=0, b=1e-6)
"""
return self._create_elements(ElementType.DANGLING_LINE_GENERATION, [df], **kwargs)

def create_lcc_converter_stations(self, df: DataFrame = None, **kwargs: ArrayLike) -> None:
"""
Creates LCC converter stations.
Expand Down
29 changes: 0 additions & 29 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,35 +1046,6 @@ def test_dangling_lines():
pd.testing.assert_frame_equal(expected, dangling_lines, check_dtype=False, atol=1e-2)


def test_dangling_line_generation():
n = util.create_dangling_lines_network()
df = n.get_dangling_lines(attributes=['min_p', 'max_p', 'target_p', 'target_q', 'target_v',
'voltage_regulator_on'])
assert not df['voltage_regulator_on']['DL']
assert math.isnan(df['min_p']['DL'])

with pytest.raises(PyPowsyblError) as context:
n.create_dangling_lines(id='DL2_wrong', voltage_level_id='VL', bus_id='BUS',
p0=100, q0=100, r=0, x=0, g=0, b=0,
target_v=100, voltage_regulator_on=True)
assert "invalid value (NaN) for active power setpoint" in str(context)

n.create_dangling_lines(id='DL2', voltage_level_id='VL', bus_id='BUS',
p0=100, q0=100, r=0, x=0, g=0, b=0,
min_p=0, max_p=100, target_p=100, target_v=100, voltage_regulator_on=True)
df2 = n.get_dangling_lines(attributes=['min_p', 'max_p', 'target_p', 'target_q', 'target_v',
'voltage_regulator_on'])
assert df2['voltage_regulator_on']['DL2']
assert math.isnan(df2['target_q']['DL2'])

n.update_dangling_lines(pd.DataFrame(index=['DL2'], columns=['target_q', 'voltage_regulator_on'],
data=[[100, False]]))
df3 = n.get_dangling_lines(attributes=['min_p', 'max_p', 'target_p', 'target_q', 'target_v',
'voltage_regulator_on'])
assert not df3['voltage_regulator_on']['DL2']
assert df3['target_q']['DL2']==100


def test_batteries():
n = util.create_battery_network()
df = n.get_batteries(all_attributes=True)
Expand Down

0 comments on commit a6a2dd0

Please sign in to comment.