# Transformer with non-trivial phase shift and tap ratio

Note

You can download this example as a Jupyter notebook or start it in interactive mode.

# Transformer with non-trivial phase shift and tap ratio#

This example is a copy of pandapowerâ€™s minimal example.

[1]:

import pypsa
import numpy as np
import pandas as pd

ERROR 1: PROJ: proj_create_from_database: Open of /home/docs/checkouts/readthedocs.org/user_builds/pypsa/conda/latest/share/proj failed

[2]:

network = pypsa.Network()

"Transformer",
"MV-LV trafo",
type="0.4 MVA 20/0.4 kV",
bus0="MV bus",
bus1="LV1 bus",
)
"Line", "LV cable", type="NAYY 4x50 SE", bus0="LV1 bus", bus1="LV2 bus", length=0.1
)
"Generator", "External Grid", bus="MV bus", control="Slack", marginal_cost=10
)

[3]:

def run_pf():
network.lpf()
network.pf(use_seed=True)
return pd.DataFrame(
{
"Voltage Angles": network.buses_t.v_ang.loc["now"] * 180.0 / np.pi,
"Volate Magnitude": network.buses_t.v_mag_pu.loc["now"],
}
)

[4]:

run_pf()

INFO:pypsa.pf:Performing linear load-flow on AC sub-network SubNetwork 0 for snapshot(s) Index(['now'], dtype='object', name='snapshot')

INFO:pypsa.pf:Performing non-linear load-flow on AC sub-network SubNetwork 0 for snapshots Index(['now'], dtype='object', name='snapshot')

INFO:pypsa.pf:Newton-Raphson solved in 3 iterations with error of 0.000000 in 0.016444 seconds

[4]:

Voltage Angles Volate Magnitude
Bus
MV bus 0.000000 1.020000
LV1 bus -150.760126 1.008843
LV2 bus -149.884141 0.964431
[5]:

network.transformers.tap_position = 2
run_pf()

INFO:pypsa.pf:Performing linear load-flow on AC sub-network SubNetwork 0 for snapshot(s) Index(['now'], dtype='object', name='snapshot')

INFO:pypsa.pf:Performing non-linear load-flow on AC sub-network SubNetwork 0 for snapshots Index(['now'], dtype='object', name='snapshot')

INFO:pypsa.pf:Newton-Raphson solved in 3 iterations with error of 0.000000 in 0.016299 seconds

[5]:

Voltage Angles Volate Magnitude
Bus
MV bus 0.000000 1.020000
LV1 bus -150.843911 0.959655
LV2 bus -149.870837 0.912713
[6]:

network.transformers.tap_position = -2
run_pf()

INFO:pypsa.pf:Performing linear load-flow on AC sub-network SubNetwork 0 for snapshot(s) Index(['now'], dtype='object', name='snapshot')

INFO:pypsa.pf:Performing non-linear load-flow on AC sub-network SubNetwork 0 for snapshots Index(['now'], dtype='object', name='snapshot')

INFO:pypsa.pf:Newton-Raphson solved in 3 iterations with error of 0.000000 in 0.015943 seconds

[6]:

Voltage Angles Volate Magnitude
Bus
MV bus 0.000000 1.020000
LV1 bus -150.681666 1.063133
LV2 bus -149.896634 1.021202

Now play with tap changer on LV side

[7]:

new_trafo_lv_tap = network.transformer_types.loc[["0.4 MVA 20/0.4 kV"]]
new_trafo_lv_tap.index = ["New trafo"]
new_trafo_lv_tap.tap_side = 1
new_trafo_lv_tap.T

[7]:

New trafo
f_nom 50.0
s_nom 0.4
v_nom_0 20.0
v_nom_1 0.4
vsc 6.0
vscr 1.425
pfe 1.35
i0 0.3375
phase_shift 150.0
tap_side 1
tap_neutral 0
tap_min -2
tap_max 2
tap_step 2.5
references pandapower;Oswald - Transformatoren - Vorlesun...
[8]:

network.transformer_types = network.transformer_types.append(new_trafo_lv_tap)
network.transformers.type = "New trafo"
network.transformers.tap_position = 2
run_pf()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_6117/2416978983.py in ?()
----> 1 network.transformer_types = network.transformer_types.append(new_trafo_lv_tap)
2 network.transformers.type = "New trafo"
3 network.transformers.tap_position = 2
4 run_pf()

6292             and name not in self._accessors
6293             and self._info_axis._can_hold_identifiers_and_holds_name(name)
6294         ):
6295             return self[name]
-> 6296         return object.__getattribute__(self, name)

AttributeError: 'DataFrame' object has no attribute 'append'

[9]:

network.transformers.T

[9]:

Transformer MV-LV trafo
attribute
bus0 MV bus
bus1 LV1 bus
type 0.4 MVA 20/0.4 kV
model t
x 0.058283
r 0.01425
g 0.003375
b -0.0
s_nom 0.4
s_nom_mod 0.0
s_nom_extendable False
s_nom_min 0.0
s_nom_max inf
s_max_pu 1.0
capital_cost 0.0
num_parallel 1.0
tap_ratio 0.95
tap_side 0
tap_position -2
phase_shift 150.0
build_year 0
v_ang_min -inf
v_ang_max inf
sub_network 0
x_pu 0.145712
r_pu 0.035618
g_pu 0.00135
b_pu -0.0
x_pu_eff 0.138423
r_pu_eff 0.033844
s_nom_opt 0.0
[10]:

network.transformers.tap_position = -2
run_pf()

INFO:pypsa.pf:Performing linear load-flow on AC sub-network SubNetwork 0 for snapshot(s) Index(['now'], dtype='object', name='snapshot')

INFO:pypsa.pf:Performing non-linear load-flow on AC sub-network SubNetwork 0 for snapshots Index(['now'], dtype='object', name='snapshot')

INFO:pypsa.pf:Newton-Raphson solved in 3 iterations with error of 0.000000 in 0.015963 seconds

[10]:

Voltage Angles Volate Magnitude
Bus
MV bus 0.000000 1.020000
LV1 bus -150.681666 1.063133
LV2 bus -149.896634 1.021202

Now make sure that the phase shift is also there in the LOPF

[11]:

network.generators.p_nom = 1.0
network.lines.s_nom = 1.0
network.optimize()
pd.DataFrame(
{
"Voltage Angles": network.buses_t.v_ang.loc["now"] * 180.0 / np.pi,
"Volate Magnitude": network.buses_t.v_mag_pu.loc["now"],
}
)

INFO:linopy.model: Solve problem using Glpk solver

INFO:linopy.io: Writing time: 0.03s

INFO:linopy.solvers:GLPSOL--GLPK LP/MIP Solver 5.0
Parameter(s) specified in the command line:
--lp /tmp/linopy-problem-3ig2ckuz.lp --output /tmp/linopy-solve-7vcqgid_.sol
9 rows, 3 columns, 11 non-zeros
GLPK Simplex Optimizer 5.0
9 rows, 3 columns, 11 non-zeros
Preprocessing...
~     0: obj =   1.000000000e+00  infeas =  0.000e+00
OPTIMAL SOLUTION FOUND BY LP PREPROCESSOR
Time used:   0.0 secs
Memory used: 0.0 Mb (39693 bytes)
Writing basic solution to '/tmp/linopy-solve-7vcqgid_.sol'...


INFO:linopy.constants: Optimization successful:
Status: ok
Termination condition: optimal
Solution: 3 primals, 9 duals
Objective: 1.00e+00
Solver model: not available
Solver message: optimal


INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-fix-p-lower, Generator-fix-p-upper, Line-fix-s-lower, Line-fix-s-upper, Transformer-fix-s-lower, Transformer-fix-s-upper were not assigned to the network.

[11]:

Voltage Angles Volate Magnitude
Bus
MV bus 0.627810 1.020000
LV1 bus -0.165294 1.063133
LV2 bus -0.462516 1.021202