Skip to main content

Detect the dominant period in univariate, equidistant time series data.

Project description

Periodicity Detection

Detect the dominant period in univariate, equidistant time series data.

CI Documentation Status codecov PyPI package License: MIT python version 3.7|3.8|3.9|3.10|3.11 Downloads


Toolbox for detecting the dominant period in univariate, equidistant time series data. The toolbox contains the following methods:

  • Autocorrelation
  • AutoPeriod
  • Fast Fourier Transform (FFT)
  • find_length
  • Python-adaption of the R package forecast's findfrequency function
  • Number of Peaks-method

📖 Periodicity Detection's documentation is hosted at https://periodicity-detection.readthedocs.io.

Recommended reading: Window Size Selection In Unsupervised Time Series Analytics: A Review and Benchmark: Workshop paper that compares the Autocorrelation, FFT (DFT in the paper), and AutoPeriod methods to three other methods (Code).

Installation

You can install Periodicity Detection as a package or from source.

Prerequisites

  • python >= 3.7, <= 3.11
  • pip >= 20

Installation using pip (recommended)

pip install periodicity-detection

Installation from source

git clone git@github.com:CodeLionX/periodicity-detection.git
cd periodicity-detection
pip install .

Usage

Periodicity Detection can be used as a Python library or as a command line tool. Please refer to the package documentation for more information.

API

import numpy as np
import periodicity_detection as pyd

# Create sample data
data = np.sin(np.linspace(0, 40 * np.pi, 1000)) + np.random.default_rng(42).random(1000)

# Calculate period size using a specific method
period_size = pyd.findfrequency(data, detrend=True)
assert period_size == 50

# Calculate period size using the default method
period_size = pyd.estimate_periodicity(data)
assert period_size == 50

Plot of the example dataset:

Example dataset

CLI

$> periodicity --help
usage: periodicity [-h] [--version] [--use-initial-n USE_INITIAL_N]
                   [--channel CHANNEL]
                   dataset_path
                   {find-length,number-peaks,autocorrelation,fft,autoperiod,findfrequency}
                   ...

Detect the dominant period in univariate, equidistant time series data.

positional arguments:
  dataset_path          Path to the dataset for which the dominant period size
                        should be estimated.
  {find-length,number-peaks,autocorrelation,fft,autoperiod,findfrequency}
    find-length         Determine period size based on ACF as in the TSB-UAD
                        repository.
    number-peaks        Calculates the number of peaks of at least support n
                        in the time series and the time series length divided
                        by the number of peaks defines the period size.
    autocorrelation     Determine period size based on ACF.
    fft                 Determine period size based on FFT.
    autoperiod          AUTOPERIOD method calculates the period size in a two-
                        step process. First, it extracts candidate periods
                        from the periodogram. Then, it uses the circular
                        autocorrelation to validate the candidate periods.
    findfrequency       Determine period size using the method findfrequency
                        from the R forecast package. Re-implementation!

optional arguments:
  -h, --help            show this help message and exit
  --version             Show version number.
  --use-initial-n USE_INITIAL_N
                        Only use the n initial points of the dataset to
                        calculate the estimated period size.
  --channel CHANNEL     If the dataset is multivariate, use the channel on
                        this integer position. The first dimension is always
                        assumed to be the index and skipped over!

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

periodicity_detection-0.1.3.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

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

periodicity_detection-0.1.3-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file periodicity_detection-0.1.3.tar.gz.

File metadata

  • Download URL: periodicity_detection-0.1.3.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for periodicity_detection-0.1.3.tar.gz
Algorithm Hash digest
SHA256 42592710a75c5b6d6b69bb6d96ade269ecf3affb6a62c92de99a099b409c2cff
MD5 2d55d91e35aa7e4a0f84beb1989fa58b
BLAKE2b-256 b3d4bc3884aeaf94c1d6f4a35f75634ba4a06a1c7ff46e1644b0511b3c9d2e8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for periodicity_detection-0.1.3.tar.gz:

Publisher: build.yml on SebastianSchmidl/periodicity-detection

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

File details

Details for the file periodicity_detection-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for periodicity_detection-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ec818870ee8d3b2504ac09d77d6ffcaaa88d3c15cdf932840bc2fb9772f57a4a
MD5 150bf59c9cc60d57014018789ecb90c1
BLAKE2b-256 8868c9a0594cb2c55bbf3d9130fc936b48dc12ab666a969035754c1859284318

See more details on using hashes here.

Provenance

The following attestation bundles were made for periodicity_detection-0.1.3-py3-none-any.whl:

Publisher: build.yml on SebastianSchmidl/periodicity-detection

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