Skip to content

Python tool for aircraft Doppler audio geolocation using historical ADS-B flight data (Source-available)

Preserve live discovery scalar metadata in prepared scoring inputs

Cinna Davis5eaee3a43120
diff --git a/src/dopplergeist/scoring_inputs.py b/src/dopplergeist/scoring_inputs.py
index 4c79b9b..bf477c6 100644
--- a/src/dopplergeist/scoring_inputs.py
+++ b/src/dopplergeist/scoring_inputs.py
@@ -14,12 +14,14 @@ _SETTING_KEYS = ("frequency_loss_scale_hz", "frequency_sigma_hz",
def _plain_copy(value, remaining):
"""Copy JSON-like builtin containers without invoking custom copy hooks."""
- if type(value) not in (str, float, int, bool, type(None), list, tuple, dict):
+ # Live discovery's support_fraction can be an immutable NumPy float64.
+ # Keep its exact type and bits; serializing it first would hide this case.
+ if type(value) not in (str, float, int, bool, type(None), np.float64, list, tuple, dict):
raise TypeError("Custom scoring input retains its original path")
remaining[0] -= sys.getsizeof(value)
if remaining[0] < 0:
raise TypeError("Prepared scoring input budget exceeded")
- if type(value) in (str, float, int, bool, type(None)):
+ if type(value) in (str, float, int, bool, type(None), np.float64):
return value
if type(value) in (list, tuple):
copied = [_plain_copy(item, remaining) for item in value]
diff --git a/tests/test_real_scoring_inputs.py b/tests/test_real_scoring_inputs.py
index d4d53f8..41878f5 100644
--- a/tests/test_real_scoring_inputs.py
+++ b/tests/test_real_scoring_inputs.py
@@ -50,6 +50,30 @@ def test_recorded_snapshot_is_private_and_immutable():
assert matching._ridge_fit_cache.get() is None
+def test_live_discovery_scalar_metadata_keeps_prepared_fits_eligible():
+ event, measurement = recorded()
+ fixture = json.loads((Path(__file__).parent / "data/real-ridge-batch-arithmetic.json").read_text())
+ factors, emissions = np.asarray(fixture["factors"]), np.asarray(fixture["emissions"])
+ # JSON erases discovery's NumPy scalar type. Restore that type on the same
+ # observed support fraction, without changing any measured numeric value.
+ support = np.float64(event["quality"]["support_fraction"])
+ event["quality"]["support_fraction"] = support
+ expected = batch_ridge.first_event_fits(measurement, event, factors, emissions)
+
+ @matching._cache_ridge_fits
+ def run():
+ events, measurements = matching._prepare_score_inputs([event], [measurement])
+ copied_event, copied = events[0], measurements[0]
+ assert matching._prepared_score_token(copied, copied_event) is not None
+ retained = copied_event["quality"]["support_fraction"]
+ assert type(retained) is np.float64 and retained.tobytes() == support.tobytes()
+ assert batch_ridge.first_event_fits(copied, copied_event, factors, emissions) == expected
+ event["quality"]["support_fraction"] = np.nextafter(support, np.inf)
+ assert copied_event["quality"]["support_fraction"] is support
+
+ run()
+
+
@pytest.mark.parametrize("changed", ["bounds", "fraction", "scale", "time", "shape", "dtype"])
def test_recorded_snapshot_token_rejects_changed_settings_or_view_metadata(changed):
event, measurement = recorded()
@@ -74,7 +98,7 @@ def test_recorded_snapshot_token_rejects_changed_settings_or_view_metadata(chang
run()
[email protected]("kind", ["weight", "bounds", "noncontiguous", "custom", "budget"])
[email protected]("kind", ["weight", "bounds", "noncontiguous", "custom", "numpy_subclass", "budget"])
def test_unsupported_recorded_inputs_keep_the_original_path(kind):
event, measurement = recorded()
if kind == "weight":
@@ -91,6 +115,11 @@ def test_unsupported_recorded_inputs_keep_the_original_path(kind):
def __sizeof__(self):
raise AssertionError("Custom size hook executed")
event = dict(event, ignored_custom_metadata=Custom())
+ elif kind == "numpy_subclass":
+ class Custom(np.float64):
+ def __sizeof__(self):
+ raise AssertionError("Custom scalar size hook executed")
+ event["quality"]["support_fraction"] = Custom(event["quality"]["support_fraction"])
@matching._cache_ridge_fits
def run():