Skip to content

Commit

Permalink
merge fixes/#683-Crossborder-lines-without-DLR
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosEpia committed Mar 10, 2022
2 parents 7677857 + 340807a commit 9c7f239
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,5 @@ Bug fixes
`#679 <https://github.com/openego/eGon-data/issues/679>`_
* Fix extraction of buildings without amenities
`#693 <https://github.com/openego/eGon-data/issues/693>`_
* Assign DLR capacities to every transmission line
`#683 <https://github.com/openego/eGon-data/issues/683>`_
27 changes: 17 additions & 10 deletions src/egon/data/datasets/calculate_dlr.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Calculate_dlr(Dataset):
def __init__(self, dependencies):
super().__init__(
name="dlr",
version="0.0.0",
version="0.0.1",
dependencies=dependencies,
tasks=(dlr,),
)
Expand Down Expand Up @@ -60,11 +60,13 @@ def dlr():
con = db.engine()

sql = f"""
SELECT scn_name, line_id, geom, s_nom FROM
SELECT scn_name, line_id, topo, s_nom FROM
{cfg['sources']['trans_lines']['schema']}.
{cfg['sources']['trans_lines']['table']}
"""
df = gpd.GeoDataFrame.from_postgis(sql, con, crs="EPSG:4326")
df = gpd.GeoDataFrame.from_postgis(
sql, con, crs="EPSG:4326", geom_col="topo"
)

trans_lines_R = {}
for i in regions.Region:
Expand All @@ -74,20 +76,22 @@ def dlr():
trans_lines["in_regions"] = [[] for i in range(len(df))]

trans_lines[["line_id", "geometry", "scn_name"]] = df[
["line_id", "geom", "scn_name"]
["line_id", "topo", "scn_name"]
]

trans_lines = gpd.GeoDataFrame(trans_lines)
# Assign to each transmission line the region to which it belongs
for i in trans_lines_R:
for j in trans_lines_R[i].index:
trans_lines.loc[j][1] = trans_lines.loc[j][1].append(i)
trans_lines["crossborder"] = ~trans_lines.within(regions.unary_union)

DLR = []

# Assign to each transmision line the final values of DLR based on location
# and type of line (overhead or underground)
for i in trans_lines.index:
# lines completely out of the Germany border have DLR = 1
if len(trans_lines.loc[i][1]) == 0:
# The concept of DLR does not apply to crossborder lines
if trans_lines.loc[i, "crossborder"] == True:
DLR.append([1] * 8760)
continue
# Underground lines have DLR = 1
Expand Down Expand Up @@ -115,7 +119,10 @@ def dlr():
trans_lines["s_max_pu"] = DLR

# delete unnecessary columns
trans_lines.drop(columns=["in_regions", "s_nom", "geometry"], inplace=True)
trans_lines.drop(
columns=["in_regions", "s_nom", "geometry", "crossborder"],
inplace=True,
)

# Modify column "s_max_pu" to fit the requirement of the table
trans_lines["s_max_pu"] = trans_lines.apply(
Expand Down Expand Up @@ -269,7 +276,7 @@ def DLR_Regions(weather_info_path, regions_shape_path):
)

# The next loop use the min wind speed and max temperature calculated previously to
# define the hourly DLR in for each region based on the table given by NEP 2020 pag 31
# define the hourly DLR for each region based on the table given by NEP 2020 pag 31
for i in range(0, len(regions)):
for j in range(0, len(time)):
if dlr.iloc[j, 1 + i * 3] <= 5:
Expand Down Expand Up @@ -325,4 +332,4 @@ def DLR_Regions(weather_info_path, regions_shape_path):
for i in range(len(regions)):
dlr_hourly["Reg_" + str(i + 1)] = dlr.iloc[:, 3 * i + 2]

return DLR_hourly_df_dic, dlr_hourly
return DLR_hourly_df_dic, dlr_hourly

0 comments on commit 9c7f239

Please sign in to comment.