This page was generated from nid.ipynb. Interactive online version: Binder badge

National Inventory of Dams#

[1]:
import geopandas as gpd
import proplot as pplt

from pygeohydro import NID, helpers

First, we need to instantiate the NID class.

[2]:
nid = NID()

Some dam coordinates are either missing or incorrect. Let’s get dams that are within Contiguous US with max storage larger than 200 acre-feet. Note that since we want to get all dams within CONUS it’s much more efficient set stage_nid=True in NID.inventory_byid. This flag downloads the latest version of the entire NID dataset and saves it as a feather file and query the inventory locally instead of NID web service.

[3]:
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
conus_geom = helpers.get_us_states("contiguous")

dam_list = nid.get_byfilter([{"maxStorage": ["[200 5000]"]}])
dams = nid.inventory_byid(dam_list[0].id.to_list(), stage_nid=True)

conus_dams = dams[dams.stateKey.isin(conus_geom.STUSPS)].reset_index(drop=True)

Next, we can get a count of the top 10 dams based on types.

[4]:
dam_types = conus_dams.primaryDamTypeId.fillna(-1).astype(int)
conus_dams["primaryDamTypeName"] = dam_types.apply(nid.dam_type.get)
[5]:
types_count = conus_dams["primaryDamTypeName"].value_counts()
_, ax = pplt.subplots(refwidth=5, refaspect=2)
ax.barh(types_count.sort_values()[-10:])
ax.format(xlim=(0, types_count.max() * 1.1), xlabel="Number of dams")
for p in ax.patches:
    ax.annotate(
        int(p.get_width()),
        (p.get_width() + 1200, p.get_y() + p.get_height() / 2),
        ha="center",
        va="center",
    )
../../_images/examples_notebooks_nid_8_0.png

Let’s compare the spatial distribution of the top five categories, excluding Earth and Other categories.

[6]:
conus_geom = conus_geom.to_crs(5070)
conus_dams = conus_dams.to_crs(5070)

fig, ax = pplt.subplots(refwidth=6)
ax.format(title="Dams within CONUS with max sotrage > 200 acre-feet")
conus_geom.plot(ax=ax, facecolor="none", edgecolor="k")
top_5types = types_count.index[:5]
marker = dict(zip(top_5types, ["o", "^", "*", "X", "d"]))
color = dict(zip(top_5types, ["r", "b", "g", "k", "c"]))

for c in top_5types:
    conus_dams[conus_dams.primaryDamTypeName == c].plot(
        ax=ax,
        alpha=0.4,
        markersize=10,
        marker=marker[c],
        color=color[c],
        label=c,
    )
ax.legend(loc="ll", ncols=1)
ax.axis(False)
fig.savefig("_static/dams.png")
../../_images/examples_notebooks_nid_10_0.png