Sky Colors

This is generated image. Each row represents a single day. Each box represents the color of a patch of sky above my house, sampled every 5 minutes. The program running on the Raspberry takes a picture, crops out a chunk of sky, finds the average color, and saves it as an RGB tuple. I can then run another python program that plots the rectangles in a black rectangle.

Here’s the script that takes the picture:

#!/bin/bash
raspistill -ss 500 -o image.jpg
convert image.jpg -crop 100x100+0+1600 cropped.jpg
time=$(date '+%Y-%m-%d=%H:%M:%S')
data=$(convert cropped.jpg -resize 1x1\! -format "%[fx:int(255*r+.5)],% \[fx:int(255*g+.5)],%[fx:int(255*b+.5)]" info:- )
text=$time"="$data
echo "$text" >> /root/log.txt

Here’s the python code that generates the image:

#!/usr/bin/python3
import sys
from PIL import Image, ImageDraw

img = Image.new(mode="RGB", size=(1460, 800))
draw = ImageDraw.Draw(img)

x = 20
y = 20
oldday = 0

path = 'log.txt'
logfile = open(path,'r')
for line in logfile:
    day,time,colors = line.split('=')
    if day != oldday:
         y = y + 50
         x = 20
         oldday = day
    r,g,b=colors.split(',')
    fill = (int(r),int(g),int(b),255)
    x=x+10
    shape = [(x, y), (x + 10, y + 50)]
    draw.rectangle(shape, fill, outline=None, width=1)

logfile.close
img.save("stripes.jpg")
img.close

Here’s a bit of the log.txt file:

2022-01-28=15:40:09=217,224,232
2022-01-28=15:50:09=197,204,214
2022-01-28=16:00:09=182,191,199
2022-01-28=16:10:09=132,132,145
2022-01-28=16:20:09=145,143,153
2022-01-28=16:30:09=116,117,129
2022-01-28=16:40:09=81,79,90
2022-01-28=16:50:09=65,63,73
2022-01-28=17:00:09=40,41,47
2022-01-28=17:10:09=12,12,17
2022-01-28=17:20:09=3,12,55
2022-01-28=17:30:09=1,3,16
2022-01-28=17:40:09=2,1,1
2022-01-28=17:50:08=0,0,0

You can see how the sky gradually turns from grey to black. On sunny days, the tuples are bluer, 78,67,221.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.