REST Web Services
You can use this service to retrieve daily, monthly or annual statistics for a USGS site and parameter.
To provide statistics, the site must serve time-series data, i.e. data is collected via an automated means and at regular intervals (typically every 15 minutes). You can use the daily values test tool or the site service test tool to find these sites. When using the site service test tool, make sure your query is qualifed with the argument &hasDataTypeCd=dv.
The service serves statistics based on approved data only. Recent data is considered provisional and is thus not approved. In general, you may find periods of unapproved statistics when requesting statistics within a year or less from today. Unapproved statistics will not show. The value may be left blank depending on the service called.
Please join the USGS Water Data for the Nation Notification List . This way you will receive an announcement when changes are made to this web service, or if it there are significant problems with the service.
With hundreds of thousands of qualifying sites across the nation, the amount of data available is very large. No one user is allowed to download all of the data with a single call. The service has consequently been engineered to facilitate common mass queries, defaulting to returning a narrower set of data. You are encouraged to make your queries efficient too, mindful that many others need access to the data at the same time. Always specify the minimum amount of data you need in your request, using built in filters and date ranges to the maximum extent possible.
Probably the best way to learn how to use the service is to try it out!
The USGS provides this tool that allows you to generate syntactically correct calls to the service. You can even run the query live in your browser. When you have perfected your query you can copy and paste the URL into your application to get the precise data you need.
Typically data is downloaded as plain text via Hypertext Transfer Protocol (HTTP). However, gzip compression is supported by this service. Use of gzip compression may markedly speed up acquisition of data, particularly on large queries. It also is a more efficient use of USGS servers, so we appreciate when you are thoughtful enough to use it. Whether you can receive the data in gzip compressed formats depends on the capabilities of your client. Web browsers support gzip compression natively, but most regular users will use specialized utility programs like wget
and curl
to acquire data. If you can handle gzip compression, please place the following string into your HTTP request headers: Accept-Encoding: gzip, compress
curl and wget are typically used to download data. They may be configured to use gzip compression if the server will accept it. You may also explicitly have to tell it to use gzip compression. If so these tips should work:
gzip files are typically returned as a file with a .gz file suffix unless you instruct your program to uncompress it. See the gzip man page for instructions on uncompressing .gz files.
Daily statistics are statistics based on the day of the year. For example, if you request a daily mean statistic for streamflow for January 1st for a site, the mean streamflow for January 1st for each year of interest is acquired and the mean of all these values is then calculated. In this case the daily statistics is the mean of all the means for that date. If you asked for minimum, you would get the minimum of all the minimums for the date, etc.
Monthly statistics are calculations based on a month and year. It answers questions like "For February 1999 what was the mean streamflow?" Using mean as an example, you will get a mean (average) of all the daily means for the site for February 1999.
Annual statistics are based on a calendar year or water year. For a given year you will get back a single statistic for a site and a parameter, such as the mean streamflow for a site for calendar year 2010.
Sometimes gages may be down or inaccessible due to equipment malfunctions or other issues. You have the option to calculate monthly or annual statistics if there is missing data using the missingData argument. Otherwise there must be a complete set of approved statistics for the type of statistic wanted to serve that statistic. If it cannot be served, the value is generally left blank or null.
Currently only tab-delimited data can be downloaded using this service. XML and JSON outputs will be added in a subsequent release. Regardless of the format downloaded, only the way it is encoded and marked up differs.
To illustrate daily statistics, the following tab-delimited (RDB) format query was imported into MS Excel and formatted for reading:
http://waterservices.usgs.gov/nwis/stat/?format=rdb&sites=01646500¶meterCd=00060
Caution: with daily statistics, the years in the output are in water years, not calendar years. Water years begin October 1 of the year before the calendar year and end September 30 of the calendar year. As a consequence, if concerned about the actual calendar year for the statistic, you must subtract 1 from the year shown if the date is between October 1 and December 31.
This query returns default statistics for site 01646500, at the Little Falls Pumping Station on the Potomac River, specifically streamflow or discharge. The site number is identified in Column B and the parameter being measured (streamflow) is identified in column C (00060). Row 1 contains column names and Row 2 contains some information about the type of data in the column. For example, 5s means expect a string (set of characters) not to exceed 5 characters. Data begin with Row 3.
Column F indicates the month of the statistic and column G indicates the day in the month of the statistic. So Row 3 contains statistics for January 1st across the entire period of record, which in this case was from the beginning of water year 1931 (October 1, 1930) to end of water year 2013 (September 30, 2013), as indicated by Columns H and I. The last row, Row 21, contains statistics for December 31. Many rows were removed for readability.
Mean is the same as average. So Cell O3 indicates that the average streamflow for this site on January 1st is 13,400 cubic feet per second across more than eighty years of record.
What was the maximum flow on January 1st? Cell L3 tells us: 118,000 cubic feet per second and this record occurred in 1943 (Cell K3). Similarly, minimum flow for January 1st occurred in 1966 (Cell M3) when streamflow was 940 cubic feet per second (Cell N3).
Columns P through X indicate percentiles, indicating the value below which a given percentage of observations in a group of observations fall. For example, the 20th percentile is the value below which 20 percent of the observations may be found, which for January 1st is 3,490 cubic feet per second (Cell R3). The median value is the same as the 50th percentile. The median value for January 1st is 9,050 cubic feet per second (Cell T3). The percentiles shown are provided by default. There is no year associated with percentile, just as there is no year associated with the mean, as it makes sense only for minimum or maximum values.
The "loc_web_ds" column (Column D) is normally blank. Some sites may measure from different locations, such as the right bank and the left bank of a river. If this site has multiple measurement locations, you will see text here describing the site location. The "dd_nu" column (Column E) indicates the Data Descriptor associated with streamflow at this site. Generally, this is of interest only to USGS scientists and can be ignored.
What is "count_nu"? In this case it represents the 83 years of statistics, or its period of record in years. This will stay the same except in the peculiar case of February 29. Since this is recorded only every four years, the number is smaller, 21 in this case.
Daily statistics are rounded using these rounding rules.
To illustrate monthly statistics, the following tab-delimited (RDB) format query was imported into MS Excel and formatted for reading:
Note that there will be one data row for each year and month in the period of interest beginning with the earliest year (Column F) and month (Column G) of the period of interest. Only mean statistics are currently available through the service.
Cell H3 tells us that there was a mean streamflow of 13,090 cubic feet per second for this site for March 1930. All the daily means were first retrieved for March 1930, then a mean of those values was calculated. Monthly statistics are rounded using these rounding rules.
To illustrate annual statistics, the following tab-delimited (RDB) format query was imported into MS Excel and formatted for reading:
Since it is not specified, calendar year statistics are given. Note that the argument &statYearType=water could have been added to created statistics based on water year, not calendar year. Water years begin October 1 of the year before the calendar year, and end September 30 of the current year. Note that there will be one data row for each year in the period of interest beginning with the earliest year of the period of interest. Since only a mean statistics were requested, no percentile, maximum or minimum statistics are in the output. If specified, statType is ignored.
Cell G3 tells us that the mean streamflow for 1931 was 5,709 cubic feet per second. All the daily values were fetched for the calendar year and the mean of those value was calculated. Annual statistics are rounded using these rounding rules.
Since this system uses Hypertext Transfer Protocol (HTTP), any application errors are reported in the HTTP headers, which are normally not seen. This means that when writing applications, when you get a response it is important to first examine the HTTP status code that is returned in the HTTP response. The application server will return the error code along with a message describing the error in the event there is a problem. Programmers should always check the HTTP response code and if not a 200 handle the response as an exception. Among the status codes you may see:
HTTP Error Code | HTTP Error Code Description | Explanation |
---|---|---|
200 | OK | The request was successfully executed and some data should have been returned. |
304 | Not_Modified | This indicates your request was redirected using the proper URL. This may occur if the "path" of your URL is not fully qualified. Ideally a / is placed before the ? in the URL. Adding in this slash may make this go away. However, the request should still be processed. If this becomes annoying, you may also be able to tell your client program to automatically follow redirects. |
400 | Bad_Request | This often occurs if the URL arguments are inconsistent. An accompanying error should describe why the request was bad. Reasons include:
|
403 | Access_Forbidden | This should only occur if for some reason the USGS has blocked your Internet Protocol (IP) address from using the service. This can happen if we believe that your use of the service is so excessive that it is seriously impacting others using the service. To get unblocked, send us the URL you are using along with your client's IP using this form. We may require changes to your query and frequency of use in order to give you access to the service again. |
404 | Not_Found | Returned if and only if the query expresses a combination of elements where data do not exist. For multi-site queries, if any data are found, it is returned for those site/parameters/date ranges where there are data. Conditions that would return a 404 Not Found include:
|
500 | Internal_Server_Error | If you see this, it means there is a problem with the web service itself. It usually means the application server is down unexpectedly. This could be caused by a host of conditions but changing your query will not solve this problem. The application support team has to fix it. Most of these errors are quickly detected and the support team is notified if they occur. |
503 | Service_Unavailable | The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. |
Adobe Flex requires our server have a crossdomain.xml file
indicating those domains that can access our web service using Adobe Flex. We are adding these on a case by case basis. If you need to access the service using Adobe Flex or the Flex API, please contact us using this form and indicate the domain of the server that will access the service.
This service supports the Cross-Origin Resource Sharing (CORS) specification. CORS permits browser-based asynchronous access to the service even though content originates from a server different than the one serving the web page. Otherwise the browser's security controls would not allow content to come from USGS servers. Most, but not all browsers, support CORS. Some frameworks, like jQuery through the Ajax
crossDomain setting, support CORS automatically. CORS is useful for developers writing Web 2.0 applications.
The URL must always be in this format:
http://waterservices.usgs.gov/nwis/stats/?<arguments>
where <arguments> are one or more HTTP GET parameter names and values based on the information below.
You specify the arguments that go in <arguments>.
Here is an example of a valid URL that should return data:
URL argument names and argument values can be in upper, lower or mixed case. They will all be handled correctly. All of the following will yield the same result:
http://waterservices.usgs.gov/nwis/stats/?stateCd=ny
http://waterservices.usgs.gov/nwis/stats/?statecd=ny
http://waterservices.usgs.gov/nwis/stats/?STATECD=ny
http://waterservices.usgs.gov/nwis/stats/?stateCd=NY
http://waterservices.usgs.gov/nwis/stats/?STATECD=NY
http://waterservices.usgs.gov/nwis/stats/?stateCd=Ny
The following conventions are used below to document URL argument values:
arg1=[ a {,x | ,y} | b | c,d,...]
In the above example, these would be the allowed legal values:
Want to only query one site? Use site (or sites) as your major filter, and put only one site number in the list! Example:
Unlike the other services on this site, at this time the statistics service is limited to accepting a list of up to ten site numbers only. At least one site number must be supplied. Further refine the query with minor filters, if needed.
Major Filter (select one of the following) |
Meaning | Minimum Number of Argument Values | Maximum Number of Argument Values | Examples |
---|---|---|---|---|
sites (aliases: site) | A list of site numbers. You can specify up to ten site numbers per query. Sites are comma separated. Sites may be prefixed with an optional agency code followed by a colon. If you don't know the site numbers you need, you can find relevant sites with the NWIS Mapper ![]() ![]() |
1 | 10 | &site=01646500 &sites=USGS:01646500 &sites=01646500,06306300 |
Choosing to specify date ranges is optional. If you don't specify a date range then statistics will be calculated against the entire period of record for a site and the parameter(s) of interest. So one site may have fifty years of record and its statistics will be calculated based on that period, while another site may have ten years of record and its statistics will be calculated over its 10 years. If you want to constrain statistics to be calculated over a narrower period of interest than the period of record, specify dates using startDt and endDt arguments.
Annual statistic can be calculated against a calendar year or water year. You can select the type of year you want with the statYearType parameter.
URL Argument Name | startDt |
---|---|
Description | Used to specify a start date for a period of interest. Statistics will be calculated based on the start date that you specify. |
Syntax |
|
Default | The start of the period of record.
The effective start date may be "rounded" to the level of accuracy needed based on whether daily, monthly or annual statistics are wanted using rules specified below. The period of record includes only approved values. |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
URL Argument Name | endDt |
---|---|
Description | Used to specify an end date for a period of interest. Statistics will be calculated based on the end date that you specify. |
Syntax |
|
Default | The end of the period of interest.
In addition, the effective end date may be "rounded" to the level of accuracy needed based on whether daily, monthly or annual statistics are wanted using rules specified below. The period of record includes only approved values. |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Dates are specified in an ISO-8601 date format. You can use the format YYYY for years, YYYY-MM for months and YYYY-MM-DD for days. Use the startDt and endDt URL arguments when you need to specify period of interest dates that are less than the period of record. startDt is the start date, month or year. endDt is the end date, month or year. endDt must always be equal to or greater than startDt.
Daily statistics:
Monthly statistics:
Annual statistics: Annual statistics can be calculated against a calendar year or a water year. The statYearType argument is used to set the type of annual statistics desired.
Daily, monthly and annual statistics all depend on daily values, so daily values must exist and they must be approved. Moreover, they will only exist if a site has been recording statistics for the entire day. This helps explain the logic on defaults for dates with this service.
Note that you can ask for annual and monthly statistics despite missing data within the month or year with the missingData argument. In some cases this will change default behavior if there are enough partial values to create a statistic for a start or end month.
Regardless of the statistics type wanted (daily, monthly or annual), statistics are computed against the period of interest by using startDt and endDt arguments. If not specified, the start and end dates for the period of record are used.
You can specify a range shorter or longer than a site's period of record using the startDt and endDt arguments.
URL Argument Name | format |
---|---|
Description | Used to specify the output format of the data returned. Only tab-delimited (RDB) is available at this time. XML, JSON and Excel will be available in the future.
|
Syntax | format=rdb{,1.0} |
Default | rdb |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
URL Argument Name | indent |
---|---|
Description | Used to specify whether block structured data formats(&format=xml|json only) should include indentation for easy viewing. Four space characters are inserted for every level of indentation. Otherwise the parameter is ignored. Since only tab-delimited (RDB) output is available at this time, this argument is effectively ignored at this time. |
Syntax | indent=[on|off] |
Default | off |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
These controls influence which statistics are served and how statistics are calculated.
URL Argument Name | statReportType (aliases reportType, statReportTypeCd) |
---|---|
Description | The type of statistics desired. Valid statistic report types include:
|
Syntax | statReportType= [ daily | monthly | annual ] |
Default | daily - daily statistics |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
URL Argument Name | statType (aliases statTypeCd, statTypesCd, statTypes) |
---|---|
Description |
|
Syntax | statType= {all | { mean,min,max,median,P05...P95 } } |
Default | all |
Minimum argument values required | 1 |
Maximum argument values allowed | 12 |
Examples |
|
URL Argument Name | missingData |
---|---|
Description | Used to indicate the rules to follow to generate statistics if there are gaps in the period of record during the requested statistics period. By default if there are any missing data for the report type, the statistic is left blank or null. This option does not apply to daily statistics, but optionally can be used with monthly and yearly statistics. If used with daily statistics, an error will occur. Missing data can happen for various reasons including there was a technical problem with the gage for part of the time period. Enabling this switch will attempt to provide a statistic if there is enough data to create one. |
Syntax | missingData={ on | off } |
Default | off |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
URL Argument Name | statYearType (aliases yearType, statYearTypeCd) |
---|---|
Description | Indicates which kind of year statistics should be created against. This only applies when requesting annual statistics, i.e. statReportType=annual. Valid year types codes include:
|
Syntax | statYearType=[ calendar | water ] |
Default | calendar |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Additional filters can be applied after specifying a major filter. This further reduces the set of expected results. Users are encouraged to use minor filters because it allows more efficient use of this service. Note: since only site numbers can be supplied as a major filter at this time, minor filters other than parameter code have limited usefulness.
URL Argument Name | parameterCd (aliases: variable, parameterCds, variables, var, vars, parmCd, parmCds) |
---|---|
Description |
|
Syntax | parameterCd|variable= { all | {parameterCd1,parameterCd2,...} } |
Default | returns statistics for all time-series parameters for the requested sites |
Minimum argument values required | 1 |
Maximum argument values allowed | 100 |
Examples |
|
URL Argument Name | siteStatus |
---|---|
Description | Selects sites based on whether or not they are active. If a site is active, it implies that it is being actively maintained. A site is considered active if:
If it does not meet these criteria, it is considered inactive. Some exceptions apply. If a site is flagged by a USGS water science center as discontinued, it will show as inactive. A USGS science center can also flag a new site as active even if it has not collected any data. The default is all (show both active and inactive sites). |
Syntax | siteStatus=[ all | active | inactive ] |
Default | all - sites of any activity status are returned |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
URL Argument Name | siteType (aliases: siteTypes, siteTypeCd, siteTypeCds) |
---|---|
Description |
|
Syntax | siteType=[all | { siteType1,siteType2,... } ] |
Default | All site types are returned |
Minimum argument values required | 1 |
Maximum argument values allowed | No limit |
Examples |
|
URL Argument Name | agencyCd (alias: agencyCds) |
---|---|
Description |
|
Syntax | agencyCd=agencyCd1 |
Default | All sites regardless of agency code are retrieved |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
URL Argument Name |
|
---|---|
Description |
|
Syntax |
|
Default | All sites are retrieved, regardless of their altitude |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Drainage Area (drainAreaMin and drainAreaMax)
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | All sites are retrieved, regardless of their drainage area |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | all |
Minimum argument values required | 0 |
Maximum argument values allowed | 1000 |
Examples |
|
Local Aquifer Code (localAquiferCd)
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | all |
Minimum argument values required | 0 |
Maximum argument values allowed | 1000 |
Examples |
|
Well Depth (wellDepthMin and wellDepthMax)
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | All sites are retrieved, regardless of their well depth |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Hole Depth (holeDepthMin and holeDepthMax)
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | All sites are retrieved, regardless of their hole depth |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Here is a simple example using the popular PHP scripting language that retrieves daily streamflow (discharge) statistics for site number 01646500 in a tab-delimited format and transforms the data into HTML for presentation on a web page.
Please provide any feedback you have on this service using this form.