Skip to main content

Period-Detection

If you use the presented period detection method or the provided Python scripts inspired you for further extensions or variations of this framework, we’ll be happy if you cite our paper “On a method for detecting periods and repeating patterns in time series data with autocorrelation and function approximation” (https://doi.org/10.1016/j.patcog.2023.109355) in course of which the Python implementations of this git repository have been worked out.

Installation

pip install period-detection

Usage

from period_detection import find_period

find_period(path="time_series_data.csv") # function call

Parameters

  • path (String, required): Path to the timeseries data
  • tol_norm_diff (float, default=0.001): The tolerance for the norm difference between the the data and the fitted model, see res_criteria = 1.5.
  • number_steps (int, default=1000): Number of steps by which the range 0 to 1 of the threshold for zero (sigma) is divided.
  • minimum_number_of_relevant_shifts (int, default=2): The minimum number of shifts required for calculation of the period.
  • minimum_number_of_datapoints_for_correlation_test (int, default=300): The minimum number of datapoints required for calculation.
  • minimum_ratio_of_datapoints_for_shift_autocorrelation (float, default=0.3): The minimum ratio of datapoints for which we calculate the autocorrelation of a shift.
  • consider_only_significant_correlation (bool, default=True): A flag declaring the usage only of correlations matching significance.
  • level_of_significance_for_pearson (float, default=0.01): The minimum significance level for the correlation criterion.
  • output_flag (bool, default=True): Output flag setting plotting to on/off.
  • plot_tolerances (bool, default=True): Output flag allowing for tolerances to be plotted.
  • reference_time (pd.Timestamp, default=pd.Timestamp('2017-01-01T12')): The reference point for phase calculation.

Output

These are the possible outputs you get when the output_flag is set during execution.

In case a period is found

  1. A comparison of the original timeseries and the one predicted by the model.
  2. A plot of the norm difference between unshifted and shifted autocorrelation function, optionally with tolerances (horizontal lines).
  3. A plot of the autocorrelation function of the data linking the autocorrelation function to the correlation coefficient r and the significance p.
  4. A plot of the difference between the original timeseries and the model. In case the model fits well this is only noise.
  5. A plot of the autocorrelation function of the original data minus the model. A low autocorrelation function value here indicates a well fit model.

In case no period was found

  1. A plot of the timeseries data
  2. A plot of the norm difference between unshifted and shifted autocorrelation function.
  3. A plot of the autocorrelation function of the data linking the autocorrelation function to the correlation coefficient r and the significance p.

Returns

The function find_period returns a namedtuple Results(period, model, criteria).

In case a period is found

  • res_period (float): The period duration itself in minutes.
  • res_model (RandomForestRegressor object): The best performing model trained to fit the timeseries.
  • res_criteria (float): A float acting as performance criterium for the model. Between 0 and 1, set to 1.5 in case of a near perfect fit for the model.

In case no period is found

  • res_period (float): Set to -1 as no period exists.
  • res_model (RandomForestRegressor object): Set to None as no model exists.
  • res_criteria (float): Set to 0 as there is no model that fits the timeseries.

In case of an error

If an error occurs during execution the error message is printed and further code will still be executed.

  • res_period (float): Set to -2 in order to indicate an error.
  • res_model (RandomForestRegressor object): Set to None as no model exists.
  • res_criteria (float): Set to -2 in order to indicate an error.

Metadata

Release files for period-detection 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for period-detection 1.1.2
File Size Uploaded Provenance Actions
period-detection-1.1.2.tar.gz 10.8 kB Without provenance Details for period-detection-1.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for period-detection 1.1.2
File Interpreter ABI Platform Actions
period_detection-1.1.2-py3-none-any.whl Python 3 none any Details for period_detection-1.1.2-py3-none-any.whl

Total release size: 21.9 kB

Release files / period-detection-1.1.2.tar.gz

Download URL period-detection-1.1.2.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
38e715b6c92b6f88eb9dd4b35c5836e1de7a0bcb39512440f399466a2bb21b83
BLAKE2b-256 checksum
How to use checksums
2d286d902d71f74cf91066566f3b361e81096747ddcbff669469aa470fbf0073
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / period_detection-1.1.2-py3-none-any.whl

Download URL period_detection-1.1.2-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
69ef1036b7d2722deb735df0d0e121bbe63446f5a3f74de3c6d310a1859f1cc6
BLAKE2b-256 checksum
How to use checksums
666217ce2337324d0eb8a549e2d207e29c177985ea7de50ed45454bc573cf463
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Security for period-detection 1.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page