Skip to content

Commit

Permalink
Merge branch 'dev' into features/#377-grid-separation
Browse files Browse the repository at this point in the history
  • Loading branch information
khelfen committed May 8, 2023
2 parents ea470ef + 5569b61 commit 2d2def2
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 89 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.0
rev: v3.4.0
hooks:
- id: pyupgrade
#- repo: https://github.com/pycqa/pylint
Expand Down
1 change: 1 addition & 0 deletions doc/whatsnew/v0-3-0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ Changes
* Added method to scale timeseries `#353 <https://github.com/openego/eDisGo/pull/353>`_
* Added method to iteratively reinforce a grid in case the power flow analysis does not always converge `#353 <https://github.com/openego/eDisGo/pull/353>`_
* Added method to aggregate LV grid buses to station bus secondary side `#353 <https://github.com/openego/eDisGo/pull/353>`_
* Adapted codebase to work with pandas 2.0 `#373 <https://github.com/openego/eDisGo/pull/373>`_
* Added option to run reinforcement with reduced number of time steps `#379 <https://github.com/openego/eDisGo/pull/379>`_
* Added a new reinforcement method that separate lv grids when the overloading is very high `#380 <https://github.com/openego/eDisGo/pull/380>`_
2 changes: 1 addition & 1 deletion eDisGo_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ channels:
dependencies:
- python >= 3.8, < 3.10
- pip
- pandas >= 1.2
- pandas >= 1.4
- conda-forge::fiona
- conda-forge::geopy
- conda-forge::geopandas
Expand Down
2 changes: 1 addition & 1 deletion eDisGo_env_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ channels:
dependencies:
- python >= 3.8, < 3.10
- pip
- pandas >= 1.2
- pandas >= 1.4
- conda-forge::fiona
- conda-forge::geopy
- conda-forge::geopandas
Expand Down
11 changes: 5 additions & 6 deletions edisgo/flex_opt/check_tech_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,6 @@ def allowed_voltage_limits(edisgo_obj, buses=None, split_voltage_band=True):
buses = edisgo_obj.results.v_res.columns

if split_voltage_band:

# MV limits
mv_buses = edisgo_obj.topology.mv_grid.buses_df.index
mv_upper, mv_lower = _mv_allowed_voltage_limits(edisgo_obj)
Expand Down Expand Up @@ -1078,7 +1077,6 @@ def _lv_allowed_voltage_limits(edisgo_obj, lv_grids=None, mode=None):
buses_in_pfa = voltages_pfa.columns

if mode == "stations":

config_string = "mv_lv_station"

# get base voltage (voltage at primary side) for each station
Expand Down Expand Up @@ -1107,14 +1105,15 @@ def _lv_allowed_voltage_limits(edisgo_obj, lv_grids=None, mode=None):

# get all secondary sides and buses in grids
buses_dict = {}
secondary_sides = pd.Series()
secondary_sides_dict = {}
for grid in lv_grids:
secondary_side = grid.station.index[0]
if secondary_side in buses_in_pfa:
secondary_sides[grid] = secondary_side
secondary_sides_dict[grid] = secondary_side
buses_dict[grid.station.index[0]] = grid.buses_df.index.drop(
grid.station.index[0]
)
secondary_sides = pd.Series(secondary_sides_dict)

voltage_base = voltages_pfa.loc[:, secondary_sides.values]

Expand All @@ -1132,14 +1131,14 @@ def _lv_allowed_voltage_limits(edisgo_obj, lv_grids=None, mode=None):
)

# rename columns to secondary side
for colname, values in upper_limits_df_tmp.iteritems():
for colname, values in upper_limits_df_tmp.items():
tmp = pd.DataFrame(
data=np.tile(values, (len(buses_dict[colname]), 1)).T,
columns=buses_dict[colname],
index=values.index,
)
upper_limits_df = pd.concat([upper_limits_df, tmp], axis=1)
for colname, values in lower_limits_df_tmp.iteritems():
for colname, values in lower_limits_df_tmp.items():
tmp = pd.DataFrame(
data=np.tile(values, (len(buses_dict[colname]), 1)).T,
columns=buses_dict[colname],
Expand Down
16 changes: 10 additions & 6 deletions edisgo/network/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class TimeSeries:
"""

def __init__(self, **kwargs):

self._timeindex = kwargs.get("timeindex", pd.DatetimeIndex([]))
self.time_series_raw = TimeSeriesRaw()

Expand Down Expand Up @@ -657,9 +656,14 @@ def _overwrite_time_series(p, q, comp_type):
periods=len(worst_cases),
freq="H",
)
self.timeindex_worst_cases = self.timeindex_worst_cases.append(
pd.Series(time_stamps, index=worst_cases)

self.timeindex_worst_cases = pd.concat(
[
self.timeindex_worst_cases,
pd.Series(data=time_stamps, index=worst_cases),
]
)

self.timeindex = self.timeindex.append(time_stamps)

if generators_names is None:
Expand Down Expand Up @@ -789,7 +793,7 @@ def _worst_case_generators(self, cases, df, configs):
# get power scaling factors for different technologies, voltage levels and
# feed-in/load case
types = ["pv", "wind", "other"]
power_scaling = pd.DataFrame(columns=types)
power_scaling = pd.DataFrame(columns=types, dtype=float)
for t in types:
for case in cases:
power_scaling.at[f"{case}_mv", t] = worst_case_scale_factors[
Expand Down Expand Up @@ -2153,8 +2157,8 @@ def _check_if_components_exist(
f"concerns the following components: {comps_not_in_network}."
)

return set(component_names) - set(comps_not_in_network)
return component_names
return list(set(component_names) - set(comps_not_in_network))
return list(component_names)

def resample(self, method: str = "ffill", freq: str | pd.Timedelta = "15min"):
"""
Expand Down
4 changes: 4 additions & 0 deletions edisgo/tools/geopandas_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ def to_geopandas(grid_obj: Grid):
),
crs=f"EPSG:{srid}",
)
if components_dict[component.replace("_df", "_gdf")].empty:
components_dict[component.replace("_df", "_gdf")].index = components_dict[
component.replace("_df", "_gdf")
].index.astype(object)

# convert lines_df
lines_df = grid_obj.lines_df
Expand Down
5 changes: 0 additions & 5 deletions edisgo/tools/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from edisgo.network.grids import Grid

if "READTHEDOCS" not in os.environ:

import geopandas as gpd

from egoio.db_tables.grid import EgoDpMvGriddistrict
Expand Down Expand Up @@ -189,7 +188,6 @@ def get_grid_district_polygon(config, subst_id=None, projection=4326):
with session_scope() as session:
# get polygon from versioned schema
if config["data_source"]["oedb_data_source"] == "versioned":

version = config["versioned"]["version"]
query = session.query(
EgoDpMvGriddistrict.subst_id, EgoDpMvGriddistrict.geom
Expand Down Expand Up @@ -1155,7 +1153,6 @@ def plot_line_text():
return [middle_node_scatter]

def plot_lines():

showscale = True

if line_color == "loading":
Expand All @@ -1181,7 +1178,6 @@ def plot_lines():

data_line_plot = []
for edge in G.edges(data=True):

x0, y0, x1, y1 = get_coordinates_for_edge(edge)
edge_x = [x0 - x_root, x1 - x_root, None]
edge_y = [y0 - y_root, y1 - y_root, None]
Expand All @@ -1207,7 +1203,6 @@ def plot_lines():
.isin([branch_name])
.any()
):

color = "red"
else:
color = "black"
Expand Down
11 changes: 5 additions & 6 deletions edisgo/tools/spatial_complexity_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def rename_virtual_buses(
partial_busmap_df.loc[nodes_to_add_a_virtual, "new_bus"]
!= transformer_node
):

partial_busmap_df.loc[nodes_to_add_a_virtual, "new_bus"] = (
"virtual_"
+ partial_busmap_df.loc[feeder_non_virtual, "new_bus"]
Expand Down Expand Up @@ -528,14 +527,14 @@ def rename_new_buses(series):
] = int(n)

dijkstra_distances_df = pd.DataFrame(
index=buses_df.index, columns=medoid_bus_name
index=buses_df.index, columns=medoid_bus_name, dtype=float
)

for bus in medoid_bus_name:
path_series = pd.Series(
nx.single_source_dijkstra_path_length(graph, bus, weight="length")
)
dijkstra_distances_df.loc[:, bus] = path_series
dijkstra_distances_df[bus] = path_series

buses_df.loc[:, "medoid"] = dijkstra_distances_df.idxmin(axis=1)
partial_busmap_df = pd.DataFrame(index=buses_df.index)
Expand Down Expand Up @@ -813,9 +812,9 @@ def transform_coordinates_back(ser):
)
dijkstra_distances_df.loc[:, bus] = path_series

feeder_buses_df.loc[:, "medoid"] = dijkstra_distances_df.idxmin(
axis=1
)
feeder_buses_df.loc[:, "medoid"] = dijkstra_distances_df.apply(
pd.to_numeric
).idxmin(axis=1)

for index in feeder_buses_df.index.tolist():
partial_busmap_df.loc[index, "new_bus"] = make_name(
Expand Down
2 changes: 1 addition & 1 deletion examples/edisgo_simple_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.9.5"
},
"toc": {
"base_numbering": 1,
Expand Down
10 changes: 6 additions & 4 deletions examples/electromobility_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,9 @@
"charging_parks_with_charging_demand = (\n",
" edisgo.electromobility.charging_processes_df.charging_park_id.unique()\n",
")\n",
"charging_parks_not_integrated = set(charging_parks_with_charging_demand) - set(\n",
"charging_parks_not_integrated = list(set(charging_parks_with_charging_demand) - set(\n",
" edisgo.electromobility.integrated_charging_parks_df.index\n",
")\n",
"))\n",
"\n",
"edisgo.electromobility.potential_charging_parks_gdf.loc[\n",
" charging_parks_not_integrated\n",
Expand Down Expand Up @@ -737,7 +737,9 @@
"cell_type": "code",
"execution_count": null,
"id": "20d98ca8",
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1, 1, figsize=(9, 5))\n",
Expand Down Expand Up @@ -774,7 +776,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.9.5"
},
"toc": {
"base_numbering": 1,
Expand Down
2 changes: 1 addition & 1 deletion rtd_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jupyter_dash
matplotlib >= 3.3.0
multiprocess
networkx >= 2.5.0
pandas >= 1.2.0, < 2.0.0
pandas >= 1.4.0
plotly
pyomo >= 6.0
pypower
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def read(fname):
"matplotlib >= 3.3.0",
"multiprocess",
"networkx >= 2.5.0",
"pandas >= 1.2.0, < 2.0.0",
"pandas >= 1.4.0",
"plotly",
"pydot",
"pygeos",
Expand Down
Loading

0 comments on commit 2d2def2

Please sign in to comment.