suncasa.utils.signal_utils

Functions

normalize(y[, ymax, ymin, center, yerr, symgamma])

smooth(x[, window_len, window, mode])

smooth the data using a window with requested size.

butter_lowpass(cutoff, fs[, order])

butter_lowpass_filter(data, cutoff, fs[, order])

lowps_filter(data, cutoff, fs, ix)

low_pass_filter(t, data[, fs, cutoff, order, showplot])

bandpass_filter(t, data[, fs, cutoff, order, showplot])

Apply a Butterworth bandpass filter to a given dataset and optionally plot the frequency response and filtered data.

c_correlateX(a, v[, returnx, returnav, s, xran, ...])

get_xcorr_info(xcorr[, cwidth_guess, showplt, verbose])

calculate the error in time lag using equation (3) in Gaskell & Peterson 1987

plot_wavelet(t, dat, dt, pl, pr[, period_pltlim, ax, ...])

Module Contents

suncasa.utils.signal_utils.normalize(y, ymax=None, ymin=None, center=None, yerr=None, symgamma=None)[source]
Parameters:
  • y

  • ymax

  • ymin

  • center – option —- None, zero, 0, mean

  • symgamma

Returns:

suncasa.utils.signal_utils.smooth(x, window_len=11, window='hanning', mode='same')[source]

smooth the data using a window with requested size.

This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the begining and end part of the output signal.

input:

x: the input signal window_len: the dimension of the smoothing window; should be an odd integer window: the type of window from ‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’, ‘blackman’

flat window will produce a moving average smoothing.

output:

the smoothed signal

example:

t=linspace(-2,2,0.1) x=sin(t)+randn(len(t))*0.1 y=smooth(x)

see also:

numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve scipy.signal.lfilter

TODO: the window parameter could be the window itself if an array instead of a string NOTE: length(output) != length(input), to correct this: return y[(window_len/2-1):-(window_len/2)] instead of just y.

suncasa.utils.signal_utils.butter_lowpass(cutoff, fs, order=5)[source]
suncasa.utils.signal_utils.butter_lowpass_filter(data, cutoff, fs, order=5)[source]
suncasa.utils.signal_utils.lowps_filter(data, cutoff, fs, ix)[source]
suncasa.utils.signal_utils.low_pass_filter(t, data, fs=1.0 / 4, cutoff=1.0 / 60, order=6, showplot=False)[source]
suncasa.utils.signal_utils.bandpass_filter(t, data, fs=1.0 / 4, cutoff=1.0 / 60, order=6, showplot=False)[source]

Apply a Butterworth bandpass filter to a given dataset and optionally plot the frequency response and filtered data.

Parameters:
  • t (array_like) – Time array corresponding to the data points.

  • data (array_like) – Data array to be filtered.

  • fs (float, optional) – Sampling frequency of the data in Hz, defaults to 0.25 Hz (1/4 Hz).

  • cutoff (tuple, optional) – Cutoff frequencies of the filter in Hz. It should be a tuple with (low, high) values, defaults to approximately 0.0167 Hz (1/60 Hz).

  • order (int, optional) – Order of the Butterworth filter, defaults to 6.

  • showplot (bool, optional) – If True, plots the frequency response and the original plus filtered data, defaults to False.

Raises:

ValueError – Raises an exception if the ‘cutoff’ parameter does not meet the expected tuple format.

Returns:

The filtered data array.

Return type:

ndarray

suncasa.utils.signal_utils.c_correlateX(a, v, returnx=False, returnav=False, s=0, xran=None, coarse=False, interp='spl')[source]
Parameters:
  • a

  • v – a and v can be a dict in following format {‘x’:[],’y’:[]}. The length of a and v can be different.

  • returnx

Returns:

suncasa.utils.signal_utils.get_xcorr_info(xcorr, cwidth_guess=2.5 / 24 / 60, showplt=False, verbose=False)[source]

calculate the error in time lag using equation (3) in Gaskell & Peterson 1987 :param xcorr: :param cwidth_guess: :return:

suncasa.utils.signal_utils.plot_wavelet(t, dat, dt, pl, pr, period_pltlim=None, ax=None, ax2=None, stscale=2, siglev=0.95, cmap='viridis', title='', levels=None, label='', units='', tunits='', sav_img=False)[source]