Gradient event boundary detection

From wenmin-wu/ds-skills · View interactive version

Gradient event boundary detection is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Detect event start/end boundaries in time series by finding extrema of the first derivative (steepest gradient points)

How to use this skill

Skill file

Gradient Event Boundary Detection

Overview

For events with gradual onset and offset (transits, dips, ramps), locate boundaries by computing the first derivative and finding its extrema. The steepest descent marks event start (ingress); steepest ascent marks event end (egress). Works without threshold tuning.

Quick Start

import numpy as np

def detect_event_boundaries(signal, search_start=None, search_end=None):
    """Find event ingress/egress via gradient extrema.
    
    Args:
        signal: 1D array of the time series
        search_start/end: optional tuple (lo, hi) to constrain search region
    Returns:
        (ingress_idx, egress_idx)
    """
    event_min = np.argmin(signal)
    # Search for steepest descent before minimum
    pre = signal[:event_min]
    grad_pre = np.gradient(pre)
    ingress = np.argmin(grad_pre)  # most negative gradient
    # Search for steepest ascent after minimum
    post = signal[event_min:]
    grad_post = np.gradient(post)
    egress = np.argmax(grad_post) + event_min
    return ingress, egress

Key Decisions

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.