Enrich your Panos with Historic Weather Data

This content was originally posted to the Trek View blog on 2022-07-29. Some of the information found in it may now be outdated.

One of the things I wanted to do was allow for filtering of my images using weather metrics.

For example, searching for sequence containing images with a wide visibility. Or searching for images in snowy conditions.

In order to do this I needed a source of historic reference data to cross-reference against photos.

There are a tons of services that provide access to such historical data to varying levels.

WeatherStack is a nice and affordable option for these requirements.

I used a photo taken in a fairly remote location (Helvellyn, Lake District, UK) because I wanted to test how measurements were reported when far from a weather station.

Here is the metadata in the photo needed to make the requests to the APIs.

exiftool -GPSLatitude -GPSLongitude -GPSDateTime -n GSAL1592.JPG 

Exiftool by default prints data as Degrees, Minutes, and Seconds (DMS). Using the -n flag turns DMS into Decimal Degrees (DD), required for both the APIs.

GPS Latitude                    : 54.5255907
GPS Longitude                   : -3.003587
GPS Date/Time                   : 2022:07:13 12:13:07Z

WeatherStack Historical Weather API

My request to OpenWeather Historic Air Pollution API takes the following structure:

https://api.weatherstack.com/historical?access_key={apikey}&query={lat},{lon}&historical_date={date}&hourly=1&units=m&interval=1

For the test photo that gives;

https://api.weatherstack.com/historical?access_key=REDACTED&query=54.5255907,-3.003587&historical_date=2022-07-13&hourly=1&units=m&interval=1

The response contains a few sections that are well suited for my use-case…

  1. The location of the weather station
  "location": {
    "name": "Glenridding",
    "country": "United Kingdom",
    "region": "Cumbria",
    "lat": "54.549",
    "lon": "-2.952",
    "timezone_id": "Europe/London",
    "localtime": "2022-08-07 17:49",
    "localtime_epoch": 1659894540,
    "utc_offset": "1.0"
  },
  1. The historical data for the day
  "historical": {
    "2022-07-13": {
      "date": "2022-07-13",
      "date_epoch": 1657670400,
      "astro": {
        "sunrise": "04:53 AM",
        "sunset": "09:42 PM",
        "moonrise": "10:21 PM",
        "moonset": "03:36 AM",
        "moon_phase": "Waxing Gibbous",
        "moon_illumination": 97
      },
      "mintemp": 8,
      "maxtemp": 15,
      "avgtemp": 13,
      "totalsnow": 0,
      "sunhour": 15.8,
      "uv_index": 3,
  1. The hourly data

Note, the hourly data section contains blobs of data representing hours during the date specified (&historical_date=2022-07-13&hourly=1&interval=1). The time property (e.g. "time": "1200", below), defines the time of the blob, in this case 12h00m (twelve o’clock in the afternoon). In total there are 24 hourly blobs for each day (0, 100, 2002300);

      "hourly": [
        {
          "time": "1200",
          "temperature": 15,
          "wind_speed": 25,
          "wind_degree": 258,
          "wind_dir": "WSW",
          "weather_code": 116,
          "weather_icons": [
            "https://assets.weatherstack.com/images/wsymbols01_png_64/wsymbol_0002_sunny_intervals.png"
          ],
          "weather_descriptions": [
            "Partly cloudy"
          ],
          "precip": 0,
          "humidity": 71,
          "visibility": 10,
          "pressure": 1024,
          "cloudcover": 37,
          "heatindex": 15,
          "dewpoint": 9,
          "windchill": 13,
          "windgust": 28,
          "feelslike": 13,
          "chanceofrain": 0,
          "chanceofremdry": 0,
          "chanceofwindy": 0,
          "chanceofovercast": 0,
          "chanceofsunshine": 0,
          "chanceoffrost": 0,
          "chanceofhightemp": 0,
          "chanceoffog": 0,
          "chanceofsnow": 0,
          "chanceofthunder": 0,
          "uv_index": 4
        },

All the fields are described in the Weather Stack documentation here.

I cannot think of another weather measurement I would choose to add – the data is very comprehensive!

You can then either save this response to a database, or add it to each photos metadata using custom tags.