pyopensky 2.18__tar.gz → 2.19__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. {pyopensky-2.18 → pyopensky-2.19}/.github/workflows/run_tests.yml +5 -5
  2. {pyopensky-2.18 → pyopensky-2.19}/PKG-INFO +3 -2
  3. {pyopensky-2.18 → pyopensky-2.19}/docs/source/rebuild.rst +8 -11
  4. {pyopensky-2.18 → pyopensky-2.19}/pyproject.toml +6 -3
  5. pyopensky-2.19/src/pyopensky/decoders/pymodes.py +150 -0
  6. {pyopensky-2.18 → pyopensky-2.19}/src/pyopensky/rebuild.py +22 -4
  7. {pyopensky-2.18 → pyopensky-2.19}/tests/test_rebuild.py +8 -9
  8. pyopensky-2.19/tests/test_rebuild_pymodes.py +89 -0
  9. {pyopensky-2.18 → pyopensky-2.19}/tests/test_trino.py +69 -92
  10. {pyopensky-2.18 → pyopensky-2.19}/uv.lock +118 -63
  11. pyopensky-2.18/src/pyopensky/decoders/pymodes.py +0 -244
  12. {pyopensky-2.18 → pyopensky-2.19}/.gitattributes +0 -0
  13. {pyopensky-2.18 → pyopensky-2.19}/.github/dependabot.yml +0 -0
  14. {pyopensky-2.18 → pyopensky-2.19}/.github/renovate.json5 +0 -0
  15. {pyopensky-2.18 → pyopensky-2.19}/.github/workflows/build-docs.yml +0 -0
  16. {pyopensky-2.18 → pyopensky-2.19}/.github/workflows/pypi_publish.yml +0 -0
  17. {pyopensky-2.18 → pyopensky-2.19}/.gitignore +0 -0
  18. {pyopensky-2.18 → pyopensky-2.19}/agents.md +0 -0
  19. {pyopensky-2.18 → pyopensky-2.19}/docs/.gitignore +0 -0
  20. {pyopensky-2.18 → pyopensky-2.19}/docs/Makefile +0 -0
  21. {pyopensky-2.18 → pyopensky-2.19}/docs/make.bat +0 -0
  22. {pyopensky-2.18 → pyopensky-2.19}/docs/source/_static/main_stylesheet.css +0 -0
  23. {pyopensky-2.18 → pyopensky-2.19}/docs/source/conf.py +0 -0
  24. {pyopensky-2.18 → pyopensky-2.19}/docs/source/credentials.rst +0 -0
  25. {pyopensky-2.18 → pyopensky-2.19}/docs/source/index.rst +0 -0
  26. {pyopensky-2.18 → pyopensky-2.19}/docs/source/installation.rst +0 -0
  27. {pyopensky-2.18 → pyopensky-2.19}/docs/source/rest.rst +0 -0
  28. {pyopensky-2.18 → pyopensky-2.19}/docs/source/trino.rst +0 -0
  29. {pyopensky-2.18 → pyopensky-2.19}/docs/source/trino_advanced.rst +0 -0
  30. {pyopensky-2.18 → pyopensky-2.19}/license.txt +0 -0
  31. {pyopensky-2.18 → pyopensky-2.19}/readme.md +0 -0
  32. {pyopensky-2.18 → pyopensky-2.19}/scripts/benchmark_trino_routes.py +0 -0
  33. {pyopensky-2.18 → pyopensky-2.19}/scripts/decode_pymodes.py +0 -0
  34. {pyopensky-2.18 → pyopensky-2.19}/scripts/decode_rs1090.py +0 -0
  35. {pyopensky-2.18 → pyopensky-2.19}/src/pyopensky/__init__.py +0 -0
  36. {pyopensky-2.18 → pyopensky-2.19}/src/pyopensky/api.py +0 -0
  37. {pyopensky-2.18 → pyopensky-2.19}/src/pyopensky/config.py +0 -0
  38. {pyopensky-2.18 → pyopensky-2.19}/src/pyopensky/decoders/__init__.py +0 -0
  39. {pyopensky-2.18 → pyopensky-2.19}/src/pyopensky/decoders/base.py +0 -0
  40. {pyopensky-2.18 → pyopensky-2.19}/src/pyopensky/decoders/rs1090.py +0 -0
  41. {pyopensky-2.18 → pyopensky-2.19}/src/pyopensky/py.typed +0 -0
  42. {pyopensky-2.18 → pyopensky-2.19}/src/pyopensky/rest.py +0 -0
  43. {pyopensky-2.18 → pyopensky-2.19}/src/pyopensky/s3.py +0 -0
  44. {pyopensky-2.18 → pyopensky-2.19}/src/pyopensky/schema.py +0 -0
  45. {pyopensky-2.18 → pyopensky-2.19}/src/pyopensky/time.py +0 -0
  46. {pyopensky-2.18 → pyopensky-2.19}/src/pyopensky/trino.py +0 -0
  47. {pyopensky-2.18 → pyopensky-2.19}/src/pyopensky/tzdata.py +0 -0
  48. {pyopensky-2.18 → pyopensky-2.19}/tests/test_rest.py +0 -0
  49. {pyopensky-2.18 → pyopensky-2.19}/tests/test_s3.py +0 -0
  50. {pyopensky-2.18 → pyopensky-2.19}/tests/test_trino_offline.py +0 -0
  51. {pyopensky-2.18 → pyopensky-2.19}/tests/test_tzdata.py +0 -0
@@ -14,7 +14,7 @@ jobs:
14
14
  steps:
15
15
  - uses: actions/checkout@v7
16
16
 
17
- - uses: astral-sh/setup-uv@v10.3.2
17
+ - uses: astral-sh/setup-uv@v10.4.0
18
18
  with:
19
19
  enable-cache: true
20
20
 
@@ -29,7 +29,7 @@ jobs:
29
29
  steps:
30
30
  - uses: actions/checkout@v7
31
31
 
32
- - uses: astral-sh/setup-uv@v10.3.2
32
+ - uses: astral-sh/setup-uv@v10.4.0
33
33
  with:
34
34
  enable-cache: true
35
35
 
@@ -45,7 +45,7 @@ jobs:
45
45
  with:
46
46
  fetch-depth: 0
47
47
 
48
- - uses: astral-sh/setup-uv@v10.3.2
48
+ - uses: astral-sh/setup-uv@v10.4.0
49
49
  with:
50
50
  enable-cache: true
51
51
 
@@ -103,7 +103,7 @@ jobs:
103
103
  with:
104
104
  fetch-depth: 0
105
105
 
106
- - uses: astral-sh/setup-uv@v10.3.2
106
+ - uses: astral-sh/setup-uv@v10.4.0
107
107
  with:
108
108
  enable-cache: true
109
109
 
@@ -113,7 +113,7 @@ jobs:
113
113
  enableCrossOsArchive: true
114
114
  key: opensky-${{ hashFiles('uv.lock') }}
115
115
 
116
- - run: uv sync --dev --python ${{ matrix.python-version }} --extra rs1090 --extra cartes
116
+ - run: uv sync --dev --python ${{ matrix.python-version }} --extra rs1090 --extra cartes --extra pymodes
117
117
 
118
118
  - name: Run tests
119
119
  env:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pyopensky
3
- Version: 2.18
3
+ Version: 2.19
4
4
  Summary: A Python interface for OpenSky database
5
5
  Project-URL: Repository, https://github.com/open-aviation/pyopensky/
6
6
  Author-email: Xavier Olive <git@xoolive.org>, Junzi Sun <j.sun-1@tudelft.nl>
@@ -21,8 +21,9 @@ Requires-Dist: typing-extensions>=4.12.2
21
21
  Requires-Dist: tzdata>=2024.2
22
22
  Provides-Extra: cartes
23
23
  Requires-Dist: cartes>=0.8.5; (python_version >= '3.10') and extra == 'cartes'
24
+ Requires-Dist: pillow>=13; (python_version >= '3.11') and extra == 'cartes'
24
25
  Provides-Extra: pymodes
25
- Requires-Dist: pymodes>=2.18; extra == 'pymodes'
26
+ Requires-Dist: pymodes<4,>=3.6.1; (python_version >= '3.11') and extra == 'pymodes'
26
27
  Provides-Extra: rs1090
27
28
  Requires-Dist: rs1090>=0.3.8; extra == 'rs1090'
28
29
  Description-Content-Type: text/markdown
@@ -63,14 +63,13 @@ Available decoders
63
63
  PyModes decoder
64
64
  ~~~~~~~~~~~~~~~
65
65
 
66
- The :class:`~pyopensky.decoders.PyModesDecoder` uses the `pyModeS <https://github.com/junzis/pyModeS>`_ library for decoding.
66
+ The :class:`~pyopensky.decoders.PyModesDecoder` uses the pyModeS v3
67
+ ``PipeDecoder`` to decode raw position messages in capture-time order.
68
+ It tracks each aircraft separately, pairs CPR frames, and checks candidate
69
+ positions against the aircraft's recent motion. Rebuild returns rows with
70
+ resolved coordinates and uses the database values for velocity and callsign.
67
71
 
68
- **Features:**
69
-
70
- - CPR position decoding with odd/even frame pairing
71
- - Reference position validation to filter outliers
72
- - BDS register decoding (BDS 4,0, BDS 5,0, BDS 6,0)
73
- - Pure Python implementation
72
+ The ``pymodes`` extra requires Python 3.11 or newer.
74
73
 
75
74
  **Installation:**
76
75
 
@@ -90,7 +89,7 @@ The :class:`~pyopensky.decoders.PyModesDecoder` uses the `pyModeS <https://githu
90
89
  rebuild = Rebuild(trino)
91
90
 
92
91
  # Using string-based selection
93
- df = rebuild.redecode_position(
92
+ df = rebuild.rebuild(
94
93
  start="2023-01-03 16:00",
95
94
  stop="2023-01-03 20:00",
96
95
  icao24="400A0E",
@@ -114,7 +113,6 @@ The :class:`~pyopensky.decoders.Rs1090Decoder` uses the Rust-based `rs1090 <http
114
113
  **Features:**
115
114
 
116
115
  - High-performance Rust implementation
117
- - Same decoding logic as PyModesDecoder
118
116
  - Significantly faster for large datasets
119
117
 
120
118
  **Installation:**
@@ -134,7 +132,7 @@ The :class:`~pyopensky.decoders.Rs1090Decoder` uses the Rust-based `rs1090 <http
134
132
  rebuild = Rebuild(trino)
135
133
 
136
134
  # Using string-based selection
137
- df = rebuild.redecode_position(
135
+ df = rebuild.rebuild(
138
136
  start="2023-01-03 16:00",
139
137
  stop="2023-01-03 20:00",
140
138
  icao24="400A0E",
@@ -184,7 +182,6 @@ Performance considerations
184
182
 
185
183
  - Use ``PyModesDecoder`` for small to medium datasets (< 1M messages) or when you need to inspect the decoding logic
186
184
  - Use ``Rs1090Decoder`` for large datasets (> 1M messages) where performance is critical
187
- - Both decoders produce equivalent results, Rs1090Decoder is simply faster
188
185
 
189
186
  **Database vs custom decoding:**
190
187
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pyopensky"
3
- version = "2.18"
3
+ version = "2.19"
4
4
  description = "A Python interface for OpenSky database"
5
5
  authors = [{ name = "Xavier Olive", email = "git@xoolive.org" }, { name = "Junzi Sun", email = "j.sun-1@tudelft.nl" }]
6
6
  license = "MIT"
@@ -26,8 +26,11 @@ dependencies = [
26
26
  Repository = "https://github.com/open-aviation/pyopensky/"
27
27
 
28
28
  [project.optional-dependencies]
29
- cartes = ["cartes>=0.8.5; python_version>='3.10'"]
30
- pymodes = ["pymodes>=2.18"]
29
+ cartes = [
30
+ "cartes>=0.8.5; python_version>='3.10'",
31
+ "pillow>=13; python_version>='3.11'",
32
+ ]
33
+ pymodes = ["pymodes>=3.6.1,<4; python_version >= '3.11'"]
31
34
  rs1090 = ["rs1090>=0.3.8"]
32
35
 
33
36
  [build-system]
@@ -0,0 +1,150 @@
1
+ """pyModeS decoder for ADS-B messages.
2
+
3
+ This module provides a decoder implementation using the pyModeS library.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import TYPE_CHECKING
9
+
10
+ from .base import Decoder
11
+
12
+ if TYPE_CHECKING:
13
+ import pandas as pd
14
+
15
+
16
+ # Match the pipe's state lifetime and finalize short encounters before expiry.
17
+ _ENCOUNTER_GAP_SECONDS = 300.0
18
+
19
+
20
+ class PyModesDecoder(Decoder):
21
+ """Decoder for ADS-B messages using pyModeS library.
22
+
23
+ This decoder implements CPR position decoding with odd/even frame pairing
24
+ and validation using reference positions.
25
+
26
+ **Example usage**::
27
+
28
+ from pyopensky.decoders import PyModesDecoder
29
+ from pyopensky.trino import Trino
30
+ from pyopensky.rebuild import Rebuild
31
+
32
+ trino = Trino()
33
+ rebuild = Rebuild(trino)
34
+ decoder = PyModesDecoder()
35
+
36
+ # Redecode position data
37
+ pos = rebuild.redecode_position(
38
+ start="2023-01-03 16:00",
39
+ stop="2023-01-03 20:00",
40
+ icao24="400A0E",
41
+ decoder=decoder
42
+ )
43
+
44
+ # Or rebuild complete state vectors
45
+ data = rebuild.rebuild(
46
+ start="2023-01-03 16:00",
47
+ stop="2023-01-03 20:00",
48
+ icao24="400A0E",
49
+ decoder=decoder
50
+ )
51
+ """
52
+
53
+ def __init__(self) -> None:
54
+ """Initialize PyModesDecoder and import pyModeS library."""
55
+ try:
56
+ from pyModeS import PipeDecoder
57
+ except ImportError as e:
58
+ raise ImportError(
59
+ "PyModesDecoder requires Python 3.11+ and pyModeS v3. "
60
+ "Install it with: pip install 'pyopensky[pymodes]'"
61
+ ) from e
62
+ self._pipe_decoder = PipeDecoder
63
+
64
+ def decode_position(self, df: pd.DataFrame) -> pd.DataFrame:
65
+ """Return positions accepted by the v3 pipe in capture-time order."""
66
+ from pyModeS import DecodeError, Message
67
+
68
+ frames = df.dropna(
69
+ subset=["rawmsg", "timestamp", "icao24"]
70
+ ).sort_values(["icao24", "timestamp"], kind="stable")
71
+ pipe = self._pipe_decoder(eviction_ttl=_ENCOUNTER_GAP_SECONDS)
72
+ previous_icao = None
73
+ previous_time = 0.0
74
+ indices = []
75
+ results = []
76
+ for index, (rawmsg, timestamp, icao24) in enumerate(
77
+ frames[["rawmsg", "timestamp", "icao24"]].itertuples(
78
+ index=False, name=None
79
+ )
80
+ ):
81
+ try:
82
+ message = Message(rawmsg)
83
+ except DecodeError:
84
+ continue
85
+ # A corrupt frame can spoil the CPR pair for a valid neighbour.
86
+ if not message.crc_valid or message.icao.lower() != icao24.lower():
87
+ continue
88
+ capture_time = timestamp.timestamp()
89
+ if previous_icao is not None and (
90
+ message.icao != previous_icao
91
+ or capture_time - previous_time > _ENCOUNTER_GAP_SECONDS
92
+ ):
93
+ pipe.flush()
94
+ pipe.reset()
95
+ indices.append(index)
96
+ results.append(pipe.decode(rawmsg, timestamp=capture_time))
97
+ previous_icao = message.icao
98
+ previous_time = capture_time
99
+
100
+ # Pairing and the final bootstrap pass update earlier results in place.
101
+ pipe.flush()
102
+ return (
103
+ frames.iloc[indices]
104
+ .assign(
105
+ lat=[result.get("latitude") for result in results],
106
+ lon=[result.get("longitude") for result in results],
107
+ altitude=[result.get("altitude") for result in results],
108
+ )
109
+ .dropna(subset=["lat", "lon"])
110
+ .sort_values("timestamp", kind="stable")
111
+ )
112
+
113
+ def decode_velocity(self, df: pd.DataFrame) -> pd.DataFrame:
114
+ """Decode velocity data from raw messages.
115
+
116
+ Decoding is not necessary as there are no easy mistakes to fix.
117
+
118
+ :param df: DataFrame with raw velocity data
119
+ :return: DataFrame with decoded velocity (currently returns as-is)
120
+ """
121
+ # Velocity data is already decoded in the database
122
+ # Could add additional validation or decoding here
123
+ return df
124
+
125
+ def decode_identification(self, df: pd.DataFrame) -> pd.DataFrame:
126
+ """Decode identification (callsign) data from raw messages.
127
+
128
+ Decoding is not necessary as there are no easy mistakes to fix.
129
+
130
+ :param df: DataFrame with raw identification data
131
+ :return: DataFrame with decoded callsign (currently returns as-is)
132
+ """
133
+ # Identification data is already decoded in the database
134
+ return df
135
+
136
+ def decode_rollcall(self, df: pd.DataFrame) -> pd.DataFrame:
137
+ """Decode rollcall data from raw messages.
138
+
139
+ TODO
140
+
141
+ This should decode Mode S rollcall replies including:
142
+ - Mode A/C: squawk codes and altitude
143
+ - BDS 5,0 (Track and Turn Report): track angle, roll angle, track rate
144
+ - BDS 6,0 (Heading and Speed Report): magnetic heading, IAS, Mach, TAS
145
+ - more BDS registers can be added as needed
146
+
147
+ :param df: DataFrame with raw rollcall data
148
+ :return: DataFrame with decoded rollcall data including BDS fields
149
+ """
150
+ return df
@@ -19,6 +19,7 @@ import numpy as np
19
19
  import pandas as pd
20
20
 
21
21
  from .decoders.base import Decoder
22
+ from .decoders.pymodes import PyModesDecoder
22
23
  from .schema import (
23
24
  IdentificationData4,
24
25
  PositionData4,
@@ -166,14 +167,19 @@ class Rebuild:
166
167
  if pos_data is None or pos_data.shape[0] == 0:
167
168
  return None
168
169
 
169
- # Prepare position data
170
+ # Repeated broadcasts at different times are separate CPR observations.
171
+ duplicate_key = (
172
+ ["icao24", "mintime", "rawmsg"]
173
+ if isinstance(decoder, PyModesDecoder)
174
+ else ["rawmsg"]
175
+ )
170
176
  pos_data = (
171
177
  pos_data.assign(
172
178
  timestamp=lambda x: pd.to_datetime(
173
179
  x.mintime, unit="s", utc=True
174
180
  )
175
181
  )
176
- .drop_duplicates("rawmsg")
182
+ .drop_duplicates(duplicate_key)
177
183
  .rename(
178
184
  columns={
179
185
  "surface": "onground",
@@ -398,8 +404,6 @@ class Rebuild:
398
404
  """
399
405
  if isinstance(decoder, str):
400
406
  if decoder == "pymodes":
401
- from .decoders.pymodes import PyModesDecoder
402
-
403
407
  decoder = PyModesDecoder()
404
408
  elif decoder == "rs1090":
405
409
  from .decoders.rs1090 import Rs1090Decoder
@@ -524,6 +528,20 @@ class Rebuild:
524
528
  if rollcall_data is not None and rollcall_data.shape[0] > 0:
525
529
  rollcall_data = _normalize_icao24_dtype(rollcall_data)
526
530
  if include_rollcall:
531
+ if isinstance(decoder, PyModesDecoder):
532
+ # Keep the roll-call mintime under its historical name.
533
+ pos_data = pos_data.rename(
534
+ columns={"mintime": "mintime_pos"}
535
+ )
536
+ # Pandas can infer different resolutions for whole-second and
537
+ # fractional capture times. merge_asof requires equal dtypes.
538
+ if pos_data.timestamp.dtype != rollcall_data.timestamp.dtype:
539
+ pos_data = pos_data.assign(
540
+ timestamp=pos_data.timestamp.dt.as_unit("ns")
541
+ )
542
+ rollcall_data = rollcall_data.assign(
543
+ timestamp=rollcall_data.timestamp.dt.as_unit("ns")
544
+ )
527
545
  pos_data = pd.merge_asof(
528
546
  pos_data,
529
547
  rollcall_data,
@@ -28,9 +28,9 @@ class TestRebuildClass:
28
28
  def test_rebuild_basic_query(self, rebuild: Rebuild) -> None:
29
29
  """Test basic rebuild without decoder."""
30
30
  df = rebuild.rebuild(
31
- start="2023-01-03 16:00:00",
32
- stop="2023-01-03 20:00:00",
33
- icao24="400a0e",
31
+ start="2025-04-13 08:56:00",
32
+ stop="2025-04-13 09:06:00",
33
+ icao24="484164",
34
34
  )
35
35
 
36
36
  # Should return a DataFrame
@@ -48,12 +48,11 @@ class TestRebuildClass:
48
48
  def test_rebuild_with_string_decoder_rs1090(self, rebuild: Rebuild) -> None:
49
49
  """Test rebuild with 'rs1090' string decoder."""
50
50
  df = rebuild.rebuild(
51
- start="2023-01-03 16:00:00",
52
- stop="2023-01-03 17:00:00",
53
- icao24="400a0e",
51
+ start="2025-04-13 08:56:00",
52
+ stop="2025-04-13 09:06:00",
53
+ icao24="484164",
54
54
  decoder="rs1090",
55
55
  )
56
56
 
57
- # If data is returned, it should be a DataFrame
58
- if df is not None:
59
- assert isinstance(df, pd.DataFrame)
57
+ assert df is not None
58
+ assert set(df.icao24) == {"484164"}
@@ -0,0 +1,89 @@
1
+ """Offline rebuild regressions using recorded ADS-B position messages."""
2
+
3
+ from unittest.mock import Mock
4
+
5
+ import pytest
6
+
7
+ import pandas as pd
8
+ from pyopensky.rebuild import Rebuild
9
+ from pyopensky.trino import Trino
10
+
11
+ pytest.importorskip("pyModeS", minversion="3.6.1")
12
+
13
+ EVEN = "8D484164602B33D825DF33A49786"
14
+ ODD = "8D484164602B275037D32FB795B8"
15
+ # A CRC-valid 4,075 ft report received while this aircraft was at 7,450 ft.
16
+ ALTITUDE_OUTLIER = "8D4841646019B736C5D12199D7CA"
17
+
18
+
19
+ def rebuild_positions(
20
+ frames: list[tuple[float, str]], rollcall: pd.DataFrame | None = None
21
+ ) -> pd.DataFrame | None:
22
+ positions = pd.DataFrame(frames, columns=["mintime", "rawmsg"]).assign(
23
+ icao24=lambda df: df.rawmsg.str[2:8].str.lower(),
24
+ lat=0.0,
25
+ lon=0.0,
26
+ alt=0.0,
27
+ )
28
+ trino = Mock(spec=Trino)
29
+ trino.rawdata.side_effect = [positions, None, None, rollcall]
30
+ return Rebuild(trino).rebuild(
31
+ "2025-04-13",
32
+ "2025-04-14",
33
+ icao24=positions.icao24.unique().tolist(),
34
+ decoder="pymodes",
35
+ include_rollcall=rollcall is not None,
36
+ )
37
+
38
+
39
+ def test_rebuild_validates_positions_and_preserves_capture_times() -> None:
40
+ result = rebuild_positions(
41
+ [
42
+ (1001.0, ODD),
43
+ (1000.0, EVEN),
44
+ (1001.2, ALTITUDE_OUTLIER),
45
+ (1001.4, "8D484164602B23D7F9DF1AFDD978"),
46
+ (1001.5, "8D484164602B275029D328D75A02"),
47
+ (1000.5, EVEN), # Same payload broadcast again.
48
+ (1000.5, EVEN), # Duplicate observation.
49
+ ]
50
+ )
51
+ assert result is not None
52
+ assert result.mintime.tolist() == [1000.0, 1000.5, 1001.0, 1001.4, 1001.5]
53
+ assert result.altitude.tolist() == [7475, 7475, 7450, 7450, 7450]
54
+ assert all(result.lat.between(47.76, 47.77))
55
+ assert all(result.lon.between(8.42, 8.43))
56
+
57
+
58
+ @pytest.mark.parametrize(
59
+ "frames",
60
+ [
61
+ [(1000.0, EVEN), (1011.0, ODD)], # Outside the CPR pairing window.
62
+ [(1000.0, EVEN), (1001.0, ODD[:-1] + "0")], # Corrupt parity.
63
+ ],
64
+ )
65
+ def test_rebuild_without_a_valid_pair(frames: list[tuple[float, str]]) -> None:
66
+ assert rebuild_positions(frames) is None
67
+
68
+
69
+ @pytest.mark.parametrize(
70
+ "later_pair",
71
+ [
72
+ (EVEN, ODD),
73
+ ("8D40058B58C901375147EFD09357", "8D40058B58C904A87F402D3B8C59"),
74
+ ],
75
+ )
76
+ def test_sparse_encounters_keep_both_pairs(later_pair: tuple[str, str]) -> None:
77
+ result = rebuild_positions(
78
+ [(1, EVEN), (2, ODD), (305, later_pair[0]), (306, later_pair[1])]
79
+ )
80
+ assert result is not None
81
+ assert sorted(result.mintime) == [1, 2, 305, 306]
82
+
83
+
84
+ def test_rollcall_merge_keeps_both_capture_times() -> None:
85
+ rollcall = pd.DataFrame({"mintime": [1.5], "icao24": ["484164"]})
86
+ result = rebuild_positions([(1.0, EVEN), (2.0, ODD)], rollcall)
87
+ assert result is not None
88
+ assert result.mintime.tolist() == [1.5, 1.5]
89
+ assert result.mintime_pos.tolist() == [1, 2]