-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOutputFile.py
140 lines (119 loc) · 4.08 KB
/
OutputFile.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
import CoordTrans as ct
import numpy as np
# Columns of the tracker output file
TRACK_ID = 0
TIME = 1
SENSOR = 2
BEACON = 3
POS_LAT = 4
POS_LON = 5
POS_ALT = 6
VEL_E = 7
VEL_N = 8
VEL_U = 9
SYS_X = 10
SYS_Y = 11
SYS_Z = 12
FUSED_TRACK_ID = 21
TRACK_TYPE = 22
BEACON_CODE = 23
ICAO = 24
MEAS_RNG = 31
MEAS_AZI = 32
MEAS_ELE = 33
MEAS_ALT = 34
MEAS_RNG_RATE = 35
EST_RNG = 39
EST_AZI = 40
EST_ELE = 41
MEAS_OWN_FRAME_RNG = 36
MEAS_OWN_FRAME_AZI = 37
MEAS_OWN_FRAME_ALT = 38
EST_OWN_FRAME_RNG = 39
EST_OWN_FRAME_AZI = 40
OWN_LAT = 44
OWN_LON = 45
OWN_ALT = 46
OWN_VEL_E = 47
OWN_VEL_N = 48
OWN_VEL_U = 49
RES_RNG = 52
RES_AZI = 53
RES_ELE = 54
RES_RNG_RATE = 55
SENSOR_TRACK = 1
OWN = 1
RADAR = 2
ADSB = 3
AST = 4
key_column_map = { 'time' : ( TIME, ),
'beacon' : ( BEACON, ),
'track id' : ( TRACK_ID, ),
'geodetic position' : ( POS_LAT, POS_LON, POS_ALT ),
'enu velocity' : ( VEL_E, VEL_N, VEL_U ),
'system position' : ( SYS_X, SYS_Y, SYS_Z ),
'ownship position' : ( OWN_LAT, OWN_LON, OWN_ALT ),
'ownship velocity' : ( OWN_VEL_E, OWN_VEL_N, OWN_VEL_U ),
'radar measurements' : ( MEAS_RNG, MEAS_AZI, MEAS_ELE, MEAS_RNG_RATE ),
'ast measurements' : ( MEAS_RNG, MEAS_AZI, MEAS_ALT ),
'residuals' : (RES_RNG, RES_AZI, RES_ELE, RES_RNG_RATE) }
sensor_map = { 'radar' : set( [ RADAR, ] ),
'adsb' : set( [ ADSB, ] ),
'ast' : set( [ AST, ] ),
'any' : set( [ RADAR, ADSB, AST ] ) }
def read( filename ) :
with open( filename, 'r' ) as file :
lines = file.readlines()
file.close()
if '\n' in lines :
lines.remove( '\n' )
data = [ [ float( x ) for x in line.strip().split( ',' ) ] for line in lines ]
#return np.array( data[ :-1 ] , dtype = float )
return [ [ float( x ) for x in line.strip().split( ',' ) ] for line in lines ]
def get( data, **kwargs ) :
if kwargs is not None :
for key, value in kwargs.iteritems() :
if key == 'item' :
item = value
if item == 'measurements' :
item = self.sensor + ' ' + item;
return data[ :, key_column_map[ item ] ]
class Track( object ) :
dataIsGood = False
def __init__( self, data, **kwargs ) :
track_type = SENSOR_TRACK
track_id = []
sensor = []
beacon = []
if kwargs is not None :
for key, value in kwargs.iteritems() :
if key == 'sensor' :
sensor = value
data = [ x for x in data if x[ SENSOR ] in sensor_map[ sensor ] ]
if key == 'beacon' :
beacon = value
data = [ x for x in data if x[ BEACON ] == beacon ]
if key == 'track_type' :
track_type = value
if key == 'track_id' :
track_id = value
data = [ x for x in data if x[ TRACK_ID ] == track_id ]
data = [ x for x in data if x[ TRACK_TYPE ] == track_type ]
#data = data[ ( data[ :, BEACON ] == beacon ) * ( data[ :, TRACK_TYPE ] == SENSOR_TRACK ), : ]
#f = np.array( [ True if x in sensor_map[ sensor ] else False for x in data[ :, SENSOR ] ] )
#data = data[ f ]
if data :
data = np.array( data )
self.dataIsGood = True
self.sensor = sensor
self.beacon = beacon
self.time = get( data, item = 'time' )
self.pos_geod = get( data, item = 'geodetic position' )
self.vel_enu = get( data, item = 'enu velocity' )
self.pos_sys = get( data, item = 'system position' )
self.own_pos_geod = get( data, item = 'ownship position' )
self.own_vel_enu = get( data, item = 'ownship velocity' )
self.track_id = get( data, item = 'track id' )
#if sensor == 'radar' :
# self.residuals = get( data, item = 'residuals' )
# self.measurements = get( data, item = 'radar measurements' )