Module:Tropical cyclone categories

MyWikiBiz, Author Your Legacy — Wednesday December 25, 2024
Jump to navigationJump to search

Template:Module rating

Usage

This module exports three functions for templates: p.color, p.name, and p.sortkey. It also provides p._color, p._name, and p._sortkey for use in other modules.

Color

Provides the color of the given tropical cyclone category code. This comes in the format of their raw hexidecimal code.

Code Output
<span style="padding:4px;border:1px solid black;background-color:#{{#invoke:Tropical cyclone categories|color|depression}}">depression</span> depression

Name

Provides the name of the given tropical cyclone category code. A optional basin argument can be provided as the second argument in order to slightly tweak the name of the category, if the given category definition supports it. This function is case-insensitive, and all non-alphanumeric characters are stripped.

Code Output
{{#invoke:Tropical cyclone categories|name|severe}} Severe tropical storm
{{#invoke:Tropical cyclone categories|name|spr - cYcL -s TorM}} Super cyclonic storm
{{#invoke:Tropical cyclone categories|name|cat5}} Category 5 tropical cyclone
{{#invoke:Tropical cyclone categories|name|cat5|WPac}} Category 5 super typhoon

Sortkey

The sortkey is a number that aids in sorting categories. Using the sortkey, it is possible to automatically sort a table of tropical cyclones given their category code. Due to the ambiguous nature of sortkeys, tables may be sorted incorrectly if values from other basins were used. For categories that span multiple basins, however, (e.g. depression and storm) they are given the lowest possible sortkeys in order to achieve maximum compatibility.

This sortkey is used in Template:T, a subtemplate of Template:T.

The sortkey format is as follows. Note that not all values between the given ranges were used. The arrangement of these were determined by their positions in the Template:T template.

Basin Sortkey range
Template:Gray 90000 to 99999
Atl/EPac/SAtl 80000 to 89999
WPac 60000 to 69999
Nio 50000 to 59999
Aus/Fiji 40000 to 49999
SWio 30000 to 39999
Historical 20000 to 29999
Global 0 to 9999

A demonstration of a sortable table using these sortkeys can be found below. Note that it does not use categories outside of its own basin (in this case, the Atl/EPac/SAtl basin) and the global range.

Category Sortkey Code
cat3 Template:Nts {{#invoke:Tropical cyclone categories|sortkey|cat3}}
cat1 Template:Nts {{#invoke:Tropical cyclone categories|sortkey|cat1}}
cat5 Template:Nts {{#invoke:Tropical cyclone categories|sortkey|cat5}}
cat4 Template:Nts {{#invoke:Tropical cyclone categories|sortkey|cat4}}
depression Template:Nts {{#invoke:Tropical cyclone categories|sortkey|depression}}
cat2 Template:Nts {{#invoke:Tropical cyclone categories|sortkey|cat2}}

Template:Ctop

Category Sortkey Code
typhoon Template:Nts {{#invoke:Tropical cyclone categories|sortkey|typhoon}}
potential Template:Nts {{#invoke:Tropical cyclone categories|sortkey|potential}}
cat5 Template:Nts {{#invoke:Tropical cyclone categories|sortkey|cat5}}
svrcyclstorm Template:Nts {{#invoke:Tropical cyclone categories|sortkey|svrcyclstorm}}
unknown Template:Nts {{#invoke:Tropical cyclone categories|sortkey|unknown}}
supertyphoon Template:Nts {{#invoke:Tropical cyclone categories|sortkey|supertyphoon}}
niodepression Template:Nts {{#invoke:Tropical cyclone categories|sortkey|niodepression}}

Template:Cbot

Compatibility

This module was designed to be backwards-compatible with Template:T as of revision 919481476 and Template:T as of revision 990905269. For category names that did not have matching colors, their colors have been guessed. For colors with aliases that were too vague (e.g. 5 for the color of cat5, but could have also meant Aus5 or shem5), the vague alias works only with p.color.

Compatibility with Template:T Compatibility with Template:T
Name Template:T Module:Tropical cyclone categories Equal?
cat5 Template:Storm colour ff6060 no
5 Template:Storm colour ff6060 no
cat4 Template:Storm colour ff8f20 no
4 Template:Storm colour ff8f20 no
cat3 Template:Storm colour ffc140 no
3 Template:Storm colour ffc140 no
cat2 Template:Storm colour ffe775 no
2 Template:Storm colour ffe775 no
cat1 Template:Storm colour ffffcc no
1 Template:Storm colour ffffcc no
storm Template:Storm colour 00faf4 no
TS Template:Storm colour 00faf4 no
subtropical Template:Storm colour 00faf4 no
subtropicalcyclone Template:Storm colour 00faf4 no
SS Template:Storm colour 00faf4 no
depression Template:Storm colour 5ebaff no
TD Template:Storm colour 5ebaff no
subdepression Template:Storm colour 5ebaff no
SD Template:Storm colour 5ebaff no
MD Template:Storm colour 5ebaff no
potential Template:Storm colour 80ccff no
PT Template:Storm colour 80ccff no
potentialtropicalcyclone Template:Storm colour 80ccff no
post-tropical Template:Storm colour cccccc no
POST Template:Storm colour cccccc no
Remnant low Template:Storm colour cccccc no
RL Template:Storm colour cccccc no
unknown Template:Storm colour c0c0c0 no
supertyphoon Template:Storm colour ff6060 no
STY Template:Storm colour ff6060 no
typhoon Template:Storm colour fdaf9a no
TY Template:Storm colour fdaf9a no
nwpsevere Template:Storm colour ccffff no
strong Template:Storm colour ccffff no
STS Template:Storm colour ccffff no
nwpstorm Template:Storm colour 00faf4 no
TS Template:Storm colour 00faf4 no
nwpdepression Template:Storm colour 5ebaff no
TD Template:Storm colour 5ebaff no
sprcyclstorm Template:Storm colour ff6060 no
SUCS Template:Storm colour ff6060 no
esvrcyclstorm Template:Storm colour ffc140 no
ESCS Template:Storm colour ffc140 no
vsvrcyclstorm Template:Storm colour ffffcc no
VSCS Template:Storm colour ffffcc no
svrcyclstorm Template:Storm colour ccffff no
SCS Template:Storm colour ccffff no
niocyclone Template:Storm colour 00faf4 no
cyclstorm Template:Storm colour 00faf4 no
CS Template:Storm colour 00faf4 no
deepdepression Template:Storm colour 5ebaff no
DD Template:Storm colour 5ebaff no
niodepression Template:Storm colour 80ccff no
D Template:Storm colour 80ccff no
nioland Template:Storm colour 80ccff no
landdepression Template:Storm colour 80ccff no
land Template:Storm colour 80ccff no
LD Template:Storm colour 80ccff no
Fiji5 Template:Storm colour ff6060 no
Aus5 Template:Storm colour ff6060 no
A5 Template:Storm colour ff6060 no
Fiji4 Template:Storm colour ffc140 no
Aus4 Template:Storm colour ffc140 no
A4 Template:Storm colour ffc140 no
Fiji3 Template:Storm colour ffffcc no
Aus3 Template:Storm colour ffffcc no
A3 Template:Storm colour ffffcc no
Fiji2 Template:Storm colour ccffff no
Aus2 Template:Storm colour ccffff no
A2 Template:Storm colour ccffff no
Fiji1 Template:Storm colour 00faf4 no
Aus1 Template:Storm colour 00faf4 no
A1 Template:Storm colour 00faf4 no
spdepression Template:Storm colour 5ebaff no
TD Template:Storm colour 5ebaff no
low Template:Storm colour 5ebaff no
TL Template:Storm colour 5ebaff no
disturbance Template:Storm colour 80ccff no
DI Template:Storm colour 80ccff no
vintense Template:Storm colour ff6060 no
VITC Template:Storm colour ff6060 no
intense Template:Storm colour ffc140 no
ITC Template:Storm colour ffc140 no
swiotc Template:Storm colour ffffcc no
TC Template:Storm colour ffffcc no
swiosts Template:Storm colour ccffff no
STS Template:Storm colour ccffff no
mtstorm Template:Storm colour 00faf4 no
sub Template:Storm colour 00faf4 no
MTS Template:Storm colour 00faf4 no
swiodepression Template:Storm colour 5ebaff no
swsubdep Template:Storm colour 5ebaff no
TD Template:Storm colour 5ebaff no
swiodisturbance Template:Storm colour 80ccff no
ZODW Template:Storm colour 80ccff no
subdisturbance Template:Storm colour 80ccff no
DI Template:Storm colour 80ccff no
shem5 Template:Storm colour ff6060 no
shem4 Template:Storm colour ffc140 no
shemsvrtc Template:Storm colour ffe775 no
shem3 Template:Storm colour ffffcc no
shemtc Template:Storm colour ffffcc no
shem2 Template:Storm colour ccffff no
shem1 Template:Storm colour 00faf4 no
shdepression Template:Storm colour 5ebaff no
shemdepression Template:Storm colour 5ebaff no
ET Template:Storm colour cccccc no
extratropical Template:Storm colour cccccc no
#default Template:Storm colour c0c0c0 no
Name Template:T Module:Tropical cyclone categories Equal?
depression Template:Tc nom list Tropical depression no
shemdepression Template:Tc nom list Tropical depression no
swiodepression Template:Tc nom list Tropical depression no
spdepression Template:Tc nom list Tropical depression no
nwpdepression Template:Tc nom list Tropical depression no
storm Template:Tc nom list Tropical storm no
nwpstorm Template:Tc nom list Tropical storm no
niodepression Template:Tc nom list Depression no
deepdepression Template:Tc nom list Deep depression no
cyclstorm Template:Tc nom list Cyclonic storm no
svrcyclstorm Template:Tc nom list Severe cyclonic storm no
vsvrcyclstorm Template:Tc nom list Very severe cyclonic storm no
esvrcyclstorm Template:Tc nom list Extremely severe cyclonic storm no
sprcyclstorm Template:Tc nom list Super cyclonic storm no
ZODW Template:Tc nom list Zone of disturbed weather no
subdisturbance Template:Tc nom list Subtropical disturbance no
moddepression Template:Tc nom list Moderate tropical depression no
mtstorm Template:Tc nom list Moderate tropical storm no
STS Template:Tc nom list Severe tropical storm no
swiosts Template:Tc nom list Severe tropical storm no
severedep Template:Tc nom list Severe tropical depression no
shemtc Template:Tc nom list Tropical cyclone no
swiotc Template:Tc nom list Tropical cyclone no
intense Template:Tc nom list Intense tropical cyclone no
vintense Template:Tc nom list Very intense tropical cyclone no
low Template:Tc nom list Tropical low no
sublow Template:Tc nom list Subtropical low no
Aus1 Template:Tc nom list Category 1 tropical cyclone no
Aus2 Template:Tc nom list Category 2 tropical cyclone no
Aus3 Template:Tc nom list Category 3 severe tropical cyclone no
Aus4 Template:Tc nom list Category 4 severe tropical cyclone no
Aus5 Template:Tc nom list Category 5 severe tropical cyclone no
shemsvrtc Template:Tc nom list Severe tropical cyclone no
disturbance Template:Tc nom list Tropical disturbance no
swiodisturbance Template:Tc nom list Tropical disturbance no
TY Template:Tc nom list Typhoon no
typhoon Template:Tc nom list Typhoon no
subdepression Template:Tc nom list Subtropical depression no
swsubdep Template:Tc nom list Subtropical depression no
subtropical Template:Tc nom list Subtropical storm no
subtropicalcyclone Template:Tc nom list Subtropical cyclone no
cat1 Template:Tc nom list Category 1 tropical cyclone no
cat2 Template:Tc nom list Category 2 tropical cyclone no
cat3 Template:Tc nom list Category 3 tropical cyclone no
cat4 Template:Tc nom list Category 4 tropical cyclone no
cat5 Template:Tc nom list Category 5 tropical cyclone no
cat1 (Atl) Template:Tc nom list Category 1 hurricane no
cat2 (Atl) Template:Tc nom list Category 2 hurricane no
cat3 (Atl) Template:Tc nom list Category 3 hurricane no
cat4 (Atl) Template:Tc nom list Category 4 hurricane no
cat5 (Atl) Template:Tc nom list Category 5 hurricane no
cat1 (EPac) Template:Tc nom list Category 1 hurricane no
cat2 (EPac) Template:Tc nom list Category 2 hurricane no
cat3 (EPac) Template:Tc nom list Category 3 hurricane no
cat4 (EPac) Template:Tc nom list Category 4 hurricane no
cat5 (EPac) Template:Tc nom list Category 5 hurricane no
cat1 (SAtl) Template:Tc nom list Category 1 hurricane no
cat2 (SAtl) Template:Tc nom list Category 2 hurricane no
cat3 (SAtl) Template:Tc nom list Category 3 hurricane no
cat4 (SAtl) Template:Tc nom list Category 4 hurricane no
cat5 (SAtl) Template:Tc nom list Category 5 hurricane no
cat1 (WPac) Template:Tc nom list Category 1 typhoon no
cat2 (WPac) Template:Tc nom list Category 2 typhoon no
cat3 (WPac) Template:Tc nom list Category 3 typhoon no
cat4 (WPac) Template:Tc nom list Category 4 typhoon no
cat5 (WPac) Template:Tc nom list Category 5 super typhoon no
potential Template:Tc nom list Potential tropical cyclone no
extratropical Template:Tc nom list Extratropical cyclone no
STY Template:Tc nom list Category 4 super typhoon no
MD Template:Tc nom list Monsoon depression no
#default Template:Tc nom list Unknown strength tropical cyclone no



local p = {}

-- Define categories

-- All sortkeys have been guessed. They may be changed by common sense
-- or consensus at [[Wikipedia talk:WikiProject Tropical cyclones]]
local cats = {
	severe = {
		color = "ccffff",
		name = "Severe tropical storm",
		sortkey = 120
	},
	mtstorm = {
		 color = "00faf4", -- {{storm colour}} did not support. Value guessed.
		 name = "Moderate tropical storm",
		 sortkey = 105
	},
	storm = {
		color = "00faf4",
		name = "Tropical storm",
		sortkey = 100
	},
	severedep = {
		color = "5ebaff", -- {{storm colour}} did not support. Value guessed.
		name = "Severe tropical depression",
		sortkey = 120
	},
	moddepression = {
		color = "5ebaff", -- {{storm colour}} did not support. Value guessed.
		name = "Moderate tropical depression",
		sortkey = 95
	},
	depression = {
		color = "5ebaff",
		name = "Tropical depression",
		sortkey = 90
	},
	disturbance = {
		color = "80ccff",
		name = "Tropical disturbance",
		sortkey = 80
	},
	subtropicalcyclone = {
		color = "00faf4",
		name = "Subtropical cyclone",
		sortkey = 70
	},
	subtropical = {
		color = "00faf4",
		name = "Subtropical storm",
		sortkey = 65
	},
	subdepression = {
		color = "5ebaff",
		name = "Subtropical depression",
		sortkey = 60
	},
	subdisturbance = {
		color = "80ccff",
		name = "Subtropical disturbance",
		sortkey = 55
	},
	extratropical = {
		color = "cccccc",
		name = "Extratropical cyclone",
		sortkey = 50
	},
	monsoondepression = {
		color = "5ebaff",
		name = "Monsoon depression",
		sortkey = 30
	},
	potential = {
		color = "80ccff",
		name = "Potential tropical cyclone",
		sortkey = 25
	},
	posttropical = {
		color = "cccccc",
		name = "Post-tropical depression",
		sortkey = 70
	},
	remnant = {
		color = "cccccc",
		name = "Post-tropical depression",
		sortkey = 70
	},
	unknown = {
		color = "c0c0c0",
		name = "Unknown strength tropical cyclone",
		sortkey = 0
	},
	cat5 = {
		color = "ff6060",
		name = {
			Atl = "Category 5 hurricane",
			EPac = "Category 5 hurricane",
			SAtl = "Category 5 hurricane",
			WPac = "Category 5 super typhoon",
			default = "Category 5 tropical cyclone"
		},
		sortkey = 80010
	},
	cat4 = {
		color = "ff8f20",
		name = {
			Atl = "Category 4 hurricane",
			EPac = "Category 4 hurricane",
			SAtl = "Category 4 hurricane",
			WPac = "Category 4 typhoon",
			default = "Category 4 tropical cyclone"
		},
		sortkey = 80008
	},
	cat3 = {
		color = "ffc140",
		name = {
			Atl = "Category 3 hurricane",
			EPac = "Category 3 hurricane",
			SAtl = "Category 3 hurricane",
			WPac = "Category 3 typhoon",
			default = "Category 3 tropical cyclone"
		},
		sortkey = 80006
	},
	cat2 = {
		color = "ffe775",
		name = {
			Atl = "Category 2 hurricane",
			EPac = "Category 2 hurricane",
			SAtl = "Category 2 hurricane",
			WPac = "Category 2 typhoon",
			default = "Category 2 tropical cyclone"
		},
		sortkey = 80004
	},
	cat1 = {
		color = "ffffcc",
		name = {
			Atl = "Category 1 hurricane",
			EPac = "Category 1 hurricane",
			SAtl = "Category 1 hurricane",
			WPac = "Category 1 typhoon",
			default = "Category 1 tropical cyclone"
		},
		sortkey = 80002
	},
	supertyphoon = {
		color = "ff6060",
		name = "Category 4 super typhoon",
		sortkey = 80015
	},
	typhoon = {
		color = "fdaf9a",
		name = "Typhoon",
		sortkey = 60010
	},
	sprcyclstorm = {
		color = "ff6060",
		name = "Super cyclonic storm",
		sortkey = 60020
	},
	esvrcyclstorm = {
		color = "ffc140",
		name = "Extremely severe cyclonic storm",
		sortkey = 50015
	},
	vsvrcyclstorm = {
		color = "ffffcc",
		name = "Very severe cyclonic storm",
		sortkey = 50010
	},
	svrcyclstorm = {
		color = "ccffff",
		name = "Severe cyclonic storm",
		sortkey = 50008
	},
	niocyclone = {
		color = "00faf4",
		name = "Cyclonic storm",
		sortkey = 50006
	},
	deepdepression = {
		color = "5ebaff",
		name = "Deep depression",
		sortkey = 50002
	},
	niodepression = {
		color = "80ccff",
		name = "Depression",
		sortkey = 50001
	},
	nioland = {
		color = "80ccff",
		name = "Land depression",
		sortkey = 50000
	},
	aus5 = {
		color = "ff6060",
		name = "Category 5 severe tropical cyclone",
		sortkey = 40015
	},
	aus4 = {
		color = "ffc140",
		name = "Category 4 severe tropical cyclone",
		sortkey = 40013
	},
	aus3 = {
		color = "ffffcc",
		name = "Category 3 severe tropical cyclone",
		sortkey = 40010
	},
	aus2 = {
		color = "ccffff",
		name = "Category 2 tropical cyclone",
		sortkey = 40008
	},
	aus1 = {
		color = "00faf4",
		name = "Category 1 tropical cyclone",
		sortkey = 40006
	},
	low = {
		color = "5ebaff",
		name = "Tropical low",
		sortkey = 40002
	},
	sublow = {
		color = "5ebaff",
		name = "Subtropical low",
		sortkey = 40000
	},
	vintense = {
		color = "ff6060",
		name = "Very intense tropical cyclone",
		sortkey = 30010
	},
	intense = {
		color = "ffc140",
		name = "Intense tropical cyclone",
		sortkey = 30008
	},
	tropicalcyclone = {
		color = "ffffcc",
		name = "Tropical cyclone",
		sortkey = 30006
	},
	mstorm = {
		color = "00faf4",
		name = "Moderate tropical storm"
	},
	zodw = {
		color = "80ccff",
		name = "Zone of disturbed weather",
		sortkey = 30000
	},
	shemsvrtc = {
		color = "ffe775",
		name = "Severe tropical cyclone",
		sortkey = 20020
	},
	shem5 = {
		color = "ff6060",
		name = "Severe tropical cyclone",
		sortkey = 20010
	},
	shem4 = {
		color = "ffc140",
		name = "Tropical cyclone",
		sortkey = 20008
	},
	shem2 = {
		color = "ccffff",
		name = "Tropical cyclone",
		sortkey = 20008
	},
	shem1 = {
		color = "00faf4",
		name = "Tropical cyclone",
		sortkey = 20008
	}
}

-- Default

local defaultCategory = "unknown"

-- Define aliases

-- All non-alphanumeric characters are already stripped, and the string is
-- already set to lowercase, so additional aliases for those are no longer
-- required.

cats["sty"] = cats["supertyphoon"]
cats["nwpsevere"] = cats["severe"]
cats["strong"] = cats["severe"]
cats["swiosts"] = cats["severe"]
cats["sts"] = cats["severe"]
cats["severets"] = cats["severe"]
cats["ty"] = cats["typhoon"]
cats["td"] = cats["depression"]
cats["ts"] = cats["storm"]
cats["nwpstorm"] = cats["storm"]
cats["d"] = cats["depression"]
cats["spdepression"] = cats["depression"]
cats["shdepression"] = cats["depression"]
cats["shemdepression"] = cats["depression"]
cats["swiodepression"] = cats["depression"]
cats["spdepression"] = cats["depression"]
cats["nwpdepression"] = cats["depression"]
cats["swsubdep"] = cats["subdepression"]
cats["sd"] = cats["subdepression"]
cats["ss"] = cats["subtropical"]
cats["et"] = cats["extratropical"]
cats["md"] = cats["monsoondepression"]
cats["pt"] = cats["potential"]
cats["potentialtropicalcyclone"] = cats["potential"]
cats["potentialtropicalcyclone"] = cats["potential"]
cats["post"] = cats["remnant"]
cats["remnantlow"] = cats["remnant"]
cats["rl"] = cats["remnant"]
cats["sucs"] = cats["sprcyclstorm"]
cats["escs"] = cats["esvrcyclstorm"]
cats["vscs"] = cats["vsvrcyclstorm"]
cats["scs"] = cats["svrcyclstorm"]
cats["cs"] = cats["niocyclone"]
cats["dd"] = cats["deepdepression"]
cats["cyclstorm"] = cats["niocyclone"]
cats["landdepression"] = cats["nioland"]
cats["land"] = cats["nioland"]
cats["ld"] = cats["nioland"]
cats["fiji5"] = cats["aus5"]
cats["fiji4"] = cats["aus4"]
cats["fiji3"] = cats["aus3"]
cats["fiji2"] = cats["aus2"]
cats["fiji1"] = cats["aus1"]
cats["tl"] = cats["low"]
cats["di"] = cats["disturbance"]
cats["swiodisturbance"] = cats["disturbance"]
cats["mts"] = cats["mstorm"]
cats["sub"] = cats["mstorm"]
cats["vitc"] = cats["vintense"]
cats["itc"] = cats["intense"]
cats["tc"] = cats["tropicalcyclone"]
cats["swiotc"] = cats["tropicalcyclone"]
cats["shem3"] = cats["tropicalcyclone"]
cats["shemtc"] = cats["tropicalcyclone"]

-- Ambiguous color names. This is because {[storm colour}} itself is extremely
-- ambiguous. This is also used to override the output of some codes.
local colors = {
	["5"] = cats["cat5"].color,
	["4"] = cats["cat4"].color,
	["3"] = cats["cat3"].color,
	["2"] = cats["cat2"].color,
	["1"] = cats["cat1"].color,
	["d"] = "80ccff",
	["a5"] = cats["aus5"].color,
	["a4"] = cats["aus4"].color,
	["a3"] = cats["aus3"].color,
	["a2"] = cats["aus2"].color,
	["a1"] = cats["aus1"].color
}

function p.color(frame)
	return p._color(frame.args[1])
end

function p.name(frame)
	return p._name(frame.args[1], frame.args[2])
end

function p.sortkey(frame)
	return p._sortkey(frame.args[1])
end

function p._color(colorCode)
	-- This looks confusing, but it's actually nested ternaries (for nil checks)
	local color = string.len(colorCode) ~= 0 and 
		string.gsub(string.lower(colorCode), "[^%w]", "")
		or defaultCategory;
		
	return colors[color] or ((cats[color] or cats[defaultCategory]).color)
end

function p._name(category, basin)
	local name_def = (cats[
		string.len(category) ~= 0 and 
			string.gsub(string.lower(category), "[^%w]", "")
			or defaultCategory
	] or cats[defaultCategory]).name
	return type(name_def) == "table" and 
		(
			name_def[basin] 
			or name_def["default"] 
			or error("No default name for basin-based category name.")
		) 
		or name_def
end

function p._sortkey(category)
	-- This looks confusing, but it's actually nested ternaries (for nil checks)
	return (cats[
		string.len(category) ~= 0 and 
			string.gsub(string.lower(category), "[^%w]", "")
			or defaultCategory
	] or cats[defaultCategory]).sortkey
end

return p