User:DukeEgr93/WeatherClock

From PrattWiki
Jump to navigation Jump to search

The Weather Clock is a project I decided to build after having a fun conversation with ENS Chris Coughlin about an art project he was doing involving controllable LEDs, IR communications, and arduinos. The thought that came to mind was to use a controllable LED ring to indicate weather conditions for the next 24 hours. I want to try to put two pieces of information on the ring, so I thought hue might be good for the temperature and either saturation or brightness or both for the chance of rain.

Preamble

For development purposes, I am writing everything using Spyder based on Python 3.6. The following are the lists of imports I have at the top of my code:

import json
from pprint import pprint
import pickle
import requests
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
import colorsys

Getting Weather Data

There are several sites that provide APIs for getting weather data. Depending on your use case and tempo, you may have to pay. For this project, I don't anticipating updating the actual weather data more than once an hour, if even that often, so I usually come in free. I looked at both:

and ended up with Weather Underground for two reasons: it would provide an hourly forecast for free, and it accepted my API key first.

To get the data from the web site, I am using the Requests library. Here's all the code it takes to get an hourly forecast data strem from Weather Underground:

response = requests.get("http://api.wunderground.com/api/KEY_GOES_HERE/hourly/q/NC/Durham.json")

Note: I am not showing you my key. If you want one, you will need to get your own :) The data set that this returns has a massive amount of information - it returns hourly forecasts for the next 36 hours, and each hour has a data list that looks like:

{'FCTTIME': {'UTCDATE': '',
                                  'age': '',
                                  'ampm': 'AM',
                                  'civil': '12:00 AM',
                                  'epoch': '1498795200',
                                  'hour': '0',
                                  'hour_padded': '00',
                                  'isdst': '1',
                                  'mday': '30',
                                  'mday_padded': '30',
                                  'min': '00',
                                  'min_unpadded': '0',
                                  'mon': '6',
                                  'mon_abbrev': 'Jun',
                                  'mon_padded': '06',
                                  'month_name': 'June',
                                  'month_name_abbrev': 'Jun',
                                  'pretty': '12:00 AM EDT on June 30, 2017',
                                  'sec': '0',
                                  'tz': '',
                                  'weekday_name': 'Friday',
                                  'weekday_name_abbrev': 'Fri',
                                  'weekday_name_night': 'Friday Night',
                                  'weekday_name_night_unlang': 'Friday Night',
                                  'weekday_name_unlang': 'Friday',
                                  'yday': '180',
                                  'year': '2017'},
                      'condition': 'Clear',
                      'dewpoint': {'english': '63', 'metric': '17'},
                      'fctcode': '1',
                      'feelslike': {'english': '71', 'metric': '22'},
                      'heatindex': {'english': '-9999', 'metric': '-9999'},
                      'humidity': '77',
                      'icon': 'clear',
                      'icon_url': 'http://icons.wxug.com/i/c/k/nt_clear.gif',
                      'mslp': {'english': '30.15', 'metric': '1021'},
                      'pop': '4',
                      'qpf': {'english': '0.0', 'metric': '0'},
                      'sky': '28',
                      'snow': {'english': '0.0', 'metric': '0'},
                      'temp': {'english': '71', 'metric': '22'},
                      'uvi': '0',
                      'wdir': {'degrees': '188', 'dir': 'S'},
                      'windchill': {'english': '-9999', 'metric': '-9999'},
                      'wspd': {'english': '5', 'metric': '8'},
                      'wx': 'Mostly Clear'}