Files
cosma-nav/tests/test_parse_usv_gps.py

36 lines
1.2 KiB
Python

import tempfile, os, io
import numpy as np
import h5py
SAMPLE_CSV = """timestamp,data,value
2026-04-08 09:31:10.100000,Easting,318234.5
2026-04-08 09:31:10.100000,Northing,4823456.7
2026-04-08 09:31:10.100000,UTM_number,32
2026-04-08 09:31:10.100000,UTM_letter,T
2026-04-08 09:31:11.200000,Easting,318235.1
2026-04-08 09:31:11.200000,Northing,4823457.2
2026-04-08 09:31:11.200000,UTM_number,32
2026-04-08 09:31:11.200000,UTM_letter,T
"""
def test_parse_usv_gps():
from extract.parse_usv_gps import parse_nav_log, write_usv_gps_group
rows = parse_nav_log(io.StringIO(SAMPLE_CSV))
assert len(rows) == 2
assert abs(rows[0]["easting"] - 318234.5) < 0.01
assert abs(rows[0]["northing"] - 4823456.7) < 0.01
assert rows[0]["utm_zone"] == "32T"
assert rows[0]["rtk_status"] == 0
with tempfile.NamedTemporaryFile(suffix=".h5", delete=False) as tmp:
path = tmp.name
try:
write_usv_gps_group(path, rows)
with h5py.File(path, "r") as f:
assert "usv_gps" in f
assert len(f["usv_gps/easting"][:]) == 2
assert len(f["usv_gps/northing"][:]) == 2
assert len(f["usv_gps/t_ns"][:]) == 2
finally:
os.unlink(path)