summaryrefslogblamecommitdiffstats
path: root/examples/weather
blob: 5291fb6e3c4d080b735f2fb08730fee18c87d246 (plain) (tree)





































































                                                                                
# -*- python -*-

# This example demonstrates how to include weather conditions
# in you 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 glas 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'

# 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)

# 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)