edgi-govdata-archiving / ECHO_modules

ECHO_modules is a Python package for analyzing a copy of the US Environmental Protection Agency's (EPA) Enforcement and Compliance History Online (ECHO) database
GNU General Public License v3.0
3 stars 6 forks source link

Fix states geojson import overriding list of states #35

Closed oliviachang29 closed 2 years ago

oliviachang29 commented 2 years ago

Realized that storing the geojson data for the states and storing it in states was overriding the states import from ECHO_modules.geographies! Renamed it to states_geography.

ericnost commented 2 years ago

Oh good catch @oliviachang29 !!!

ericnost commented 2 years ago

I'll merge the pull. A cleaner approach, in the future, might be to load in the states_geography geojson (or indeed, any spatial data) in the notebook environment and then pass it to the choropleth_mapper() like so:

def state_choropleth_mapper(states_geo, state_data, column, legend_name, color_scheme="PuRd"):
    map = folium.Map()  

    m = folium.Choropleth(
    geo_data = states_geo,
    name="choropleth",
    data=state_data,
    columns=["STUSPS",column],
    .....

and then in the notebook doing:

states_geography = geopandas.read_file("https://raw.githubusercontent.com/edgi-govdata-archiving/ECHO-Geo/main/cb_2018_us_state_500k.json")
states_geography.crs = "EPSG:4326"
state_choropleth_mapper(states_geography, data, "column", "legend")

this would lead the way to making the state_choropleth_mapper() a more general choropleth mapper, handling any input (would need to add an option to change the matching column from STUSPS to the input.

oliviachang29 commented 2 years ago

Got it!