Play direction normalization

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

Play direction normalization is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Mirror spatial coordinates and angles so all plays face the same direction — removes left/right asymmetry from sports and spatial data

How to use this skill

Skill file

Play Direction Normalization

Overview

In spatial datasets (sports tracking, autonomous driving, robotics), events can occur in either direction. Normalize by flipping X-coordinates, orientation, and direction angles so all events face the same way. This halves the effective feature space and prevents models from learning spurious left/right patterns.

Quick Start

import numpy as np

def normalize_direction(df, direction_col='PlayDirection',
                        x_col='X', orient_col='Orientation',
                        dir_col='Dir', field_length=120.0):
    """Mirror coordinates so all plays go left-to-right."""
    df = df.copy()
    is_left = df[direction_col] == 'left'
    
    # Flip X coordinate
    df.loc[is_left, x_col] = field_length - df.loc[is_left, x_col]
    
    # Flip Y coordinate (optional, for symmetry)
    # df.loc[is_left, 'Y'] = field_width - df.loc[is_left, 'Y']
    
    # Flip angles (0-360 degrees)
    for col in [orient_col, dir_col]:
        flipped = 360.0 - df.loc[is_left, col]
        flipped[flipped == 360.0] = 0.0
        df.loc[is_left, col] = flipped
    
    return df

df = normalize_direction(tracking_data)

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.