Hydrology Plotting Tool

hooch-hydro.py started as a project for a hydrologist friend who needed help creating a several different plots for an analysis she was doing on rivers in Alaska. When researching the project, I found that the USGS has a webservice that provides .rdb files for any gagued river in the country. The .rdb format is a special tab-delimited format the USGS created for dissemenating stream gauge data. The format is described here.


Design

  • Command line program
  • Built on Python, numpy and matplotlib
  • cross platform (develop on OSX, needs to run on Windows)

Result

Here is an example of one of the plots for a river in Alaska:

hooch-hydro.py stats example plot

The command line call to generate the above plot was as follows:

$ ./hooch-hydro.py --save --stationid 15300520 stats --wateryear --calmonth --traces std min max

This specifies the station by ID number, that the plot should be shown with the axes "rolled" to use a water year (starts Oct 1), and that calendar month should be used to label the x axis ("Jan, Feb..." instead of "1, 2..").

Here is the information output to the console when running the above command:

$ ./hooch-hydro.py --save --stationid 15300520 stats --wateryear --calmonth --traces std min max
loading data from the web by station id...
trying to download this: http://waterservices.usgs.gov/nwis/dv/?site=15300520&format=rdb&parameterCd=00060&startDT=1900-01-01
  extract the station description line...
  commenting header and data description line...
  writing to temporary file...
  reading the temporary file with numpy.genfromtxt()...
  removing the temporary file...
  index the pandas DataFrame by date and time...
  zip discharge and quality columns together...
  1856 rows of data...
  1856 non-null discharge readings
  1856 non-null quality readings
  dropping all 'P' and 'P:e' data...
    ignoring discharge with 'P' in quality column. 1856 remaining
    ignoring discharge with 'P:e' in quality column. 1856 remaining
  drop quality column...
  convert index to actual pandas.DatetimeIndex
  expand data frame to include (empty) places for every point in period of record
  Period of Record: 2008-06-01 00:00:00 to 2013-06-30 00:00:00
  1856 days in period of record
  1856 days with data in period of record
  100.00% of period of record has data
  returning a pandas DataFrame and some metadata (1856 discharge values)...
  removing the temporary file...
preparing the stats only hydrograph...
  buidling statistics trace(s)...
  checking length of arrays for plotting...
  using wateryear, rolling stats data forward 91 days...
  plotting traces...
    standard tick locations...
          Month start: [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335]
                       ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    15th day of month: [15, 46, 75, 106, 136, 167, 197, 228, 259, 289, 320, 350]
                       []
    adding marker for jan 1...
    rolling the x axis labels...
    tick locations after rolling for water year...
          Month start: [0, 30, 61, 91, 122, 153, 182, 213, 243, 274, 304, 335]
                       ['Oct' 'Nov' 'Dec' 'Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep']
    15th day of month: [15, 45, 76, 106, 137, 168, 197, 228, 258, 289, 319, 350]
                       []
Saving file...