允许 HHD 下采样率不同的标定保持兼容
按实际运行上下文核对其余处理参数,保留文件指纹与设备身份校验。115 项标定及运行时检查通过。
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Feature identities use effective measurement settings, never display metadata."""
|
||||
|
||||
from copy import deepcopy
|
||||
import json
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
@@ -57,3 +58,77 @@ def test_domain_fingerprint_binds_map_content_not_only_dimensions():
|
||||
changed[key].flat[0] = not changed[key].flat[0] if key == "valid_mask" else 1
|
||||
assert domain_fingerprint(changed) != original
|
||||
assert domain_fingerprint({key: value.copy() for key, value in domain.items()}) == original
|
||||
|
||||
|
||||
def _model(data):
|
||||
from orisys.calibration import parse
|
||||
|
||||
return parse({
|
||||
"schema_version": 3, "unit": "N",
|
||||
"identity": {"sensor_type": "box", "sn": "A1"},
|
||||
"pipeline": build_context(data),
|
||||
"model": {
|
||||
"type": "global_gain/1", "input_profile": "force_delta/1",
|
||||
"output_frame": "sdk_force/1", "outputs": ["fn"],
|
||||
"params": {"gains_N_per_raw": {"fn": .001}, "valid_force_range_N": [0, 3]},
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@pytest.mark.parametrize("downsample", [1, 2, 4])
|
||||
def test_downsample_only_difference_accepts_existing_model_without_rewriting_it(downsample):
|
||||
from orisys.calibration import validate_for_device
|
||||
|
||||
data = config()
|
||||
data["tracker"]["hhd_downsample"] = 3
|
||||
model = _model(data)
|
||||
original = model.to_dict()
|
||||
fingerprint = model.fingerprint
|
||||
data["tracker"]["hhd_downsample"] = downsample
|
||||
actual = build_context(data)
|
||||
assert json.loads(json.dumps(actual)) == actual
|
||||
assert actual["feature_signature_sha256"] != model.pipeline["feature_signature_sha256"]
|
||||
validate_for_device(model, "box", "A1", pipeline=actual)
|
||||
model.validate_for_context(actual)
|
||||
assert model.to_dict() == original
|
||||
assert model.fingerprint == fingerprint
|
||||
assert actual["hhd_downsample"] == downsample
|
||||
|
||||
|
||||
def test_runtime_context_binds_a_different_downsample_model_and_predicts():
|
||||
from orisys.force_readout import ForceReadout
|
||||
from orisys.sensor import Sensor
|
||||
|
||||
data = config()
|
||||
data["tracker"]["hhd_downsample"] = 3
|
||||
sensor = Sensor.__new__(Sensor)
|
||||
sensor._config = data
|
||||
sensor.calibration = _model(data)
|
||||
sensor._force_raw = (100.0, 0.0, 0.0)
|
||||
sensor._force_readout = ForceReadout({})
|
||||
sensor._model_readouts = {}
|
||||
sensor._reset_calibration_session()
|
||||
data["tracker"]["hhd_downsample"] = 2
|
||||
sensor.bind_calibration_context(build_context(data))
|
||||
sensor.set_calibration_reference({"fn": 100.0}, reference_id="unloaded")
|
||||
result = sensor.apply_calibration_frame(
|
||||
frame_id=1, timestamp_s=0.1, raw=(120.0, 0.0, 0.0), contact_found=True,
|
||||
)
|
||||
assert result.values_N["fn"] == pytest.approx(.02)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("section,key,value", [
|
||||
("camera", "resolution_raw", [640, 480]),
|
||||
("tracker", "dis_mode", 1),
|
||||
("tracker", "flow_iterations", 99),
|
||||
("contact", "threshold", .9),
|
||||
("filters", "flow_ema_alpha", .5),
|
||||
])
|
||||
def test_downsample_tolerance_does_not_hide_other_pipeline_changes(section, key, value):
|
||||
data = config()
|
||||
data["tracker"]["hhd_downsample"] = 3
|
||||
model = _model(data)
|
||||
data["tracker"]["hhd_downsample"] = 2
|
||||
data.setdefault(section, {})[key] = value
|
||||
with pytest.raises(ValueError, match="pipeline mismatch"):
|
||||
model.validate_for_context(build_context(data))
|
||||
|
||||
Reference in New Issue
Block a user