CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-gwpy

A python package for gravitational-wave astrophysics

Pending
Overview
Eval results
Files

signal-processing.mddocs/

Signal Processing

Advanced signal processing algorithms including digital filtering, spectral estimation, and specialized techniques for gravitational-wave data analysis. GWpy provides these capabilities primarily through TimeSeries methods that handle the complexity of proper signal processing workflows.

Capabilities

Digital Filtering

Apply digital filters directly to TimeSeries data with automatic handling of edge effects and metadata preservation.

class TimeSeries:
    def highpass(self, frequency, gpass=2, gstop=30, fstop=None, 
                type='iir', filtfilt=True, **kwargs):
        """
        High-pass filter the TimeSeries.
        
        Parameters:
        - frequency: float, cutoff frequency (Hz)
        - gpass: float, maximum loss in passband (dB)
        - gstop: float, minimum attenuation in stopband (dB)
        - fstop: float, stop frequency (Hz), defaults to frequency/5
        - type: str, filter type ('iir' or 'fir')
        - filtfilt: bool, apply zero-phase filtering
        
        Returns:
        TimeSeries, filtered data
        """
    
    def lowpass(self, frequency, gpass=2, gstop=30, fstop=None,
               type='iir', filtfilt=True, **kwargs):
        """
        Low-pass filter the TimeSeries.
        
        Parameters:
        - frequency: float, cutoff frequency (Hz) 
        - gpass: float, maximum loss in passband (dB)
        - gstop: float, minimum attenuation in stopband (dB)
        - fstop: float, stop frequency (Hz), defaults to frequency*5
        - type: str, filter type ('iir' or 'fir')
        - filtfilt: bool, apply zero-phase filtering
        
        Returns:
        TimeSeries, filtered data
        """
    
    def bandpass(self, flow, fhigh, gpass=2, gstop=30, fstop=None,
                type='iir', filtfilt=True, **kwargs):
        """
        Band-pass filter the TimeSeries.
        
        Parameters:
        - flow: float, low cutoff frequency (Hz)
        - fhigh: float, high cutoff frequency (Hz)
        - gpass: float, maximum loss in passband (dB)
        - gstop: float, minimum attenuation in stopband (dB)
        - fstop: tuple, stop frequencies (Hz), defaults to (flow/5, fhigh*5)
        - type: str, filter type ('iir' or 'fir')
        - filtfilt: bool, apply zero-phase filtering
        
        Returns:
        TimeSeries, filtered data
        """
    
    def notch(self, frequency, type='iir', filtfilt=True, **kwargs):
        """
        Notch out a frequency from the TimeSeries.
        
        Parameters:
        - frequency: float, frequency to notch (Hz)
        - type: str, filter type ('iir' or 'fir')
        - filtfilt: bool, apply zero-phase filtering
        - quality: float, quality factor (frequency/bandwidth)
        
        Returns:
        TimeSeries, filtered data
        """
    
    def filter(self, *filt, **kwargs):
        """
        Apply arbitrary filter to the TimeSeries.
        
        Parameters:
        - *filt: filter specification (zpk, sos, ba tuples)
        - filtfilt: bool, apply zero-phase filtering
        
        Returns:
        TimeSeries, filtered data
        """
    
    def zpk(self, zeros, poles, gain, analog=True, **kwargs):
        """
        Apply zero-pole-gain filter to the TimeSeries.
        
        Parameters:
        - zeros: array-like, filter zeros
        - poles: array-like, filter poles  
        - gain: float, filter gain
        - analog: bool, analog (True) or digital (False) filter
        
        Returns:
        TimeSeries, filtered data
        """

Spectral Analysis Methods

Calculate power spectral densities and related spectral estimates using various algorithms.

class TimeSeries:
    def psd(self, fftlength=None, overlap=None, window='hann', 
           method='median', **kwargs):
        """
        Calculate power spectral density using Welch's method variants.
        
        Parameters:
        - fftlength: float, FFT length in seconds
        - overlap: float, overlap between segments in seconds
        - window: str or array, window function ('hann', 'hamming', etc.)
        - method: str, averaging method ('median', 'mean', 'bartlett')
        
        Returns:
        FrequencySeries, power spectral density
        """
    
    def asd(self, fftlength=None, overlap=None, window='hann',
           method='median', **kwargs):
        """
        Calculate amplitude spectral density (square root of PSD).
        
        Parameters:
        - fftlength: float, FFT length in seconds
        - overlap: float, overlap between segments in seconds  
        - window: str or array, window function
        - method: str, averaging method
        
        Returns:
        FrequencySeries, amplitude spectral density
        """
    
    def average_fft(self, fftlength=None, overlap=0, window=None):
        """
        Calculate averaged discrete Fourier transform.
        
        Parameters:
        - fftlength: float, FFT length in seconds
        - overlap: float, overlap between segments in seconds
        - window: str or array, window function
        
        Returns:
        FrequencySeries, averaged complex spectrum
        """

Cross-Spectral Analysis

Calculate coherence, transfer functions, and cross-spectral densities between TimeSeries.

class TimeSeries:
    def coherence(self, other, fftlength=None, overlap=None, 
                 window='hann', **kwargs):
        """
        Calculate frequency-coherence with another TimeSeries.
        
        Parameters:
        - other: TimeSeries, reference series for coherence
        - fftlength: float, FFT length in seconds
        - overlap: float, overlap between segments in seconds
        - window: str or array, window function
        
        Returns:
        FrequencySeries, magnitude-squared coherence
        """
    
    def transfer_function(self, other, fftlength=None, overlap=None,
                         window='hann', **kwargs):
        """
        Calculate transfer function to another TimeSeries.
        
        Parameters:
        - other: TimeSeries, output series for transfer function
        - fftlength: float, FFT length in seconds
        - overlap: float, overlap between segments in seconds
        - window: str or array, window function
        
        Returns:
        FrequencySeries, complex transfer function
        """
    
    def csd(self, other, fftlength=None, overlap=None, window='hann', **kwargs):
        """
        Calculate cross-spectral density with another TimeSeries.
        
        Parameters:
        - other: TimeSeries, reference series
        - fftlength: float, FFT length in seconds
        - overlap: float, overlap between segments in seconds
        - window: str or array, window function
        
        Returns:
        FrequencySeries, cross-spectral density
        """

Signal Conditioning

Methods for whitening, tapering, detrending and other signal conditioning operations.

class TimeSeries:
    def whiten(self, fftlength=None, overlap=0, method='median', 
              window='hann', detrend='constant', **kwargs):
        """
        Whiten the TimeSeries using inverse spectrum truncation.
        
        Parameters:
        - fftlength: float, FFT length for PSD estimation
        - overlap: float, overlap between segments in seconds
        - method: str, PSD averaging method ('median', 'mean')
        - window: str, window function for PSD estimation
        - detrend: str, detrending method before whitening
        
        Returns:
        TimeSeries, whitened data
        """
    
    def taper(self, side='leftright', duration=None, nsamples=None):
        """
        Taper the TimeSeries smoothly to zero at the edges.
        
        Parameters:
        - side: str, which side to taper ('left', 'right', 'leftright')
        - duration: float, taper duration in seconds
        - nsamples: int, taper length in samples
        
        Returns:
        TimeSeries, tapered data
        """
    
    def detrend(self, detrend='constant'):
        """
        Remove linear trend from the TimeSeries.
        
        Parameters:
        - detrend: str or callable, detrending method
          ('constant', 'linear', or custom function)
        
        Returns:
        TimeSeries, detrended data
        """
    
    def resample(self, rate, window='hamming', ftype='fir', n=None):
        """
        Resample to a different sampling rate using polyphase filtering.
        
        Parameters:
        - rate: float, new sample rate in Hz
        - window: str, anti-aliasing filter window
        - ftype: str, filter type ('fir' or 'iir')
        - n: int, filter order (None = automatic)
        
        Returns:
        TimeSeries, resampled data
        """

Q-Transform Analysis

High-resolution time-frequency analysis using Q-transforms for transient detection.

class TimeSeries:
    def q_transform(self, qrange=(4, 64), frange=(10, 2048), 
                   gps=None, search=0.5, tres=0.002, fres=0.5, 
                   outseg=None, whiten=True, **kwargs):
        """
        Scan using multi-Q transform for high-resolution time-frequency analysis.
        
        Parameters:
        - qrange: tuple, (qmin, qmax) quality factor range
        - frange: tuple, (fmin, fmax) frequency range in Hz
        - gps: float, central GPS time for analysis
        - search: float, search window duration in seconds
        - tres: float, time resolution in seconds
        - fres: float, fractional frequency resolution
        - outseg: Segment, output time segment
        - whiten: bool, whiten data before transformation
        
        Returns:
        Spectrogram, high-resolution time-frequency representation
        """
    
    def q_gram(self, qrange=(4, 64), frange=(10, 2048), **kwargs):
        """
        Scan using multi-Q transform and return peak parameters.
        
        Parameters:
        - qrange: tuple, (qmin, qmax) quality factor range
        - frange: tuple, (fmin, fmax) frequency range in Hz
        
        Returns:
        EventTable, table of significant Q-transform peaks
        """

Gating and Transient Removal

Tools for identifying and removing loud transients (glitches) from data.

class TimeSeries:
    def gate(self, tzero=1.0, tpad=0.5, whiten=True, **kwargs):
        """
        Remove high amplitude peaks using inverse Planck window gating.
        
        Parameters:
        - tzero: float, half-width of gate zero region (seconds)
        - tpad: float, half-width of gate transition region (seconds) 
        - whiten: bool, whiten data to identify outliers
        
        Returns:
        TimeSeries, gated data with transients removed
        """
    
    def find_gates(self, tzero=1.0, whiten=True, **kwargs):
        """
        Identify points that should be gated based on amplitude.
        
        Parameters:
        - tzero: float, gate zero region half-width (seconds)
        - whiten: bool, whiten data before peak identification
        
        Returns:
        SegmentList, time segments containing loud transients
        """

Usage Examples

Basic Filtering Workflow

import numpy as np
from gwpy.timeseries import TimeSeries

# Read gravitational-wave strain data
strain = TimeSeries.fetch_open_data('H1', 1126259446, 1126259478)

# Apply standard LIGO analysis filters
# High-pass to remove low-frequency noise
strain_hp = strain.highpass(20)  # 20 Hz high-pass

# Band-pass around expected signal frequencies  
strain_bp = strain_hp.bandpass(35, 350)  # 35-350 Hz band-pass

# Calculate power spectral density
psd = strain_bp.psd(fftlength=4, overlap=2)

# Whiten the data using the PSD
strain_white = strain_bp.whiten(fftlength=4, overlap=2)

Spectral Analysis Workflow

# Compare power spectral densities using different methods
psd_median = strain.psd(fftlength=8, method='median')  # Robust to outliers
psd_mean = strain.psd(fftlength=8, method='mean')      # Traditional average

# Calculate coherence between two detectors
h1_strain = TimeSeries.fetch_open_data('H1', 1126259446, 1126259478)
l1_strain = TimeSeries.fetch_open_data('L1', 1126259446, 1126259478)

coherence = h1_strain.coherence(l1_strain, fftlength=4, overlap=2)

Transient Analysis with Q-Transform

# High-resolution time-frequency analysis around GW150914
gw150914_time = 1126259462.4  # GPS time of detection

# Calculate Q-transform for transient analysis
qspectrogram = strain.q_transform(
    gps=gw150914_time,
    frange=(20, 512),
    search=4.0,
    tres=0.001
)

# Plot the result
plot = qspecgrogram.plot()
plot.show()

Install with Tessl CLI

npx tessl i tessl/pypi-gwpy

docs

astrophysics.md

detector.md

frequencyseries.md

index.md

plotting.md

segments.md

signal-processing.md

spectrogram.md

timeseries.md

tile.json