-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsfparser.py
282 lines (210 loc) · 8.19 KB
/
sfparser.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import math
import os
import json
import re
def sfCoordsToNormalCoords(lat: str, lon: str):
outLat = 0
outLon = 0
latSections = lat.split(".")
outLat = float(latSections[0][1:])
outLat += float(latSections[1]) / 60
outLat += float(latSections[2]) / 3600
outLat += float(latSections[3]) / 3600000
if latSections[0][0] == "S": outLat *= -1
lonSections = lon.split(".")
outLon = float(lonSections[0][1:])
outLon += float(lonSections[1]) / 60
outLon += float(lonSections[2]) / 3600
outLon += float(lonSections[3]) / 3600000
if lonSections[0][0] == "W": outLon *= -1
return (round(outLat, 5), round(outLon, 5))
def parseFixes(path=None):
if path is None:
fixesPath = r"data\Navaids\FIXES_UK.txt"
with open(fixesPath, "r") as f:
lines = f.read().split("\n")
belgiumPath = r"data\Navaids\Fixes_Non-UK\FIXES_Belgium.txt"
with open(belgiumPath, "r") as f:
belgiumPath = f.read().split("\n")
for line in belgiumPath:
try:
lines.append(line)
except IndexError:
pass
netherlandsPath = r"data\Navaids\Fixes_Non-UK\FIXES_Netherlands.txt"
with open(netherlandsPath, "r") as f:
netherlandsPath = f.read().split("\n")
for line in netherlandsPath:
try:
lines.append(line)
except IndexError:
pass
ciczPath = r"data\Navaids\FIXES_CICZ.txt"
with open(ciczPath, "r") as f:
ciczPath = f.read().split("\n")
for line in ciczPath:
try:
lines.append(line)
except IndexError:
pass
vorPath = r"data\Navaids\VOR_UK.txt"
with open(vorPath, "r") as f:
vorLines = f.read().split("\n")
for line in vorLines:
try:
lines.append(" ".join([line.split(" ")[0], line.split(" ")[2], line.split(" ")[3]]))
except IndexError:
pass
vorNonukPath = r"data\Navaids\VOR_Non-UK.txt"
with open(vorNonukPath, "r") as f:
vorLines = f.read().split("\n")
for line in vorLines:
try:
lines.append(" ".join([line.split(" ")[0], line.split(" ")[2], line.split(" ")[3]]))
except IndexError:
pass
ndbPath = r"data\Navaids\NDB_All.txt"
with open(ndbPath, "r") as f:
ndbPath = f.read().split("\n")
for line in ndbPath:
if line.startswith(";") or line == "":
continue
line = line.replace(" ", " ")
try:
lines.append(" ".join([line.split(" ")[0], line.split(" ")[2], line.split(" ")[3]]))
except IndexError:
pass
else:
with open(path, "r") as f:
lines = f.read().split("\n")
fixes = {}
for line in lines:
line = line.strip()
if line.startswith(";") or line == "":
continue
line = line.split(" ")
fixes[line[0]] = sfCoordsToNormalCoords(line[1], line[2])
return fixes
def parseADs():
# get all foklders in Airports
ads = {}
for ad in os.listdir(r"data\Airports"):
adPath = rf"data\Airports\{ad}\Basic.txt"
with open(adPath, "r") as f:
lines = f.read().split("\n")
coordLine = lines[1].split(" ")
ads[ad] = sfCoordsToNormalCoords(coordLine[0], coordLine[1])
return ads
def parseATS():
with open("data/ATS Routes/ats.json") as f:
raw = f.read().replace("'", '"')
data = json.loads(raw)
outData = {}
for route, routeData in data.items():
outData[route] = []
for wpt in routeData["waypoints"]:
outData[route].append(wpt["name"])
return outData
def loadStarAndFixData(icao) -> tuple[dict[str, dict[str, str]], list[str]]:
with open(rf"data\Airports\{icao}\Stars.txt", "r") as f:
lines = f.read().split("\n")
starData = {}
for line in lines:
if line.startswith("STAR"):
currentStarData = line.split(":")
runway = currentStarData[2]
starName = currentStarData[3]
try:
starData[starName][runway] = currentStarData[4]
except KeyError:
starData[starName] = {runway: currentStarData[4]}
fixes = parseFixes(rf"data\Airports\{icao}\Fixes.txt")
return starData, fixes
def loadSidAndFixData(icao) -> tuple[dict[str, dict[str, str]], list[str]]:
with open(rf"data\Airports\{icao}\Sids.txt", "r") as f:
lines = f.read().split("\n")
starData = {}
for line in lines:
if line.startswith("SID"):
currentStarData = line.split(":")
runway = currentStarData[2]
starName = currentStarData[3]
try:
starData[starName][runway] = currentStarData[4]
except KeyError:
starData[starName] = {runway: currentStarData[4]}
fixes = parseFixes(rf"data\Airports\{icao}\Fixes.txt")
return starData, fixes
def loadRunwayData(icao) -> dict[str, list[str, tuple[float, float]]]:
with open(rf"data\Airports\{icao}\Runway.txt", "r") as f:
lines = f.read().split("\n")
runwayData = {}
for line in lines:
if line == "":
continue
runwayAIdentifier = line[:3].strip()
runwayBIdentifier = line[4:7].strip()
runwayAHeading = int(line[8:11])
runwayBHeading = int(line[12:15])
runwayALat = line[16:30]
runwayALon = line[31:45]
runwayBLat = line[46:60]
runwayBLon = line[61:75]
runwayACoords = sfCoordsToNormalCoords(runwayALat, runwayALon)
runwayBCoords = sfCoordsToNormalCoords(runwayBLat, runwayBLon)
runwayData[runwayAIdentifier] = [runwayAHeading, runwayACoords]
runwayData[runwayBIdentifier] = [runwayBHeading, runwayBCoords]
return runwayData
SECTOR_NAME_MAP = {
"AC West": "LON_W_CTR",
"Clacton": "LON_E_CTR",
"Daventry": "LON_M_CTR",
"Dover": "LON_D_CTR",
"Lakes": "LON_NW_CTR",
"North Sea": "LON_NE_CTR",
"Worthing": "LON_S_CTR",
"East": "LTC_E_CTR",
"Midlands": "LTC_M_CTR",
"North East": "LTC_NE_CTR",
"North West": "LTC_NW_CTR",
"South East": "LTC_SE_CTR",
"South West": "LTC_SW_CTR",
"PC NE": "MAN_NE_CTR",
"PC SE": "MAN_SE_CTR",
"PC W": "MAN_W_CTR",
"Deancross": "SCO_D_CTR",
"North": "SCO_N_CTR",
"Rathlin": "SCO_R_CTR",
"South": "SCO_S_CTR",
"West": "SCO_W_CTR",
"Antrim": "STC_A_CTR",
"Galloway": "STC_W_CTR",
"Talla": "STC_E_CTR"
}
IGNORE_SECTORS = ["Berry Head", "Brecon", "LUS", "Sector 23", "Maastricht UAC Delta", "Maastricht UAC Jever", "East"]
def loadSectorData():
folders = ["LON", "LTC", "MPC", "SCO", "STC"]
sectorData = {}
for folder in folders:
files = os.listdir(f"data/Static/{folder}")
for file in files:
if file.replace(".txt", "") in IGNORE_SECTORS:
continue
currentSectorData = []
with open(f"data/Static/{folder}/{file}", "r") as f:
data = f.read().split("\n")
prevCoords = None
for i, line in enumerate(data):
if i == 0:
continue
coordData = re.match(r"^[ \t]*(N.*? [EW].*?) (N.*? [EW]\d{3}\.\d{2}\.\d{2}\.\d{3})", line)
if coordData is not None:
if prevCoords != coordData.group(1) and prevCoords is not None: # smaller sector
currentSectorData.append(sfCoordsToNormalCoords(*prevCoords.split(" ")))
break
currentSectorData.append(sfCoordsToNormalCoords(*coordData.group(1).split(" ")))
prevCoords = coordData.group(2)
sectorData[SECTOR_NAME_MAP[file.replace(".txt", "")]] = currentSectorData
return sectorData
if __name__ == "__main__":
print(loadRunwayData("EGBB"))