Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add script to translate urban and rural shapefiles to USA tamu loadzones #319

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

merrielle
Copy link
Collaborator

@merrielle merrielle commented Oct 25, 2022

Pull Request doc

Purpose

Create a matrix that can be used to transform urban and rural USA data to USA tamu data. Currently this transformation is strictly based on area.

The USA Tamu shapefiles can be found here: https://besciences.blob.core.windows.net/shapefiles/USA/usa-tamu-loadzones-convex-hull/usa-tamu-loadzones-convex-hull.shp

The resulting matrix generated by this script currently lives here: https://www.dropbox.com/s/y2oopigjg0bxrhb/translate-urban-rural-to-usa-tamu.csv

What the code is doing

  • Download state borders shapefiles and urban / rural areas shapefiles from our azure blob storage account.
  • Create a shapefile for USA Tamu loadzones:
    • Use lat-lon data to create a GeoDataFrame of USA Tamu substations
    • Approximate the shapes of the USA Tamu loadzones by generating the convex hull polygon of substations within each zone.
    • Trim these new shapes to fit inside USA state borders
  • Use translate_zone_set() to generate a matrix translation from the urban/rural data to the newly created USA Tamu data

Testing

Unit tests in test_generate_rural_shapefiles.py
I tested all the code except the translate_urban_rural_to_usa_tamu() because that function requires lots of downloading / writing / reading files.

Where to look

create_usa_tamu_convex_hull_shapefile() has the most important code.

Usage Example/Visuals

How the code can be used and/or images of any graphs, tables or other visuals (not always applicable).

Time estimate

20 mins

@merrielle merrielle marked this pull request as ready for review November 15, 2022 05:48
@merrielle merrielle changed the title Merrielle urban-rural to tamu feat: add script to translate urban and rural shapefiles to USA tamu loadzones Nov 15, 2022
@merrielle merrielle self-assigned this Nov 15, 2022
lower_48_states_abv.remove("AK")
lower_48_states_abv.remove("HI")

zone2state_abv = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we could reuse the same lookup from powersimdata, e.g.

from powersimdata.network.model import ModelImmutables
mi = ModelImmutables("usa_tamu")
zone2state_abv = mi.zones["loadzone2abv"]


def translate_urban_rural_to_usa_tamu():
"""Downloads US state borders as well as census data for urban and rural
areas in the US. Creates a matrix that can be used to transform
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was there supposed to be more after "Creates a matrix that can be used to transform"?

rural_areas["urban"] = False

return urban_areas.append(rural_areas, ignore_index=True)[
return pd.concat([urban_areas, rural_areas], verify_integrity=True)[
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hadn't seen the verify_integrity parameter before, that's neat.

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.

2 participants