<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Writing Valid Requests for NWIS
The USGS National Water Information System (NWIS) is capable of handling a wide range of requests. A few features in Hydrofunctions are set up to help you write a successful request.
Step1:  What can we specify?
The NWIS can handle data requests that specify
Step2:  Since we only specified the where, the NWIS will assume the following elements
Step3:  Here's what the data look like in table form
Step4:  Different ways to specify which site you want
You can specify a site four different ways
Step5:  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.
Step6:  Getting help
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?
The User's Guide
The USGS guide to their waterservices
But we also have a few built-in helpers that you can use right here, right now
<ASSISTANT_TASK:>
Python Code:
# First, import hydrofunctions.
import hydrofunctions as hf
Explanation: Writing Valid Requests for NWIS
The USGS National Water Information System (NWIS) is capable of handling a wide range of requests. A few features in Hydrofunctions are set up to help you write a successful request.
End of explanation
minimum_request = hf.NWIS('01585200')
Explanation: What can we specify?
The NWIS can handle data requests that specify:
Where: we need to specify which stations we are interested in.
Service: the NWIS provides daily averages ('dv') and 'instantaneous values' ('iv')
When: we can specify a range of dates, a period of time before now, or just get the most recent observation.
What: we can specify which parameter we want, or just get everything collected at the site.
the data service we want. 
The only required element is a station:
End of explanation
minimum_request
Explanation: Since we only specified the where, the NWIS will assume the following elements:
Service: if not specified, provide the daily average value ('dv')
When: if a start_date or period is not given, then provide the most recent reading.
What: if you don't ask for a specific parameter (parameterCd), you will get everything.
Let's see what our request came back with:
End of explanation
minimum_request.df()
Explanation: Here's what the data look like in table form:
End of explanation
# For example, let's mistpye one of our parameters that worked so well above:
notSoGoodNWIS = hf.NWIS('01585200', 'xx', period='P200D')
Explanation: Different ways to specify which site you want
You can specify a site four different ways:
as a number or list of site numbers
using stateCd and a two letter postal code to retrieve every site in the state
using countyCd and a FIPS code to retrieve every site in a county or list of counties
using bBox 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
Different ways to specify time
You can specify time in three different ways:
if you specify nothing, you'll get the most recent reading.
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.
What happens when you make a bad request?
The power of the NWIS also makes it easy to make mistakes.
So, we've added a series of helpful error messages to let you know when something went wrong, and why it went wrong.
End of explanation
# 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')
Explanation: 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.
End of explanation
# 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)
# 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)
Explanation: Getting help
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?
The User's Guide
The USGS guide to their waterservices
But we also have a few built-in helpers that you can use right here, right now:
help() and ? will list the docstring for whatever object you are curious about 
dir() and .\<TAB> will tell you about available methods.
End of explanation
<END_TASK>