Skip to content

Remove deprecated spatial mapping and aggregation code and inputs#123

Merged
kodiobika merged 34 commits into
mainfrom
ko/spatial_cleanup
Jun 26, 2026
Merged

Remove deprecated spatial mapping and aggregation code and inputs#123
kodiobika merged 34 commits into
mainfrom
ko/spatial_cleanup

Conversation

@kodiobika

@kodiobika kodiobika commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Spatial mapping and aggregation can now be done with just county2zone.csv and hierarchy.csv, so this PR removes related switches, files, and functions that are no longer needed.

Technical details

  • Deletes hard-coding of and uses of GSw_RegionResolution switch
  • Deletes hierarchy_from134.csv files
  • Deletes reeds.spatial.get_agglevel_variables function
  • Adds reeds.io.get_county_zones and reeds.io.has_county_zones functions, which are used in cases where we still need to know whether a zone set is at county/mixed resolution and/or what the county-level zones of the set are
  • The following files no longer get written to inputs_case: agglevels.csv, r_ba.csv, val_ba.csv, county.csv, and hierarchy_with_res.csv
  • A model zone column r is now added to the generator database (unitdata.csv) in input_processing/copy_files.py in place of the reeds_ba column. Places where generators were being mapped to model zones in subsequent parts of input_processing or postprocessing are now removed.

Switches added/removed/changed

  • Removed hard-coded/deprecated GSw_RegionResolution switch

Issues resolved

Part of #16

Validation, testing, and comparison report(s)

I ran all of the non-github cases in cases_test.csv and confirmed the changes are minimal or nonexistent. In the BA resolution national cases, there are small changes expected due to census divisions now following state boundaries. In county and mixed resolution cases, there are small changes expected due to the fact that in reeds/resource_adequacy/reeds2pras/src/utils/reeds_data_parsing.jl we were previously reading the reeds_ba column from unitdata.csv (which only contained BAs, even when model zones were at the county-level), whereas now we're reading the r column, which contains model zones.

Checklist for author

Details to double-check

  • Charge code provided to reviewers
  • Included comparison reports for appropriate test cases
  • Code formatting standardized
  • Reusable functions used where possible instead of copy/pasted code

General information to guide review

  • Zero impact on results of default case
  • No large data file(s) added/modified
  • No substantive impact on runtime for full-US reference case
  • No substantive impact on folder size for full-US reference case
  • No change to process flow (runreeds.py, reeds/core/solve/solve.py)
  • No change to code organization
  • No change to package requirements (environment.yml or Project.toml)

Did you use LLM tools (chatbot or copilot) in the preparation of this PR? If so, describe how

No

Tag points of contact here if you would like additional review of the relevant parts of the model

@kodiobika kodiobika self-assigned this Jun 16, 2026
@kodiobika kodiobika requested a review from patrickbrown4 June 16, 2026 19:39
@kodiobika kodiobika changed the title Remove deprecated spatial aggregation features Remove deprecated spatial aggregation code and inputs Jun 16, 2026
@kodiobika

Copy link
Copy Markdown
Contributor Author

@pesap Is agglevels.csv still needed in R2X or can we delete it?

@kodiobika kodiobika changed the title Remove deprecated spatial aggregation code and inputs Remove deprecated spatial mapping and aggregation code and inputs Jun 17, 2026
Comment thread reeds/io.py Outdated
Comment thread reeds/input_processing/writecapdat.py Outdated
Comment thread reeds/input_processing/transmission.py Outdated

@patrickbrown4 patrickbrown4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks a ton for all the cleanup and tests; it looks great, and I'm excited to get it in. I tried it with GSw_ZoneSet=z90 and it worked (at least for the Pacific region), so we're super close.

This PR will also fix #125, since I forgot to update the hierarchy_from134.csv files in #121 and they're out of sync with state_groups.csv (which will no longer be a problem since hierarchy_from134.csv is being removed).

It's up to you how you want to implement the zoneset config we discussed; I added a few suggestions, but if you think a different file format would be clearer, we can go with that. Happy to approve once that's settled.

Comment thread postprocessing/tableau/tableau_viz_suite.py Outdated
Comment thread reeds/input_processing/copy_files.py Outdated
Comment thread reeds/input_processing/copy_files.py Outdated
Comment thread reeds/input_processing/copy_files.py Outdated

@patrickbrown4 patrickbrown4 Jun 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are a couple more references to hierarchy_from134.csv:

  • docs/source/faq.md, under "How do I change the spatial resolution of a ReEDS case?": change to hierarchy.csv
  • reeds.inputs.validate_zoneset(): Can delete the bottom check under "TEMPORARY 20260402" and the check_aggreg_unique() function

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.

Oops thanks; I also updated part of that section of the FAQ to make some things a little clearer but let me know if any of my edits don't work

Comment thread runreeds.py Outdated
Comment thread reeds/resource_adequacy/prep_data.py Outdated
Comment thread reeds/inputs.py Outdated
Comment thread reeds/io.py Outdated
counties = get_county_zones(case)
else:
counties = []
if len(counties):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here's where the new config would be applied:

Suggested change
if len(counties):
if len(counties) and zoneconfig.get('drop_single_county_reinforcement_cost', 0):

Using .get() so that you can just provide the switch if it needs to be applied, so the file could be formatted as something like

z3109:
  drop_single_county_reinforcement_cost: 1
  reeds2pras_unitsize_unconstrain_counties: 1
  drop_interfaces_missing_cost: 1
PJMcounty:
  drop_single_county_reinforcement_cost: 1
  reeds2pras_unitsize_unconstrain_counties: 1
  drop_interfaces_missing_cost: 1
UTcounty:
  drop_single_county_reinforcement_cost: 1
  reeds2pras_unitsize_unconstrain_counties: 1
  drop_interfaces_missing_cost: 1
z2972:
  drop_single_county_reinforcement_cost: 1
  reeds2pras_unitsize_unconstrain_counties: 1

And then you could read it like:

with open(fpath_zoneconfig, 'r') as f:
    zoneconfig = yaml.safe_load(f).get(sw.GSw_ZoneSet, {})

(Or there could be one zoneconfig file in each inputs/zones/{GSw_ZoneSet} folder; I'm not sure which is easier but either works)

@patrickbrown4 patrickbrown4 Jun 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On second thought, .get(switchname, 0) opens us up to the kind of switch-name typo bugs that have caused big problems in the past. So it's probably best to be explicit. So you could instead do something like:

GSw_ZoneSet,drop_single_county_reinforcement_cost,reeds2pras_unitsize_unconstrain_counties,drop_interfaces_missing_cost
z3109,1,1,1
PJMcounty,1,1,1
UTcounty,1,1,1
z2972,1,1,0
z90,0,0,0
z134,0,0,0
...

and then

zoneconfig = pd.read_csv(fpath_zoneconfig, index_col='GSw_ZoneSet').loc[sw.GSw_ZoneSet]

Or stick with yaml if you like; the point is that it's safer to explicitly define each switch for each zoneset and then just access them with zoneconfig[switchname] instead of the .get() with fallback I initially suggested.

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.

I ended up sticking with yaml but formatting it so that each switch/setting has a list of applicable zonesets rather than vice-versa. That felt more natural to me for some reason (probably just because the zoneset names are shorter), but let me know if you have any issues with that format

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good call, yeah that's much easier to read. Thanks!

Comment thread reeds/results.py Outdated
@pesap

pesap commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

@pesap Is agglevels.csv still needed in R2X or can we delete it?

I have already a branch for it. We can merge it today and bump the r2x-reeds version on the CI.

NatLabRockies/r2x-reeds#76

@kodiobika

Copy link
Copy Markdown
Contributor Author

@pesap Is agglevels.csv still needed in R2X or can we delete it?

I have already a branch for it. We can merge it today and bump the r2x-reeds version on the CI.

NatLabRockies/r2x-reeds#76

Great, thanks!

@pesap

pesap commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

@kodiobika, we got the new tag. The runner should pick it right away. Let me know if not! https://github.com/NatLabRockies/r2x-reeds/releases/tag/v0.6.0

@kodiobika

Copy link
Copy Markdown
Contributor Author

@kodiobika, we got the new tag. The runner should pick it right away. Let me know if not! https://github.com/NatLabRockies/r2x-reeds/releases/tag/v0.6.0

Sounds good, appreciate it!

@kodiobika

Copy link
Copy Markdown
Contributor Author

Tagging @ahamilton5 for visibility on the tableau visualization changes

@patrickbrown4 patrickbrown4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great! I like your structure for the zoneset_config.yaml file; it's much more readable that way. I added a description of it to inputs/zones/README.md but otherwise it's all good to go from my end.

@kodiobika

kodiobika commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Confirmed with @ahamilton5 that the tableau visualization changes are okay to push. The script is already broken for county-level runs in the main branch as it's reading from the old county2zone filepath (inputs/county2zone.csv), and with this change, the script runs to completion and produces outputs for county-level runs. At some point she and/or I will plug the outputs into Tableau to see if things work end-to-end and then work on a fix in a follow-up PR if not

@kodiobika kodiobika merged commit 2f6be36 into main Jun 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants