Precipitation
Returns derived precipitation totals or intervals for a requested time period and set of stations. This service encompasses Synoptic's Advanced Precipitation Service.
Request Format
A Precipitation request is an HTTP URL with the following form:
https://api.synopticdata.com/v2/stations/precip
Acquiring data from this web service requires certain parameters. When encoding URLs, all parameters are separated using the ampersand (&) character and their value is indicated by an equal sign (=). Below is a list of accepted parameters.
token
(required), Your application’s API token. This is used to identify who is requesting API data. You are never required to use multiple tokens, but you can use as many as you need. Learn more in our tokens overview.Any number of station selection parameters (optional). Including no station selections will return results for all stations. This can result in extremely large results for services that support it.
Either
start
andend
orrecent
(one is required but not both)start
&end
, Defines the start and end time of the request with the form of YYYYmmddHHMM. Where YYYY is year, mm is month, dd is day, HH is hour, and MM is minutes. The start parameter must be used with the end parameter. For example:start=201306011800&end=201306021215
.
All times are requested in UTC, but may be returned in either UTC or local time format for each station. See the
obtimezone
parameter.
recent
, Indicates the number of minutes to return, previous to the current time. For example:recent=120
will return the last two hours of observations.
Optional Parameters
pmode
(totals, intervals, last), defines the interval mode to calculate precipitation. If omitted the default istotals
, however the returned JSON formatting will be significantly different. (See JSON Format examples below)pmode=totals
, Returns totals for the start and end dates.pmode=intervals
, Returns accumulated precipitation for intervals provided in the additionalinterval
argument. Valid keywords forinterval
are hour, day, week, month, year, or non-zero integer in hours. Integers must be a factor or multiple of 24 (1,2,3,4,6,8,12,24,48,72,etc). Default value is day ifinterval
is not provided. Partial intervals at the end of a requested range are still returned. Note that all keywords or integers provided tointerval
will use UTC time zone to define the start and end of each interval. However, each interval respects the requested start hour such that intervals can be offset for a local time zone.pmode=last
, Returns accumulated precipitation intervals based onend
date. The additionalaccum_hours
argument accepts a comma separated list of hours, starting fromend
and moving back through time. Ifaccum_hours
is omitted the default is 1. If astart
value is given, it is ignored. Ifend
is omitted, the default is “now”. Each interval always ends on theend
date.
obtimezone
(UTC [default], local), Indicates if the time zone of the response is in UTC or the local time zone of the station. Sets the time zone applied to the observation output (input times associated withstart
andend
are always UTC). Example:obtimezone=local
showemptystations
(0 [default], 1), Indicates if stations with no observations will be returned. Setting to1
will return any station meeting the defined time period, variables, and geographic or network parameters, even if there are no observation data available.units
(metric [default], english, [custom format]), Defines the unit of measure for returned data. For standard measurements used by many in North Americaenglish
will fill most needs. There is also the ability to support custom unit configurations. This is achieved by accessing the variable group such as “temp” and setting the desired unit using a pipe (|
) character. The following list describes the available units for each variable group.precip
(mm, cm, in), Precipitation: Millimeters, centimeters, inches.
interval_window
, defines a time window (hours) to allow returned intervals that are less than and/or greater than the requested interval. This parameter is useful for stations that may not report at regular frequency, resulting in variable interval durations between reports. Only applicable withpmode=intervals
requests, and can be passed as a single argument or as two comma-separated args that define windows specific to shorter and longer allowed intervals. For example,interval_window=0
returns interval data that only match requestedinterval
.interval_window=0,1
returns intervals at requestedinterval
, but will return intervals up to duration ofinterval
+ 1 hour in the case that duration ofinterval
is not available. Default value isinterval_window=0.5,0.5
, which returns interval data betweeninterval
- 0.5 hours andinterval
+ 0.5 hours if interval data at the requestedinterval
are not available.all_reports
(0 [default], 1), Indicates if reports from all available precipitation variables should be returned. Some networks (such as ASOS/AWOS) can report precipitation in multiple forms (e.g.precip_accum_one_hour
andprecip_accum_six_hour
). By default, the precipitation service will use the single most representative and consistently reporting variable to calculate derived precipitation.
Note: If a station has moved >5 km during the requested time range, precipitation for the most recent location will be returned.
The following example requests precipitation from from stid=wbb
for all of January 2017 in terms of day intervals.
https://api.synopticdata.com/v2/stations/precip?stid=wbb&start=201701010000&end=201702010000&pmode=intervals&interval=day&token=YOUR_TOKEN_HERE
Response Format Parameters
timeformat
, Defines a time format that all time stamps in the data response to be formatted to. By default the API will return time values in ISO 8601 format. This behavior can be changed by passing a string with a valid strftime expression. Below are some common examples.timeformat=%m/%d/%Y at %H:%M
would yield “06/22/2017 at 17:06”timeformat=%b%20%d%20%Y%20-%20%H:%M
would yield “Jun 22 2017 - 17:06”timeformat=%s
returns Unix/POSIX time in terms of seconds (this parameter cannot be used withobtimezone
). This is a special function in addition to the supported strftime arguments.
output
(json [default], xml), Indicates the response format of the request. It’s recommended to use the JSON format which there are well supported parsing libraries in all major languages.
Request Response
JSON Format
The Precipitation service will return its results in a single organized and self describing JSON object. At a minimum, every request will return a JSON object with a "SUMMARY"
field.
An example JSON response would be:
{
"UNITS": {
"precipitation": "Millimeters"
},
"STATION": [
{
"STATUS": "ACTIVE",
"MNET_ID": "153",
"PERIOD_OF_RECORD": {
"start": "1997-01-01T00:00:00Z",
"end": "2018-01-10T12:00:00Z"
},
"ELEVATION": "4806",
"NAME": "U of U William Browning Building",
"RESTRICTED": false,
"STID": "WBB",
"ELEV_DEM": "4738",
"LONGITUDE": "-111.84755",
"STATE": "UT",
"LATITUDE": "40.76623",
"TIMEZONE": "America/Denver",
"ID": "1",
"OBSERVATIONS": {
"precipitation": [
{
"count": 12,
"first_report": "2017-01-31T23:00:00Z",
"interval": 1,
"report_type": "precip_accum_five_minute",
"last_report": "2017-01-31T23:55:00Z",
"total": 0
}
]
}
}
],
"SUMMARY": {
"DATA_QUERY_TIME": 169.8219776154,
"RESPONSE_CODE": 1,
"RESPONSE_MESSAGE": "OK",
"NUMBER_OF_OBJECTS": 1
}
}
If pmode
is omitted, the OBSERVATIONS
block will be of this form (to comply with legacy output formats):
"OBSERVATIONS": {
"ob_start_time_1": "2017-01-31T23:00:00Z",
"total_precip_value_1": 0,
"ob_end_time_1": "2017-01-31T23:55:00Z",
"count_1": 12
},
SUMMARY[]
NUMBER_OF_OBJECTS
, (always returned) is a integer value of the number of stations returned.RESPONSE_CODE
, (always returned) is a numerical code indicating the status of the request.“1” = “OK”
“2” = “Zero Results”
“200” = “Authentication failure”
“400” = “Violates a rule of the API”
RESPONSE_MESSAGE
, (always returned) is a string explaining theRESPONSE_CODE
.RESPONSE_TIME
, (always returned) server time to process the request.
STATION[]
OBSERVATIONS[]
, contains all the observational data.