Met Office Historical Data

FREEMIUM
By Anthony Tickner-Jones | Updated a month ago | Weather
Health Check

N/A

README

Introduction

UK Historical weather data from the met office. This API returns monthly; Average Maximum Temperature Degrees Celcius, Average Minimum Temperature Degrees Celcius,Total Air Frost Days, Total Rain Fall in Millimeters and Total Sun Hours for a number of weather stations around the UK with data going back over 100 years in some cases.

API with two end points, the first, “Get Nearest Weather Station” will return the top 3 nearest weather stations based on a latitude and longitude passed in, this will also show the Distance in Miles from the passed in co-ordinates, Lat and Long of the Station, the year that records started and the latest year of records ( in case where station has closed), when the record was last updated, some Met Office file header info and finally the ID of the weather station. This ID is used along with a year is passed to the second endpoint; “Get Weather Data By Station and Year” to get the twelve months of data for that year in monthly averages.

Endpoint: “Get Nearest Weather Station” : /api/nearestweatherstation

Sample Request Payload

This should be JSON sent as part of the body on the “HTTP Post Request”, there are two required parameters, “lat” and “lon” both take a floating point number, failure to supply both arguments, you will receive an “http” status error 400 and a message like (’“lat” and “lon” are required parameters.)

{ “lat” : 51.2899393, “lon” : -1.287739 }

Sample Response Payload

{ "weatherstations": [ { "distanceinmiles": "27.57", "stationid": "29", "stationname": "Southampton", "lat": "50.89822", "lon": "-1.40839", "startyear": 1855, "endyear": 2000, "lastupdated": "2023-10-24T15:53:56.325Z", "headertext": "Location 442000E 112500N, 20 metres amsl (1855 to 1969) \r\n& 441600E 111200N, Lat 50.898 Lon -1.408, 3 metres amsl (1970 to 2000)\r\nEstimated data is marked with a * after the value.\r\nMissing data (more than 2 days missing in month) is marked by ---.\r\nSunshine data taken from an automatic Kipp & Zonen sensor marked with a #, otherwise sunshine data taken from a Campbell Stokes recorder.\r\n" }, { "distanceinmiles": "32.55", "stationid": "23", "stationname": "Oxford", "lat": "51.76073", "lon": "-1.2625", "startyear": 1853, "endyear": 2023, "lastupdated": "2023-10-24T15:46:13.491Z", "headertext": "Location: 450900E 207200N, Lat 51.761 Lon -1.262, 63 metres amsl\r\nEstimated data is marked with a * after the value.\r\nMissing data (more than 2 days missing in month) is marked by ---.\r\nSunshine data taken from an automatic Kipp & Zonen sensor marked with a #, otherwise sunshine data taken from a Campbell Stokes recorder.\r\n" }, { "distanceinmiles": "38.45", "stationid": "15", "stationname": "Heathrow", "lat": "51.47872", "lon": "-0.44904", "startyear": 1948, "endyear": 2023, "lastupdated": "2023-10-24T15:35:46.785Z", "headertext": "Location 507800E 176700N, Lat 51.479 Lon -0.449, 25m amsl\r\nEstimated data is marked with a * after the value.\r\nMissing data (more than 2 days missing in month) is marked by ---.\r\nSunshine data taken from an automatic Kipp & Zonen sensor marked with a #, otherwise sunshine data taken from a Campbell Stokes recorder.\r\n" } ] }

distanceinmiles

Definition

Distance in miles as the crow flies/straight line from the original passed in lat (latitude) and lon (longitude)

Implementation

Use as a guide to decide which of the top three closest weather stations returned by the endpoint are close enough to passed in location and have sufficient data. i.e. the closest weather station might not have recent years data.

stationid

Definition

IMPORTANT! This is an api internal id of the weather station and is used to pass into the second end point “Get Weather Data By Station and Year” as the first parameter (stationid).

Implementation

In your local code you will need to store this value so it can be used as the first parameter in the “Get Weather Data By Station and Year” endpoint.

stationname

Definition

The weather station name as supplied by the UK Met Office, used for display purposes.

lat

Definition

The current latitude of the weather station as supplied by the UK Met Office in decimal format.

lon

Definition

The current longitude of the weather station as supplied by the UK Met Office in decimal format.

startyear

Definition

The first year that the weather station started recording data.

endyear

Definition

The last year that the weather station has data on record. In most cases it will be the current year unless a weather station has been closed or stopped recording data.

lastupdated

Definition

This is an api internal value which shows when data was last updated from the Met Office source data.

headertext

Definition

This is purely informational data that is found in the header of the Met Office source file. Contains general information including latitude and longitude in both decimal and northing/easting formats. Information about which sensors records certain data and information about provisional data.

Code Examples

As taken from “Rapid API” hub playground / code snippets

Node.js (fetch)

               const axios = require('axios');

                  const options = {
                    method: 'POST',
                    url: 'https://met-office-historical-data.p.rapidapi.com/api/nearestweatherstation',
                    headers: {
                      'content-type': 'application/json',
                      'X-RapidAPI-Key': 'YOUR_API_KEY_HERE',
                      'X-RapidAPI-Host': 'met-office-historical-data.p.rapidapi.com'
                    },
                    data: {
                      lat: 51.2899393,
                      lon: -1.287739
                    }
                  };
                  
                  try {
                    const response = await axios.request(options);
                    console.log(response.data);
                  } catch (error) {
                    console.error(error);
                  }

Python (requests)

                    import requests

               
 url = "https://met-office-historical-data.p.rapidapi.com/api/nearestweatherstation"

                    payload = {
                      "lat": 51.2899393,
                      "lon": -1.287739
                    }
                    headers = {
                      "content-type": "application/json",
                      "X-RapidAPI-Key": "YOUR_API_KEY_HERE",
                      "X-RapidAPI-Host": "met-office-historical-data.p.rapidapi.com"
                    }

                    response = requests.post(url, json=payload, headers=headers)

                    print(response.json())

Endpoint: “Get Weather Data By Station and Year” : api/weatherstationdatabyyear

Sample Request Payload

This should be JSON sent as part of the body on the “HTTP Post Request”, there are two required parameters, “stationid” and “year” both numeric/integer values, failure to supply both arguments will generate an “http” status error 400 and a message like (“stationid” and “year” are required parameters.)

stationid should be the stationid property of the desired weather station returned from the first api call (api/nearestweatherstation)

{ "stationid": 29, "year": 1999 }

Sample Response Payload

{ "historicdata": [ { "year": 1999, "month": 1, "monthtext": "January", "temp_max_degc": "9.9", "temp_max_is_estimated": false, "temp_min_degc": "4.1", "temp_min_is_estimated": false, "air_frost_days": "5", "air_frost_is_estimated": false, "rain_mm": "129.4", "rain_mm_is_estimated": false, "sun_hours": null, "sun_hours_is_estimated": false, "is_provisional": false }, { "year": 1999, "month": 2, "monthtext": "February", "temp_max_degc": "9.5", "temp_max_is_estimated": false, "temp_min_degc": "3.3", "temp_min_is_estimated": false, "air_frost_days": "4", "air_frost_is_estimated": false, "rain_mm": "28.8", "rain_mm_is_estimated": false, "sun_hours": null, "sun_hours_is_estimated": false, "is_provisional": false }, { "year": 1999, "month": 3, "monthtext": "March", "temp_max_degc": "12.0", "temp_max_is_estimated": false, "temp_min_degc": "4.2", "temp_min_is_estimated": false, "air_frost_days": "1", "air_frost_is_estimated": false, "rain_mm": "32.2", "rain_mm_is_estimated": false, "sun_hours": null, "sun_hours_is_estimated": false, "is_provisional": false }, { "year": 1999, "month": 4, "monthtext": "April", "temp_max_degc": "14.4", "temp_max_is_estimated": false, "temp_min_degc": "6.7", "temp_min_is_estimated": false, "air_frost_days": "0", "air_frost_is_estimated": false, "rain_mm": "57.2", "rain_mm_is_estimated": false, "sun_hours": null, "sun_hours_is_estimated": false, "is_provisional": false }, { "year": 1999, "month": 5, "monthtext": "May", "temp_max_degc": "18.6", "temp_max_is_estimated": false, "temp_min_degc": "10.4", "temp_min_is_estimated": false, "air_frost_days": "0", "air_frost_is_estimated": false, "rain_mm": "17.2", "rain_mm_is_estimated": false, "sun_hours": null, "sun_hours_is_estimated": false, "is_provisional": false }, { "year": 1999, "month": 6, "monthtext": "June", "temp_max_degc": "19.4", "temp_max_is_estimated": false, "temp_min_degc": "10.9", "temp_min_is_estimated": false, "air_frost_days": "0", "air_frost_is_estimated": false, "rain_mm": "75.3", "rain_mm_is_estimated": false, "sun_hours": null, "sun_hours_is_estimated": false, "is_provisional": false }, { "year": 1999, "month": 7, "monthtext": "July", "temp_max_degc": "24.2", "temp_max_is_estimated": false, "temp_min_degc": "14.0", "temp_min_is_estimated": false, "air_frost_days": "0", "air_frost_is_estimated": false, "rain_mm": "11.8", "rain_mm_is_estimated": false, "sun_hours": null, "sun_hours_is_estimated": false, "is_provisional": false }, { "year": 1999, "month": 8, "monthtext": "August", "temp_max_degc": "21.8", "temp_max_is_estimated": false, "temp_min_degc": "14.1", "temp_min_is_estimated": false, "air_frost_days": "0", "air_frost_is_estimated": false, "rain_mm": "119.5", "rain_mm_is_estimated": false, "sun_hours": null, "sun_hours_is_estimated": false, "is_provisional": false }, { "year": 1999, "month": 9, "monthtext": "September", "temp_max_degc": "21.2", "temp_max_is_estimated": false, "temp_min_degc": "13.3", "temp_min_is_estimated": false, "air_frost_days": "0", "air_frost_is_estimated": false, "rain_mm": "111.9", "rain_mm_is_estimated": false, "sun_hours": null, "sun_hours_is_estimated": false, "is_provisional": false }, { "year": 1999, "month": 10, "monthtext": "October", "temp_max_degc": "16.1", "temp_max_is_estimated": false, "temp_min_degc": "8.1", "temp_min_is_estimated": false, "air_frost_days": "0", "air_frost_is_estimated": false, "rain_mm": "66.8", "rain_mm_is_estimated": false, "sun_hours": null, "sun_hours_is_estimated": false, "is_provisional": false }, { "year": 1999, "month": 11, "monthtext": "November", "temp_max_degc": "11.8", "temp_max_is_estimated": false, "temp_min_degc": "6.0", "temp_min_is_estimated": false, "air_frost_days": "0", "air_frost_is_estimated": false, "rain_mm": "49.6", "rain_mm_is_estimated": false, "sun_hours": null, "sun_hours_is_estimated": false, "is_provisional": false }, { "year": 1999, "month": 12, "monthtext": "December", "temp_max_degc": "9.3", "temp_max_is_estimated": false, "temp_min_degc": "3.0", "temp_min_is_estimated": false, "air_frost_days": "5", "air_frost_is_estimated": false, "rain_mm": "138.8", "rain_mm_is_estimated": false, "sun_hours": null, "sun_hours_is_estimated": false, "is_provisional": false } ] }


year

Definition

The year of the data as supplied by Met Office, should be the same as the original argument but there for when you iterate through and call the api through multiple years etc.

month

Definition

Numerical month range 1 to 12.

Implementation

1 = Jan, 2 = Feb, 3 = Mar, 4 = Apr, 5 = May, 6 = Jun, 7 = Jul, 8 = Aug, 9 = Sep, 10 = Oct, 11 = Nov, 12 = Dec

monthtext

Definition

Full month name as text for display purpose.

temp_max_degc

Definition

Floating point number OR null supplied by Met Office showing the average monthly maximum temperature in degrees celcius.

#temp_max_is_estimated
##Definition
Boolean value, true or false , default is false. The value will read true if the Met Office has marked the “Average Max Temperature” (temp_max_degc) as estimted.

temp_min_degc

Definition

Floating point number OR null supplied by Met Office showing the average monthly minimum temperature in degrees celcius.

temp_min_is_estimated

Definition

Boolean value, true or false , default is false. The value will read true if the Met Office has marked the “Average Min Temperature” (temp_min_degc) as estimted.

air_frost_days

Definition

Numeric value OR null supplied by Met Office showing the total monthly air frost days.

air_frost_is_estimated

Definition

Boolean value, true or false , default is false. The value will read true if the Met Office has marked the “Number of Air Frost Days” (air_frost_days) as estimted.

rain_mm

Definition

Floating point number OR null supplied by Met Office showing the total monthly rain fall in millimeters.

rain_mm_is_estimated

Definition

Boolean value, true or false , default is false. The value will read true if the Met Office has marked the “Total Rain Fall” (rain_mm) as estimted.

sun_hours

Definition

Floating point number OR null supplied by Met Office showing the monthly total number of sunshine hours.

sun_hours_is_estimated

Definition

Boolean value, true or false , default is false. The value will read true if the Met Office has marked the “Total Sunshine Hours” (sun_hours) as estimted.

is_provisional

Definition

Boolean value, true or false , default is false. The value will read true if the Met Office has marked the data in this month as provisional. Normally the last few months of current year.

Code Examples

As taken from “Rapid API” hub playground / code snippets

Node.js (fetch)

                  const axios = require('axios');
                  const options = {
                    method: 'POST',
                    url: 'https://met-office-historical-data.p.rapidapi.com/api/weatherstationdatabyyear',
                    headers: {
                      'content-type': 'application/json',
                      'X-RapidAPI-Key': 'API_KEY_HERE',
                      'X-RapidAPI-Host': 'met-office-historical-data.p.rapidapi.com'
                    },
                    data: {
                      stationid: 29,
                      year: 1999
                    }
                  };

                  try {
                    const response = await axios.request(options);
                    console.log(response.data);
                  } catch (error) {
                    console.error(error);
                  }

Python (requests)

                    import requests

                    url = "https://met-office-historical-data.p.rapidapi.com/api/weatherstationdatabyyear"

                    payload = {
                    "stationid": 29,
                    "year": 1999
                    }
                    headers = {
                    "content-type": "application/json",
                    "X-RapidAPI-Key": "YOUR_API_KEY_HERE",
                    "X-RapidAPI-Host": "met-office-historical-data.p.rapidapi.com"
                    }

                    response = requests.post(url, json=payload, headers=headers)

                    print(response.json())
Followers: 0
Resources:
Product Website
API Creator:
Rapid account: Anthony Tickner Jones
Anthony Tickner-Jones
anttickner
Log In to Rate API
Rating: 5 - Votes: 1