We'll start with the usual imports:
In [1]:
import hydrofunctions as hf
import pandas as pd
%matplotlib inline
hf.__version__
pd.__version__
Out[1]:
We're going to use two datasets in the following examples. The first dataset was collected at two sites along the Shenandoah River.
In [2]:
sites = ['01634000', '01632000'] # the first is downstream of the second.
start = '2008-01-01'
end = '2018-01-01'
service = 'dv'
# Request our data.
request = hf.NWIS(sites, service, start, end, file='graphing-1.parquet')
request # Verify that the data request went fine.
Out[2]:
This second dataset is for two years of data collected every five minutes, with five different parameters collected. This request may take a while the first time! After that, Hydrofunctions will automatically access the data from the parquet file.
In [3]:
site = '01581752'
request2 = hf.NWIS(site, 'iv', '2016-01-01', '2018-12-31', file='graphing-2.parquet')
request2
Out[3]:
Create two nice clean dataframes that we'll plot with.
In [4]:
Q = request.df('q') # Q stands for discharge
T = request2.df('00010') # T stands for water temperature.
Rename the columns to something easier to remember.
In [5]:
Q = Q.rename(columns={"USGS:01632000:00060:00003": "Upstream", "USGS:01634000:00060:00003": "Downstream"})
Q.head(2)
Out[5]:
In [6]:
T = T.rename(columns={"USGS:01581752:00010:00000": "Plumtree"})
T.head(2)
Out[6]:
In [7]:
Q.plot()
Out[7]:
In [8]:
hf.flow_duration(Q, xscale='linear')
Out[8]:
Now let's plot the same data using the default 'logit' scale
In [9]:
hf.flow_duration(Q, xscale='logit')
Out[9]:
The cycleplot helps to illustrate various natural cycles in your dataset. It plots a single column of data so that the data value is on the Y axis, and time is on the X axis. The time axis is set to show either an annual cycle (shown below), a weekly cycle, or a diurnal cycle (default).
In our example below, the ten years of daily data are plotted over the course of a year, and all of the values within a week are averaged and plotted by week number. The median and mean for each week are shown with lines, while the 20th, 40th, 60th, and 80th percentile are shown with shaded fills.
For our dataset, you can see the lower flows that start occuring around week 25 (early June) and last through the summer to week 45 (start of November). You can also bin values by day ('annual-day') or by month ('annual-month'). The smaller the bins, the greater the variation.
In [10]:
hf.cycleplot(Q.loc[:,'Upstream'], 'annual-week')
Out[10]:
In this chart, we plot the hourly temperature for each month of the year. Note that the times are UTC, so midnight for this site should occur at hour 6.
In [11]:
hf.cycleplot(T, 'diurnal', compare='month', y_label="Water Temperature (°C)")
Out[11]:
In [12]:
Q.hist(bins=20, sharex=True, sharey=True)
Out[12]:
In [13]:
Q.plot.box(logy=True)
Out[13]: