In [1]:
# First, import hydrofunctions.
import hydrofunctions as hf
The NWIS can handle data requests that specify:
The only required element is a station:
In [2]:
minimum_request = hf.NWIS('01585200')
Since we only specified the where, the NWIS will assume the following elements:
start_date
or period
is not given, then provide the most recent reading.parameterCd
), you will get everything.Let's see what our request came back with:
In [3]:
minimum_request
Out[3]:
Here's what the data look like in table form:
In [4]:
minimum_request.df()
Out[4]:
You can specify a site four different ways:
stateCd
and a two letter postal code to retrieve every site in the statecountyCd
and a FIPS code to retrieve every site in a county or list of countiesbBox
to retrieve everything inside of a bounding box of latitudes and longitudes.You are required to set one of these parameters, but only one.
All of these parameters are demonstrated in Selecting Sites
You can specify time in three different ways:
period
will return up to 999 days of the most recent data: period='P11D'
start_date
will return all of the data starting at this date: start_date='2014-12-31'
If you specify a start_date
, you can also specify an end_date
, which is given in the same format.
In [6]:
# For example, let's mistpye one of our parameters that worked so well above:
notSoGoodNWIS = hf.NWIS('01585200', 'xx', period='P200D')
Okay, maybe I shouldn't have typed 'xx' for our service.
Some errors get caught by hydrofunctions, but some don't. Sometimes we end up asking NWIS for something that doesn't make sense, or something that it doesn't have, or maybe NWIS isn't available. In this case, hydrofunctions will receive an error message from NWIS and help you figure out what went wrong.
In [7]:
# Let's ask for the impossible: the start date is AFTER the end date:
badRequest = hf.get_nwis('01585200', 'dv', '2017-12-31', '2017-01-01')
I probably shouldn't have started with all of the things that go wrong! My point is that we've got ya.
Where can you go to learn how to do things the RIGHT way?
But we also have a few built-in helpers that you can use right here, right now:
In [8]:
# Use the help() function to see all of the parameters for a function, their default values,
# and a short explanation of what it all means. Or you can type ?hf.NWIS to access the same information.
help(hf.NWIS)
In [9]:
# Use the dir() function to see what sort of methods you have available to you,
# or type hf.NWIS.<TAB> to see the same list.
dir(hf.NWIS)
Out[9]: