Weather data from the cloud

Recently, a mobile app I was working on required a real time calculation to convert the pressure recorded in a submerged river sensor to a figure based on the ambient air pressure for that location.

“You should be able to get that from the BBC, or the Met Office, I think.”

I headed to the BBC weather site, but their weather RSS feed is limited, and doesn’t provide the granularity of location data I required. It also only provides forecast data, and I needed to know the factual recent data for that location, not what it might be.

So I investigated the Met Office site, and discovered their marvellous Datapoint service. Specifically, they offer “UK hourly site-specific observations”, which seemed perfect. So I registered for an API key, and set to investigating the data.

It turned out that I could easily make an API request for data an hour old, which would give me a full list of all the UK stations, complete with their observations. “Perfect!”, I thought. However, on more detailed examination, it became clear that the data was not complete for the previous hour, whereas going back to the nearest two hours was consistent. This was close enough for the project.

The second issue, was that I needed to find out the observations for the station nearest to the location at which the sample was taken. I found the easiest way to manage this was to download the entire dataset to the phone, and then iterate through it, checking the station location coordinates against those for the site at which the reading was being done. This was made significantly easier by a set of GIS scripts from Movable Type which allow you to easily perform this calculation. So I could now determine which of the stations in the Datapoint data was nearest to the sample point.

The final issue was that I noticed that some stations appeared not to record the pressure data I needed. So to prevent any problems, when parsing the data to determine location, I first rejected any station data which did not include the pressure data. This may mean that the station we then used the data for was not actually the closest, but it was the closest with the required dataset.

So now I could pull in a record for the nearest weather station to the sample location which had the relevant pressure data. All I had to do now was a simple calculation to convert the value from PSI to metres of pressure, and display it in the app.