Skip to main content

Basic Utilities for Solar Wind Turbulence

Project description

Power Spectral Density and Smoothing Analysis

This package provides tools for analyzing time series data using spectral methods, including Fourier and wavelet transforms. It includes functionality for smoothing data, estimating the power spectral density (PSD) using both FFT and wavelet methods, and other utility functions for handling spectral data.

Features

  • Data Smoothing:

    • smooth: Logarithmic smoothing of data, using indices generated based on the FFT frequency distribution.
    • smoothing_function: Core function for smoothing with a logarithmic window size.
  • Power Spectral Density Estimation:

    • TracePSD: PSD estimation using the Fourier transform for a 3-component signal.
    • trace_PSD_wavelet: PSD estimation using the Continuous Wavelet Transform (CWT), with optional Cone of Influence (CoI) consideration.

Installation

Clone this repository to your local machine and install the required dependencies:

pip install SWTurbPy

Dependencies

  • numpy: For numerical operations and FFT.
  • pycwt: For wavelet analysis.
  • numba: For JIT-compiled performance optimization of smoothing functions.

Usage

1. Smoothing Data

import numpy as np
from SWTurbPy.SWTurbPy import smooth

# Example data
x = np.fft.rfftfreq(1000, d=0.01)
y = np.random.random(len(x))

# Apply smoothing
xoutmean, yout = smooth(x, y, pad=10)

2. PSD Estimation with FFT

from SWTurbPy.SWTurbPy import TracePSD

# Example data
x = np.sin(np.linspace(0, 10, 1000))
y = np.cos(np.linspace(0, 10, 1000))
z = np.sin(np.linspace(0, 10, 1000)) * 0.5

dt = 0.01  # Sampling time
freqs, B_pow = TracePSD(x, y, z, dt, norm='forward')

3. PSD Estimation with Wavelet Transform

from SWTurbPy.SWTurbPy import trace_PSD_wavelet

# Example data
x = np.sin(np.linspace(0, 10, 1000))
y = np.cos(np.linspace(0, 10, 1000))
z = np.sin(np.linspace(0, 10, 1000)) * 0.5

dt = 0.01  # Sampling time
dj = 0.1   # Scale resolution

db_x, db_y, db_z, freqs, PSD, scales, coi = trace_PSD_wavelet(x, y, z, dt, dj, consider_coi=True)

Function Descriptions

smooth(x, y, pad)

Description: A wrapper for smoothing data based on logarithmic spacing of indices. Assumes x is the output of numpy.fft.rfftfreq.

Parameters:

  • x (numpy.ndarray): FFT frequency array.
  • y (numpy.ndarray): Data to smooth.
  • pad (int): Controls the density of smoothing intervals.

Returns:

  • xoutmean (numpy.ndarray): Smoothed x-values.
  • yout (numpy.ndarray): Smoothed y-values.

TracePSD(x, y, z, dt, norm=None)

Description: Estimate the PSD using the Fourier transform for a 3-component signal.

Parameters:

  • x, y, z (numpy.ndarray): Time series data for each component.
  • dt (float): Sampling time.
  • norm (str, optional): Normalization method for FFT. Options are {'forward', 'backward', 'ortho'}.

Returns:

  • freqs (numpy.ndarray): Frequencies of the PSD.
  • B_pow (numpy.ndarray): Power spectral density.

trace_PSD_wavelet(x, y, z, dt, dj, consider_coi=True)

Description: Estimate the PSD using wavelet transform for a 3-component signal.

Parameters:

  • x, y, z (numpy.ndarray): Time series data for each component.
  • dt (float): Sampling time.
  • dj (float): Scale resolution.
  • consider_coi (bool, optional): Whether to exclude regions in the Cone of Influence (CoI).

Returns:

  • db_x, db_y, db_z (numpy.ndarray): Wavelet coefficients for each component.
  • freqs (numpy.ndarray): Frequencies of the PSD.
  • PSD (numpy.ndarray): Power spectral density.
  • scales (numpy.ndarray): Scales used for the wavelet transform.
  • coi (numpy.ndarray): Cone of Influence (CoI).

Example Plots

You can visualize the smoothed data or PSD using libraries like matplotlib.

import matplotlib.pyplot as plt

# Plot FFT-based PSD
plt.loglog(freqs, B_pow)
plt.title('Power Spectral Density (FFT)')
plt.xlabel('Frequency')
plt.ylabel('PSD')
plt.grid()
plt.show()

# Plot Wavelet-based PSD
plt.loglog(freqs, PSD)
plt.title('Power Spectral Density (Wavelet)')
plt.xlabel('Frequency')
plt.ylabel('PSD')
plt.grid()
plt.show()

Contribution

Contributions are welcome! Please submit issues or pull requests to improve the code or documentation.

License

This project is licensed under the MIT License.

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

swturbpy-0.0.5.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

swturbpy-0.0.5-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file swturbpy-0.0.5.tar.gz.

File metadata

  • Download URL: swturbpy-0.0.5.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for swturbpy-0.0.5.tar.gz
Algorithm Hash digest
SHA256 2a84fc827b8b629d223e27274ffc12eef8a7ced1e5dee57f28ea825dbf891e36
MD5 c1e510a5e59de27953af2785285823bf
BLAKE2b-256 89e23570a44353d5c6dd82d0184ff28f8ded247674bfe8e6ce14ec8315bcff75

See more details on using hashes here.

File details

Details for the file swturbpy-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: swturbpy-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for swturbpy-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1456a0d1e3b2adcd91888c46b225724d3d1d85f1cbe3d6fd9be35c9a491cb33a
MD5 65be52c66e30abaae7d4dbb9bcae9716
BLAKE2b-256 4a7d0e3e963a0f281ca9ca79fa398e71ee98b983c2d70d87cde0d7e94bda9a70

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