Skip to main content

Detect anomalies in UAV telemetry logs using Hampel filtering, optional STL decomposition, and GPS jump checks.

Project description

Flight Log Anomaly Detector (Hampel + optional STL)

Flags weird events in UAV telemetry: battery voltage spikes, GPS drift/jumps, IMU outliers.

What it does

  • Hampel filter (rolling median + MAD) on chosen numeric columns.
  • Optional STL decomposition to remove trend/seasonality before Hampel (per-column).
  • Optional GPS jump detector using lat/lon vs reported speed.
  • Outputs an anomalies JSON list with timestamps, columns, values, and reasons.

MVP model

  • For each selected column, apply a windowed Hampel filter:
    • window size k (neighbors on each side, so total window = 2k+1)
    • threshold n_sigma (default 3.0) on MAD-scaled deviation
  • If you pass --stl-cols, we run STL (if available) and apply Hampel to the residuals.
  • If lat, lon, and gps_speed_mps exist, we can also flag GPS jumps where the per-sample movement exceeds a plausible distance given speed.

This is deliberately simple, fast, and explainable. Treat it as triage; you can review flagged rows.

Quick start

  1. CSV columns you can use (example below):

    • timestamp (ISO)
    • batt_voltage_v
    • gps_speed_mps
    • lat, lon (optional, for GPS jump detector)
    • imu_ax, imu_ay, imu_az (optional)
  2. Detect anomalies and write JSON:

python flight_log_anomaly_detector.py detect   --csv example_log.csv   --time-col timestamp   --cols batt_voltage_v,gps_speed_mps,imu_ax,imu_ay,imu_az   --out anomalies.json   --k 7 --n-sigma 3.0   --stl-cols batt_voltage_v --stl-period 60   --gps-jump 1 --gps-alpha 2.0 --gps-margin-m 30
  1. Output: anomalies.json like:
[
  {"index": 120, "timestamp": "2025-01-01T12:00:10Z", "column": "batt_voltage_v", "value": 15.9, "reason": "hampel", "residual": -0.8},
  {"index": 245, "timestamp": "2025-01-01T12:02:05Z", "column": "gps", "value": 185.3, "reason": "gps_jump", "distance_m": 185.3, "allowed_m": 70.1}
]

Arguments

detect
  --csv <path.csv>                Input telemetry CSV
  --out <anomalies.json>          Output JSON path
  --time-col <name>               Timestamp column (ISO or parseable)
  --cols <c1,c2,...>              Numeric columns to Hampel-scan
  --k <int>                       Half-window size (neighbors). Default 7
  --n-sigma <float>               MAD threshold. Default 3.0
  --stl-cols <c1,c2,...>          Columns to detrend/seasonal-remove with STL before Hampel
  --stl-period <int>              Seasonal period (samples). Example: 60 for 1 Hz * 1 minute
  --gps-jump <0|1>                Enable GPS jump detector (requires lat,lon,gps_speed_mps)
  --gps-alpha <float>             Allowed multiplier on speed*dt (default 2.0)
  --gps-margin-m <float>          Extra fixed margin in meters (default 30)

Notes

  • If statsmodels isn't installed, STL is skipped with a warning.
  • Time deltas are inferred from --time-col differences; if missing/invalid, GPS jump is skipped.
  • Hampel flags are independent per column; review context in your log viewer.

Example data

example_log.csv contains a synthetic 10-minute flight at 1 Hz with planted anomalies.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uav_anomaly_detector-0.1.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uav_anomaly_detector-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file uav_anomaly_detector-0.1.0.tar.gz.

File metadata

  • Download URL: uav_anomaly_detector-0.1.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for uav_anomaly_detector-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bb2a2736c30e3f0d49244d409b94ef857cdc8842998774b96d3d7dd52793d9ef
MD5 715ba9f20b86cb899708f827d0a1a3fe
BLAKE2b-256 86c61f76b70004d54847dbeeb683f1f7e098624267bf0be942557705abb9f173

See more details on using hashes here.

File details

Details for the file uav_anomaly_detector-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for uav_anomaly_detector-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d09e0c33ac735ab6f3a9811d42bed8f69f3599f5fd40eb72e425df8fb2e2f3a0
MD5 9bdc793b93d13c0810086f638d8ae7ba
BLAKE2b-256 1f407249a1bc7460368c51723d0f4aa82ca4db3c365d123f5c2e7e9cb735f8e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page