Last active
December 17, 2021 20:31
-
-
Save orjanv/53d787c83ce44d7a0b7b6fedd5d5bdd4 to your computer and use it in GitHub Desktop.
A year in colors, -25 to 24 degrees over a range of colors from blue to red.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from subprocess import Popen | |
import sys | |
''' | |
A year in colors, -25 to 24 degrees over a range of colors from blue to red. | |
Color palette from: | |
- https://www.color-hex.com/color-palette/33335 | |
- https://meyerweb.com/eric/tools/color-blend/#194BFF:0022C9:10:hex | |
- new table from: https://www.google.com/welltemperedtraveler/ | |
Data from: https://frost.met.no/ | |
It works on linux with Imagemagick installed | |
- Fedora: sudo dnf install imagemagick | |
- Ubuntu: sudo apt install imagemagick | |
How to get station list? | |
- | |
Run the script like this: | |
$ python a_year_in_colors.py STATION YEAR FILENAME | |
''' | |
color_table_new = { | |
24: ("#940000"), | |
23: ("#940000"), | |
22: ("#940000"), | |
21: ("#940000"), | |
20: ("#940000"), | |
19: ("#ff0022"), | |
18: ("#ff0022"), | |
17: ("#ff0022"), | |
16: ("#ff0022"), | |
15: ("#ff0022"), | |
14: ("#ff8c00"), | |
13: ("#ff8c00"), | |
12: ("#ff8c00"), | |
11: ("#ff8c00"), | |
10: ("#ff8c00"), | |
9: ("#ffff00"), | |
8: ("#ffff00"), | |
7: ("#ffff00"), | |
6: ("#ffff00"), | |
5: ("#ffff00"), | |
4: ("#03ba00"), | |
3: ("#03ba00"), | |
2: ("#03ba00"), | |
1: ("#03ba00"), | |
0: ("#03ba00"), | |
-1: ("#05ffd9"), | |
-2: ("#05ffd9"), | |
-3: ("#05ffd9"), | |
-4: ("#05ffd9"), | |
-5: ("#05ffd9"), | |
-6: ("#00a7ef"), | |
-7: ("#00a7ef"), | |
-8: ("#00a7ef"), | |
-9: ("#00a7ef"), | |
-10: ("#00a7ef"), | |
-11: ("#004eea"), | |
-12: ("#004eea"), | |
-13: ("#004eea"), | |
-14: ("#004eea"), | |
-15: ("#004eea"), | |
-16: ("#0039bf"), | |
-17: ("#0039bf"), | |
-18: ("#0039bf"), | |
-19: ("#0039bf"), | |
-20: ("#0039bf"), | |
-21: ("#0039bf"), | |
-22: ("#0039bf"), | |
-23: ("#0039bf"), | |
-24: ("#0039bf"), | |
-25: ("#0039bf") | |
} | |
color_table = { | |
24: ("#F00A0A"), | |
23: ("#F00A0A"), | |
22: ("#F00A0A"), | |
21: ("#F00A0A"), | |
20: ("#F00A0A"), | |
19: ("#EA0909"), | |
18: ("#E50808"), | |
17: ("#DF0707"), | |
16: ("#D90606"), | |
15: ("#D40505"), | |
14: ("#CE0505"), | |
13: ("#C90404"), | |
12: ("#C30303"), | |
11: ("#BD0202"), | |
10: ("#B80101"), | |
9: ("#B20000"), | |
8: ("#AA080B"), | |
7: ("#A31017"), | |
6: ("#9B1722"), | |
5: ("#931F2D"), | |
4: ("#8B2738"), | |
3: ("#842F44"), | |
2: ("#7C374F"), | |
1: ("#743F5A"), | |
0: ("#6C4665"), | |
-1: ("#654E71"), | |
-2: ("#5D567C"), | |
-3: ("#575588"), | |
-4: ("#515494"), | |
-5: ("#4A53A0"), | |
-6: ("#4452AC"), | |
-7: ("#3E51B8"), | |
-8: ("#3850C3"), | |
-9: ("#324FCF"), | |
-10: ("#2C4EDB"), | |
-11: ("#254DE7"), | |
-12: ("#1F4CF3"), | |
-13: ("#194BFF"), | |
-14: ("#1747FA"), | |
-15: ("#1444F5"), | |
-16: ("#1240F0"), | |
-17: ("#103CEB"), | |
-18: ("#0E38E6"), | |
-19: ("#0B35E2"), | |
-20: ("#0931DD"), | |
-21: ("#072DD8"), | |
-22: ("#0529D3"), | |
-23: ("#0226CE"), | |
-24: ("#0022C9"), | |
-25: ("#0022C9") | |
} | |
# Needs a better parameter control | |
station = sys.argv[1] # 'SN90495' is Tromsø og 'SN87110' is Andenes | |
year = sys.argv[2] | |
output_filename = sys.argv[3] | |
# Define url and parameters | |
# You need a client id from frost.met.no | |
client_id = 'ID GOES HERE' | |
url = 'https://frost.met.no/observations/v0.jsonld' | |
parameters = { | |
'sources': station, | |
'elements': 'mean(air_temperature P1D)', | |
'referencetime': f'{year}-01-01/{year}-12-31', | |
} | |
# Issue an HTTP GET request and Extract JSON data | |
r = requests.get(url, parameters, auth=(client_id,'')) | |
json = r.json() | |
# Check if the request worked, print out any errors | |
if r.status_code == 200: | |
data = json['data'] | |
print('Data retrieved from frost.met.no!') | |
else: | |
print('Error! Returned status code %s' % r.status_code) | |
print('Message: %s' % json['error']['message']) | |
print('Reason: %s' % json['error']['reason']) | |
exit(1) | |
temp_list = [] | |
# Some stations doesn't have two daily readings. This can be improved upon | |
for i in range(len(data)): | |
try: | |
temp_list.append(data[i]['observations'][0]['value']) # reading 1 | |
except: | |
pass | |
try: | |
temp_list.append(data[i]['observations'][1]['value']) # reading 2 | |
except: | |
pass | |
# Create all the color-stripes | |
temp_pos = 1 | |
for i in temp_list: | |
temp_color = color_table_new.get(round(i)) | |
p = Popen([f'convert -size 2x700 xc:{temp_color} img/stripe-{temp_pos}.png'], shell=True) | |
p.wait() | |
temp_pos += 1 | |
# make a wide panoramic image | |
p = Popen([f'convert +append img/stripe-*.png img/{output_filename}'], shell=True) | |
p.wait() | |
# Clean up | |
p = Popen([f'rm -rf img/stripe-*.png'], shell=True) | |
p.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment