Skip to content

feat: add correct_clock_drift and document scale_time_index use case#290

Open
sorlob wants to merge 5 commits into
mainfrom
feat/correct-clock-drift
Open

feat: add correct_clock_drift and document scale_time_index use case#290
sorlob wants to merge 5 commits into
mainfrom
feat/correct-clock-drift

Conversation

@sorlob
Copy link
Copy Markdown
Collaborator

@sorlob sorlob commented May 16, 2026

Summary

  • Add TimeSeriesBase.correct_clock_drift(anchor_time, drift_point, *, drift=..., true_time=...) for the common workflow of correcting a linear clock drift from one anchor and one drift observation. The drift is expressed either as a signed Timedelta (device − true) or via the wall-clock time at the second observation; the two forms are mutually exclusive. Internally delegates to scale_time_index.
  • Rework the scale_time_index docstring so clock-drift correction is named as the primary use case, with the explicit mapping formula and a recipe for deriving scale_factor from two sync points — making the method discoverable to users searching for "drift".
  • Inherited by both Channel and Label via TimeSeriesBase.

Test plan

  • pytest tests/test_timeseries.py -k "scale_time_index or correct_clock_drift" (6 passed)
    • Existing scale_time_index tests still pass.
    • New tests cover the drift= form, the true_time= form, the "exactly one of" guard (neither / both), and the zero-interval guard.

🤖 Generated with Claude Code

Add TimeSeriesBase.correct_clock_drift(anchor_time, drift_point, *,
drift=..., true_time=...) for the common workflow of correcting a
linear clock drift from one anchor and one drift observation. The
drift can be expressed either as a signed Timedelta (device − true)
or via the wall-clock time at the second observation; the two forms
are mutually exclusive. The method computes the appropriate
scale_factor and delegates to scale_time_index.

Rework the scale_time_index docstring to name clock-drift correction
as the primary use case, give the explicit mapping formula, and
explain how to derive scale_factor from two sync points so the
method is discoverable by users searching for "drift".

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@sorlob sorlob requested a review from behackl May 16, 2026 19:35
sorlob and others added 4 commits May 16, 2026 22:18
Clock drift is a property of a clock, which typically governs more
than one channel/label of a recording — and some devices have
several clocks (e.g. via OEM modules). Correcting only some of the
channels sharing a drifted clock would desynchronise them, and
correcting unaffected channels would introduce new desync. Document
that users should loop over all channels and labels driven by the
affected clock.
Allow modifying the time index in-place by passing inplace=True, avoiding
the copy overhead when the original object is no longer needed. Default
remains inplace=False to preserve the existing copy-on-modify semantics.
The offset represents a deliberate alignment shift, not a clock-rate
artefact — it should not be scaled along with the recording. Previously
scale_time_index absorbed the offset into time_index and reset _offset
to zero, making it impossible to recover the original alignment after
the fact.

Now the offset is un-baked before scaling and re-applied unchanged
afterwards, so _offset is preserved on the returned series and the
effective timestamps (as returned by get_data) remain consistent.
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.

2 participants