Skip to content

Instantly share code, notes, and snippets.

@7yl4r
Last active May 27, 2025 17:21
Show Gist options
  • Save 7yl4r/6860faa0e5877566bd05c7a78fbd9f53 to your computer and use it in GitHub Desktop.
Save 7yl4r/6860faa0e5877566bd05c7a78fbd9f53 to your computer and use it in GitHub Desktop.
import re
def canonical_station_name(station_name):
station_aliases = {
"1": ["1"],
"2": ["2"],
"3": ["3"],
"4": ["4"],
"5": ["5"],
"5.5": ["5.5"],
"6": ["6"],
"6.5": ["6.5"],
"7": ["7"],
"8": ["8"],
"9": ["9"],
"9.5": ["9.5"],
"10": ["10"],
"11": ["11"],
"12": ["12"],
"13": ["13"],
"14": ["14"],
"15": ["15"],
"15.5": ["15.5"],
"16": ["16"],
"17": ["17"],
"18": ["18"],
"19": ["19"],
"20": ["20"],
"21/LK": ["21/LK", "LK", "21"],
"21.5": ["21.5"],
"22": ["22"],
"22.5": ["22.5"],
"23": ["23"],
"24": ["24"],
"WS": ["WS"],
"30": ["30"],
"30.5": ["30.5"],
"31": ["31"],
"32": ["32"],
"33": ["33"],
"34": ["34"],
"39": ["39"],
"40": ["40"],
"41": ["41"],
"42": ["42"],
"45": ["45"],
"46": ["46"],
"47": ["47"],
"48": ["48"],
"49": ["49"],
"50": ["50"],
"51": ["51"],
"52": ["52"],
"53": ["53"],
"54": ["54"],
"55": ["55"],
"56": ["56"],
"57": ["57"],
"57.1": ["57.1"],
"57.2": ["57.2"],
"57.3": ["57.3"],
"58": ["58"],
"59": ["59"],
"60": ["60"],
"61": ["61"],
"62": ["62"],
"63": ["63"],
"64": ["64"],
"65": ["65"],
"66": ["66"],
"67": ["67"],
"68": ["68"],
"69": ["69"],
"70": ["70"],
"AMI1": ["AMI1"],
"AMI2": ["AMI2"],
"AMI3": ["AMI3"],
"AMI4": ["AMI4"],
"AMI5": ["AMI5"],
"AMI6": ["AMI6"],
"AMI7": ["AMI7"],
"AMI8": ["AMI8"],
"AMI9": ["AMI9"],
"BG1": ["BG1"],
"BG2": ["BG2"],
"BG3": ["BG3"],
"BG4": ["BG4"],
"CAL1": ["CAL1"],
"CAL2": ["CAL2"],
"CAL3": ["CAL3"],
"CAL4": ["CAL4"],
"CAL5": ["CAL5"],
"CAL6": ["CAL6"],
"CW1": ["CW1"],
"CW2": ["CW2"],
"CW3": ["CW3"],
"CW4": ["CW4"],
"EB1": ["EB1"],
"EB2": ["EB2"],
"EK_IN": ["EK_IN"],
"EK_MID": ["EK_MID"],
"EK_OFF": ["EK_OFF"],
"GP5": ["GP5"],
"KW1": ["KW1"],
"KW2": ["KW2"],
"KW3": ["KW3"],
"KW4": ["KW4"],
"L1": ["L1"],
"L3": ["L3"],
"L5": ["L5"],
"L7": ["L7"],
"L9": ["L9"],
"MR": ["MR"],
"RP1": ["RP1"],
"RP2": ["RP2"],
"RP3": ["RP3"],
"RP4": ["RP4"],
"TB1": ["TB1"],
"TB2": ["TB2"],
"TB3": ["TB3"],
"TB4": ["TB4"],
"TB5": ["TB5"],
"TB6": ["TB6"],
"TB7": ["TB7"],
"TB8": ["TB8"],
"TB9": ["TB9"],
"TB10": ["TB10"],
"UK_IN": ["UK_IN"],
"UK_MID": ["UK_MID"],
"UK_OFF": ["UK_OFF"],
"V1": ["V1"],
"V2": ["V2"],
"V3": ["V3"],
"V4": ["V4"],
"V5": ["V5"],
"V6": ["V6"],
"V7": ["V7"],
"V8": ["V8"],
"V9": ["V9"],
"ROME5": ["ROME5"],
"CW7": ["CW7"],
"BG7": ["BG7"],
"LK": ["LK"],
"BG10": ["BG10"],
"BG11": ["BG11"],
"BG12": ["BG12"],
"BG13": ["BG13"],
"BG14": ["BG14"],
"BG15": ["BG15"],
"BG15B": ["BG15B"],
"BG16": ["BG16"],
"BG17": ["BG17"],
"BG17B": ["BG17B"],
"BG18": ["BG18"],
"BG20": ["BG20"],
"BG6": ["BG6"],
"BG7B": ["BG7B"],
"BG8": ["BG8"],
"BG9": ["BG9"],
"BG19": ["BG19"],
"CW5": ["CW5"],
"CW6": ["CW6"],
"PLUME": ["PLUME"],
"ROME4": ["ROME4"],
"BLANK": ["BLANK"]
}
name = station_name.strip()
# normalize by stripping leading zeros
normalized = name.lstrip("0")
for canonical, aliases in station_aliases.items():
for alias in aliases:
if normalized == alias.lstrip("0"):
return canonical
raise ValueError(f"Station name '{station_name}' is not recognized.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment