Quick Start with HydroPy!

an example of incorporating HydroCloud into a Jupyter Notebook.

NOTE: HydroPy is not required to use HydroCloud in a notebook.


In [1]:
# Import the libraries that we'll be using
import numpy as np
import pandas as pd
import hydropy as hp

# Set the notebook to plot graphs in the output cells.
%matplotlib inline

Load USGS data into a dataframe


In [2]:
# Use HydroCloud.org to find a stream gauge to investigate.
# Click on the red points to find the site number.
from IPython.display import HTML
HTML('<iframe src=https://hydrocloud.org/ width=700 height=400></iframe>')


Out[2]:

In [45]:
# Create a Pandas dataframe using the USGS daily discharge for Herring Run.
herring = hp.get_usgs('01585200', 'dv', '2011-01-01', '2016-01-01')

# List the first few values from the top of the dataframe.
herring.head()


Out[45]:
value
datetime
2011-01-01 0.73
2011-01-02 0.89
2011-01-03 0.73
2011-01-04 0.72
2011-01-05 0.71

In [46]:
# Calculate some basic statistics for the dataframe.
herring.describe()


Out[46]:
value
count 1827.000000
mean 3.670432
std 10.723327
min 0.070000
25% 0.720000
50% 1.200000
75% 2.200000
max 179.000000

In [47]:
# For more advanced analysis, use the HydroAnalysis class.
my_analysis = hp.HydroAnalysis(herring)

# Plot discharge on a logarithmic scale for the Y axis.
my_analysis.plot(figsize=(16,6), logy=True)


Out[47]:
<matplotlib.axes._subplots.AxesSubplot at 0x1e0da53f748>

In [ ]:
## Finding Help

In [3]:
# Use help() to learn more about a particular function.
help(hp.get_usgs)


Help on function get_usgs in module hydropy.reading_third_party_data:

get_usgs(site, service, start_date, end_date)
    Request stream gauge data from the USGS NWIS.
    
    Args:
        site (str):
            a valid site is 01585200
        service (str):
            can either be 'iv' or 'dv' for instantaneous or daily data.
            iv data are instantaneous values usually recorded every 15 minutes;
                units are expressed as cubic feet/second.
            dv data are daily mean discharges expressed as cubic feet/second.
        start_date (str):
           should take on the form yyyy-mm-dd
        end_date (str):
            should take on the form yyyy-mm-dd
    
    Returns:
        A Pandas dataframe object.
    
    Raises:
        ConnectionError  due to connection problems like refused connection
            or DNS Error.
        HydroNoDataError  when the request is valid, but NWIS has no data for
            the parameters provided in the request.
    
    Example::
    
        >>> from hydropy import hydropy as hp
        >>> my_df = hp.get_usgs('01585200', 'dv', '2012-06-01', '2012-06-05')
        
        >>> my_df
                    value
        datetime         
        2012-06-01  97.00
        2012-06-02   5.80
        2012-06-03   1.70
        2012-06-04   1.40
        2012-06-05   0.96

Learn More!

To learn more about hydropy, read the documentation, visit us on github, or try out more notebooks!