Skip to content

Fix waveform arithmetic validation and integration - #34

Merged
gituser789 merged 2 commits into
upb-lea:mainfrom
MooMooCow29:fix/power-waveform-numerics
Aug 27, 2026
Merged

gituser789 merged 2 commits into
upb-lea:mainfrom
MooMooCow29:fix/power-waveform-numerics

Conversation

@MooMooCow29

Copy link
Copy Markdown
Contributor

Summary

This pull request improves the numerical correctness and validation of
waveform arithmetic and integration operations.

Changes

  • Validate that channels used in addition, subtraction, and multiplication
    have matching timebases.
  • Reject malformed channel data before waveform arithmetic.
  • Correctly support multiplication when no custom label is provided.
  • Replace constant-step integration with cumulative trapezoidal integration
    using the actual sampling intervals.
  • Support nonuniformly sampled waveform data.
  • Support valid two-sample integration.
  • Reject time vectors that are too short or not strictly increasing.
  • Add regression tests for the corrected behaviour.

Motivation

Oscilloscope data may contain nonuniform sample intervals. Using one assumed
sample period can therefore produce inaccurate integrated energy values.

Waveform arithmetic also requires corresponding samples to represent the same
points in time. Explicit timebase validation prevents silent numerical errors
when channels are misaligned.

Testing

Local environment:

  • Windows
  • Python 3.13.5
  • standard-xdrlib installed because xdrlib was removed from Python 3.13

Results:

  • Targeted regression tests: 10 passed
  • Complete project test suite: 97 passed, 3 warnings
  • pycodestyle: passed
  • Ruff: All checks passed

The warnings are existing dependency deprecation warnings involving
standard-xdrlib and findiff; they are not failures in this change.

Validate channel timebases, support nonuniform cumulative integration, and add regression tests.
@MooMooCow29
MooMooCow29 marked this pull request as ready for review July 30, 2026 20:41

@SevenOfNinePE SevenOfNinePE left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update is valuable and makes sense. Mainly some updates of unit tests are necessary. Moreover don't hold back on comments.

Comment thread pysignalscope/scope.py Outdated
if label is None:
# Log missing user input
logging.info(f"{class_modulename} :Label was not defined. So default value is used", class_modulename)
logging.info(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not remove the comment. '# Log missing user input'.
Also if the comment is obviously by code it helps the readability.
In general more comments help to understand the program flow.

Comment thread tests/test_scope_power_operations.py
Add parametrized coverage for timebase validation, restore flow comments,
and keep non-equidistant integration close to the existing implementation.
@MooMooCow29

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing it and for the feedback;

I appreciate it.

@gituser789
gituser789 merged commit e8588fa into upb-lea:main Aug 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants