From 3dae0438bf4d90063c3693cbf1e711d34c3261f8 Mon Sep 17 00:00:00 2001 From: Junzi Sun Date: Tue, 29 Oct 2019 23:19:37 +0100 Subject: [PATCH] update tests --- tests/benchmark.py | 97 ++++++++++++++++++++++++++++++++++++++ tests/sample_run_adsb.py | 65 +++++++++++-------------- tests/sample_run_c_adsb.py | 35 ++++++++++++++ 3 files changed, 160 insertions(+), 37 deletions(-) create mode 100644 tests/benchmark.py create mode 100644 tests/sample_run_c_adsb.py diff --git a/tests/benchmark.py b/tests/benchmark.py new file mode 100644 index 0000000..68d3cbd --- /dev/null +++ b/tests/benchmark.py @@ -0,0 +1,97 @@ +import sys +import time +import pandas as pd +from tqdm import tqdm + +fin = sys.argv[1] + +df = pd.read_csv(fin, names=["ts", "df", "icao", "msg"]) +df_adsb = df[df["df"] == 17].copy() + +total = df_adsb.shape[0] + + +def native(): + + from pyModeS.decoder import adsb + from pyModeS.decoder import common + + msg0 = None + msg1 = None + + for i, r in tqdm(df_adsb.iterrows(), total=total): + ts = r.ts + m = r.msg.encode() + + downlink_format = common.df(m) + crc = common.crc(m) + icao = adsb.icao(m) + tc = adsb.typecode(m) + + if 1 <= tc <= 4: + category = adsb.category(m) + callsign = adsb.callsign(m) + if tc == 19: + velocity = adsb.velocity(m) + if 5 <= tc <= 18: + if adsb.oe_flag(m): + msg1 = m + t1 = ts + else: + msg0 = m + t0 = ts + + if msg0 and msg1: + try: + position = adsb.position(msg0, msg1, t0, t1) + except: + continue + altitude = adsb.altitude(m) + + +def cython(): + + from pyModeS.c_decoder import adsb + from pyModeS.c_decoder import common + + msg0 = None + msg1 = None + + for i, r in tqdm(df_adsb.iterrows(), total=total): + ts = r.ts + m = r.msg.encode() + + downlink_format = common.df(m) + crc = common.crc(m) + icao = adsb.icao(m) + tc = adsb.typecode(m) + + if 1 <= tc <= 4: + category = adsb.category(m) + callsign = adsb.callsign(m) + if tc == 19: + velocity = adsb.velocity(m) + if 5 <= tc <= 18: + if adsb.oe_flag(m): + msg1 = m + t1 = ts + else: + msg0 = m + t0 = ts + + if msg0 and msg1: + try: + position = adsb.position(msg0, msg1, t0, t1) + except: + continue + altitude = adsb.altitude(m) + + +if __name__ == "__main__": + t1 = time.time() + native() + dt1 = time.time() - t1 + + t2 = time.time() + cython() + dt2 = time.time() - t2 diff --git a/tests/sample_run_adsb.py b/tests/sample_run_adsb.py index c6c7c16..543d867 100644 --- a/tests/sample_run_adsb.py +++ b/tests/sample_run_adsb.py @@ -1,44 +1,35 @@ -from __future__ import print_function -from pyModeS import adsb, ehs +import csv +from pyModeS import adsb +import logging +# logging.basicConfig(level=logging.INFO) -# === Decode sample data file === +logging.info("===== Decode ADS-B sample data=====") +f = open("tests/data/sample_data_adsb.csv", "rt") -def adsb_decode_all(n=None): - print("===== Decode ADS-B sample data=====") - import csv +msg0 = None +msg1 = None - f = open("tests/data/sample_data_adsb.csv", "rt") +for i, r in enumerate(csv.reader(f)): - msg0 = None - msg1 = None + ts = r[0] + m = r[1] + icao = adsb.icao(m) + tc = adsb.typecode(m) + if 1 <= tc <= 4: + logging.info([ts, m, icao, tc, adsb.category(m), adsb.callsign(m)]) + if tc == 19: + logging.info([ts, m, icao, tc, adsb.velocity(m)]) + if 5 <= tc <= 18: + if adsb.oe_flag(m): + msg1 = m + t1 = ts + else: + msg0 = m + t0 = ts - for i, r in enumerate(csv.reader(f)): - if n and i > n: - break - - ts = r[0] - m = r[1] - icao = adsb.icao(m) - tc = adsb.typecode(m) - if 1 <= tc <= 4: - print(ts, m, icao, tc, adsb.category(m), adsb.callsign(m)) - if tc == 19: - print(ts, m, icao, tc, adsb.velocity(m)) - if 5 <= tc <= 18: - if adsb.oe_flag(m): - msg1 = m - t1 = ts - else: - msg0 = m - t0 = ts - - if msg0 and msg1: - pos = adsb.position(msg0, msg1, t0, t1) - alt = adsb.altitude(m) - print(ts, m, icao, tc, pos, alt) - - -if __name__ == "__main__": - adsb_decode_all(n=100) + if msg0 and msg1: + pos = adsb.position(msg0, msg1, t0, t1) + alt = adsb.altitude(m) + logging.info([ts, m, icao, tc, pos, alt]) diff --git a/tests/sample_run_c_adsb.py b/tests/sample_run_c_adsb.py new file mode 100644 index 0000000..02b078a --- /dev/null +++ b/tests/sample_run_c_adsb.py @@ -0,0 +1,35 @@ +from pyModeS.c_decoder import adsb +import logging +import csv + +# logging.basicConfig(level=logging.INFO) + +logging.info("===== Decode ADS-B sample data=====") + +f = open("tests/data/sample_data_adsb.csv", "rt") + +msg0 = None +msg1 = None + +for i, r in enumerate(csv.reader(f)): + + ts = int(r[0]) + m = str.encode(r[1]) + icao = adsb.icao(m) + tc = adsb.typecode(m) + if 1 <= tc <= 4: + logging.info([ts, m, icao, tc, adsb.category(m), adsb.callsign(m)]) + if tc == 19: + logging.info([ts, m, icao, tc, adsb.velocity(m)]) + if 5 <= tc <= 18: + if adsb.oe_flag(m): + msg1 = m + t1 = ts + else: + msg0 = m + t0 = ts + + if msg0 and msg1: + pos = adsb.position(msg0, msg1, t0, t1) + alt = adsb.altitude(m) + logging.info([ts, m, icao, tc, pos, alt])