Update choropleth maps - #170
clairehalloran wants to merge 40 commits into
Conversation
patrickbrown4
left a comment
There was a problem hiding this comment.
Thanks Claire and sorry for the slow followup. Some high-level questions first and then I'll take another closer look.
| - scipy=1.18 | ||
| - shapely=2.1 | ||
| - tqdm=4.68 | ||
| - adjustText |
There was a problem hiding this comment.
With the prevalence of LLM code I'm more wary of introducing dependencies on small / less-well-vetted packages; there are examples of them getting taken over and hosting malicious code. (That's not unique to LLM code but it is easier to do now, though I might be overreacting.) So I'm on the fence about introducing a new dependency for something that's not required for the model.
- How hard do you think it would be to implement this functionality ourselves by tweaking
reeds.plots.optimize_label_positions()? - Could this be an optional package (like
seabornorscikit-learn-extra; you can see examples of how we handle those here and here)? i.e., only used and imported within a single function, and bypassed if it isn't present? - If we keep it as is, we should at least pin the version number installed.
There was a problem hiding this comment.
I lean towards either the first or third bullet. I think labeling maps without overlap is a helpful feature for many existing figures, so it would be harder to use as an optional package.
I'll look further into how adjustText and reeds.plots.optimize_label_positions are implemented to see if it would be easy to tweak the latter function.
There was a problem hiding this comment.
We discussed this a bit yesterday, but I'm confirming that adjustText uses a pretty different algorithm than the LP in reeds.plots.optimize_label_positions. Per the docstring:
First "explodes" all texts to move them apart.
Then in each iteration pushes all texts away from each other, and any specified
points or objects. At the same time slowly tries to pull the texts closer to their
original locations that they label (this reduces chances that a text ends up super
far away). In the end adds arrows connecting the texts to the respective points.
I'll work on making this package optional as we discussed.
| dfbase[valcol] *= unitscaler | ||
| dfcomp[valcol] *= unitscaler | ||
|
|
||
| ### Aggregate selected technologies to one value per region for the target year |
There was a problem hiding this comment.
Could you say more about what these changes do? I've also been working on a rewrite of this function on the pb/mapdiff branch but I should have opened an issue to clarify.
There was a problem hiding this comment.
The current behavior plots all technologies in the titles list without combining into a single i_plot value (so 'DPV' and 'UPV 'capacity are plotted on top of each other on the same map, rather than being combined into a single 'Solar' capacity for each region).
These changes combine all technologies in the value list titles into a single total capacity for the i_plot category. This sum occurs prior to calculating differences so a single i_plot difference between cases can be calculated. This change fixes a bug that made the absolute and difference plots misleading.
The difference calculation now calculates both absolute and percent differences so that there's only one conditional like this:
elif plot in ['absdiff', 'abs_diff', 'diffabs', 'diff_abs']:
This change is less important.
Summary
Adds adjustText package to environment as an optional package to avoid label overlap in maps and adds regional labels to some maps.
Before:

After:

Technical details
Added labels to net import, technology capacity, and H2 capacity maps in
single_case_plots.py:Added labels to difference maps in

compare_cases.pyfor both 2-case and multi-case comparison:In

hourly_plots.py, NaN values (such as for land-locked regions' offshore wind cf) are now colored light gray and unlabeled:Implementation notes
I incorporated the
adjust_textfunction into the existingreedsplots.label_region_valuefunction for easy reuse.Additional changes
plot_diff_mapsused for 2-case comparison incompare_cases.pyplot_diff_mapsfunction inreedsplots.pydiagnostic_plots.pyValidation, testing, and comparison report(s)
I compared USA_defaults run on this branch with a run from main. There were no changes in results, and a negligible increase in runtime (0.15 hours). Note that the difference in directory size is because I was saving vre_gen, max_cap, and load files from PRAS to run
diagnostic_plots.py.Full results here: results-main,update-maps.pptx
Checklist for author
Details to double-check
- [ ] Documentation updated if necessaryGeneral information to guide review
Did you use LLM tools (chatbot or copilot) in the preparation of this PR? If so, describe how
Yes, I used Copilot to simplify techs to their maptechs groups in
plot_diff_mapsfunction inreedsplots.py. I attempted this change manually and couldn't find a more elegant solution.Tag points of contact here if you would like additional review of the relevant parts of the model