Skip to content

Commit 4366563

Browse files
committed
feat(arinc767): add flight archives to fixtures, batch example, and decoder updates
1 parent 4d0e21d commit 4366563

4 files changed

Lines changed: 94 additions & 5 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import zipfile
2+
from pathlib import Path
3+
4+
from pyarinc.arinc767.decoder import Arinc767Decoder
5+
from pyarinc.io.csv_export import export_csv
6+
from pyarinc.io.datafile import read_binary
7+
from pyarinc.io.parquet_export import export_parquet
8+
from pyarinc.models.parameter import Parameter
9+
10+
11+
def process_zip_archive(zip_path: Path, output_dir: Path) -> None:
12+
"""Extract and process only the valid flight data files inside an ARINC 767 ZIP archive."""
13+
print(f"\nProcessing archive: {zip_path.name}")
14+
15+
with zipfile.ZipFile(zip_path, "r") as zf:
16+
namelist = zf.namelist()
17+
print(f"Contents: {namelist}")
18+
19+
# Filter out schemas, specifications, and directories—keep only payload files
20+
data_files = [
21+
f for f in namelist if not f.lower().endswith((".xml", ".xsd", "/"))
22+
]
23+
24+
if not data_files:
25+
print(f"-> Skipping: No binary flight data files found in {zip_path.name}")
26+
return
27+
28+
extract_dir = output_dir / "extracted" / zip_path.stem
29+
extract_dir.mkdir(parents=True, exist_ok=True)
30+
31+
# Target only the right files directly
32+
for file_name in data_files:
33+
zf.extract(file_name, extract_dir)
34+
extracted_file = extract_dir / file_name
35+
36+
print(f"-> Found target flight data file: {extracted_file.name}")
37+
try:
38+
raw_bytes = read_binary(extracted_file)
39+
40+
# Define parameters matching a 767 dataset
41+
sample_params = [
42+
Parameter(
43+
"ALTITUDE",
44+
start_bit=0,
45+
bit_length=16,
46+
data_type="BNR",
47+
rate=1.0,
48+
),
49+
Parameter(
50+
"AIRSPEED",
51+
start_bit=16,
52+
bit_length=16,
53+
data_type="BNR",
54+
rate=1.0,
55+
),
56+
]
57+
58+
decoder = Arinc767Decoder(sample_params, frames_per_second=1.0)
59+
df = decoder.decode_raw_bytes(raw_bytes, strict=False)
60+
61+
out_name = f"{zip_path.stem}_{extracted_file.stem}"
62+
csv_path = output_dir / f"{out_name}_decoded.csv"
63+
parquet_path = output_dir / f"{out_name}_decoded.parquet"
64+
65+
export_csv(df, csv_path)
66+
export_parquet(df, parquet_path)
67+
print(
68+
f" Successfully decoded and exported {len(df)} rows to {csv_path.name}"
69+
)
70+
71+
except Exception as e:
72+
print(f" Could not decode {extracted_file.name}: {e}")
73+
74+
75+
if __name__ == "__main__":
76+
fixtures_dir = Path("tests/fixtures/ags767")
77+
output_directory = Path("output")
78+
output_directory.mkdir(parents=True, exist_ok=True)
79+
80+
zip_files = list(fixtures_dir.glob("*.zip"))
81+
82+
if zip_files:
83+
for z_file in zip_files:
84+
process_zip_archive(z_file, output_directory)
85+
print("\nAll batch archives processed successfully!")
86+
else:
87+
print("No ZIP fixtures found in tests/fixtures/ags767/")

‎pyarinc/arinc767/decoder.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,20 @@ def decode_frames(self, frames: Iterable[Arinc767Frame]) -> pd.DataFrame:
9595

9696
return pd.DataFrame(rows)
9797

98-
def decode_raw_bytes(self, data: bytes) -> pd.DataFrame:
98+
def decode_raw_bytes(self, data: bytes, **kwargs: Any) -> pd.DataFrame:
9999
"""Public helper to parse raw bytes into frames and decode them."""
100-
frames = Arinc767FrameParser.iter_frames(data)
100+
frames = Arinc767FrameParser.iter_frames(data, **kwargs)
101101
return self.decode(frames)
102102

103-
def decode(self, data: bytes | Iterable[Arinc767Frame]) -> pd.DataFrame:
103+
def decode(
104+
self, data: bytes | Iterable[Arinc767Frame], **kwargs: Any
105+
) -> pd.DataFrame:
104106
"""Decode raw bytes or frames into a scheduled, long-format DataFrame."""
105107
fps = self.frames_per_second
106108

107-
# Case 1: raw bytes → parse frames via helper
109+
# Case 1: raw bytes → parse frames via helper (passing down kwargs)
108110
if isinstance(data, (bytes, bytearray)):
109-
frames = list(Arinc767FrameParser.iter_frames(data))
111+
frames = list(Arinc767FrameParser.iter_frames(data, **kwargs))
110112
else:
111113
frames = list(data)
112114

‎tests/fixtures/ags767/647a-1.zip‎

12.1 KB
Binary file not shown.
403 KB
Binary file not shown.

0 commit comments

Comments
 (0)