Skip to content

Within capacity scaling, detect zones collisions and add ability to specify target area type#284

Merged
danielolsen merged 3 commits intodevelopfrom
daniel/capacity_scaling_zones
Sep 5, 2020
Merged

Within capacity scaling, detect zones collisions and add ability to specify target area type#284
danielolsen merged 3 commits intodevelopfrom
daniel/capacity_scaling_zones

Conversation

@danielolsen
Copy link
Copy Markdown
Contributor

@danielolsen danielolsen commented Sep 3, 2020

Purpose

When attempting to refactor the quick bite script to calculate shortfall for future scenarios, @BainanXia and I found a bug: if there are two target names which both include the same zone, the demand from that zone will be arbitrarily assigned to one or the other. E.g. if we include Texas and El Paso, Texas will by default look up the state of Texas which includes El Paso as one of its zones. We would like to detect this condition and return an error to the user to ask them to be more specific.

This can create a new challenge, where in some scenarios when we say Texas we mean just the interconnection, with El Paso specified separately. In this case, we would like to be able to optionally specify an area_type for each target in the input CSV.

What is the code doing

  • in load_targets_from_csv(), we add another optional column area_type with a default value of np.nan.
  • in _make_zonename2target() we refactor the input parameters to expect a dataframe, not just a list of strings: this is so that we can check for a non-nan entry in the area_type column when looking up which zones are in each area, and if we find one then we pass that along to the area_to_loadzone() lookup. This also allows us to remove the enforced_area_type input, since these are enforced target-wise via the dataframe. We also detect the case when there is a zone collision, and raise an error message.
  • in add_resource_data_to_targets() and add_demand_to_targets(), we update the calls to _make_zonename2target().

Validation

If we pass a CSV with both Texas and El Paso, we get an error message: ValueError: zone in two target areas: El Paso in {'Texas', 'El Paso'}.

If we correct this by specifying an area_type of 'interconnect' for Texas, then we get a new error, demonstrating pre-existing checks: ValueError: Targets do not cover all load zones. Missing: {'East Texas', 'Texas Panhandle'}. When we add these, or when we remove El Paso (since in this case we do want to include it with the rest of Texas) the process runs as before.

Time to review

15 minutes. This is a relatively low priority, but will help us avoid mistakes when analyzing future scenarios.

Copy link
Copy Markdown
Collaborator

@BainanXia BainanXia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is consistent with our discussion. Thanks!

Comment thread powersimdata/design/clean_capacity_scaling.py
Comment thread powersimdata/design/clean_capacity_scaling.py
Comment thread powersimdata/design/clean_capacity_scaling.py Outdated
@danielolsen danielolsen force-pushed the daniel/capacity_scaling_zones branch from 3bf6cff to 51a24a8 Compare September 4, 2020 19:38
@danielolsen danielolsen force-pushed the daniel/capacity_scaling_zones branch 4 times, most recently from ce12387 to f32a229 Compare September 4, 2020 20:54
@danielolsen
Copy link
Copy Markdown
Contributor Author

@jon-hagg I believe I've addressed all of your comments, please let me know if you think the latest version looks good.

zone_sets = target_zones.values()
if len(set.union(*zone_sets)) != sum([len(t) for t in zone_sets]):
zone_sets_list = sum([list(z) for z in zone_sets], [])
duplicates = set([x for x in zone_sets_list if zone_sets_list.count(x) > 1])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple ideas, mostly for readability

  • I think we can define duplicates using a set comprehension, e.g. {x for x in ...}
  • We could also define zone_sets_list = [z for s in zone_sets for z in s]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! I updated those comprehensions for more readability, as well as the error_areas comprehension.

@jenhagg
Copy link
Copy Markdown
Collaborator

jenhagg commented Sep 4, 2020

@jon-hagg I believe I've addressed all of your comments, please let me know if you think the latest version looks good.

Thanks, looks good! I put a couple more comments if you're interested, but I'll go ahead and approve.

@danielolsen danielolsen force-pushed the daniel/capacity_scaling_zones branch from f32a229 to 0f86c50 Compare September 4, 2020 21:26
@danielolsen danielolsen merged commit 9d6ca5c into develop Sep 5, 2020
@danielolsen danielolsen deleted the daniel/capacity_scaling_zones branch September 5, 2020 18:15
@ahurli ahurli mentioned this pull request Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants