# Start with the usual.
import hydrofunctions as hf
%matplotlib inline
hf.__version__

# request data for our two sites for a three-year period.
sites = ['01589330', '01581830']
request = hf.NWIS(sites, start_date='2002-01-01', end_date='2005-01-01', file='Urban_Rural.parquet')
request # Describe the dataset that we've received.

# We'll store our discharge data in a dataframe named 'Q'
Q = request.df('discharge')
Q.head()  # Print the first five rows to verify.

# Rename the columns to 'Urban' and 'Rural' so we remember which is which!
Q = Q.rename(columns={"USGS:01589330:00060:00003": "Urban", "USGS:01581830:00060:00003": "Rural"})
Q.head()  # List the first five rows.

# Let's plot our data to create a hydrograph. plot() is a method that is built-in to dataframes.
Q.plot()

# Let's create a flow duration chart for our two sites!
# .flow_duration is a function included in Hydrofunctions. It accepts dataframes as input.
hf.flow_duration(Q)

"""
Explanation: Comparing Urban and Rural Streams
In this notebook we'll compare the hydrology of two streams in the Baltimore area:
* Grave Run, a rural stream with only 0.3% impervious surfaces, and
* Dead Run, an urban stream that is 39% impervious surfaces.
These two watersheds are similar in size, topography, and geology. They also have very emo names.
End of explanation
"""


# let's compare stats for the two sites!
Q.describe()

"""
Explanation: Description of the two sites
If you look carefully at the hydrograph above, you can see that the orange urban site tends to have lower baseflow,
but it also tends to have higher peaks during storms. Unfortunately, this obscures the hydrograph for the rural site a little!
The second diagram is a flow duration chart. The default Y axis is logarithmic, with values ranging from less than 1 to about 400 cfs. The default X axis uses a logit scale to plot the chance of exceedance. Values range from greater than zero to less than one, with a value of 0.9 meaning that 90% of the flows are higher than this value. The logit scale stretches out the extreme high and extreme low values so that the distance from the center to one standard deviation is approximately the same as from two standard deviations out to three standard deviations. This approximates the probability scale that Flow Duration charts are often plotted on.
Comparing the two sites, you can see that the orange urban site has lower baseflows than the blue rural site, but also has higher peak flows.
End of explanation
"""


