Repository navigation
Min/max curve downsampling preserving peaks - #85
Merged
Merged
Conversation
Curve downsampling kept one point out of N (`data[::N]`), which discards extrema: narrow peaks could disappear and the envelope of noisy signals looked thinner than it is. - New `CurveParam.dsamp_method` parameter: "minmax" (new default) keeps the minimum and the maximum of each group of 2 x N points, in their original order, with the first and last points; "stride" restores the former method. NaN values are ignored, except in groups containing only NaN values, which keep one so that the curve is still interrupted - The indices of the points kept are stored (`get_dsamp_indices`), so that X, Y and error data are downsampled consistently (`minmax_downsampling_indices` computes them) - `hit_test` maps original indices to indices of points kept, and `move_local_point_to` moves the corresponding original point (it used the handle as an index into the full data) - `EditPointTool` edits original points through these indices, and keeps the points drawn while a point is dragged (`frozen_downsampling`) - French translations Closes #83 Assisted-by: Claude Opus 5.5
This was referenced Oct 29, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #83. Part of DataLab-Platform/DataLab#453 (curve readability).
Problem
Curve downsampling kept one point out of N (
data[::N]), which discards extrema. Narrow peaks may disappear or change height depending on their position relative to the stride, and the envelope of noisy signals looks thinner than it is.Changes
Downsampling method
CurveParam.dsamp_methodparameter, shown in the curve parameters dialog:dsamp_method) load with the default value.Indices of the points kept
minmax_downsampling_indices(data, factor)is vectorized with NumPy.CurveItem.get_dsamp_indices()returns the indices of the points kept.dsamp()uses them, so X, Y and error data are downsampled consistently (ErrorBarCurveItemincluded).Point handles
hit_testmaps original indices to indices of points kept, for both methods.move_local_point_tonow moves the original point corresponding to the drawn point. It used the handle as an index into the full data, so a different point was moved when downsampling was enabled.EditPointTooledits original points through these indices.CurveItem.frozen_downsampling()context keeps the points drawn while a point is dragged. Otherwise, with min/max downsampling, a moved point could be replaced by another point of its group.Translations
Tests
plotpy/tests/unit/test_curve_downsampling.py, covering:hit_testand moving points on downsampled curves.test_builder_curve.pychecks both methods.plotpy/tests): 384 passed, 16 skipped locally.test_edit_point_tool, which failed locally ondevelop, now passes.Notes
This PR and #84 (fast thick curves) both modify
plotpy/items/curve/base.py, in different methods. The second one to be merged may need a trivial rebase.