Skip to content

Commit

Permalink
refactor: check for all zone collisions at once, raise single error
Browse files Browse the repository at this point in the history
  • Loading branch information
danielolsen committed Sep 4, 2020
1 parent 9084688 commit 0f86c50
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions powersimdata/design/clean_capacity_scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,22 @@ def _make_zonename2target(grid, targets):
else area_to_loadzone(grid, target_name, targets.loc[target_name, "area_type"])
for target_name in targets.index.tolist()
}
# Check for any collisions
zone_sets = target_zones.values()
if len(set.union(*zone_sets)) != sum([len(t) for t in zone_sets]):
zone_sets_list = [zone for _set in zone_sets for zone in _set]
duplicates = {zone for zone in zone_sets_list if zone_sets_list.count(zone) > 1}
error_areas = {
zone: {area for area, zone_set in target_zones.items() if zone in zone_set}
for zone in duplicates
}
error_msgs = [f"{k} within: {', '.join(v)}" for k, v in error_areas.items()]
raise ValueError(f"Zone(s) within multiple area! {'; '.join(error_msgs)}")
zonename2target = {}
for target_name, zone_set in target_zones.items():
# Filter out parts of states not in this interconnect
# Filter out parts of states not in the interconnect(s) in this Grid
filtered_zone_set = zone_set & set(grid.zone2id.keys())
for zone in filtered_zone_set:
if zone in zonename2target:
targets = {zonename2target[zone], target_name}
raise ValueError(f"zone in two target areas: {zone} in {targets}")
else:
zonename2target[zone] = target_name
zonename2target.update({zone: target_name for zone in filtered_zone_set})
untargetted_zones = set(grid.zone2id.keys()) - set(zonename2target.keys())
if len(untargetted_zones) > 0:
err_msg = f"Targets do not cover all load zones. Missing: {untargetted_zones}"
Expand Down

0 comments on commit 0f86c50

Please sign in to comment.