PyPSA / pypsa-eur

PyPSA-Eur: A Sector-Coupled Open Optimisation Model of the European Energy System
https://pypsa-eur.readthedocs.io/
335 stars 235 forks source link

Line num_parallel = 0 after simplification and clustering #444

Closed euronion closed 5 months ago

euronion commented 1 year ago

Checklist

Describe the Bug

Line number "3" after clustering (clusters=128) has num_parallel = 0 which does not make any sense. Where does the line with this unrealistic value come from?

Here's the line in question:

n.lines.query("num_parallel == 0").iloc[0]
Out[6]:
bus0                                      AL1 0
bus1                                      MK1 0
num_parallel                                0.0
length                               175.650433
type                Al/St 240/40 4-bundle 380.0
s_max_pu                                    0.7
s_nom                                       0.0
capital_cost                        9031.968712
x                                           0.0
r                                           0.0
g                                           0.0
b                                           0.0
s_nom_extendable                          False
s_nom_min                                   0.0
s_nom_max                                   inf
build_year                                    0
lifetime                                    inf
carrier
terrain_factor                              1.0
v_ang_min                                  -inf
v_ang_max                                   inf
sub_network
x_pu                                        0.0
r_pu                                        0.0
g_pu                                        0.0
b_pu                                        0.0
x_pu_eff                                    0.0
r_pu_eff                                    0.0
s_nom_opt                                   0.0
Name: 3, dtype: object
martacki commented 1 year ago

Very interesting. But in fact, this is not a bug, because the un-aggregated lines of elec.nc that build line 3 in elec_s_128.nc already have the attributes num_paralell = 0. This is because they are all under_construction=True.

If you don't believe me, you can check:

linemap = pd.read_csv("resources/linemap_elec_s_128.csv", dtype={"Line": str, "name": str}, index_col=0)
aggregated_lines = linemap.query("name == '3'").index
n_full = pypsa.Network("networks/elec.nc")
n_full.lines.loc[aggregated_lines][["under_construction", "num_parallel"]]

For my test-run, the array aggregated_lines has only one index (14988), and the respective line in elec.nc has the following attributes:

under_construction    True
num_parallel           0.0
Name: 14988, dtype: object

Thus, line 3 also has num_parallel=0.

In fact, my aggregated test-network with 128 nodes had another line in Germany (Line 59) with num_parallel=0. The same statement is true in this case. Here, the array aggregated_lines again consists of a single index (3575), and the respective line 3575 in elec.nc has the attributes

under_construction    True
num_parallel           0.0
Name: 3575, dtype: object
martacki commented 1 year ago

We might rather think about the model assumptions if it makes sense to assign some artificial num_parallel value to lines that are under construction, for example based on their intended voltage level.

euronion commented 1 year ago

Interesting! This information is not really preserved in the aggregated links, right? So difficult to understand? Can we do something about it?

Looking at it from a different angle:

If I set

config["lines"]["under_construction"] = "remove"

instead of zero the line should be gone, right?

martacki commented 1 year ago

You are right, the under_construction tag is being removed after simplify_network, see: https://github.com/PyPSA/pypsa-eur/blob/master/scripts/simplify_network.py#L587-L594.

I never tried removing lines using the config, so I don't know. I usually try one of

n.lines = n.lines.query("under_construction == False")
n.lines = n.lines[~n.lines.under_construction]
...