Skip to main content

Python package for calculating derivatives of time series data using various methods

Project description

PyDelt

A Python package for calculating derivatives and integrals of time series data using various methods:

  • Local Linear Approximation (LLA)
  • Generalized Orthogonal Local Derivative (GOLD)
  • Generalized Local Linear Approximation (GLLA)
  • Functional Data Analysis (FDA)
  • Integration with Error Estimation

Installation

pip install pydelt

Usage

import numpy as np
from pydelt import lla, gold, glla, fda, integrate_derivative, integrate_derivative_with_error

# Generate sample data
time = np.linspace(0, 10, 500)
signal = np.sin(time) + np.random.normal(0, 0.1, size=time.shape)

# Calculate derivatives using different methods
derivative, steps = lla(time.tolist(), signal.tolist(), window_size=5)
result_gold = gold(signal, time, embedding=5, n=2)
result_glla = glla(signal, time, embedding=5, n=2)
result_fda = fda(signal, time)

# Reconstruct signal through integration
reconstructed = integrate_derivative(time, derivative, initial_value=signal[0])

# Get integration with error estimates
reconstructed_with_error, error = integrate_derivative_with_error(time, derivative, initial_value=signal[0])

Methods

Implements the method described in:

LLA (Local Linear Approximation)

A sliding window approach that uses min-normalization and linear regression to estimate derivatives. By normalizing the data within each window relative to its minimum value, LLA reduces the impact of local offsets and trends. The method is particularly effective for data with varying baselines or drift, and provides robust first-order derivative estimates even in the presence of moderate noise.

GLLA (Generalized Local Linear Approximation)

An extension of the LLA method that enables calculation of higher-order derivatives using a generalized linear approximation framework. GLLA uses a local polynomial fit of arbitrary order and combines it with a sliding window approach. This method is particularly useful when you need consistent estimates of multiple orders of derivatives simultaneously, and it maintains good numerical stability even for higher-order derivatives.

GOLD (Generalized Orthogonal Local Derivative)

A robust method for calculating derivatives using orthogonal polynomials. GOLD constructs a local coordinate system at each point using orthogonal polynomials, which helps reduce the impact of noise and provides accurate estimates of higher-order derivatives. The method is particularly effective for noisy time series data and can estimate multiple orders of derivatives simultaneously.

FDA (Functional Data Analysis)

A sophisticated approach that uses spline-based smoothing to represent the time series as a continuous function. FDA automatically determines an optimal smoothing parameter based on the data characteristics, balancing the trade-off between smoothness and fidelity to the original data. This method is particularly well-suited for smooth underlying processes and can provide consistent derivatives up to the order of the chosen spline basis.

Integration Methods

The package provides two integration methods:

Basic Integration (integrate_derivative)

Uses the trapezoidal rule to integrate a derivative signal and reconstruct the original time series. You can specify an initial value to match known boundary conditions.

Integration with Error Estimation (integrate_derivative_with_error)

Performs integration using both trapezoidal and rectangular rules to provide an estimate of the integration error. This is particularly useful when working with noisy or uncertain derivative data.

Testing

PyDelt includes a comprehensive test suite to verify the correctness of its implementations. To run the tests:

# Activate your virtual environment (if using one)
source venv/bin/activate

# Install pytest if not already installed
pip install pytest

# Run all tests
python -m pytest src/pydelt/tests/

# Run specific test files
python -m pytest src/pydelt/tests/test_derivatives.py
python -m pytest src/pydelt/tests/test_integrals.py

The test suite includes verification of:

  • Derivative calculation accuracy for various methods
  • Integration accuracy and error estimation
  • Input validation and error handling
  • Edge cases and boundary conditions

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

pydelt-0.3.0.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

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

pydelt-0.3.0-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file pydelt-0.3.0.tar.gz.

File metadata

  • Download URL: pydelt-0.3.0.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for pydelt-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ee0339a64516a05cd320e08dab994d9720d896d96a6d30f733895e216b8cd06b
MD5 a9eacc19764162f062662ed957d6b1a9
BLAKE2b-256 e33d69f371f3ac88c66777def8c202dd0bcb66c8d0779e7fbdb60d5a0c775874

See more details on using hashes here.

File details

Details for the file pydelt-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pydelt-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for pydelt-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 54100d35e089a6c76afaf28284aac9642d11e4e7662f77ca98f3805e4512eed6
MD5 aff76bb212e08b1c9f7d0c4e98a61016
BLAKE2b-256 d8b78832a0adaf40ecc1774c4c17ecddd23e35332c2014e7737bbce8ddeb31ca

See more details on using hashes here.

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