Synthetic anomaly injection for time series with auto baseline estimation.
Project description
sanin
A lightweight package for injecting synthetic anomalies into time series without requiring prior metadata.
It internally estimates level, trend, and seasonality, then applies user-selected anomalies.
Local Installation
pip install -e .
Uso rápido
import numpy as np, pandas as pd
from sanin import AnomalyInjector, AnomalyType
# Example series
t = np.arange(1000)
y = 100 + 0.01*t + 5*np.sin(2*np.pi*t/50) + np.random.normal(0, 1, size=len(t))
s = pd.Series(y, index=pd.date_range("2024-01-01", periods=len(t), freq="min"))
inj = AnomalyInjector(random_state=123)
# 1) Positive spikes in 5 points
y1, rep1, mask1 = inj.inject(s, AnomalyType.SPIKE, severity=1.0, n_points=5, return_mask=True)
# 2) Level shift starting at a point
y2, rep2, mask2 = inj.inject(s, AnomalyType.LEVEL_SHIFT, severity=2.0, return_mask=True)
# 3) Variance change within a window
y3, rep3, mask3 = inj.inject(s, AnomalyType.VARIANCE_CHANGE, severity=1.5, return_mask=True)
Anomaly Types
SPIKE(point anomaly, +)DROP(point anomaly, −)LEVEL_SHIFT(step change in level)VARIANCE_CHANGE(increased noise in a window)TREND_DRIFT(slope change)SEASON_AMP_CHANGE(seasonal amplitude change in a window)FLATLINE(sensor stuck at constant value)MISSING(segment with NaNs)STUCK_HIGH,STUCK_LOW(saturation at high/low value)BLACKOUT(zeroing or fixed value in a window)
Each injection also returns a report with affected indices and resolved parameters.
Design
- No heavy dependencies: uses
numpy/pandas. - Internal decomposition:
- level = robust median;
- trend = moving average over ~10% of the length;
- seasonality = mean by phase with period estimated via autocorrelation;
- residual = observed - (level + trend + seasonality).
- Parameters have robust defaults derived from the series itself.
Tests
pytest -q
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sanin-1.0.0.tar.gz.
File metadata
- Download URL: sanin-1.0.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
438fb1f376c0f0c5d1446f7564670f6d0368a6ab8996b6330a1cd614fea675bb
|
|
| MD5 |
8830941c6e0cad27b30bdd8c7e329fbb
|
|
| BLAKE2b-256 |
ff46b6d76d433e691272ce1e27217aecfd0505ed6de07bf78ceab3abc69d6c73
|
Provenance
The following attestation bundles were made for sanin-1.0.0.tar.gz:
Publisher:
publish.yml on Mpaape/sanin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sanin-1.0.0.tar.gz -
Subject digest:
438fb1f376c0f0c5d1446f7564670f6d0368a6ab8996b6330a1cd614fea675bb - Sigstore transparency entry: 520607721
- Sigstore integration time:
-
Permalink:
Mpaape/sanin@eb3c3f26c332050cb7a5c303df2dab1af388eedb -
Branch / Tag:
refs/tags/v1.0.0.first - Owner: https://github.com/Mpaape
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@eb3c3f26c332050cb7a5c303df2dab1af388eedb -
Trigger Event:
release
-
Statement type:
File details
Details for the file sanin-1.0.0-py3-none-any.whl.
File metadata
- Download URL: sanin-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb03ac817dc2790896a771680d55d192b618cc0fc7ec6e61bad5cbefdfa304dd
|
|
| MD5 |
e7360dd9c9495964fc78c758d266a3c2
|
|
| BLAKE2b-256 |
e408f90e27b2ba23682483851b72ac533b3b662378350fe2d0f5301bf69d63d6
|
Provenance
The following attestation bundles were made for sanin-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on Mpaape/sanin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sanin-1.0.0-py3-none-any.whl -
Subject digest:
bb03ac817dc2790896a771680d55d192b618cc0fc7ec6e61bad5cbefdfa304dd - Sigstore transparency entry: 520607727
- Sigstore integration time:
-
Permalink:
Mpaape/sanin@eb3c3f26c332050cb7a5c303df2dab1af388eedb -
Branch / Tag:
refs/tags/v1.0.0.first - Owner: https://github.com/Mpaape
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@eb3c3f26c332050cb7a5c303df2dab1af388eedb -
Trigger Event:
release
-
Statement type: