<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 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
Step1:  This following the suggested import call for the well application function.
Step2:  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.
Step3:  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.
Step4:  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.
Step5:  We can clean up the value data to improve the quality and select a single station.
Step6:  Use the get_elev function to call the point elevation service of the USGS. The Elevation Point Query Service <a href=http
Step7:  The default site data provide the HUC 8.  You can use ESRI services to get the 12-digit HUC and the HUC name.
Step8:  The avg_wl() function can produce an average monthly changes over time
Step9:  The function will produce mean HUC-wide groundwater level trends over time.
Step10:  Individual sites and time periods can also be specified.
Step11:  The heat map function can create a heat map hydrograph of an existing wellapplication object.
Step12:  The package also comes with a built-in flow duration curve.
Step13:  The fdc function also creates datasets for analysis.
<ASSISTANT_TASK:>
Python Code:
%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
Explanation: 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:
* USGS Station Summaries
* Flow duration curves
* Iterative import and compilation of USGS station information and data
* boxplots using pandas
* iterative charts (one monthly summary boxplot per station)
* Gantt charts of USGS stations
Check out this for some great pandas applications:
http://earthpy.org/time_series_analysis_with_pandas_part_2.html
End of explanation
import wellapplication as wa
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__))
Explanation: This following the suggested import call for the well application function.
End of explanation
USGS = wa.nwis('gwlevels',[16020301],'huc')
Explanation: 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.
End of explanation
siteinfo = USGS.sites
wldata = USGS.data
siteinfo.head()
Explanation: 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.
End of explanation
detail_siteinfo = USGS.get_info(hasDataTypeCd='gw')
detail_siteinfo.head()
Explanation: 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.
End of explanation
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()
Explanation: We can clean up the value data to improve the quality and select a single station.
End of explanation
siteinfo['Elev'] = siteinfo[['dec_long_va','dec_lat_va']].apply(lambda x: wa.get_elev(x),1)
Explanation: Use the get_elev function to call the point elevation service of the USGS. The Elevation Point Query Service <a href=http://ned.usgs.gov/epqs/> EPQS </a>
End of explanation
siteinfo['HUC12'] = siteinfo[['dec_long_va','dec_lat_va']].apply(lambda x: wa.get_huc(x),1)
siteinfo.head()
Explanation: The default site data provide the HUC 8.  You can use ESRI services to get the 12-digit HUC and the HUC name.
End of explanation
df = USGS.avg_wl()
Explanation: The avg_wl() function can produce an average monthly changes over time
End of explanation
df[['mean','median']].plot()
Explanation: The function will produce mean HUC-wide groundwater level trends over time.
End of explanation
USGS = wa.nwis('dv', 10109000,'site',startDT='1965-01-01',endDT='1975-01-01')
USGS.data.value.plot()
Explanation: Individual sites and time periods can also be specified.
End of explanation
USGS.nwis_heat_map()
plt.ylim(1965,1974)
Explanation: The heat map function can create a heat map hydrograph of an existing wellapplication object.
End of explanation
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')
Explanation: The package also comes with a built-in flow duration curve.
End of explanation
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()
Explanation: The fdc function also creates datasets for analysis.
End of explanation
<END_TASK>