-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelative-precision.py
More file actions
124 lines (96 loc) · 3.95 KB
/
relative-precision.py
File metadata and controls
124 lines (96 loc) · 3.95 KB
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
#!/usr/bin/env python
# coding: utf-8
"""Calculate GNSS errors precision respect to the railways reference."""
# Standard packages
import geopandas as gpd
from tqdm import tqdm
import warnings
import os
# Local Packages: Parser
from lib import nmea_df
# Local Packages: Tools
from lib import geolib as gl
from lib import gui_precision as gui
from lib import input_
# Ignore future warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
class GetGnssError:
"""Estimate the receiver errors which is the ortho distance 2 the rail."""
def __init__(self, filename: str):
"""Init."""
self.filename = filename
# Load rails als shapefile
self.rail_back = gpd.read_file(input_.rail_back)
self.rail_forth = gpd.read_file(input_.rail_forth)
def main(self):
"""Do all neccessary step."""
# ----------------------------------------------------------------
# Import NMEA as dataframe
# ----------------------------------------------------------------
print('\nData frame is uploading: ', self.filename)
df_full, valid = nmea_df(self.filename)
# ----------------------------------------------------------------
# Coordinate Transformation : MN95 projection
# ----------------------------------------------------------------
# Drop rows where there is no coordinates (No fix)
df = df_full.dropna(subset=['lat', 'lon'])
if 'sapcorda' in self.filename:
df = gl.mn95_projection(df, degmin=True, itrf14=True, std=True)
else:
df = gl.mn95_projection(df, degmin=True, std=True)
# Reinsert in df_full
df_full.loc[df.index] = df
# ----------------------------------------------------------------
# Split Track
# ----------------------------------------------------------------
track_index = gl.split_track(df_full)
# ----------------------------------------------------------------
# Mesure distance to the reference rail
# ----------------------------------------------------------------
# Loop over each track
loop = tqdm(total=100, position=0, desc='Calculating distances')
for track in track_index:
df, empty = gl.err2rail(df_full[track[0]:track[1]],
self.rail_back, self.rail_forth)
# Remove unsafe area
if not empty:
df = gl.rmv_unsafe_points(df)
if not df.empty:
gl.save_track(df, self.filename)
loop.update(1)
loop.close()
# --------------------------------------------------------------
# Save df_full as CSV
# ----------------------------------------------------------------
gl.save_all(df_full, self.filename)
class Batch:
"""Batch the GetGnssError() over all the .snmea files inside foldername."""
def __init__(self, foldername):
"""Init."""
self.foldername1 = foldername
print('Start process\n\n')
def scanDir(self):
"""Scan directory to search files with .snmea extension."""
for entry in os.scandir(self.foldername1):
if os.path.isdir(entry.path):
self.foldername1 = entry
self.scanDir()
if os.path.isfile(entry.path):
root, extension = os.path.splitext(entry.path)
if extension == '.snmea':
# print(f'File that is parsing {os.path.basename(entry)}: ')
tracks = GetGnssError(entry.path)
tracks.main()
app = gui.Interface()
app.title('Parse UBX messages')
app.mainloop()
filepath = app.output()
# Executre once for the selcted file
if os.path.isfile(filepath):
tracks = GetGnssError(filepath)
tracks.main()
# Iteration over all files in folder
if os.path.isdir(filepath):
batch = Batch(filepath)
batch.scanDir()
print('End of batch process')