This notebook uses the Scientific Python (scipy) stack tools to generate flow duration curves from current USGS NWIS data.
Using recipes from this notebook, you can make:
Check out this for some great pandas applications:
http://earthpy.org/time_series_analysis_with_pandas_part_2.html
In [1]:
%matplotlib inline
import pandas as pd
import platform
import sys
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from pylab import rcParams
rcParams['figure.figsize'] = 10, 10
This following the suggested import call for the well application function.
In [2]:
import wellapplication as wa
In [3]:
print("Operating System " + platform.system() + " " + platform.release())
print("Python Version " + str(sys.version))
print("Pandas Version " + str(pd.__version__))
print("Numpy Version " + str(np.__version__))
print("Matplotlib Version " + str(matplotlib.__version__))
print("WellApplication Version " + str(wa.__version__))
Call function class nwis and assign it as USGS. This will allow for the implementation of all of the usgs functions. This function class allows for the import of USGS data.
In [4]:
USGS = wa.nwis('gwlevels',[16020301],'huc')
Once the class sucessfully connects, it downloads abbreviated site information and data for the location values entered. The data can be accessed as objects of the variable assigned to the class.
In [5]:
siteinfo = USGS.sites
wldata = USGS.data
siteinfo.head()
Out[5]:
For a more rigourous description of the sites, call get_info() on the class. We use the rest arguement hasDataTypeCd to select only sites with groundwater level (gw) data.
In [6]:
detail_siteinfo = USGS.get_info(hasDataTypeCd='gw')
detail_siteinfo.head()
Out[6]:
We can clean up the value data to improve the quality and select a single station.
In [9]:
clean_wl = USGS.cleanGWL(wldata)
onesite = clean_wl[(clean_wl['value']>0)&(clean_wl.index.get_level_values('site_no') == '383023114115302')]
onesite.reset_index(inplace=True)
onesite.set_index('datetime',inplace=True)
onesite['value'].plot()
Out[9]:
Use the get_elev function to call the point elevation service of the USGS. The Elevation Point Query Service EPQS
In [10]:
siteinfo['Elev'] = siteinfo[['dec_long_va','dec_lat_va']].apply(lambda x: wa.get_elev(x),1)
The default site data provide the HUC 8. You can use ESRI services to get the 12-digit HUC and the HUC name.
In [11]:
siteinfo['HUC12'] = siteinfo[['dec_long_va','dec_lat_va']].apply(lambda x: wa.get_huc(x),1)
In [12]:
siteinfo.head()
Out[12]:
The avg_wl() function can produce an average monthly changes over time
In [13]:
df = USGS.avg_wl()
The function will produce mean HUC-wide groundwater level trends over time.
In [14]:
df[['mean','median']].plot()
Out[14]:
Individual sites and time periods can also be specified.
In [15]:
USGS = wa.nwis('dv', 10109000,'site',startDT='1965-01-01',endDT='1975-01-01')
In [16]:
USGS.data.value.plot()
Out[16]:
The heat map function can create a heat map hydrograph of an existing wellapplication object.
In [18]:
USGS.nwis_heat_map()
plt.ylim(1965,1974)
Out[18]:
The package also comes with a built-in flow duration curve.
In [24]:
df = wa.fdc(USGS.data,'value')
USGS2 = wa.nwis('dv', 10109000,'site',startDT='1975-01-01')
df2 = wa.fdc(USGS2.data,'value')
plt.ylabel('Discharge (cfs)')
plt.xlabel('Probability that discharge is met or exceeded')
Out[24]:
The fdc function also creates datasets for analysis.
In [27]:
plt.figure()
plt.plot(df[0],df[1], label = 'pre-1975')
plt.plot(df2[0],df2[1], label = 'post-1975')
plt.legend()
plt.ylabel('Discharge (cfs)')
plt.xlabel('Probability that discharge is met or exceeded')
plt.grid()
In [ ]: