Skip to main content

Streamlined anomaly detection system for time series data

Project description

SpotAnomaly2

Forecast-based anomaly detection for multi-channel time-series data. Each channel is forecast by a per-channel model; residuals between forecast and actual are scored, and points whose residuals exceed a calibrated threshold are flagged as anomalies. The same pipeline runs as a one-shot batch job or as a long-running live monitor.

Requirements

  • Python 3.13+ (uv installs a matching interpreter for you; .python-version pins it)
  • uv package manager

Installation

Install uv:

# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Homebrew
brew install uv
# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

Set up the project (creates the virtualenv and installs everything):

uv sync                 # runtime dependencies
uv sync --all-groups    # + dev tools (ruff, ty, reuse, pytest, jupyter)

Repository layout

spotanomaly2/           # package
  application/          # config loading + Pipeline orchestration
  domain/               # forecasting, anomaly detection, model training
  infrastructure/       # logging, IO, adapters
  dashboard/            # live monitor + HTML report server
  examples/
  __main__.py → main.py # CLI entry point
config/                 # default.yaml (bundled default) + config.yaml
tests/                  # pytest suite
notebooks/              # exploratory analysis notebooks
data/                   # raw / processed / models / results (generated)

Configuration

The CLI loads config/default.yaml unless you pass --config:

uv run python -m spotanomaly2 detect --config ./config/config.yaml

Key sections in the config: panels (channels per panel), paths (data/model/result dirs), fetch / process (download & preprocessing), train (split + per-channel models), detect (hist_window, threshold, scorer_fit_scope), tune (SpotOptim hyperparameter search) and report (live HTML output). See default.yaml for the full, commented schema.

Usage

Run via the module (python -m spotanomaly2 <command>); an installed console script named spotanomaly2 is also available (e.g. uv run spotanomaly2 detect).

Command What it does
download Fetch raw data from the configured API and save as Parquet
process Convert, resample and preprocess raw data
tune Search per-channel forecaster hyperparameters with SpotOptim (optional)
train Train per-channel forecasting models
detect Score residuals with a trained model and flag anomalies
live Download → process → predict with an existing model (no training)

Typical end-to-end run:

uv run python -m spotanomaly2 download
uv run python -m spotanomaly2 process
uv run python -m spotanomaly2 tune      # optional
uv run python -m spotanomaly2 train
uv run python -m spotanomaly2 detect

Useful options:

# Run any step against a specific config
uv run python -m spotanomaly2 process --config ./config/config.yaml

# Detect with a specific trained model (default: most recent)
uv run python -m spotanomaly2 detect --model 20250115_143022

# Pin the raw-data version used by process / train / detect (default: most recent)
uv run python -m spotanomaly2 train --raw-data-version 20260105_174531

# Tune a single panel/channel, overriding trial counts
uv run python -m spotanomaly2 tune --panel 1 --channel channel_1_ph --n-trials 50 --n-initial 10

Run uv run python -m spotanomaly2 <command> --help for the full option list of any command.

Live monitoring

Run once, or continuously every N minutes:

uv run python -m spotanomaly2 live                 # single pass, then exit
uv run python -m spotanomaly2 live --interval 5    # re-run every 5 minutes

Live mode serves an auto-updating report at data/results/live/report.html.

Analyzing results

Explore processed data, forecasts and detected anomalies interactively in notebooks/analyze_combined.ipynb and the other notebooks under notebooks/.

Development

uv sync --all-groups        # install dev tools

uv run ruff check .         # lint
uv run ruff format .        # format
uv run ty check .           # type-check
uv run reuse lint           # SPDX/license headers
uv run pytest               # tests

License

AGPL-3.0-or-later. This project is REUSE-compliant — every source file carries an SPDX header (see REUSE.toml and LICENSES/).

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

spotanomaly2-2.2.0.tar.gz (436.5 kB view details)

Uploaded Source

Built Distribution

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

spotanomaly2-2.2.0-py3-none-any.whl (161.2 kB view details)

Uploaded Python 3

File details

Details for the file spotanomaly2-2.2.0.tar.gz.

File metadata

  • Download URL: spotanomaly2-2.2.0.tar.gz
  • Upload date:
  • Size: 436.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for spotanomaly2-2.2.0.tar.gz
Algorithm Hash digest
SHA256 65f5f8d18c658c2f1190141c363402bebf5b0abd87704853e7866d9a211dacfa
MD5 3a285e923bde533bb075976c76868138
BLAKE2b-256 9330334dd66f55c3aec063ff3d515e8c4d3017ec93ae81e2fc3d645b102a15ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for spotanomaly2-2.2.0.tar.gz:

Publisher: release.yml on sequential-parameter-optimization/spotanomaly2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spotanomaly2-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: spotanomaly2-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 161.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for spotanomaly2-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28cfd531709d60e5f41121b1e661ab8815079a7366e2191a9074780cffe23a29
MD5 10effd14729ed285b8780f521e814a5f
BLAKE2b-256 d5327da1e29b1e22e6f7e0f7c6e86456ed046f608e4b9190cce2b3309b46beb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for spotanomaly2-2.2.0-py3-none-any.whl:

Publisher: release.yml on sequential-parameter-optimization/spotanomaly2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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