This notebook is to illustrate the Python API usage for 'tsgettoolbox' to download and work with data from the National Water Information System (NWIS). There is a different notebook to do the same things from the command line called tsgettoolbox-nwis-cli. The CLI version of tsgettoolbox can be used from other languages that have the ability to make a system call.
In [1]:
%matplotlib inline
from tsgettoolbox import tsgettoolbox
Let's say that I want flow (parameterCd=00060) for site '02325000'. All of the tsgettoolbox functions create a pandas DataFrame.
In [2]:
df = tsgettoolbox.nwis_dv(sites='02325000',
startDT='2000-01-01',
parameterCd='00060')
In [3]:
df.head() # The .head() function gives the first 5 values of the time-series
Out[3]:
In [4]:
from tstoolbox import tstoolbox
In [11]:
tstoolbox.plot(input_ts=df,
ofilename='plot_api.png')
'tstoolbox plot' has many options that can be used to modify the plot.
In [7]:
tstoolbox.plot(input_ts=df,
ofilename='flow_api.png',
ytitle='Flow (cfs)',
title='02325000: FENHOLLOWAY RIVER NEAR PERRY, FLA',
legend=False)
In [8]:
mdf = tstoolbox.aggregate(input_ts=df,
agg_interval='M',
statistic='mean')
In [9]:
tstoolbox.plot(input_ts=mdf,
drawstyle='steps-pre',
ofilename='flow_api_monthly.png')
In [ ]: