# Water Quality Portal#

[1]:

import contextily as ctx
import geopandas as gpd
import proplot as pplt
from shapely.geometry import Point

from pygeohydro import WaterQuality


The WaterQuality has a number of convenience methods to retrieve data from the web service. Since there are many parameter combinations that can be used to retrieve data, a general method is provided to retrieve data from any of the valid endpoints. You can use get_json to retrieve stations info as a geopandas.GeoDataFrame or get_csv to retrieve stations data as a pandas.DataFrame. You can construct a dictionary of the parameters and pass it to one of these functions. For more information on the parameters, please consult the Water Quality Data documentation. For example, let’s find all the stations within a bounding box that have Caffeine data:

[2]:

wq = WaterQuality()
stations = wq.station_bybbox((-92.8, 44.2, -88.9, 46.0), {"characteristicName": "Caffeine"})


Or the same criterion but within a 30 mile radius of a point:

[3]:

stations = wq.station_bydistance(-92.8, 44.2, 30, {"characteristicName": "Caffeine"})

[4]:

point = gpd.GeoSeries([Point(-92.8, 44.2)], crs="epsg:4326")
point = point.to_crs(point.estimate_utm_crs())
buff = point.buffer(30 * 1609.344)

fig, ax = pplt.subplots(refwidth=4)
buff.plot(ax=ax, facecolor="b", edgecolor="black", alpha=0.1)
point.plot(ax=ax, color="g", marker="x")
stations.to_crs(buff.crs).plot(ax=ax, color="r", marker="o")
ax.set_axis_off()
ax.margins(0)
fig.savefig("_static/water_quality.png")


Then we can get for al these stations the data like this:

[5]:

sids = stations.MonitoringLocationIdentifier.tolist()
caff = wq.data_bystation(sids, {"characteristicName": "Caffeine"})

[5]: