From 177e076399ea7cef1d42121b9c9480e47b51f310 Mon Sep 17 00:00:00 2001 From: David Northover Date: Fri, 20 Nov 2026 17:45:27 -0500 Subject: [PATCH 1/3] fix: use per-point speed in adaptive curvature weighting --- python/ouroboros/helpers/spline.py | 6 +- python/test/helpers/test_spline.py | 71 ++++++++++++++++++- .../test/pipeline/test_round_trip_accuracy.py | 3 +- release/README.md | 8 +++ 4 files changed, 83 insertions(+), 5 deletions(-) diff --git a/python/ouroboros/helpers/spline.py b/python/ouroboros/helpers/spline.py index 178be9be..c20a5007 100644 --- a/python/ouroboros/helpers/spline.py +++ b/python/ouroboros/helpers/spline.py @@ -306,7 +306,7 @@ def calculate_spline_curvature(spline: Spline, t: np.ndarray) -> np.ndarray: # Calculate the curvature numerator = np.linalg.norm(np.cross(first_derivative, second_derivative), axis=1) - denominator = np.linalg.norm(first_derivative) ** 3 + denominator = np.linalg.norm(first_derivative, axis=1) ** 3 curvature = numerator / denominator return curvature @@ -331,9 +331,9 @@ def calculate_curvature_parameterization(spline: Spline, t: np.ndarray) -> np.nd # Calculate the curvature curvature = calculate_spline_curvature(spline, t) - # Calculate the first derivative of the curvature + # Calculate speed at each parameter to accumulate curvature along the curve. first_derivative = spline(t, derivative=1).T - len_term = np.linalg.norm(first_derivative) + len_term = np.linalg.norm(first_derivative, axis=1) # Calculate the cumulative sum of the curvature curvature_sum = np.cumsum(curvature * len_term) diff --git a/python/test/helpers/test_spline.py b/python/test/helpers/test_spline.py index bc938cb1..6800f543 100644 --- a/python/test/helpers/test_spline.py +++ b/python/test/helpers/test_spline.py @@ -1,8 +1,77 @@ import numpy as np -from ouroboros.helpers.spline import Spline +from ouroboros.helpers.spline import ( + Spline, + calculate_curvature_parameterization, + calculate_spline_curvature, +) from test.sample_data import generate_sample_curve_helix +class VariableSpeedCircle(Spline): + """Exact radius-two circle with angle t + t**2 and positive, varying speed.""" + + def __init__(self): + self.u = np.linspace(0, 1, 1001) + + def __call__(self, times, derivative=0): + angle = times + times**2 + angular_speed = 1 + 2 * times + zeros = np.zeros_like(times) + + if derivative == 0: + return 2 * np.array([np.cos(angle), np.sin(angle), zeros]) + if derivative == 1: + return 2 * np.array([ + -np.sin(angle) * angular_speed, + np.cos(angle) * angular_speed, + zeros, + ]) + if derivative == 2: + return 2 * np.array([ + -np.cos(angle) * angular_speed**2 - 2 * np.sin(angle), + -np.sin(angle) * angular_speed**2 + 2 * np.cos(angle), + zeros, + ]) + raise ValueError("Only derivatives up to order two are used in these tests.") + + +def test_spline_curvature_is_independent_of_speed_and_batch(): + circle = VariableSpeedCircle() + times = np.linspace(0, 1, 9) + + # The curvature of a circle is 1 / radius under any regular parameterization. + np.testing.assert_allclose(calculate_spline_curvature(circle, times), 0.5) + np.testing.assert_allclose(calculate_spline_curvature(circle, times[::2]), 0.5) + + +def test_curvature_parameterization_weights_each_sample_by_its_speed(): + circle = VariableSpeedCircle() + times = np.linspace(0, 1, 9) + + cumulative_curvature = calculate_curvature_parameterization(circle, times) + + # Integrated curvature on a circle is its turning angle. The existing + # unscaled cumulative sum therefore adds the angular speed at each sample. + contributions = np.diff(cumulative_curvature, prepend=0) + np.testing.assert_allclose(contributions, 1 + 2 * times) + + +def test_adaptive_parameters_follow_physical_progress_at_variable_speed(): + circle = VariableSpeedCircle() + + parameters = circle.calculate_adaptive_parameters( + distance_between_points=0.1, ratio=1, calculation_params_ratio=100 + ) + + # Constant curvature gives equal turning-angle and arc-length progress. + # The tolerance allows the existing cumulative-sum quadrature on the + # uniform calculation grid; no exact continuous integral is assumed. + angle = parameters + parameters**2 + np.testing.assert_allclose( + angle, np.linspace(0, 2, len(parameters)), atol=1e-3 + ) + + def test_evaluate_spline(): import numpy as np diff --git a/python/test/pipeline/test_round_trip_accuracy.py b/python/test/pipeline/test_round_trip_accuracy.py index ed2aa368..87de3d93 100644 --- a/python/test/pipeline/test_round_trip_accuracy.py +++ b/python/test/pipeline/test_round_trip_accuracy.py @@ -146,7 +146,8 @@ def centerline(z): assert masks["binary"]["recall"] > 0.98 assert masks["binary"]["precision"] > 0.73 assert masks["binary"]["hd95"] < 2 - assert masks["binary"]["centroid_distance"] < 0.1 + # Calibrated on adaptive geometry using per-point spline speed. + assert masks["binary"]["centroid_distance"] < 0.15 assert masks["binary"]["precision"] < masks["weighted"]["precision"] assert masks["binary"]["dice"] < masks["weighted"]["dice"] for name, mode in masks.items(): diff --git a/release/README.md b/release/README.md index 7d41fe31..1866ffc8 100644 --- a/release/README.md +++ b/release/README.md @@ -2,6 +2,14 @@ [`release-lock.json`](release-lock.json) is the production source of truth for the server image, bundled plugin assets, and package flavors. The packaging scripts and workflows do not carry fallback production pins. +## Unreleased notes + +- Fixed adaptive slicing's curvature weighting to use the spline speed at + each point instead of one norm for the whole curve ([#258](https://github.com/ChengLabResearch/ouroboros/issues/258)). + Adaptive slice positions, and therefore straightened output, can change + for the same trace and options compared with earlier versions. Equidistant + slicing is unchanged. + ## Prepare an application release Make release changes either as direct commits to `main` or through a single PR containing all release commits. Separate commits do not mean separate PRs; do not create a PR for each preparation commit. From 60d68558a24ae8a35b52516ebd5a09d969f8849c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 20 Nov 2026 22:49:23 +0000 Subject: [PATCH 2/3] Updated coverage.svg --- python/coverage.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/coverage.svg b/python/coverage.svg index c38194f4..40e140b8 100644 --- a/python/coverage.svg +++ b/python/coverage.svg @@ -1 +1 @@ -coverage: 98.99%coverage98.99% \ No newline at end of file +coverage: 98.95%coverage98.95% \ No newline at end of file From c5f84a0209cabcc9bf5c39307e8c059cb183f160 Mon Sep 17 00:00:00 2001 From: David Northover Date: Fri, 20 Nov 2026 18:33:28 -0500 Subject: [PATCH 3/3] docs: keep compatibility note with release body --- release/README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/release/README.md b/release/README.md index 1866ffc8..7d41fe31 100644 --- a/release/README.md +++ b/release/README.md @@ -2,14 +2,6 @@ [`release-lock.json`](release-lock.json) is the production source of truth for the server image, bundled plugin assets, and package flavors. The packaging scripts and workflows do not carry fallback production pins. -## Unreleased notes - -- Fixed adaptive slicing's curvature weighting to use the spline speed at - each point instead of one norm for the whole curve ([#258](https://github.com/ChengLabResearch/ouroboros/issues/258)). - Adaptive slice positions, and therefore straightened output, can change - for the same trace and options compared with earlier versions. Equidistant - slicing is unchanged. - ## Prepare an application release Make release changes either as direct commits to `main` or through a single PR containing all release commits. Separate commits do not mean separate PRs; do not create a PR for each preparation commit.