pygwb.spectral

The spectral module contains all functions in the pygwb package that are related to the computation of the power spectral density (PSD) and the cross spectral density (CSD).

The functions in this module compute an fftgram from a timeseries in the form of a gwpy.spectrogram.Spectrogram, a Welch-averaged PSD and coarse-grain any data. An additional functionality of the module is to compute PSDs and CSDs, which is implemented in the power_spectral_density and cross_spectral_density methods.

Examples

To illustrate some of the main features of the this module, we compute the CSD and PSD of two timeseries representing data from two interferometers.

The data are read in for two interferometers using methods from the pygwb.preprocessing module.

>>> import pygwb.preprocessing as ppp
>>> import pygwb.spectral as psp
>>> data_timeseries = ppp.read_data(
        "H1",                      # IFO
        "public",                  # data_type
        "H1:GWOSC-4KHZ_R1_STRAIN", # channel
        1247644138,                # t0
        1247648138,                # tf
        "",                        # local_data_path
        16384                      # input_sample_rate
    )
>>> data_timeseries_L = ppp.read_data(
        "L1",                      # IFO
        "public",                  # data_type
        "L1:GWOSC-4KHZ_R1_STRAIN", # channel
        1247644138,                # t0
        1247648138,                # tf
        "",                        # local_data_path
        16384                      # input_sample_rate
    )

The PSD can be computed by calling the appropriate method:

>>> PSD_H1 = psp.power_spectral_density(
        data_timeseries,
        segment_duration=192,
        frequency_resolution=1/32.,
        overlap_factor=0.5,
        window_fftgram_dict_welch_psd={"window_fftgram": "hann"},
        overlap_factor_welch_psd=0.5,
    )
>>> PSD_L1 = psp.power_spectral_density(
        data_timeseries_L,
        segment_duration=192,
        frequency_resolution=1/32.,
        overlap_factor=0.5,
        window_fftgram_dict_welch_psd={"window_fftgram": "hann"},
        overlap_factor_welch_psd=0.5,
    )

The CSD is calculated by invoking the following lines of codes.

>>> CSD_baseline = psp.cross_spectral_density(
        data_timeseries,
        data_timeseries_L,
        segment_duration=192,
        frequency_resolution=1/32.,
        overlap_factor=0.5,
        zeropad=True,
        window_fftgram_dict={"window_fftgram": "hann"},
    )

For any additional information on the parameters that enter the methods described here, we refer the reader to the more detailed API documentation of the module.

Functions

before_after_average(psdgram, ...)

Average the requested number of PSDs from segments adjacent to the segment of interest (for which CSD is calculated).

coarse_grain(data, coarsening_factor)

Coarse grain a frequency series by an integer factor.

coarse_grain_exact(data, coarsening_factor)

Coarse grain an array using any coarsening factor.

coarse_grain_naive(data, coarsening_factor)

Naive implementation of a coarse graining factor that ignores edge effects.

coarse_grain_spectrogram(spectrogram[, ...])

Coarsen a spectrogram in time and/or frequency, e.g., Welch averaging / coarse-graining.

cross_spectral_density(time_series_data1, ...)

Compute the cross spectral density from two time series inputs.

fftgram(time_series_data, fftlength[, ...])

Create a fftgram from a timeseries.

power_spectral_density(time_series_data, ...)

Compute the PSDs of every segment (defined by the segment duration) in the time series using pwelch method.

pwelch_psd(psdgram, segment_duration[, ...])

Estimate PSD using Welch' method.

running_mean(data[, coarsening_factor, axis])

Compute the running mean of an array, this uses the default axis of numpy cumsum.