tsgettoolbox and tstoolbox - Python Programming Interface

‘tsgettoolbox nwis …’: Download data from the National Water Information System (NWIS)

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.

[1]:
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.

[2]:
df = tsgettoolbox.nwis(sites='02325000',
                       startDT='2000-01-01',
                       parameterCd='00060')
[8]:
df.head()  # The .head() function gives the first 5 values of the time-series
[8]:
USGS-02325000-00060
Datetime
2000-01-01 82
2000-01-02 81
2000-01-03 80
2000-01-04 79
2000-01-05 75

‘tstoolbox …’: Process data using ‘tstoolbox’

Now lets use “tstoolbox” to plot the time-series. The ‘input_ts’ option is used to read in the time-series from the DataFrame.

[4]:
from tstoolbox import tstoolbox
[5]:
tstoolbox.plot(input_ts=df,
               ofilename='plot_api.png')

image0

‘tstoolbox plot’ has many options that can be used to modify the plot.

[6]:
tstoolbox.plot(input_ts=df,
               ofilename='flow_api.png',
               ytitle='Flow (cfs)',
               title='02325000: FENHOLLOWAY RIVER NEAR PERRY, FLA',
               legend=False)

image0

[10]:
mdf = tstoolbox.aggregate(input_ts=df,
                          agg_interval='M',
                          statistic='mean')
[12]:
tstoolbox.plot(input_ts=mdf,
               drawstyle='steps-pre',
               ofilename='flow_api_monthly.png')

image0

[ ]: