From 0ea2cf7adec04a52c725b113b8a4d9bd9dcba225 Mon Sep 17 00:00:00 2001 From: Richard Janssen Date: Tue, 3 Sep 2019 12:15:34 +0200 Subject: [PATCH] Fix surface positions for negative longitude --- .gitignore | 10 ++++++++++ pyModeS/decoder/bds/bds06.py | 3 +++ tests/test_bds_inference.py | 15 +++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/.gitignore b/.gitignore index 68d6eaa..ddc0d0a 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,13 @@ target/ # PyCharm .idea/ + +# Environments +.env +.venv +.virtualenvs +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ diff --git a/pyModeS/decoder/bds/bds06.py b/pyModeS/decoder/bds/bds06.py index 2c6c346..a31fe64 100644 --- a/pyModeS/decoder/bds/bds06.py +++ b/pyModeS/decoder/bds/bds06.py @@ -89,6 +89,9 @@ def surface_position(msg0, msg1, t0, t1, lat_ref, lon_ref): # four possible longitude solutions lons = [lon, lon + 90.0, lon + 180.0, lon + 270.0] + # make sure lons are between -180 and 180 + lons = [(l + 180) % 360 - 180 for l in lons] + # the closest solution to receiver is the correct one dls = [abs(lon_ref - l) for l in lons] imin = min(range(4), key=dls.__getitem__) diff --git a/tests/test_bds_inference.py b/tests/test_bds_inference.py index f7b8f2f..a6e6ca4 100644 --- a/tests/test_bds_inference.py +++ b/tests/test_bds_inference.py @@ -18,3 +18,18 @@ def test_bds_is50or60(): assert bds.is50or60("A0001838201584F23468207CDFA5", 0, 0, 0) == None assert bds.is50or60("A0000000FFDA9517000464000000", 182, 237, 1250) == 'BDS50' assert bds.is50or60("A0000000919A5927E23444000000", 413, 54, 18700) == 'BDS60' + + +def test_surface_position(): + msg0 = "8FE48C033A9FA184B934E744C6FD" + msg1 = "8FE48C033A9FA68F7C3D39B1C2F0" + + t0 = 1565608663102 + t1 = 1565608666214 + + lat_ref = -23.4265448 + lon_ref = -46.4816258 + + lat, lon = bds.bds06.surface_position(msg0, msg1, t0, t1, lat_ref, lon_ref) + + assert abs(lon_ref - lon) < 0.05