Jump to content

Module:Weather box: Difference between revisions

From Humanipedia
hp>Johnuniq
known parameters: add 'uv colour' which had been missed (unused?) and add 'x color' alias for each 'x colour'
m 1 revision imported
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<includeonly>{{#invoke:weather box|main}}</includeonly>{{#invoke:Check for unknown parameters|check|unknown={{Namespace detect | main = [[Category:Pages using weather box with unknown parameters|_VALUE_{{PAGENAME}}]] | template = [[Category:Pages using weather box with unknown parameters|Template_VALUE_{{PAGENAME}}]] | other = <!-- do not categorize -->}}|preview=Page using [[Template:Weather box]] with unknown parameter "_VALUE_"|ignoreblank=y| Apr afthumidity | Apr avg record high C | Apr avg record high F | Apr avg record low C | Apr avg record low F | Apr chill | Apr dew point C | Apr dew point F | Apr high C | Apr high F | Apr humidity | Apr light | Apr low C | Apr low F | Apr maximum humidex | Apr mean C | Apr mean F | Apr percentsun | Apr precipitation cm | Apr precipitation days | Apr precipitation inch | Apr precipitation mm | Apr rain cm | Apr rain days | Apr rain inch | Apr rain mm | Apr record high C | Apr record high F | Apr record low C | Apr record low F | Apr snow cm | Apr snow days | Apr snow inch | Apr snow mm | Apr snow depth cm | Apr snow depth inch | Apr snow depth mm | Apr sun | Aprd sun | Apr uv | Aug afthumidity | Aug avg record high C | Aug avg record high F | Aug avg record low C | Aug avg record low F | Aug chill | Aug dew point C | Aug dew point F | Aug high C | Aug high F | Aug humidity | Aug light | Aug low C | Aug low F | Aug maximum humidex | Aug mean C | Aug mean F | Aug percentsun | Aug precipitation cm | Aug precipitation days | Aug precipitation inch | Aug precipitation mm | Aug rain cm | Aug rain days | Aug rain inch | Aug rain mm | Aug record high C | Aug record high F | Aug record low C | Aug record low F | Aug snow cm | Aug snow days | Aug snow inch | Aug snow mm | Aug snow depth cm | Aug snow depth inch | Aug snow depth mm | Aug sun | Augd sun | Aug uv | collapsed | daily | date | Dec afthumidity | Dec avg record high C | Dec avg record high F | Dec avg record low C | Dec avg record low F | Dec chill | Dec dew point C | Dec dew point F | Dec high C | Dec high F | Dec humidity | Dec light | Dec low C | Dec low F | Dec maximum humidex | Dec mean C | Dec mean F | Dec percentsun | Dec precipitation cm | Dec precipitation days | Dec precipitation inch | Dec precipitation mm | Dec rain cm | Dec rain days | Dec rain inch | Dec rain mm | Dec record high C | Dec record high F | Dec record low C | Dec record low F | Dec snow cm | Dec snow days | Dec snow inch | Dec snow mm | Dec snow depth cm | Dec snow depth inch | Dec snow depth mm | Dec sun | Decd sun | Dec uv | Feb afthumidity | Feb avg record high C | Feb avg record high F | Feb avg record low C | Feb avg record low F | Feb chill | Feb dew point C | Feb dew point F | Feb high C | Feb high F | Feb humidity | Feb light | Feb low C | Feb low F | Feb maximum humidex | Feb mean C | Feb mean F | Feb percentsun | Feb precipitation cm | Feb precipitation days | Feb precipitation inch | Feb precipitation mm | Feb rain cm | Feb rain days | Feb rain inch | Feb rain mm | Feb record high C | Feb record high F | Feb record low C | Feb record low F | Feb snow cm | Feb snow days | Feb snow inch | Feb snow mm | Feb snow depth cm | Feb snow depth inch | Feb snow depth mm | Feb sun | Febd sun | Feb uv | humidity colour | humidity color | Jan afthumidity | Jan avg record high C | Jan avg record high F | Jan avg record low C | Jan avg record low F | Jan chill | Jan dew point C | Jan dew point F | Jan high C | Jan high F | Jan humidity | Jan light | Jan low C | Jan low F | Jan maximum humidex | Jan mean C | Jan mean F | Jan percentsun | Jan precipitation cm | Jan precipitation days | Jan precipitation inch | Jan precipitation mm | Jan rain cm | Jan rain days | Jan rain inch | Jan rain mm | Jan record high C | Jan record high F | Jan record low C | Jan record low F | Jan snow cm | Jan snow days | Jan snow inch | Jan snow mm | Jan snow depth cm | Jan snow depth inch | Jan snow depth mm | Jan sun | Jand sun | Jan uv | Jul afthumidity | Jul avg record high C | Jul avg record high F | Jul avg record low C | Jul avg record low F | Jul chill | Jul dew point C | Jul dew point F | Jul high C | Jul high F | Jul humidity | Jul light | Jul low C | Jul low F | Jul maximum humidex | Jul mean C | Jul mean F | Jul percentsun | Jul precipitation cm | Jul precipitation days | Jul precipitation inch | Jul precipitation mm | Jul rain cm | Jul rain days | Jul rain inch | Jul rain mm | Jul record high C | Jul record high F | Jul record low C | Jul record low F | Jul snow cm | Jul snow days | Jul snow inch | Jul snow mm | Jul snow depth cm | Jul snow depth inch | Jul snow depth mm | Jul sun | Juld sun | Jul uv | Jun afthumidity | Jun avg record high C | Jun avg record high F | Jun avg record low C | Jun avg record low F | Jun chill | Jun dew point C | Jun dew point F | Jun high C | Jun high F | Jun humidity | Jun light | Jun low C | Jun low F | Jun maximum humidex | Jun mean C | Jun mean F | Jun percentsun | Jun precipitation cm | Jun precipitation days | Jun precipitation inch | Jun precipitation mm | Jun rain cm | Jun rain days | Jun rain inch | Jun rain mm | Jun record high C | Jun record high F | Jun record low C | Jun record low F | Jun snow cm | Jun snow days | Jun snow inch | Jun snow mm | Jun snow depth cm | Jun snow depth inch | Jun snow depth mm | Jun sun | Jund sun | Jun uv | location | Mar afthumidity | Mar avg record high C | Mar avg record high F | Mar avg record low C | Mar avg record low F | Mar chill | Mar dew point C | Mar dew point F | Mar high C | Mar high F | Mar humidity | Mar light | Mar low C | Mar low F | Mar maximum humidex | Mar mean C | Mar mean F | Mar percentsun | Mar precipitation cm | Mar precipitation days | Mar precipitation inch | Mar precipitation mm | Mar rain cm | Mar rain days | Mar rain inch | Mar rain mm | Mar record high C | Mar record high F | Mar record low C | Mar record low F | Mar snow cm | Mar snow days | Mar snow inch | Mar snow mm | Mar snow depth cm | Mar snow depth inch | Mar snow depth mm | Mar sun | Mard sun | Mar uv | margin | May afthumidity | May avg record high C | May avg record high F | May avg record low C | May avg record low F | May chill | May dew point C | May dew point F | May high C | May high F | May humidity | May light | May low C | May low F | May maximum humidex | May mean C | May mean F | May percentsun | May precipitation cm | May precipitation days | May precipitation inch | May precipitation mm | May rain cm | May rain days | May rain inch | May rain mm | May record high C | May record high F | May record low C | May record low F | May snow cm | May snow days | May snow inch | May snow mm | May snow depth cm | May snow depth inch | May snow depth mm | May sun | Mayd sun | May uv | metric first | name | Nov afthumidity | Nov avg record high C | Nov avg record high F | Nov avg record low C | Nov avg record low F | Nov chill | Nov dew point C | Nov dew point F | Nov high C | Nov high F | Nov humidity | Nov light | Nov low C | Nov low F | Nov maximum humidex | Nov mean C | Nov mean F | Nov percentsun | Nov precipitation cm | Nov precipitation days | Nov precipitation inch | Nov precipitation mm | Nov rain cm | Nov rain days | Nov rain inch | Nov rain mm | Nov record high C | Nov record high F | Nov record low C | Nov record low F | Nov snow cm | Nov snow days | Nov snow inch | Nov snow mm | Nov snow depth cm | Nov snow depth inch | Nov snow depth mm | Nov sun | Novd sun | Nov uv | Oct afthumidity | Oct avg record high C | Oct avg record high F | Oct avg record low C | Oct avg record low F | Oct chill | Oct dew point C | Oct dew point F | Oct high C | Oct high F | Oct humidity | Oct light | Oct low C | Oct low F | Oct maximum humidex | Oct mean C | Oct mean F | Oct percentsun | Oct precipitation cm | Oct precipitation days | Oct precipitation inch | Oct precipitation mm | Oct rain cm | Oct rain days | Oct rain inch | Oct rain mm | Oct record high C | Oct record high F | Oct record low C | Oct record low F | Oct snow cm | Oct snow days | Oct snow inch | Oct snow mm | Oct snow depth cm | Oct snow depth inch | Oct snow depth mm | Oct sun | Octd sun | Oct uv | open | precip days colour | precip days color | precipitation colour | precipitation color | rain colour | rain color | Sep afthumidity | Sep avg record high C | Sep avg record high F | Sep avg record low C | Sep avg record low F | Sep chill | Sep dew point C | Sep dew point F | Sep high C | Sep high F | Sep humidity | Sep light | Sep low C | Sep low F | Sep maximum humidex | Sep mean C | Sep mean F | Sep percentsun | Sep precipitation cm | Sep precipitation days | Sep precipitation inch | Sep precipitation mm | Sep rain cm | Sep rain days | Sep rain inch | Sep rain mm | Sep record high C | Sep record high F | Sep record low C | Sep record low F | Sep snow cm | Sep snow days | Sep snow inch | Sep snow mm | Sep snow depth cm | Sep snow depth inch | Sep snow depth mm | Sep sun | Sepd sun | Sep uv | single line | snow colour | snow color | source | source 1 | source 2 | sun colour | sun color | temperature colour | temperature color | time day | trace | unit precipitation days | unit rain days | unit snow days | uv colour | uv color | width | year afthumidity | year avg record high C | year avg record high F | year avg record low C | year avg record low F | year chill | year dew point C | year dew point F | year high C | year high F | year humidity | year light | year low C | year low F | year maximum humidex | year mean C | year mean F | year percentsun | year precipitation days | year precipitation inch | year precipitation cm | year precipitation mm | year rain days | year rain inch | year rain cm | year rain mm | year record high C | year record high F | year record low C | year record low F | year snow days | year snow inch | year snow cm | year snow mm | year snow depth cm | year snow depth inch | year snow depth mm | year sun | yeard sun | year uv }}<noinclude>
-- Implement [[Template:Weather box]].
{{Documentation}}
 
</noinclude>
local _precision = require('Module:Math')._precision
local function precision(text)
-- Input like 'Jan precipitation inch = trace' calls this with text = 'trace'
-- which would cause _precision to throw an error since it is not numeric.
-- Workaround: Return 0 as the precision if an error occurs.
local success, result = pcall(_precision, text)
if success then
return result
end
return 0
end
 
local function stripToNil(text)
-- If text is a non-empty string, return its trimmed content.
-- Otherwise, return nothing (text is an empty string or is not a string).
if type(text) == 'string' then
return text:match('(%S.-)%s*$')
end
end
 
local function isAny(args, suffix)
local months = { 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' }
for _, month in ipairs(months) do
if stripToNil(args[month .. suffix]) then
return true
end
end
end
 
local function makeLabel(args, options, is_first, base, what)
local first
if isAny(args, ' ' .. what .. ' cm') then
first = 'cm'
elseif isAny(args, ' ' .. what .. ' mm') then
first = 'mm'
else
first = (what:sub(1, 4) == 'snow' or
precision(args['Jan ' .. what .. ' inch'] or '0') < 1)
and 'cm'
or 'mm'
end
local second = 'inches'
if not stripToNil(args['metric first']) then
first, second = second, first
end
if is_first then
if options.wantSingleLine then
first = first .. ' (' .. second .. ')'
end
else
first = second
end
return base .. ' ' .. first
end
 
local function makeSources(frame, args)
local source1 = stripToNil(args.source) or stripToNil(args['source 1'])
local source2 = stripToNil(args['source 2']) or stripToNil(args['source2'])
local result = '|-\n|colspan="14" style="text-align:center;font-size:95%;"|'
local text
if source1 or source2 then
if source1 and source2 then
text = 'Source 1: ' .. source1 .. '\n' .. result .. 'Source 2: ' .. source2
else
text = 'Source: ' .. (source1 and source1 or source2)
end
else
text = frame:expandTemplate({ title = 'citation needed', args = {date = stripToNil(args.date)} })
end
return result .. text .. '\n|}'
end
 
local function wantSingle(parm)
--------------------------------------------------------------------------------
-- Result before July 2022 for single_line setting:
-- blank/omitted : separate table rows for metric and imperial (two rows)
-- N            : bug: only one row with either metric or imperial (not both)
--                      but heading like "cm (inches)"
-- Y/junk        : single row with both metric/imperial in same cell
--------------------------------------------------------------------------------
-- Intend changing in July 2022 so single_line=Y is the default and
-- need single_line=N for separate lines.
-- However, this release (1 July 2022) keeps blank/omitted as meaning "no"
-- so the other large changes can be tested before switching the default.
parm = (parm or ''):lower()
return not (parm == 'no' or parm == 'n' or parm == '')
end
 
local function getDefinitions(frame, args, options)
-- Return a list of tables or strings that define each row.
local function _if(parm, a, b)
return stripToNil(args[parm]) and a or b or ''
end
local function _ifset(parm, a)
return stripToNil(args[parm]) and args[parm] or a
end
local function _ifany(suffix)
return isAny(args, suffix)
end
local function _ifSingle(a, b)
return options.wantSingleLine and a or b or ''
end
local function _colorscheme(what, default)
return stripToNil(args[what .. ' colour']) or stripToNil(args[what .. ' color']) or default
end
local function _margin()
if stripToNil(args.margin) then
return 'margin:' .. args.margin .. ';'
end
return ''
end
local location = _if('location', args.location, '{{{location}}}')  -- show "{{{location}}}" to alert editor if parameter is blank
local navbarText
if not stripToNil(args.open) then
if stripToNil(args.name) then
local navbar = require('Module:Navbar')._navbar
navbarText = navbar({'Climate data for ' .. location, args.name, collapsible=1})
end
end
return {
 
----------- HEADER ----------
'{| class="wikitable ' .. _if('open', '', 'mw-collapsible' .. _if('collapsed', ' mw-collapsed')) ..
'" style="width:' .. _ifset('width', 'auto') ..
'; text-align:center; line-height:1.2em;' ..
_margin() .. '"' ..
_if('open',
'\n|+Climate data for ' .. location,
'\n|-' ..
'\n!colspan="14" | ' .. _if('name', navbarText, 'Climate data for ' .. location)
) ..
[=[
 
|-
!scope="row" |Month
!scope="col" |Jan
!scope="col" |Feb
!scope="col" |Mar
!scope="col" |Apr
!scope="col" |May
!scope="col" |Jun
!scope="col" |Jul
!scope="col" |Aug
!scope="col" |Sep
!scope="col" |Oct
!scope="col" |Nov
!scope="col" |Dec
!scope="col" style="border-left-width:medium" |Year
]=],
 
{---------- FIRST LINE MAXIMUM HUMIDEX ----------
WANTROW = _ifany(' maximum humidex') and (_ifset('metric first') or options.wantSingleLine),
mode = 'basic',
group_name = 'maximum humidex',
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Record high [[humidex]]',
annual_mode = 'max',
},
{---------- FIRST LINE RECORD HIGH TEMPERATURES ----------
WANTROW = _ifany(' record high C') or _ifany(' record high F'),
mode = 'temperature',
group_name = 'record high',
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Record high °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'max',
},
{---------- FIRST-SECOND LINE AVG MONTHLY MAXIMUM TEMPERATURES ----------
WANTROW = _ifany(' avg record high C') or _ifany(' avg record high F'),
mode = 'temperature',
group_name = 'avg record high',
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Mean maximum °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'max',
},
{---------- FIRST LINE MEAN DAILY MAXIMUM TEMPERATURES ----------
WANTROW = _ifany(' high C') or _ifany(' high F'),
mode = 'temperature',
group_name = 'high',
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Mean daily maximum °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'avg',
},
{---------- FIRST LINE DAILY MEAN TEMPERATURES ----------
WANTROW = _ifany(' mean C') or _ifany(' mean F'),
mode = 'temperature',
group_name = 'mean',
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Daily mean °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'avg',
},
{---------- FIRST LINE MEAN DAILY MINIMUM TEMPERATURES ----------
WANTROW = _ifany(' low C') or _ifany(' low F'),
mode = 'temperature',
group_name = 'low',
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Mean daily minimum °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'avg',
},
{---------- FIRST-SECOND LINE AVG MONTHLY MINIMUM TEMPERATURES ----------
WANTROW = _ifany(' avg record low C') or _ifany(' avg record low F'),
mode = 'temperature',
group_name = 'avg record low',
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Mean minimum °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'min',
},
{---------- FIRST LINE RECORD LOW TEMPERATURES ----------
WANTROW = _ifany(' record low C') or _ifany(' record low F'),
mode = 'temperature',
group_name = 'record low',
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Record low °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'min',
},
{---------- FIRST LINE MINIMUM WIND CHILL ----------
WANTROW = _ifany(' chill') and (_ifset('metric first') or options.wantSingleLine),
mode = 'basic',
group_name = 'chill',
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Record low [[wind chill]]',
annual_mode = 'min',
},
{---------- FIRST LINE TOTAL PRECIPITATION ----------
WANTROW = _ifany(' precipitation cm') or _ifany(' precipitation mm') or _ifany(' precipitation inch'),
mode = 'precipitation',
group_name = 'precipitation',
color_scheme = _colorscheme('precipitation', 'p'),
date_mode = true,
scale_factor = '1',
prefer_cm = precision(_ifset('Jan precipitation inch', '0')) < 1,
label = makeLabel(args, options, true, 'Average [[precipitation]]', 'precipitation'),
annual_mode = 'sum',
},
{---------- FIRST LINE RAINFALL ----------
WANTROW = _ifany(' rain cm') or _ifany(' rain mm') or _ifany(' rain inch'),
mode = 'precipitation',
group_name = 'rain',
color_scheme = _colorscheme('rain', 'p'),
date_mode = true,
scale_factor = '1',
prefer_cm = precision(_ifset('Jan rain inch', '0')) < 1,
label = makeLabel(args, options, true, 'Average rainfall', 'rain'),
annual_mode = 'sum',
},
{---------- FIRST LINE SNOWFALL ----------
WANTROW = _ifany(' snow cm') or _ifany(' snow mm') or _ifany(' snow inch'),
mode = 'precipitation',
group_name = 'snow',
prefer_cm = true,
color_scheme = _colorscheme('snow', 'p'),
date_mode = true,
scale_factor = '1',
label = makeLabel(args, options, true, 'Average snowfall', 'snow'),
annual_mode = 'sum',
},
{---------- FIRST LINE AVERAGE EXTREME SNOW DEPTH ----------
WANTROW = _ifany(' snow depth cm') or _ifany(' snow depth mm') or _ifany(' snow depth inch'),
mode = 'precipitation',
group_name = 'snow depth',
prefer_cm = true,
color_scheme = _colorscheme('snow', 'p'),
scale_factor = '0.2',
label = makeLabel(args, options, true, 'Average extreme snow depth', 'snow depth'),
annual_mode = 'max',
},
{---------- SECOND LINE MAXIMUM HUMIDEX ----------
WANTROW = not options.wantSingleLine and _ifany(' maximum humidex'),
mode = 'basic',
group_name = 'maximum humidex',
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = '[[Humidex]]',
annual_mode = 'max',
second_line = true,
},
{---------- SECOND LINE RECORD HIGH TEMPERATURES ----------
WANTROW = not options.wantSingleLine and (_ifany(' record high C') or _ifany(' record high F')),
mode = 'temperature',
group_name = 'record high',
second_line = true,
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Record high °' .. _if('metric first', 'F', 'C'),
annual_mode = 'max',
},
{---------- SECOND LINE MEAN DAILY MAXIMUM TEMPERATURES ----------
WANTROW = not options.wantSingleLine and (_ifany(' high C') or _ifany(' high F')),
mode = 'temperature',
group_name = 'high',
second_line = true,
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Mean daily maximum °' .. _if('metric first', 'F', 'C'),
annual_mode = 'avg',
},
{---------- SECOND LINE DAILY MEAN TEMPERATURES ----------
WANTROW = not options.wantSingleLine and (_ifany(' mean C') or _ifany(' mean F')),
mode = 'temperature',
group_name = 'mean',
second_line = true,
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Daily mean °' .. _if('metric first', 'F', 'C'),
show = _if('metric first', '2', '1'),
annual_mode = 'avg',
},
{---------- SECOND LINE MEAN DAILY MINIMUM TEMPERATURES ----------
WANTROW = not options.wantSingleLine and (_ifany(' low C') or _ifany(' low F')),
mode = 'temperature',
group_name = 'low',
second_line = true,
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Mean daily minimum °' .. _if('metric first', 'F', 'C'),
show = _if('metric first', '2', '1'),
annual_mode = 'avg',
},
{---------- SECOND LINE RECORD LOW TEMPERATURES ----------
WANTROW = not options.wantSingleLine and (_ifany(' record low C') or _ifany(' record low F')),
mode = 'temperature',
group_name = 'record low',
second_line = true,
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Record low °' .. _if('metric first', 'F', 'C'),
show = _if('metric first', '2', '1'),
annual_mode = 'min',
},
{---------- SECOND LINE MINIMUM WIND CHILL ----------
WANTROW = not options.wantSingleLine and (_ifany(' chill') and _if('metric first')),
mode = 'basic',
group_name = 'chill',
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = '[[Wind chill]]',
annual_mode = 'min',
},
{---------- SECOND LINE TOTAL PRECIPITATION ----------
WANTROW = not options.wantSingleLine and (_ifany(' precipitation cm') or _ifany(' precipitation mm') or _ifany(' precipitation inch')),
mode = 'precipitation',
group_name = 'precipitation',
second_line = true,
color_scheme = _colorscheme('precipitation', 'p'),
date_mode = true,
scale_factor = '1',
prefer_cm = precision(_ifset('Jan precipitation inch', '0')) < 1,
label = makeLabel(args, options, false, 'Average [[precipitation]]', 'precipitation'),
annual_mode = 'sum',
},
{---------- SECOND LINE RAINFALL ----------
WANTROW = not options.wantSingleLine and (_ifany(' rain cm') or _ifany(' rain mm') or _ifany(' rain inch')),
mode = 'precipitation',
group_name = 'rain',
second_line = true,
color_scheme = _colorscheme('rain', 'p'),
date_mode = true,
scale_factor = '1',
prefer_cm = precision(_ifset('Jan rain inch', '0')) < 1,
label = makeLabel(args, options, false, 'Average rainfall', 'rain'),
annual_mode = 'sum',
},
{---------- SECOND LINE SNOWFALL ----------
WANTROW = not options.wantSingleLine and (_ifany(' snow cm') or _ifany(' snow mm') or _ifany(' snow inch')),
mode = 'precipitation',
group_name = 'snow',
second_line = true,
prefer_cm = true,
color_scheme = _colorscheme('snow', 'p'),
date_mode = true,
scale_factor = '1',
label = makeLabel(args, options, false, 'Average snowfall', 'snow'),
annual_mode = 'sum',
},
{---------- SECOND LINE AVERAGE EXTREME SNOW DEPTH ----------
WANTROW = not options.wantSingleLine and (_ifany(' snow depth cm') or _ifany(' snow depth mm') or _ifany(' snow depth inch')),
mode = 'precipitation',
group_name = 'snow depth',
second_line = true,
prefer_cm = true,
color_scheme = _colorscheme('snow', 'p'),
scale_factor = '0.2',
label = makeLabel(args, options, false, 'Average extreme snow depth', 'snow depth'),
annual_mode = 'max',
},
{---------- PRECIPITATION DAYS ----------
WANTROW = _ifany(' precipitation days'),
mode = 'basic',
group_name = 'precipitation days',
color_scheme = _colorscheme('precip days', 'd'),
date_mode = true,
scale_factor = '1',
label = 'Average precipitation days' .. _if('unit precipitation days', ' <span style="font-size:90%;" class="nowrap">(≥ ' .. _ifset('unit precipitation days', '') .. ')</span>'),
annual_mode = 'sum',
},
{---------- RAINY DAYS ----------
WANTROW = _ifany(' rain days'),
mode = 'basic',
group_name = 'rain days',
color_scheme = _colorscheme('precip days', 'd'),
date_mode = true,
scale_factor = '1',
label = 'Average rainy days' .. _if('unit rain days', ' <span style="font-size:90%;" class="nowrap">(≥ ' .. _ifset('unit rain days', '') .. ')</span>'),
annual_mode = 'sum',
},
{---------- SNOWY DAYS ----------
WANTROW = _ifany(' snow days'),
mode = 'basic',
group_name = 'snow days',
color_scheme = _colorscheme('precip days', 'd'),
date_mode = true,
scale_factor = '1',
label = 'Average snowy days' .. _if('unit snow days', ' <span style="font-size:90%;" class="nowrap">(≥ ' .. _ifset('unit snow days', '') .. ')</span>'),
annual_mode = 'sum',
},
{---------- PERCENT RELATIVE HUMIDITY ----------
WANTROW = _ifany(' humidity'),
mode = 'basic',
group_name = 'humidity',
color_scheme = _colorscheme('humidity', 'h'),
scale_factor = '1',
label = 'Average [[relative humidity]] (%)' ..
_if('time day', ' <span style="font-size:90%;" class="nowrap">(at ' .. _ifset('time day', '') .. ')</span>') ..
_if('daily', ' <span style="font-size:90%;" class="nowrap">(daily average)</span>'),
annual_mode = 'avg',
},
{---------- AFTERNOON PERCENT RELATIVE HUMIDITY ----------
WANTROW = _ifany(' afthumidity'),
mode = 'basic',
group_name = 'afthumidity',
color_scheme = _colorscheme('humidity', 'h'),
scale_factor = '1',
label = 'Average afternoon [[relative humidity]] (%)' ..
_if('time day', ' <span style="font-size:90%;" class="nowrap">(at ' .. _ifset('time day', '') .. ')</span>') ..
_if('daily', ' <span style="font-size:90%;" class="nowrap">(daily average)</span>'),
annual_mode = 'avg',
},
{---------- FIRST LINE AVERAGE DEW POINT ----------
WANTROW = _ifany(' dew point C') or _ifany(' dew point F'),
mode = 'temperature',
group_name = 'dew point',
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Average [[dew point]] °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'avg',
},
{---------- SECOND LINE AVERAGE DEW POINT----------
WANTROW = not options.wantSingleLine and (_ifany(' dew point C') or _ifany(' dew point F')),
mode = 'temperature',
group_name = 'dew point',
second_line = true,
color_scheme = _colorscheme('temperature', 't'),
scale_factor = '1',
label = 'Average [[dew point]] °' .. _if('metric first', 'F', 'C'),
show = _if('metric first', '2', '1'),
annual_mode = 'avg',
},
{---------- MONTHLY SUNSHINE HOURS ----------
WANTROW = _ifany(' sun'),
mode = 'basic',
group_name = 'sun',
color_scheme = _colorscheme('sun', 's'),
date_mode = true,
scale_factor = '1',
label = 'Mean monthly [[Sunshine duration|sunshine hours]]',
annual_mode = 'sum',
},
{---------- DAILY SUNSHINE HOURS ----------
WANTROW = _ifany('d sun'),
mode = 'basic',
group_name = 'd sun',
color_scheme = _colorscheme('sun', 's'),
include_space = false,
scale_factor = '30.44',
label = 'Mean daily [[Sunshine duration|sunshine hours]]',
annual_mode = 'avg',
},
{---------- DAILY DAYLIGHT HOURS ----------
WANTROW = _ifany(' light'),
mode = 'basic',
group_name = ' light',
color_scheme = _colorscheme('sun', 's'),
include_space = false,
scale_factor = '30.44',
label = 'Mean daily [[Daytime|daylight hours]]',
annual_mode = 'avg',
},
{---------- PERCENT SUNSHINE ----------
WANTROW = _ifany(' percentsun'),
mode = 'basic',
group_name = 'percentsun',
color_scheme = _colorscheme('sun', 's'),
scale_factor = '7.2',
label = 'Percent [[Sunshine duration|possible sunshine]]',
annual_mode = 'avg',
},
{---------- ULTRAVIOLET INDEX ----------
WANTROW = _ifany(' uv'),
mode = 'basic',
group_name = 'uv',
color_scheme = _colorscheme('uv', 'u'),
scale_factor = '1',
label = 'Average [[ultraviolet index]]',
annual_mode = 'avg',
},
----------- SOURCES ----------
makeSources(frame, args),
}
end
 
local function main(frame)
local sandbox = frame:getTitle():find('sandbox', 1, true) and '/sandbox' or ''
local buildRow = require('Module:Weather box/row' .. sandbox)._buildRow
local args = frame:getParent().args
local options = {
wantSingleLine = wantSingle(args['single line']),
sandbox = sandbox,
}
local results = {}
for i, definition in ipairs(getDefinitions(frame, args, options)) do
local row
if type(definition) == 'string' then
row = definition
elseif definition.WANTROW then
row = buildRow(definition, args, options)
else
row = ''
end
results[i] = row
end
return '<div>\n'..table.concat(results)..'\n</div>'  -- prevent Scribunto from inserting a blank line before the table
end
 
return {
main = main,
}

Latest revision as of 14:01, 3 February 2025

Script error: No such module "High-use". Lua error in package.lua at line 80: module 'Module:Yesno' not found. Lua error in package.lua at line 80: module 'Module:Yesno' not found.

Usage[edit source]

This module is used by {{Weather box}}.

{{#invoke:Weather box|function_name}}


Climate data for Edmonton City Centre (Blatchford Field) Airport (1981−2010)
Month Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Year
Record high °C (°F) 11.7
(53.1)
14.0
(57.2)
23.9
(75.0)
31.1
(88.0)
32.3
(90.1)
34.9
(94.8)
34.6
(94.3)
34.5
(94.1)
33.9
(93.0)
28.6
(83.5)
21.7
(71.1)
16.7
(62.1)
34.9
(94.8)
Mean daily maximum °C (°F) −6.0
(21.2)
−2.7
(27.1)
2.2
(36.0)
11.2
(52.2)
17.5
(63.5)
21.0
(69.8)
23.1
(73.6)
22.6
(72.7)
17.1
(62.8)
10.4
(50.7)
0.0
(32.0)
−4.5
(23.9)
9.3
(48.7)
Daily mean °C (°F) −10.4
(13.3)
−7.6
(18.3)
−2.5
(27.5)
5.4
(41.7)
11.5
(52.7)
15.5
(59.9)
17.7
(63.9)
16.9
(62.4)
11.4
(52.5)
5.1
(41.2)
−4.1
(24.6)
−8.8
(16.2)
4.2
(39.6)
Mean daily minimum °C (°F) −14.8
(5.4)
−12.5
(9.5)
−7.2
(19.0)
−0.5
(31.1)
5.4
(41.7)
9.9
(49.8)
12.3
(54.1)
11.3
(52.3)
5.8
(42.4)
−0.2
(31.6)
−8.2
(17.2)
−13.1
(8.4)
−1.0
(30.2)
Record low °C (°F) −44.4
(−47.9)
−46.1
(−51.0)
−36.1
(−33.0)
−25.6
(−14.1)
−12.2
(10.0)
−1.1
(30.0)
0.6
(33.1)
−1.2
(29.8)
−11.7
(10.9)
−25.0
(−13.0)
−34.1
(−29.4)
−48.3
(−54.9)
−48.3
(−54.9)
Record low wind chill −52.8 −50.7 −44.6 −37.5 −14.5 0.0 0.0 −3.7 −13.3 −34.3 −50.2 −55.5 −55.5
Average precipitation mm (inches) 21.7
(0.85)
12.0
(0.47)
15.8
(0.62)
28.8
(1.13)
46.1
(1.81)
77.5
(3.05)
93.8
(3.69)
61.9
(2.44)
43.5
(1.71)
21.7
(0.85)
18.0
(0.71)
15.0
(0.59)
455.7
(17.94)
Average rainfall mm (inches) 1.3
(0.05)
0.76
(0.03)
1.7
(0.07)
14.5
(0.57)
40.7
(1.60)
77.5
(3.05)
93.8
(3.69)
61.8
(2.43)
42.4
(1.67)
10.9
(0.43)
1.6
(0.06)
0.73
(0.03)
347.8
(13.69)
Average snowfall cm (inches) 24.5
(9.6)
13.4
(5.3)
17.4
(6.9)
15.3
(6.0)
4.9
(1.9)
0.0
(0.0)
0.0
(0.0)
0.0
(0.0)
1.0
(0.4)
11.6
(4.6)
19.1
(7.5)
16.4
(6.5)
123.5
(48.6)
Average precipitation days (≥ 0.2 mm) 11.0 7.9 8.3 8.8 11.0 14.2 14.6 11.1 9.8 8.0 8.8 9.4 122.9
Average rainy days (≥ 0.2 mm) 1.1 0.83 1.4 5.9 10.5 14.2 14.6 11.1 9.6 5.6 1.5 0.75 77.3
Average snowy days (≥ 0.2 cm) 10.7 7.7 7.7 4.2 1.2 0.0 0.0 0.0 0.50 3.2 7.9 9.3 52.4
Average relative humidity (%) 65.2 61.2 56.5 42.9 40.4 48.2 52.6 51.4 50.1 50.5 64.7 65.4 54.1
Mean monthly sunshine hours 100.8 121.7 176.3 244.2 279.9 285.9 307.5 282.3 192.7 170.8 98.4 84.5 2,344.8
Percent possible sunshine 40.2 44.1 48.1 58.2 56.8 56.2 60.2 61.5 50.4 52.0 37.8 36.0 50.1
Average ultraviolet index 0 1 3 5 7 9 11 9 7 5 3 1 5
Source: Environment Canada,[1] Weather Atlas[2]

References

  1. Lua error in Module:Citation/CS1/Configuration at line 2088: attempt to index field '?' (a nil value).
  2. Lua error in Module:Citation/CS1/Configuration at line 2088: attempt to index field '?' (a nil value).

-- Implement [[Template:Weather box]].

local _precision = require('Module:Math')._precision
local function precision(text)
	-- Input like 'Jan precipitation inch = trace' calls this with text = 'trace'
	-- which would cause _precision to throw an error since it is not numeric.
	-- Workaround: Return 0 as the precision if an error occurs.
	local success, result = pcall(_precision, text)
	if success then
		return result
	end
	return 0
end

local function stripToNil(text)
	-- If text is a non-empty string, return its trimmed content.
	-- Otherwise, return nothing (text is an empty string or is not a string).
	if type(text) == 'string' then
		return text:match('(%S.-)%s*$')
	end
end

local function isAny(args, suffix)
	local months = { 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' }
	for _, month in ipairs(months) do
		if stripToNil(args[month .. suffix]) then
			return true
		end
	end
end

local function makeLabel(args, options, is_first, base, what)
	local first
	if isAny(args, ' ' .. what .. ' cm') then
		first = 'cm'
	elseif isAny(args, ' ' .. what .. ' mm') then
		first = 'mm'
	else
		first = (what:sub(1, 4) == 'snow' or
			precision(args['Jan ' .. what .. ' inch'] or '0') < 1)
				and 'cm'
				or 'mm'
	end
	local second = 'inches'
	if not stripToNil(args['metric first']) then
		first, second = second, first
	end
	if is_first then
		if options.wantSingleLine then
			first = first .. ' (' .. second .. ')'
		end
	else
		first = second
	end
	return base .. ' ' .. first
end

local function makeSources(frame, args)
	local source1 = stripToNil(args.source) or stripToNil(args['source 1'])
	local source2 = stripToNil(args['source 2']) or stripToNil(args['source2'])
	local result = '|-\n|colspan="14" style="text-align:center;font-size:95%;"|'
	local text
	if source1 or source2 then
		if source1 and source2 then
			text = 'Source 1: ' .. source1 .. '\n' .. result .. 'Source 2: ' .. source2
		else
			text = 'Source: ' .. (source1 and source1 or source2)
		end
	else
		text = frame:expandTemplate({ title = 'citation needed', args = {date = stripToNil(args.date)} })
	end
	return result .. text .. '\n|}'
end

local function wantSingle(parm)
	--------------------------------------------------------------------------------
	-- Result before July 2022 for single_line setting:
	-- blank/omitted : separate table rows for metric and imperial (two rows)
	-- N             : bug: only one row with either metric or imperial (not both)
	--                      but heading like "cm (inches)"
	-- Y/junk        : single row with both metric/imperial in same cell
	--------------------------------------------------------------------------------
	-- Intend changing in July 2022 so single_line=Y is the default and
	-- need single_line=N for separate lines.
	-- However, this release (1 July 2022) keeps blank/omitted as meaning "no"
	-- so the other large changes can be tested before switching the default.
	parm = (parm or ''):lower()
	return not (parm == 'no' or parm == 'n' or parm == '')
end

local function getDefinitions(frame, args, options)
	-- Return a list of tables or strings that define each row.
	local function _if(parm, a, b)
		return stripToNil(args[parm]) and a or b or ''
	end
	local function _ifset(parm, a)
		return stripToNil(args[parm]) and args[parm] or a
	end
	local function _ifany(suffix)
		return isAny(args, suffix)
	end
	local function _ifSingle(a, b)
		return options.wantSingleLine and a or b or ''
	end
	local function _colorscheme(what, default)
		return stripToNil(args[what .. ' colour']) or stripToNil(args[what .. ' color']) or default
	end
	local function _margin()
		if stripToNil(args.margin) then
			return 'margin:' .. args.margin .. ';'
		end
		return ''
	end
	local location = _if('location', args.location, '{{{location}}}')  -- show "{{{location}}}" to alert editor if parameter is blank
	local navbarText
	if not stripToNil(args.open) then
		if stripToNil(args.name) then
			local navbar = require('Module:Navbar')._navbar
			navbarText = navbar({'Climate data for ' .. location, args.name, collapsible=1})
		end
	end
	return {

----------- HEADER ----------
'{| class="wikitable ' .. _if('open', '', 'mw-collapsible' .. _if('collapsed', ' mw-collapsed')) ..
'" style="width:' .. _ifset('width', 'auto') ..
'; text-align:center; line-height:1.2em;' ..
_margin() .. '"' ..
_if('open',
	'\n|+Climate data for ' .. location,
	'\n|-' ..
	'\n!colspan="14" | ' .. _if('name', navbarText, 'Climate data for ' .. location)
) ..
[=[

|-
!scope="row" |Month
!scope="col" |Jan
!scope="col" |Feb
!scope="col" |Mar
!scope="col" |Apr
!scope="col" |May
!scope="col" |Jun
!scope="col" |Jul
!scope="col" |Aug
!scope="col" |Sep
!scope="col" |Oct
!scope="col" |Nov
!scope="col" |Dec
!scope="col" style="border-left-width:medium" |Year
]=],

{---------- FIRST LINE MAXIMUM HUMIDEX ----------
	WANTROW = _ifany(' maximum humidex') and (_ifset('metric first') or options.wantSingleLine),
	mode = 'basic',
	group_name = 'maximum humidex',
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Record high [[humidex]]',
	annual_mode = 'max',
},
{---------- FIRST LINE RECORD HIGH TEMPERATURES ----------
	WANTROW = _ifany(' record high C') or _ifany(' record high F'),
	mode = 'temperature',
	group_name = 'record high',
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Record high °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
	annual_mode = 'max',
},
{---------- FIRST-SECOND LINE AVG MONTHLY MAXIMUM TEMPERATURES ----------
	WANTROW = _ifany(' avg record high C') or _ifany(' avg record high F'),
	mode = 'temperature',
	group_name = 'avg record high',
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Mean maximum °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
	annual_mode = 'max',
},
{---------- FIRST LINE MEAN DAILY MAXIMUM TEMPERATURES ----------
	WANTROW = _ifany(' high C') or _ifany(' high F'),
	mode = 'temperature',
	group_name = 'high',
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Mean daily maximum °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
	annual_mode = 'avg',
},
{---------- FIRST LINE DAILY MEAN TEMPERATURES ----------
	WANTROW = _ifany(' mean C') or _ifany(' mean F'),
	mode = 'temperature',
	group_name = 'mean',
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Daily mean °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
	annual_mode = 'avg',
},
{---------- FIRST LINE MEAN DAILY MINIMUM TEMPERATURES ----------
	WANTROW = _ifany(' low C') or _ifany(' low F'),
	mode = 'temperature',
	group_name = 'low',
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Mean daily minimum °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
	annual_mode = 'avg',
},
{---------- FIRST-SECOND LINE AVG MONTHLY MINIMUM TEMPERATURES ----------
	WANTROW = _ifany(' avg record low C') or _ifany(' avg record low F'),
	mode = 'temperature',
	group_name = 'avg record low',
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Mean minimum °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
	annual_mode = 'min',
},
{---------- FIRST LINE RECORD LOW TEMPERATURES ----------
	WANTROW = _ifany(' record low C') or _ifany(' record low F'),
	mode = 'temperature',
	group_name = 'record low',
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Record low °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
	annual_mode = 'min',
},
{---------- FIRST LINE MINIMUM WIND CHILL ----------
	WANTROW = _ifany(' chill') and (_ifset('metric first') or options.wantSingleLine),
	mode = 'basic',
	group_name = 'chill',
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Record low [[wind chill]]',
	annual_mode = 'min',
},
{---------- FIRST LINE TOTAL PRECIPITATION ----------
	WANTROW = _ifany(' precipitation cm') or _ifany(' precipitation mm') or _ifany(' precipitation inch'),
	mode = 'precipitation',
	group_name = 'precipitation',
	color_scheme = _colorscheme('precipitation', 'p'),
	date_mode = true,
	scale_factor = '1',
	prefer_cm = precision(_ifset('Jan precipitation inch', '0')) < 1,
	label = makeLabel(args, options, true, 'Average [[precipitation]]', 'precipitation'),
	annual_mode = 'sum',
},
{---------- FIRST LINE RAINFALL ----------
	WANTROW = _ifany(' rain cm') or _ifany(' rain mm') or _ifany(' rain inch'),
	mode = 'precipitation',
	group_name = 'rain',
	color_scheme = _colorscheme('rain', 'p'),
	date_mode = true,
	scale_factor = '1',
	prefer_cm = precision(_ifset('Jan rain inch', '0')) < 1,
	label = makeLabel(args, options, true, 'Average rainfall', 'rain'),
	annual_mode = 'sum',
},
{---------- FIRST LINE SNOWFALL ----------
	WANTROW = _ifany(' snow cm') or _ifany(' snow mm') or _ifany(' snow inch'),
	mode = 'precipitation',
	group_name = 'snow',
	prefer_cm = true,
	color_scheme = _colorscheme('snow', 'p'),
	date_mode = true,
	scale_factor = '1',
	label = makeLabel(args, options, true, 'Average snowfall', 'snow'),
	annual_mode = 'sum',
},
{---------- FIRST LINE AVERAGE EXTREME SNOW DEPTH ----------
	WANTROW = _ifany(' snow depth cm') or _ifany(' snow depth mm') or _ifany(' snow depth inch'),
	mode = 'precipitation',
	group_name = 'snow depth',
	prefer_cm = true,
	color_scheme = _colorscheme('snow', 'p'),
	scale_factor = '0.2',
	label = makeLabel(args, options, true, 'Average extreme snow depth', 'snow depth'),
	annual_mode = 'max',
},
{---------- SECOND LINE MAXIMUM HUMIDEX ----------
	WANTROW = not options.wantSingleLine and _ifany(' maximum humidex'),
	mode = 'basic',
	group_name = 'maximum humidex',
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = '[[Humidex]]',
	annual_mode = 'max',
	second_line = true,
},
{---------- SECOND LINE RECORD HIGH TEMPERATURES ----------
	WANTROW = not options.wantSingleLine and (_ifany(' record high C') or _ifany(' record high F')),
	mode = 'temperature',
	group_name = 'record high',
	second_line = true,
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Record high °' .. _if('metric first', 'F', 'C'),
	annual_mode = 'max',
},
{---------- SECOND LINE MEAN DAILY MAXIMUM TEMPERATURES ----------
	WANTROW = not options.wantSingleLine and (_ifany(' high C') or _ifany(' high F')),
	mode = 'temperature',
	group_name = 'high',
	second_line = true,
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Mean daily maximum °' .. _if('metric first', 'F', 'C'),
	annual_mode = 'avg',
},
{---------- SECOND LINE DAILY MEAN TEMPERATURES ----------
	WANTROW = not options.wantSingleLine and (_ifany(' mean C') or _ifany(' mean F')),
	mode = 'temperature',
	group_name = 'mean',
	second_line = true,
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Daily mean °' .. _if('metric first', 'F', 'C'),
	show = _if('metric first', '2', '1'),
	annual_mode = 'avg',
},
{---------- SECOND LINE MEAN DAILY MINIMUM TEMPERATURES ----------
	WANTROW = not options.wantSingleLine and (_ifany(' low C') or _ifany(' low F')),
	mode = 'temperature',
	group_name = 'low',
	second_line = true,
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Mean daily minimum °' .. _if('metric first', 'F', 'C'),
	show = _if('metric first', '2', '1'),
	annual_mode = 'avg',
},
{---------- SECOND LINE RECORD LOW TEMPERATURES ----------
	WANTROW = not options.wantSingleLine and (_ifany(' record low C') or _ifany(' record low F')),
	mode = 'temperature',
	group_name = 'record low',
	second_line = true,
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Record low °' .. _if('metric first', 'F', 'C'),
	show = _if('metric first', '2', '1'),
	annual_mode = 'min',
},
{---------- SECOND LINE MINIMUM WIND CHILL ----------
	WANTROW = not options.wantSingleLine and (_ifany(' chill') and _if('metric first')),
	mode = 'basic',
	group_name = 'chill',
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = '[[Wind chill]]',
	annual_mode = 'min',
},
{---------- SECOND LINE TOTAL PRECIPITATION ----------
	WANTROW = not options.wantSingleLine and (_ifany(' precipitation cm') or _ifany(' precipitation mm') or _ifany(' precipitation inch')),
	mode = 'precipitation',
	group_name = 'precipitation',
	second_line = true,
	color_scheme = _colorscheme('precipitation', 'p'),
	date_mode = true,
	scale_factor = '1',
	prefer_cm = precision(_ifset('Jan precipitation inch', '0')) < 1,
	label = makeLabel(args, options, false, 'Average [[precipitation]]', 'precipitation'),
	annual_mode = 'sum',
},
{---------- SECOND LINE RAINFALL ----------
	WANTROW = not options.wantSingleLine and (_ifany(' rain cm') or _ifany(' rain mm') or _ifany(' rain inch')),
	mode = 'precipitation',
	group_name = 'rain',
	second_line = true,
	color_scheme = _colorscheme('rain', 'p'),
	date_mode = true,
	scale_factor = '1',
	prefer_cm = precision(_ifset('Jan rain inch', '0')) < 1,
	label = makeLabel(args, options, false, 'Average rainfall', 'rain'),
	annual_mode = 'sum',
},
{---------- SECOND LINE SNOWFALL ----------
	WANTROW = not options.wantSingleLine and (_ifany(' snow cm') or _ifany(' snow mm') or _ifany(' snow inch')),
	mode = 'precipitation',
	group_name = 'snow',
	second_line = true,
	prefer_cm = true,
	color_scheme = _colorscheme('snow', 'p'),
	date_mode = true,
	scale_factor = '1',
	label = makeLabel(args, options, false, 'Average snowfall', 'snow'),
	annual_mode = 'sum',
},
{---------- SECOND LINE AVERAGE EXTREME SNOW DEPTH ----------
	WANTROW = not options.wantSingleLine and (_ifany(' snow depth cm') or _ifany(' snow depth mm') or _ifany(' snow depth inch')),
	mode = 'precipitation',
	group_name = 'snow depth',
	second_line = true,
	prefer_cm = true,
	color_scheme = _colorscheme('snow', 'p'),
	scale_factor = '0.2',
	label = makeLabel(args, options, false, 'Average extreme snow depth', 'snow depth'),
	annual_mode = 'max',
},
{---------- PRECIPITATION DAYS ----------
	WANTROW = _ifany(' precipitation days'),
	mode = 'basic',
	group_name = 'precipitation days',
	color_scheme = _colorscheme('precip days', 'd'),
	date_mode = true,
	scale_factor = '1',
	label = 'Average precipitation days' .. _if('unit precipitation days', ' <span style="font-size:90%;" class="nowrap">(≥ ' .. _ifset('unit precipitation days', '') .. ')</span>'),
	annual_mode = 'sum',
},
{---------- RAINY DAYS ----------
	WANTROW = _ifany(' rain days'),
	mode = 'basic',
	group_name = 'rain days',
	color_scheme = _colorscheme('precip days', 'd'),
	date_mode = true,
	scale_factor = '1',
	label = 'Average rainy days' .. _if('unit rain days', ' <span style="font-size:90%;" class="nowrap">(≥ ' .. _ifset('unit rain days', '') .. ')</span>'),
	annual_mode = 'sum',
},
{---------- SNOWY DAYS ----------
	WANTROW = _ifany(' snow days'),
	mode = 'basic',
	group_name = 'snow days',
	color_scheme = _colorscheme('precip days', 'd'),
	date_mode = true,
	scale_factor = '1',
	label = 'Average snowy days' .. _if('unit snow days', ' <span style="font-size:90%;" class="nowrap">(≥ ' .. _ifset('unit snow days', '') .. ')</span>'),
	annual_mode = 'sum',
},
{---------- PERCENT RELATIVE HUMIDITY ----------
	WANTROW = _ifany(' humidity'),
	mode = 'basic',
	group_name = 'humidity',
	color_scheme = _colorscheme('humidity', 'h'),
	scale_factor = '1',
	label = 'Average [[relative humidity]] (%)' ..
		_if('time day', ' <span style="font-size:90%;" class="nowrap">(at ' .. _ifset('time day', '') .. ')</span>') ..
		_if('daily', ' <span style="font-size:90%;" class="nowrap">(daily average)</span>'),
	annual_mode = 'avg',
},
{---------- AFTERNOON PERCENT RELATIVE HUMIDITY ----------
	WANTROW = _ifany(' afthumidity'),
	mode = 'basic',
	group_name = 'afthumidity',
	color_scheme = _colorscheme('humidity', 'h'),
	scale_factor = '1',
	label = 'Average afternoon [[relative humidity]] (%)' ..
		_if('time day', ' <span style="font-size:90%;" class="nowrap">(at ' .. _ifset('time day', '') .. ')</span>') ..
		_if('daily', ' <span style="font-size:90%;" class="nowrap">(daily average)</span>'),
	annual_mode = 'avg',
},
{---------- FIRST LINE AVERAGE DEW POINT ----------
	WANTROW = _ifany(' dew point C') or _ifany(' dew point F'),
	mode = 'temperature',
	group_name = 'dew point',
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Average [[dew point]] °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
	annual_mode = 'avg',
},
{---------- SECOND LINE AVERAGE DEW POINT----------
	WANTROW = not options.wantSingleLine and (_ifany(' dew point C') or _ifany(' dew point F')),
	mode = 'temperature',
	group_name = 'dew point',
	second_line = true,
	color_scheme = _colorscheme('temperature', 't'),
	scale_factor = '1',
	label = 'Average [[dew point]] °' .. _if('metric first', 'F', 'C'),
	show = _if('metric first', '2', '1'),
	annual_mode = 'avg',
},
{---------- MONTHLY SUNSHINE HOURS ----------
	WANTROW = _ifany(' sun'),
	mode = 'basic',
	group_name = 'sun',
	color_scheme = _colorscheme('sun', 's'),
	date_mode = true,
	scale_factor = '1',
	label = 'Mean monthly [[Sunshine duration|sunshine hours]]',
	annual_mode = 'sum',
},
{---------- DAILY SUNSHINE HOURS ----------
	WANTROW = _ifany('d sun'),
	mode = 'basic',
	group_name = 'd sun',
	color_scheme = _colorscheme('sun', 's'),
	include_space = false,
	scale_factor = '30.44',
	label = 'Mean daily [[Sunshine duration|sunshine hours]]',
	annual_mode = 'avg',
},
{---------- DAILY DAYLIGHT HOURS ----------
	WANTROW = _ifany(' light'),
	mode = 'basic',
	group_name = ' light',
	color_scheme = _colorscheme('sun', 's'),
	include_space = false,
	scale_factor = '30.44',
	label = 'Mean daily [[Daytime|daylight hours]]',
	annual_mode = 'avg',
},
{---------- PERCENT SUNSHINE ----------
	WANTROW = _ifany(' percentsun'),
	mode = 'basic',
	group_name = 'percentsun',
	color_scheme = _colorscheme('sun', 's'),
	scale_factor = '7.2',
	label = 'Percent [[Sunshine duration|possible sunshine]]',
	annual_mode = 'avg',
},
{---------- ULTRAVIOLET INDEX ----------
	WANTROW = _ifany(' uv'),
	mode = 'basic',
	group_name = 'uv',
	color_scheme = _colorscheme('uv', 'u'),
	scale_factor = '1',
	label = 'Average [[ultraviolet index]]',
	annual_mode = 'avg',
},
----------- SOURCES ----------
makeSources(frame, args),
}
end

local function main(frame)
	local sandbox = frame:getTitle():find('sandbox', 1, true) and '/sandbox' or ''
	local buildRow = require('Module:Weather box/row' .. sandbox)._buildRow
	local args = frame:getParent().args
	local options = {
		wantSingleLine = wantSingle(args['single line']),
		sandbox = sandbox,
	}
	local results = {}
	for i, definition in ipairs(getDefinitions(frame, args, options)) do
		local row
		if type(definition) == 'string' then
			row = definition
		elseif definition.WANTROW then
			row = buildRow(definition, args, options)
		else
			row = ''
		end
		results[i] = row
	end
	return '<div>\n'..table.concat(results)..'\n</div>'  -- prevent Scribunto from inserting a blank line before the table
end

return {
	main = main,
}