Skip to main content

stf_decomposition

stf_decomposition: Seasonal-Trend decomposition using the Fast Fourier transform

Installation

Installing stf_deocmposition can be done with pip installation syntax

pip install stf-decomposition

The package is tested on Python 3.7, 3.8 and 3.9.

Getting Started

In order to use stf_decomposition you will need a time series dataset of type pandas DataFrame or pandas Series. You will also need to specify the following input variables:

  • window: A string indicating the name of a window function for use during the Fast Fourier transform process to reduce spectral leakage. The possible window inputs can be found in the get_window scipy documentation.
  • period: An integer indicating the period of the time series input data. The period must be specified by the user if the input data does not have a frequency.

Optional input variable:

  • seasonal: An integer indicating the seasonal window of the time series input data. If no input is given than an optimization function will be run to find the seasonal window that produces the smallest correlation between the seasonal and trend decomposed components. The code below shows reading in a Carbon Emissions time series dataset as a pandas DataFrame and creating an STF object from the DataFrame with a "blackman" window. The CO2 input data has a frequency so a user specified period is not needed.
co2 = pd.read_csv('data/co2.csv', index_col='date', parse_dates=True, squeeze=True)

stf = STF(co2, "blackman")

Example

This demonstration will walkthrough the complete process of reading in data, creating an STF object, fitting the object, and plotting the decomposed components.

  1. Read in time series data as a pandas DataFrame or Series
from stf_decomposition import STF

data = pd.read_csv('data/AirPassengers.csv', index_col = "Month", parse_dates=True, squeeze=True)
  1. Create an STF object and indicate a window, period (if needed), and seasonal window (if desired).
stf = STF(data, window = "hanning")
  1. Fit the object. After fitting the decomposition you can access the trend, seasonal, and residual components.
res = stf.fit()

# View decomposed components
print(res.trend.head())
print(res.seasonal.head())
print(res.residual.head())
  1. Plot the trend, seasonal, and residual components
fig = res.plot()

Testing

The package include a test suite that can be run in the main directory using the pystest library

pytest

Metadata

Release files for stf-decomposition 0.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 stf-decomposition 0.1.2
File Size Uploaded Provenance Actions
stf-decomposition-0.1.2.tar.gz 6.3 kB Without provenance Details for stf-decomposition-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for stf-decomposition 0.1.2
File Interpreter ABI Platform Actions
stf_decomposition-0.1.2-py3-none-any.whl Python 3 none any Details for stf_decomposition-0.1.2-py3-none-any.whl

Total release size: 13.1 kB

Release files / stf-decomposition-0.1.2.tar.gz

Download URL stf-decomposition-0.1.2.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
41dc6f45ffbcd3009c3dfa09b19634274999aa6feeff35de58319ed7a44ac482
BLAKE2b-256 checksum
How to use checksums
8003c5fa4817730361676427ff32bcd73b3ebd2e83eb7fd3cbc742113ef4e99f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / stf_decomposition-0.1.2-py3-none-any.whl

Download URL stf_decomposition-0.1.2-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8edfe53c7e0eb481fc1ec7284e0c367315c5e7e2855de863c153dbf3b7fc3cc4
BLAKE2b-256 checksum
How to use checksums
39c8b0d4ecffb15ee42f4aa48bf09c99059d31d932b18b674fb2581aed1d529b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Security for stf-decomposition 0.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.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

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