summaryrefslogtreecommitdiffstats
path: root/examples/weather
blob: 3fac3e4dfbfd9d7579880b79e73ed45ba0e2bb48 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- python -*-

# This example demonstrates how to include weather conditions
# in your configuration scripts.


# Copyright © 2014  Mattias Andrée (maandree@member.fsf.org)
# 
# Permission is granted to copy, distribute and/or modify this document
# under the terms of the GNU Free Documentation License, Version 1.3
# or any later version published by the Free Software Foundation;
# with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
# You should have received a copy of the GNU General Public License
# along with this software package.  If not, see <http://www.gnu.org/licenses/>.


# Geographical coodinates.
# ("Kristall, vertikal accent i glas och stål" (Crystal, vertical accent
# in glass and steal) in this example. A glass obelisk, lit from the inside
# with adjustable colours and a default colour of 5600 K, in the middle
# of a hyperelliptic roundabout.)
latitude, longitude = 59.3326, 18.0652

# International Civil Aviation Organization (ICAO)
# code of the nearest airport.
# (Stockholm Bromma Airport in this example.)
airport = 'ESSB'

# Command used to download a file at an HTTP URL
download_command = None
# This is what if used if `None` is selected:
# download_command = lambda url : ['wget', url, '-O', '-']

# The colour temperature at day and at night.
temperature_day, temperature_night = 6500, 3700

# Dayness modifiers based on weather and sky conditions.
modifiers = { 'clear'         : 1.00
            , 'mostly clear'  : 0.95
            , 'partly cloudy' : 0.90
            , 'mostly cloudy' : 0.85
            , 'overcast'      : 0.80
            , 'obscured'      : 0.75
            }

# The maximum for visibility range for when to
# account for the visibility range.
visibility_max = 4


# The visibility of the Sun.
dayness = sun(latitude, longitude)

# Get weather report.
metar = weather(airport, download_command)

# Account for weather.
if metar is not None:
    conditions = [metar[0]] + metar[2]
    for condition in conditions:
        if condition in modifiers:
            dayness *= modifiers[condition]
    _bound, visibility = metar[1]
    if (visibility_max is not None) and (visibility is not None):
        if visibility < visibility_max:
            dayness *= visibility / visibility_max

# Calculation of the colour temperature.
temp = temperature_day * dayness + temperature_night * (1 - dayness)

## Calculate the whitepoint with adjusted colour temperature.
whitepoint = temperature(temp, lambda t : divide_by_maximum(cmf_10deg(t)))

# Apply adjustments.
randr(0)