Skip to content

Follow-up: time-warped newtimef marker and cycle GUI workflows #146

Closed

Description

@suraj-ranganath

🤖 Follow-up from Phase 7 (#138) of epic #131.\n\nRows covered: pop_newtimef, newtimef, timewarp, angtimewarp, tf_cycle_calc.\n\nScope: port or redesign the EEGLAB time-warped event-marker workflow for ERSP/ITC and the cycle-calculation GUI helper with standalone EEGPrep runtime behavior, tests, and GUI parity evidence where user-facing.\n\nNon-goal: do not make package runtime depend on src/eegprep/eeglab.

Activity

  1. claude commented on Jun 6, 2026

    @claude
    Contributor

    🤖 Plan:

    Research

    Scope of #146 spans five EEGLAB rows that together form one workflow: time-warped event markers feeding newtimef's wavelet path, plus the GUI cycle-calculator that picks cycles/winsize from the dialog. Three of the five have no EEGPrep port today (timewarp, angtimewarp, tf_cycle_calc); the other two exist but explicitly reject the time-warp options and disable the cycle-calc button in the GUI, so they are not user-reachable yet. Root cause is missing helper modules plus a hard-rejection guard added during the initial pop_newtimef port that needs to be replaced once the helpers land. This is multi-module (>100 LOC) and design-shaped, so per instructions I'm posting analysis instead of a PR.

    Relevant code

    Proposed Approach (design)

    Multi-module port. EEGLAB parity oracle: eeglab/functions/timefreqfunc/{timewarp,angtimewarp,newtimef}.m and eeglab/functions/popfunc/pop_newtimef.m (the vendored tree is not in this CI checkout; I'll read it at implementation time and cite real lines in the PR).

    1. New module src/eegprep/functions/timefreqfunc/timewarp.py exposing timewarp(latencies, newlatencies) -> (warpmat, warped_indices) — linear piecewise time mapping between per-trial event latencies (pnts-units) and target latencies. Pure NumPy, channel-major; returns both the index map and the sparse warp matrix EEGLAB returns. EEGLAB latencies are 1-based; converted at the boundary.
    2. New module src/eegprep/functions/timefreqfunc/angtimewarp.py exposing angtimewarp(latencies, newlatencies, phases) -> warped_phases — circular interpolation of phases along the warp map from (1). Reuses that map; does not re-derive.
    3. Extend compute_time_frequency and newtimef in functions/timefreqfunc/newtimef.py with timewarp (per-trial event-latency matrix, ms), timewarpms (common target latencies, ms), timewarpidx (optional event subset to mark). When timewarp is supplied, _trial_wavelet shifts each trial's time-output indices through timewarp(...) before applying Morlet wavelets; ITC uses angtimewarp-aligned phases. STFT path raises a clear NotImplementedError to match EEGLAB (wavelet-only).
    4. New helper src/eegprep/functions/timefreqfunc/tf_cycle_calc.py exposing tf_cycle_calc(srate, frame_count, freqs, cycles) -> dict returning winsize, min_freq, max_freq, n_cycles_low, n_cycles_high. Pure numeric; no plotting. A small Qt dialog (functions/guifunc/tf_cycle_calc_dialog.py) wraps it and writes results back into the parent pop_newtimef dialog.
    5. pop_newtimef.py:
      • Drop timewarp* from _reject_unsupported_options; thread the options through to newtimef.
      • Replace enabled=False on calcpush with a callback that opens the tf_cycle_calc dialog and writes results back into the cycles/tlimits controls.
      • Add three GUI controls behind a "Time warp (optional)" section: timewarp (per-trial event-latency matrix or workspace name), timewarpms (target latencies), timewarpidx (event indices to mark). Defaults empty so the no-warp path stays byte-identical.
      • Update history_command so generated pop_newtimef(EEG, ...) is replayable from eegprep-console.
    6. Help: extend src/eegprep/resources/help/pop_newtimef.md; add src/eegprep/resources/help/tf_cycle_calc.md. No MD for timewarp/angtimewarp — not directly user-facing.
    7. Tests:
      • tests/test_timewarp.py (new): identity warp, known-fixture latency → expected linear map, unsorted-input rejection; angtimewarp wrap-around at ±π, numeric parity on a hand-computed case.
      • tests/test_tf_cycle_calc.py (new): deterministic outputs for representative (srate, frames, freqs, cycles) tuples.
      • Extend tests/test_phase4_timefreq_statistics.py: pop_newtimef with timewarp=..., timewarpms=..., timewarpidx=... on sample_epoch; assert result.times aligns to timewarpms, history is replayable, GUI path round-trips through _run_gui with the default renderer.
      • Extend tests/test_console_workspace.py: bare pop_newtimef(EEG, ..., timewarp=...) auto-stores.
      • Visual parity case under tools/visual_parity/pop_newtimef_timewarp/, gated by the existing visual marker.
      • MATLAB parity (@pytest.mark.matlab): numerical compare against newtimef(..., 'timewarp', ...) on a 4-channel synthetic; skipped under EEGPREP_SKIP_MATLAB=1.

    Open questions before implementation:

    1. EEGLAB's cycle-calc button pops a modal sub-dialog with its own inputs. Ship the Qt dialog now, or land the numeric tf_cycle_calc() first and the GUI dialog in a follow-up?
    2. EEGLAB accepts timewarp as either an (ntrials × nevents) matrix or per-trial cell arrays. Restrict to the matrix form (recommended path) and reject cell input with a clear message?
    3. Visual parity snapshot — gate behind the visual marker and skip when X11 capture is unavailable, matching other pop_* parity cases?

    Estimated diff: ~600-800 LOC across 5 source files + 3 test files + 2 help files. Branch will be agent/20260606-fix-146 once approach is approved.

  2. suraj-ranganath commented on Jun 7, 2026

    @suraj-ranganath
    MemberAuthor

    🤖 Resolved by the work now included in PR #152. Closing this constituent phase/follow-up issue now; parent epic #131 remains open until the epic PR merges.

  3. arnodelorme commented on Dec 1, 2026

    @arnodelorme
    Collaborator

    🤖 The tf_cycle_calc dialog and native jamming captures are tracked in #928.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions