Skip to content

Commit 43f6f09

Browse files
committed
Small adjustments in console output
1 parent 7320c5a commit 43f6f09

2 files changed

Lines changed: 108 additions & 35 deletions

File tree

edisgo/io/electromobility_import.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,13 +1440,35 @@ def integrate_charging_parks_14a(edisgo_obj):
14401440
from collections import defaultdict
14411441

14421442
charging_parks = list(edisgo_obj.electromobility.potential_charging_parks)
1443-
1443+
1444+
#temp1
1445+
total_parks = len(charging_parks)
1446+
1447+
parks_demand_gt_0 = [
1448+
cp for cp in charging_parks
1449+
if cp.designated_charging_point_capacity > 0
1450+
]
1451+
parks_within_grid = [
1452+
cp for cp in charging_parks
1453+
if cp.within_grid
1454+
]
1455+
#temp2
1456+
14441457
designated_charging_parks = [
14451458
cp
14461459
for cp in charging_parks
14471460
if (cp.designated_charging_point_capacity > 0) and cp.within_grid
14481461
]
14491462

1463+
#temp1
1464+
print("\nCharging park filter check (14a)")
1465+
print("-" * 44)
1466+
print(f"{'Total parks in all mv_grid_ids':<30}{total_parks:>6}")
1467+
print(f"{'CP with Demand > 0':<30}{len(parks_demand_gt_0):>6}")
1468+
print(f"{'CP within grid':<30}{len(parks_within_grid):>6}")
1469+
print(f"{'Designated CP (both true)':<30}{len(designated_charging_parks):>6}")
1470+
#temp2
1471+
14501472
charging_park_ids = []
14511473
edisgo_ids = []
14521474
comp_type = "charging_point"
@@ -1457,10 +1479,9 @@ def integrate_charging_parks_14a(edisgo_obj):
14571479
}
14581480
voltage_level_counter = defaultdict(int)
14591481

1460-
print("\n\n=========== START INTEGRATING CHARGING PARKS (_14a) ===========\n")
1461-
print(f"Designated charging parks: {len(designated_charging_parks)}\n")
1462-
1463-
total_start = time.perf_counter()
1482+
print("\nIntegrating charging parks (14a)")
1483+
print("-" * 44)
1484+
print(f"{'Designated parks':<30}{len(designated_charging_parks):>6}\n")
14641485

14651486
for i, cp in enumerate(designated_charging_parks, start=1):
14661487
park_start = time.perf_counter()
@@ -1490,7 +1511,7 @@ def integrate_charging_parks_14a(edisgo_obj):
14901511
charging_park_ids.append(cp.id)
14911512
edisgo_ids.append(edisgo_id)
14921513

1493-
if i % 1000 == 0:
1514+
if i % 500 == 0:
14941515
avg_park = stats["parks"]["total_time"] / stats["parks"]["count"]
14951516
print(f"[{i:>5}/{len(designated_charging_parks)}] last={park_dt:8.4f}s | avg={avg_park:8.4f}s")
14961517

@@ -1502,20 +1523,16 @@ def integrate_charging_parks_14a(edisgo_obj):
15021523
print("Exception: ", e)
15031524
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
15041525
raise
1505-
1506-
total_dt = time.perf_counter() - total_start
1507-
1508-
print("\n=========== FINISHED INTEGRATING CHARGING PARKS (_14a) ===========\n")
1526+
1527+
print("\nIntegration finished (14a)")
1528+
print("-" * 44)
1529+
print(f"{'Integrated parks':<30}{len(charging_park_ids):>6}")
15091530

15101531
edisgo_obj.electromobility.integrated_charging_parks_df = pd.DataFrame(
15111532
columns=COLUMNS["integrated_charging_parks_df"],
15121533
data=edisgo_ids,
15131534
index=charging_park_ids,
15141535
)
1515-
1516-
if stats["parks"]["count"] > 0:
1517-
print(f"Total parks: {stats['parks']['count']}")
1518-
print(f"Total time: {total_dt:.4f}s")
15191536

15201537
def import_electromobility_from_oedb(
15211538
edisgo_obj: EDisGo,
@@ -1694,10 +1711,12 @@ def potential_charging_parks_from_oedb_14a(
16941711
"""
16951712
14a variant of potential_charging_parks_from_oedb.
16961713
1697-
Test variant:
1698-
Do NOT filter charging parks directly by shapefile geometry.
1714+
Does not filter charging parks directly by shapefile geometry.
16991715
Instead, determine intersecting mv_grid_ids from the shapefile and then
17001716
load all charging parks belonging to those mv_grid_ids.
1717+
1718+
Later on in integrate_charging_parks_14a only the charging parks that are
1719+
within_grid are kept.
17011720
"""
17021721
if shapefile_path is None:
17031722
raise ValueError("shapefile_path must be provided.")

examples/loma-14a.py

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ def run_optimization_14a(edisgo):
238238
edisgo.topology.grid_district["geom"] = mv_grid_geom.loc[0, "geometry"]
239239
edisgo.topology.grid_district["srid"] = 4326
240240

241-
# edisgo.topology.check_integrity()
242-
# pypsa_n = edisgo.to_pypsa()
243-
# edisgo.analyze()
241+
edisgo.topology.check_integrity()
242+
pypsa_n = edisgo.to_pypsa()
243+
edisgo.analyze()
244244

245245
############################# MANUAL FIXES ####################################
246246
edisgo.topology.generators_df = edisgo.topology.generators_df[
@@ -262,13 +262,27 @@ def run_optimization_14a(edisgo):
262262
buses_with_existing_loads,
263263
)
264264

265+
#Temporary Check: Amount of CPs before importing eDisGo CPs
266+
names = edisgo.topology.loads_df.query("type == 'charging_point'").index.astype(str)
267+
print({
268+
"existing": names.str.contains("Existing", case=False).sum(),
269+
"additional": names.str.contains("Additional", case=False).sum(),
270+
"rest": (~(names.str.contains("Existing", case=False) |
271+
names.str.contains("Additional", case=False))).sum(),
272+
"total": len(names)
273+
})
274+
265275
# -------------------------
266276
# Import + distribute + integrate EV data (creates new charging points)
267277
# -------------------------
268278
'''
269279
After this function there are no time series yet. Only charging points and
270280
a overall demand which is then transferred into a time series in
271281
apply_charging_strategy.
282+
283+
Note: Afterwards there should be the Existing CP (411) and Additional CP (589)
284+
from the LoMa side for the 2035 scenario and all new eDisGo CP (for whole Husum
285+
there should be 2337). So the total should be 3337.
272286
'''
273287
edisgo.import_electromobility_14a(
274288
scenario="eGon2035",
@@ -277,13 +291,25 @@ def run_optimization_14a(edisgo):
277291
},
278292
)
279293

294+
#Temporary Check: Amount of CPs after importing eDisGo CPs
295+
names = edisgo.topology.loads_df.query("type == 'charging_point'").index.astype(str)
296+
print({
297+
"existing": names.str.contains("Existing", case=False).sum(),
298+
"additional": names.str.contains("Additional", case=False).sum(),
299+
"rest": (~(names.str.contains("Existing", case=False) |
300+
names.str.contains("Additional", case=False))).sum(),
301+
"total": len(names)
302+
})
303+
280304
# -------------------------
281-
# Apply charging strategy (writes time series for the new integrated charging points from eDisGo)
305+
# Apply charging strategy
282306
# -------------------------
283307
'''
308+
This step created the time series for the new eDisGo charging points.
284309
Without the preparation of Q before charging strategy I got an error while
285-
apply_charging_strategy which was caused by deviating time index.
286-
After this step only the charging point from eDisGo have a time series.
310+
apply_charging_strategy which was caused by a deviating time index.
311+
312+
Note: After this step ONLY the charging points from eDisGo have a time series.
287313
'''
288314
# Prepare Q before charging strategy
289315
ti = edisgo.timeseries.timeindex
@@ -304,6 +330,10 @@ def run_optimization_14a(edisgo):
304330
This step then finally transfers the time series from suitable eDisGo
305331
charging_points to Existing_ und Additional_ charging points which are
306332
created on the LoMa side.
333+
334+
Note: After this step there should be 411 Existing CP and 589 Additional for
335+
the 2035 scenario and 1337 eDisGo CP as 1000 of those were used for matching
336+
and transferring the time series and deleted afterwards.
307337
'''
308338
ev_match_results = transfer_ts_from_new_to_existing_cp(
309339
edisgo,
@@ -314,6 +344,16 @@ def run_optimization_14a(edisgo):
314344
tol_2=0.9,
315345
)
316346

347+
#Temporary Check: Amount of CPs fter transferring time series
348+
names = edisgo.topology.loads_df.query("type == 'charging_point'").index.astype(str)
349+
print({
350+
"existing": names.str.contains("Existing", case=False).sum(),
351+
"additional": names.str.contains("Additional", case=False).sum(),
352+
"rest": (~(names.str.contains("Existing", case=False) |
353+
names.str.contains("Additional", case=False))).sum(),
354+
"total": len(names)
355+
})
356+
317357
# ============================================================
318358
# Optional Utilities for sensitivity analysis/chaning the amount of cp/hp
319359
# - target by absolute value or relative percentage
@@ -324,23 +364,27 @@ def run_optimization_14a(edisgo):
324364
Either by percentage or by a total amount including the infrastructure from
325365
LoMa. When deleting CP/HP there is an option to export the deleted ones.
326366
New CP/HP will have 'dup' in their name.
367+
368+
Note: for the 2035 scenario the target total would need to be set to 1000.
369+
CPs with the marker Additional and Existing in their name will be removed last.
370+
This way only the remaining 1337 eDisGo CP would be deleted.
327371
'''
328372
output_dir = "/home/paul/LoMa/test/shapes"
329373

330374
cp_eligible_buses = buses_with_existing_loads(edisgo)
331375
hp_eligible_buses = buses_with_existing_loads(edisgo)
332376

333-
# change_cp_amount = set_charging_points_to_target(
334-
# edisgo,
335-
# target_total=500, # sets total amount of CP to 1000
336-
# #percentage=0.10, # increases total amount of CP by 10%
337-
# #percentage=-0.10, # decreases total amount of CP by 10%
338-
# eligible_buses=cp_eligible_buses,
339-
# removal_priority=["Additional", "Existing"],
340-
# add_tracking_columns=False,
341-
# export_removed=True, # only applies when negative percentage for debugging
342-
# export_dir=output_dir, # only applies when negative percentage for debugging
343-
# )
377+
change_cp_amount = set_charging_points_to_target(
378+
edisgo,
379+
target_total=1000, # sets total amount of CP to 1000
380+
#percentage=0.10, # increases total amount of CP by 10%
381+
#percentage=-0.10, # decreases total amount of CP by 10%
382+
eligible_buses=cp_eligible_buses,
383+
removal_priority=["Additional", "Existing"],
384+
add_tracking_columns=False,
385+
export_removed=True, # only applies when there are deleted CP
386+
export_dir=output_dir, # only applies when there are deleted CP
387+
)
344388

345389
# change_hp_amount = set_heat_pumps_to_target(
346390
# edisgo,
@@ -349,10 +393,20 @@ def run_optimization_14a(edisgo):
349393
# #percentage=-0.10, # decreases total amount of CP by 10%
350394
# eligible_buses=hp_eligible_buses,
351395
# add_tracking_columns=False,
352-
# export_removed=True, # only applies when negative percentage for debugging
353-
# export_dir=output_dir, # only applies when negative percentage for debugging
396+
# export_removed=True, # only applies when there are deleted HP
397+
# export_dir=output_dir, # only applies when there are deleted HP
354398
# )
355399

400+
#Temporary Check: Amount of CPs after total amount changed
401+
names = edisgo.topology.loads_df.query("type == 'charging_point'").index.astype(str)
402+
print({
403+
"existing": names.str.contains("Existing", case=False).sum(),
404+
"additional": names.str.contains("Additional", case=False).sum(),
405+
"rest": (~(names.str.contains("Existing", case=False) |
406+
names.str.contains("Additional", case=False))).sum(),
407+
"total": len(names)
408+
})
409+
356410
############################ EV INTEGRATION PART ##############################
357411

358412
# Set Zero active power for batteries (let the OPF optimize dispatch freely)

0 commit comments

Comments
 (0)