This notebook contains material from Controlling Natural Watersheds; content is available on Github.
The purpose of this notebook is to create a data series for the outflows from Namakan Lake. The data series is written to a file NL_outflow.pkl
that can be read into other notebooks using NL = pd.read_pickle('../data/NL_outflow.pkl')
.
The data series is constructed using data provided by Matt DeWolfe of the International Joint Commission.
# Display graphics inline with the notebook
%matplotlib notebook
# Standard Python modules
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import os
import datetime
import requests
# Modules to display images and data tables
from IPython.display import Image
from IPython.core.display import display
NL_outflow = pd.read_excel('../data/Namakan_Outflows.xls',index_col=0,header=3)['Stn 47']
plt.figure(figsize=(10,5))
plt.hold(True)
NL_outflow.plot()
plt.hold(False)
plt.xlabel('Year')
plt.ylabel('Level [meters]')
plt.grid()
RLLevelFlow = pd.read_csv('../data/RLLevelFlow.csv',index_col=0,parse_dates=True)
RL_inflow = RLLevelFlow['Inflow']
plt.figure(figsize=(10,5))
plt.hold(True)
NL_outflow.plot()
RL_inflow.plot()
plt.hold(False)
plt.xlabel('Year')
plt.ylabel('Level [meters]')
plt.grid()
flows = pd.concat([RL_inflow,NL_outflow],axis=1).dropna()
plt.figure(figsize=(10,5))
plt.hold(True)
flows['Inflow'].plot()
flows['Stn 47'].plot()
<matplotlib.axes._subplots.AxesSubplot at 0x12dc4d710>
plt.figure(figsize=(10,5))
plt.hold(True)
plt.plot(flows.ix['1970':'1999','Inflow'],flows.ix['1970':'1999','Stn 47'],'.',ms=5,color='b',alpha=0.6)
plt.plot(flows.ix['2000':,'Inflow'],flows.ix['2000':,'Stn 47'],'.',ms=5,color='r',alpha=0.6)
plt.xlim(0,2000)
plt.ylim(0,1000)
plt.grid()
plt.title('Namakan Outflow vs Rainy Lake Inflow, Daily for 1970-2014')
plt.ylabel('Namakan Outflow [cubic meters/sec]')
plt.xlabel('Rainy Lake Inflow [cubic meters/sec]')
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-6-4c3798fd194d> in <module>() 2 3 plt.hold(True) ----> 4 plt.plot(flows.ix['1970':'1999','Inflow'],flows.ix['1970':'1999','Stn 47'],'.',ms=5,color='b',alpha=0.6) 5 plt.plot(flows.ix['2000':,'Inflow'],flows.ix['2000':,'Stn 47'],'.',ms=5,color='r',alpha=0.6) 6 NameError: name 'flows' is not defined
q = (flows['Stn 47']/flows['Inflow'])
plt.ylim(0,1)
q.plot(makers='.')
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-125-8e696748cff2> in <module>() 1 q = (flows['Stn 47']/flows['Inflow']) 2 plt.ylim(0,1) ----> 3 q.plot(makers='.') /Users/jeff/anaconda/lib/python2.7/site-packages/pandas/tools/plotting.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds) 3495 colormap=colormap, table=table, yerr=yerr, 3496 xerr=xerr, label=label, secondary_y=secondary_y, -> 3497 **kwds) 3498 __call__.__doc__ = plot_series.__doc__ 3499 /Users/jeff/anaconda/lib/python2.7/site-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds) 2585 yerr=yerr, xerr=xerr, 2586 label=label, secondary_y=secondary_y, -> 2587 **kwds) 2588 2589 /Users/jeff/anaconda/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds) 2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds) 2383 -> 2384 plot_obj.generate() 2385 plot_obj.draw() 2386 return plot_obj.result /Users/jeff/anaconda/lib/python2.7/site-packages/pandas/tools/plotting.pyc in generate(self) 985 self._compute_plot_data() 986 self._setup_subplots() --> 987 self._make_plot() 988 self._add_table() 989 self._make_legend() /Users/jeff/anaconda/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _make_plot(self) 1662 stacking_id=stacking_id, 1663 is_errorbar=is_errorbar, -> 1664 **kwds) 1665 self._add_legend_handle(newlines[0], label, index=i) 1666 /Users/jeff/anaconda/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _plot(cls, ax, x, y, style, column_num, stacking_id, **kwds) 1676 cls._initialize_stacker(ax, stacking_id, len(y)) 1677 y_values = cls._get_stacked_values(ax, stacking_id, y, kwds['label']) -> 1678 lines = MPLPlot._plot(ax, x, y_values, style=style, **kwds) 1679 cls._update_stacker(ax, stacking_id, y) 1680 return lines /Users/jeff/anaconda/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _plot(cls, ax, x, y, style, is_errorbar, **kwds) 1298 else: 1299 args = (x, y) -> 1300 return ax.plot(*args, **kwds) 1301 1302 def _get_index_name(self): /Users/jeff/anaconda/lib/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs) 1810 warnings.warn(msg % (label_namer, func.__name__), 1811 RuntimeWarning, stacklevel=2) -> 1812 return func(ax, *args, **kwargs) 1813 pre_doc = inner.__doc__ 1814 if pre_doc is None: /Users/jeff/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in plot(self, *args, **kwargs) 1422 kwargs['color'] = c 1423 -> 1424 for line in self._get_lines(*args, **kwargs): 1425 self.add_line(line) 1426 lines.append(line) /Users/jeff/anaconda/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in _grab_next_args(self, *args, **kwargs) 384 return 385 if len(remaining) <= 3: --> 386 for seg in self._plot_args(remaining, kwargs): 387 yield seg 388 return /Users/jeff/anaconda/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in _plot_args(self, tup, kwargs) 372 ncx, ncy = x.shape[1], y.shape[1] 373 for j in xrange(max(ncx, ncy)): --> 374 seg = func(x[:, j % ncx], y[:, j % ncy], kw, kwargs) 375 ret.append(seg) 376 return ret /Users/jeff/anaconda/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in _makeline(self, x, y, kw, kwargs) 279 self._setdefaults(default_dict, kw, kwargs) 280 seg = mlines.Line2D(x, y, **kw) --> 281 self.set_lineprops(seg, **kwargs) 282 return seg 283 /Users/jeff/anaconda/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in set_lineprops(self, line, **kwargs) 187 def set_lineprops(self, line, **kwargs): 188 assert self.command == 'plot', 'set_lineprops only works with "plot"' --> 189 line.set(**kwargs) 190 191 def set_patchprops(self, fill_poly, **kwargs): /Users/jeff/anaconda/lib/python2.7/site-packages/matplotlib/artist.pyc in set(self, **kwargs) 934 if func is None: 935 raise TypeError('There is no %s property "%s"' % --> 936 (self.__class__.__name__, k)) 937 ret.extend([func(v)]) 938 return ret TypeError: There is no Line2D property "makers"
plt.figure(figsize=(10,5))
q = q[q > 0]
q = q[q < 1]
q.hist(bins=100,normed=True)
plt.xlim(0,1)
print q.mean()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-7-e96f90d2e0a5> in <module>() 1 plt.figure(figsize=(10,5)) ----> 2 q = q[q > 0] 3 q = q[q < 1] 4 q.hist(bins=100,normed=True) 5 plt.xlim(0,1) NameError: name 'q' is not defined
<matplotlib.axes._subplots.AxesSubplot at 0x12cd48250>
NL.to_pickle('../data/NL.pkl')