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

National Inventory of Dams#

[1]:
import proplot as pplt

import pygeohydro as gh

First, we need to instantiate the NID class.

[2]:
nid = gh.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]:
conus_geom = gh.get_us_states("contiguous")

min_storage = 2500
dam_list = nid.get_byfilter([{"maxStorage": [f"[{min_storage} +inf]"]}])
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_purpose = conus_dams.primaryPurposeId.astype("Int8")
conus_dams["primaryPurposeIdName"] = dam_purpose.apply(nid.dam_purpose.get)
[5]:
purpose_count = conus_dams["primaryPurposeIdName"].value_counts()
_, ax = pplt.subplots(refwidth=5, refaspect=2)
ax.barh(purpose_count.sort_values()[-10:])
ax.format(xlim=(0, purpose_count.max() * 1.1), xlabel="Number of dams")
for p in ax.patches:
    ax.annotate(
        int(p.get_width()),
        (p.get_width() + 120, 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=f"Dams within CONUS with max sotrage > {min_storage} acre-feet")
conus_geom.plot(ax=ax, facecolor="none", edgecolor="k")
top_5types = purpose_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.primaryPurposeIdName == c].plot(
        ax=ax,
        alpha=0.4,
        markersize=12,
        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