implementation of uncertainty values from csv files

This commit is contained in:
JoseAndresMR
2018-06-26 16:22:42 +02:00
parent 6db5ea8023
commit 715d0a3c66
9 changed files with 241 additions and 135 deletions

View File

@@ -19,6 +19,7 @@ The wrapper for decoding ADS-B messages
from __future__ import absolute_import, print_function, division
from pyModeS.decoder import common
import pandas as pd # JoseAndresMR: I suppose you already have pandas in a common function, just change all occurrencies
# from pyModeS.decoder.bds import bds05, bds06, bds09
from pyModeS.decoder.bds.bds05 import airborne_position, airborne_position_with_ref, altitude
@@ -197,63 +198,30 @@ def version(msg):
return version
def nic_v1(msg, nic_sup_b):
"""Calculate NIC, navigation integrity category for ADS-B version 1
def nic_v1(msg,nic_sup_b):
"""Calculate NIC, navigation integrity category, for ADS-B version 1
Args:
msg (string): 28 bytes hexadecimal message string
nic_sup_b (int or string): NIC supplement
Returns:
int: NIC number (from 0 to 11), -1 if not applicable
int or string: Horizontal Radius of Containment
int or string: Vertical Protection Limit
"""
if typecode(msg) < 5 or typecode(msg) > 22:
raise RuntimeError("%s: Not a surface position message (5<TC<8), \
airborne position message (8<TC<19), \
or airborne position with GNSS height (20<TC<22)" % msg)
tc = typecode(msg)
tc = typecode(msg)
if nic_sup_b in ['0', '1']:
nic_sup_b = int(nic_sup_b)
nic_df = pd.read_csv('/home/josmilrom/Libraries/pyModeS/pyModeS/decoder/adsb_ua_parameters/NIC_v1.csv', sep=',')
nic_df_extract = nic_df[(nic_df.TC == tc) & (nic_df.NICs == nic_sup_b)]
if tc in [0, 8, 18, 22]:
nic = 0
elif tc == 17:
nic = 1
elif tc == 16:
if nic_sup_b:
nic = 3
else:
nic = 2
elif tc == 15:
nic = 4
elif tc == 14:
nic = 5
elif tc == 13:
if nic_sup_b:
nic = 6
else:
nic = 6
elif tc == 12:
nic = 7
elif tc == 11:
if nic_sup_b:
nic = 9
else:
nic = 8
elif tc in [6, 10, 21]:
nic = 10
elif tc in [5, 9, 20]:
nic = 11
elif tc == 7:
if nic_sup_b:
nic = 9
else:
nic = 8
else:
nic = -1
return nic
Rc = nic_df_extract['Rc'][0]
VPL = nic_df_extract['VPL'][0]
return Rc, VPL
def nic_v2(msg, nic_a, nic_b, nic_c):
@@ -264,77 +232,31 @@ def nic_v2(msg, nic_a, nic_b, nic_c):
nic_a (int or string): NIC supplement
nic_b (int or srting): NIC supplement
nic_c (int or string): NIC supplement
Returns:
int: NIC number (from 0 to 11), -1 if not applicable
int or string: Horizontal Radius of Containment
"""
if typecode(msg) < 5 or typecode(msg) > 22:
raise RuntimeError("%s: Not a surface position message (5<TC<8) \
airborne position message (8<TC<19), \
or airborne position with GNSS height (20<TC<22)" % msg)
tc = typecode(msg)
tc = typecode(msg)
if nic_a in ['0', '1']:
nic_a = int(nic_a)
nic_df = pd.read_csv('/home/josmilrom/Libraries/pyModeS/pyModeS/decoder/adsb_ua_parameters/NIC_v2.csv', sep=',')
if nic_b in ['0', '1']:
nic_b = int(nic_b)
if tc in range(5,9):
nic_df_extract = [(nic_df.TC == tc) & (nic_df.NICa == nic_a) & (nic_df.NICc == nic_c)]
elif tc in range(9,19):
nic_df_extract = [(nic_df.TC == tc) & (nic_df.NICa == nic_a) & (nic_df.NICb == nic_b)]
elif tc in range(20,23):
nic_df_extract = [nic_df.TC == tc]
if nic_c in ['0', '1']:
nic_c = int(nic_c)
if tc in [0, 18, 22]:
nic = 0
elif tc == 17:
nic = 1
elif tc == 16:
if nic_a:
nic = 3
else:
nic = 2
elif tc == 15:
nic = 4
elif tc == 14:
nic = 5
elif tc == 13:
if nic_a:
nic = 6
else:
if nic_b:
nic = 6
else:
nic = 6
elif tc == 12:
nic = 7
elif tc == 11:
if nic_a:
nic = 9
else:
nic = 8
elif tc in [6, 10, 21]:
nic = 10
elif tc in [5, 9, 20]:
nic = 11
elif tc == 8:
if nic_a:
if nic_c:
nic = 7
else:
nic = 6
else:
if nic_c:
nic = 6
else:
nic = 0
elif tc == 7:
if nic_a:
nic = 9
else:
nic = 8
else:
nic = -1
return nic
Rc = nic_df_extract['Rc'][0]
return Rc
def nic_s(msg):
"""Obtain NIC supplement bit, TC=31 message
@@ -404,7 +326,8 @@ def nac_p(msg):
msg (string): 28 bytes hexadecimal message string, TC = 29 or 31
Returns:
int: NACp number (0 or 1)
int or string: 95% horizontal accuracy bounds, Estimated Position Uncertainty
int or string: 95% vertical accuracy bounds, Vertical Estimated Position Uncertainty
"""
tc = typecode(msg)
@@ -414,13 +337,19 @@ def nac_p(msg):
msgbin = common.hex2bin(msg)
nacp_df = pd.read_csv('/home/josmilrom/Libraries/pyModeS/pyModeS/decoder/adsb_ua_parameters/NACp.csv', sep=',')
if tc == 29:
nac_p = common.bin2int(msgbin[71:75])
nacp_df_extract = nac_p[nacp_df.NACp == nac_p]
elif tc == 31:
nac_p = common.bin2int(msgbin[76:80])
nacp_df_extract = nac_p[nacp_df.NACp == nac_p]
return nac_p
HFU = nacp_df_extract['HFU'][0]
VEPU = nacp_df_extract['VEPU'][0]
return HFU, VEPU
def nac_v(msg):
"""Calculate NACv, Navigation Accuracy Category - Velocity
@@ -429,16 +358,23 @@ def nac_v(msg):
msg (string): 28 bytes hexadecimal message string, TC = 19
Returns:
int: NACv number (from 0 to 4), -1 if not applicable
int or string: 95% horizontal accuracy bounds for velocity, Horizontal Figure of Merit
int or string: 95% vertical accuracy bounds for velocity, Vertical Figure of Merit
"""
tc = typecode(msg)
if tc != 19:
raise RuntimeError("%s: Not an airborne velocity message, expecting TC = 19" % msg)
nacv_df = pd.read_csv('/home/josmilrom/Libraries/pyModeS/pyModeS/decoder/adsb_ua_parameters/NACv.csv', sep=',')
msgbin = common.hex2bin(msg)
nac_v = common.bin2int(msgbin[42:45])
return nac_v
nacv_df_extract = nacv_df[nacv_df.NACv == nac_v]
HFOMr = nacv_df_extract['HFOMr'][0]
VFOMr = nacv_df_extract['VFOMr'][0]
return HFOMr, VFOMr
def sil(msg, version):
@@ -448,7 +384,9 @@ def sil(msg, version):
msg (string): 28 bytes hexadecimal message string with TC = 29, 31
Returns:
(int, int): sil number and sil supplement (only for v2)
int or string: Probability of exceeding Horizontal Radius of Containment RCu
int or string: Probability of exceeding Vertical Integrity Containment Region VPL
string: SIL supplement based on "per hour" or "per sample"
"""
tc = typecode(msg)
@@ -456,6 +394,8 @@ def sil(msg, version):
raise RuntimeError("%s: Not a target state and status messag, \
or operation status message, expecting TC = 29 or 31" % msg)
sil_df = pd.read_csv('/home/josmilrom/Libraries/pyModeS/pyModeS/decoder/adsb_ua_parameters/SIL.csv', sep=',')
msgbin = common.hex2bin(msg)
if tc == 29:
@@ -463,12 +403,76 @@ def sil(msg, version):
elif tc == 31:
sil = common.bin2int(msg[82:84])
sil_sup = None
sil_df_extract = sil_df[sil_df.NACv == sil]
PR_RCu = sil_df_extract['PR_RCu'][0]
PE_VPL = sil_df_extract['PE_VPL'][0]
if version == 1:
return PR_RCu, PE_VPL
if version == 2:
if version == 29:
if tc == 29:
sil_sup = common.bin2int(msgbin[39])
elif version == 31:
elif tc == 31:
sil_sup = common.bin2int(msgbin[86])
if sil_sup == 0:
base = "per hour"
elif sil_sup == 1:
base = "per sample"
return sil, sil_sup
return PR_RCu, PE_VPL, base
def nuc_p(msg):
"""Calculate NUCp, Navigation Uncertainty Category - Position
Args:
msg (string): 28 bytes hexadecimal message string,
Returns:
int or string: Horizontal Protection Limit
int or string: 95% Containment Radius - Horizontal
int or string: 95% Containment Radius - Vertical (only for airborne position with GNSS height messages)
"""
tc = typecode(msg)
if typecode(msg) < 5 or typecode(msg) > 22:
raise RuntimeError("%s: Not a surface position message (5<TC<8), \
airborne position message (8<TC<19), \
or airborne position with GNSS height (20<TC<22)" % msg)
nucp_df = pd.read_csv('/home/josmilrom/Libraries/pyModeS/pyModeS/decoder/adsb_ua_parameters/NUCp.csv', sep=',')
nucp_df_extract = nucp_df[nucp_df.TC == tc]
HPL = nucp_df_extract['HPL'][0]
RCu = nucp_df_extract['RCu'][0]
if tc not in range(20,23):
return HPL, RCu
else:
RCv = nucp_df_extract['RCv'][0]
return HPL, RCu, RCv
def nuc_v(msg):
"""Calculate NUCv, Navigation Uncertainty Category - Velocity
Args:
msg (string): 28 bytes hexadecimal message string,
Returns:
int or string: 95% Horizontal Velocity Error
int or string: 95% Vertical Velocity Error
"""
tc = typecode(msg)
if tc != 19:
raise RuntimeError("%s: Not an airborne velocity message, expecting TC = 19" % msg)
nucv_df = pd.read_csv('/home/josmilrom/Libraries/pyModeS/pyModeS/decoder/adsb_ua_parameters/NUCv.csv', sep=',')
nucv_df_extract = nucv_df[nucv_df.TC == tc]
HVE = nucv_df_extract['HVE'][0]
VVE = nucv_df_extract['VVE'][0]
return HVE, VVE

View File

@@ -0,0 +1,13 @@
NACp,HFU,VEPU
11,3,4
10,10,15
9,30,45
8,93,'undefined
7,185,'undefined
6,556,'undefined
5,926,'undefined
4,1852,'undefined
3,3704,'undefined
2,7408,'undefined
1,18520,'undefined
0,unknown,'undefined
1 NACp HFU VEPU
2 11 3 4
3 10 10 15
4 9 30 45
5 8 93 'undefined’
6 7 185 'undefined’
7 6 556 'undefined’
8 5 926 'undefined’
9 4 1852 'undefined’
10 3 3704 'undefined’
11 2 7408 'undefined’
12 1 18520 'undefined’
13 0 ‘unknown’ 'undefined’

View File

@@ -0,0 +1,6 @@
NAVc,HFOMr,VFOMr
0,'unknown,'unknown
1,10,"15,2"
2,3,"4,5"
3,1,"1,5"
4,"0,3","0,46"
1 NAVc HFOMr VFOMr
2 0 'unknown’ 'unknown’
3 1 10 15,2
4 2 3 4,5
5 3 1 1,5
6 4 0,3 0,46

View File

@@ -0,0 +1,22 @@
TC,NICs,NIC,Rc,VPL
5,0,12,"7,5",'undefined
6,0,11,25,'undefined
7,1,10,75,'undefined
7,0,9,185,'undefined
8,0,1,'unknown,'undefined
9,0,11,"7,5",11
10,0,10,25,"37,5"
11,1,9,75,112
11,0,8,185,'undefined
12,0,7,370,'undefined
13,0,6,926,'undefined
13,1,6,1111,'undefined
14,0,5,1852,'undefined
15,0,4,3702,'undefined
16,1,3,7408,'undefined
16,0,2,14008,'undefined
17,0,1,37000,'undefined
18,0,0,'unknown,'undefined
20,0,11,"7,5",11
21,0,10,25,"37,5"
22,0,0,'unknown,112
1 TC NICs NIC Rc VPL
2 5 0 12 7,5 'undefined’
3 6 0 11 25 'undefined’
4 7 1 10 75 'undefined’
5 7 0 9 185 'undefined’
6 8 0 1 'unknown’ 'undefined’
7 9 0 11 7,5 11
8 10 0 10 25 37,5
9 11 1 9 75 112
10 11 0 8 185 'undefined’
11 12 0 7 370 'undefined’
12 13 0 6 926 'undefined’
13 13 1 6 1111 'undefined’
14 14 0 5 1852 'undefined’
15 15 0 4 3702 'undefined’
16 16 1 3 7408 'undefined’
17 16 0 2 14008 'undefined’
18 17 0 1 37000 'undefined’
19 18 0 0 'unknown’ 'undefined’
20 20 0 11 7,5 11
21 21 0 10 25 37,5
22 22 0 0 'unknown’ 112

View File

@@ -0,0 +1,26 @@
TC,NICa,NICb,NICc,NIC,Rc
5,0,0,0,11,"7,5"
6,0,0,0,10,25
7,1,0,0,9,75
7,0,0,0,8,185
8,1,0,1,7,370
8,1,0,0,6,556
8,0,0,1,6,1111
8,0,0,0,0,'unknown
9,0,0,0,11,"7,5"
10,0,0,0,10,25
11,1,1,0,9,75
11,0,0,0,8,185
12,0,0,0,4,370
13,0,1,0,6,556
13,0,0,0,6,926
13,1,1,0,6,1111
14,0,0,0,5,1852
15,0,0,0,4,3704
16,1,1,0,3,7408
16,0,0,0,2,14800
17,0,0,0,1,37000
18,0,0,0,0,'unknown
20,0,0,0,11,"7,5"
21,0,0,0,10,25
22,0,0,0,0,'unknown
1 TC NICa NICb NICc NIC Rc
2 5 0 0 0 11 7,5
3 6 0 0 0 10 25
4 7 1 0 0 9 75
5 7 0 0 0 8 185
6 8 1 0 1 7 370
7 8 1 0 0 6 556
8 8 0 0 1 6 1111
9 8 0 0 0 0 'unknown’
10 9 0 0 0 11 7,5
11 10 0 0 0 10 25
12 11 1 1 0 9 75
13 11 0 0 0 8 185
14 12 0 0 0 4 370
15 13 0 1 0 6 556
16 13 0 0 0 6 926
17 13 1 1 0 6 1111
18 14 0 0 0 5 1852
19 15 0 0 0 4 3704
20 16 1 1 0 3 7408
21 16 0 0 0 2 14800
22 17 0 0 0 1 37000
23 18 0 0 0 0 'unknown’
24 20 0 0 0 11 7,5
25 21 0 0 0 10 25
26 22 0 0 0 0 'unknown’

View File

@@ -0,0 +1,18 @@
TC,NUCp,HPL,Rcu,Rcv
5,9,"7,5",3,'undefined
6,8,25,10,'undefined
7,7,185,93,'undefined
8,6,'unknown,'unknown,'undefined
9,9,"7,5",3,'undefined
10,8,25,10,'undefined
11,7,185,93,'undefined
12,6,370,185,'undefined
13,5,926,463,'undefined
14,4,1852,926,'undefined
15,3,3704,1852,'undefined
16,2,18520,9260,'undefined
17,1,37040,18520,'undefined
18,0,'unknown,'unknown,'undefined
20,9,"7,5",3,4
21,8,25,10,15
22,0,'unknown,'unknown,'unknown
1 TC NUCp HPL Rcu Rcv
2 5 9 7,5 3 'undefined’
3 6 8 25 10 'undefined’
4 7 7 185 93 'undefined’
5 8 6 'unknown’ 'unknown’ 'undefined’
6 9 9 7,5 3 'undefined’
7 10 8 25 10 'undefined’
8 11 7 185 93 'undefined’
9 12 6 370 185 'undefined’
10 13 5 926 463 'undefined’
11 14 4 1852 926 'undefined’
12 15 3 3704 1852 'undefined’
13 16 2 18520 9260 'undefined’
14 17 1 37040 18520 'undefined’
15 18 0 'unknown’ 'unknown’ 'undefined’
16 20 9 7,5 3 4
17 21 8 25 10 15
18 22 0 'unknown’ 'unknown’ 'unknown’

View File

@@ -0,0 +1,6 @@
NUCp,HVE,VVE
0,'unknown,'unknown
1,10,"15,2"
2,3,"4,5"
3,1,"1,5"
4,"0,3","1,46"
1 NUCp HVE VVE
2 0 'unknown’ 'unknown’
3 1 10 15,2
4 2 3 4,5
5 3 1 1,5
6 4 0,3 1,46

View File

@@ -0,0 +1,5 @@
SIL,PE_Rcu,PE_VPL
0,'unknown,'unknown
1,10**(-3),10**(-3)
2,10**(-5),10**(-5)
3,10**(-7),10**(-7)
1 SIL PE_Rcu PE_VPL
2 0 'unknown’ 'unknown’
3 1 10**(-3) 10**(-3)
4 2 10**(-5) 10**(-5)
5 3 10**(-7) 10**(-7)

View File

@@ -48,10 +48,10 @@ class Stream():
'mach': None,
'hdg': None,
'ver' : None,
'NIC' : None,
'NACp' : None,
'NACv' : None,
'SIL' : None
'nic_s' : None,
'nic_a' : None,
'nic_b' : None,
'nic_c' : None
}
self.acs[icao]['live'] = int(t)
@@ -106,38 +106,44 @@ class Stream():
self.acs[icao]['tpos'] = t
self.acs[icao]['lat'] = latlon[0]
self.acs[icao]['lon'] = latlon[1]
<<<<<<< HEAD
self.acs[icao]['alt'] = adsb.altitude(msg)
# local_updated_acs_buffer.append(icao)acs[icao]['adsb_version']
local_updated_acs_buffer.append(acs[icao]['adsb_version'])
=======
self.acs[icao]['alt'] = pms.adsb.altitude(msg)
local_updated_acs_buffer.append(icao)
>>>>>>> upstream/master
# Uncertainty & accuracy
ac = self.acs[icao]
if (5 <= tc <= 8) or (9 <= tc <= 18) or (20 <= tc <= 22):
if 20 <= tc <= 22:
ac['HPL'], ac['RCu'], ac['RCv'] = pms.adsb.nuc_p(msg)
else:
ac['HPL'], ac['RCu'] = pms.adsb.nuc_p(msg)
if (ac['ver'] == 1) and ('nic_s' in ac.keys()):
self.acs[icao]['NIC'] = pms.adsb.nic_v1(msg, ac['nic_s'])
ac['Rc'], ac['VPL'] = pms.adsb.nic_v1(msg, ac['nic_s'])
elif (ac['ver'] == 2) and ('nic_a' in ac.keys()) and ('nic_b' in ac.keys()):
self.acs[icao]['NIC'] = pms.adsb.nic_v2(msg, ac['nic_a'], ac['nic_b'], ac['nic_c'])
ac['Rc'], ac['VPL'] = pms.adsb.nic_v2(msg, ac['nic_a'], ac['nic_b'], ac['nic_c'])
if tc == 19:
ac['HVE'], ac['VVE'] = pms.adsb.nuc_v(msg)
if ac['ver'] in [1, 2]:
self.acs[icao]['NACv'] = pms.adsb.nac_v(msg)
ac['HFU'], ac['VEPU'] = pms.adsb.nac_v(msg)
if tc == 29:
if ac['ver'] != None:
self.acs[icao]['SIL'], self.acs[icao]['sil_s'] = pms.adsb.sil(msg, ac['ver'])
self.acs[icao]['NACp'] = pms.adsb.nac_p(msg)
if ac['ver'] == 1:
ac['PR_RCu'], ac['PE_VPL'] = pms.adsb.sil(msg, ac['ver'])
elif ac['ver'] == 2:
ac['PR_RCu'], ac['PE_VPL'], ac['sil_base'] = pms.adsb.sil(msg, ac['ver'])
ac['HFOMr'], ac['VFOMr'] = pms.adsb.nac_p(msg)
if tc == 31:
self.acs[icao]['ver'] = pms.adsb.version(msg)
self.acs[icao]['SIL'] = pms.adsb.version(msg)
self.acs[icao]['NACp'] = pms.adsb.nac_p(msg)
if self.acs[icao]['ver'] == 1:
self.acs[icao]['nic_s'] = pms.adsb.nic_s(msg)
elif self.acs[icao]['ver'] == 2:
self.acs[icao]['nic_a'], self.acs[icao]['nic_c'] = pms.adsb.nic_a_c(msg)
ac['ver'] = pms.adsb.version(msg)
ac['HFOMr'], ac['VFOMr'] = pms.adsb.nac_p(msg)
if ac['ver'] == 1:
ac['nic_s'] = pms.adsb.nic_s(msg)
ac['PR_RCu'], ac['PE_VPL'] = pms.adsb.sil(msg, ac['ver'])
elif ac['ver'] == 2:
ac['nic_a'], ac['nic_c'] = pms.adsb.nic_a_c(msg)
ac['PR_RCu'], ac['PE_VPL'], ac['sil_base'] = pms.adsb.sil(msg, ac['ver'])
# process commb message