Skip to content

Commit

Permalink
Fix for a corner-case numerical problem and corresponding unit test. (#…
Browse files Browse the repository at this point in the history
…181)

* Fix for a corner-case numerical problem and corresponding unit test.

* Added the missing CRC to the message.

* Applied the same fix to the surface position decoding.

---------

Co-authored-by: Eduardo Fuentetaja <[email protected]>
  • Loading branch information
EdFuentetaja and edf-spire authored Feb 9, 2025
1 parent 715fb35 commit 30a16a8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
9 changes: 3 additions & 6 deletions src/pyModeS/decoder/bds/bds05.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ def airborne_position_with_ref(
i = int(mb[21])
d_lat = 360 / 59 if i else 360 / 60

j = common.floor(lat_ref / d_lat) + common.floor(
0.5 + ((lat_ref % d_lat) / d_lat) - cprlat
)
# From 1090 MOPS, Vol.1 DO-260C, A.1.7.5
j = common.floor(0.5 + lat_ref / d_lat - cprlat)

lat = d_lat * (j + cprlat)

Expand All @@ -123,9 +122,7 @@ def airborne_position_with_ref(
else:
d_lon = 360

m = common.floor(lon_ref / d_lon) + common.floor(
0.5 + ((lon_ref % d_lon) / d_lon) - cprlon
)
m = common.floor(0.5 + lon_ref / d_lon - cprlon)

lon = d_lon * (m + cprlon)

Expand Down
9 changes: 3 additions & 6 deletions src/pyModeS/decoder/bds/bds06.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ def surface_position_with_ref(
i = int(mb[21])
d_lat = 90 / 59 if i else 90 / 60

j = common.floor(lat_ref / d_lat) + common.floor(
0.5 + ((lat_ref % d_lat) / d_lat) - cprlat
)
# From 1090 MOPS, Vol.1 DO-260C, A.1.7.6
j = common.floor(0.5 + lat_ref / d_lat - cprlat)

lat = d_lat * (j + cprlat)

Expand All @@ -132,9 +131,7 @@ def surface_position_with_ref(
else:
d_lon = 90

m = common.floor(lon_ref / d_lon) + common.floor(
0.5 + ((lon_ref % d_lon) / d_lon) - cprlon
)
m = common.floor(0.5 + lon_ref / d_lon - cprlon)

lon = d_lon * (m + cprlon)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_adsb.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ def test_adsb_airborne_position_with_ref():
assert pos == (approx(49.81755, 0.001), approx(6.08442, 0.001))


def test_adsb_airborne_position_with_ref_numerical_challenge():
lat_ref = 30.508474576271183 # Close to (360.0/59.0)*5
lon_ref = 7.2*5.0+3e-15
pos = adsb.airborne_position_with_ref(
"8D06A15358BF17FF7D4A84B47B95", lat_ref, lon_ref
)
assert pos == (approx(30.50540, 0.001), approx(33.44787, 0.001))


def test_adsb_surface_position_with_ref():
pos = adsb.surface_position_with_ref(
"8FC8200A3AB8F5F893096B000000", -43.5, 172.5
Expand Down

0 comments on commit 30a16a8

Please sign in to comment.