WAVEPAL - Quick start

Train yourself by reproducing this code in python. For in-depth analyses, I strongly recommend the use of the ipython notebook. This tutorial was made with that tool.

1. Reading the data and initializing Wavepal

Start importing wavepal and other usual packages


In [1]:
% matplotlib inline
# other option (instead of "inline"): nbagg
# N.B.: the two previous lines are used by ipython. Do not write them in your python code.  
import numpy as np
import matplotlib.pyplot as plt
import copy
import wavepal as wv

wavepal is illustrated here with ODP1148 d18O benthic time series. Ref: Z. Jian, Q. Zhao, X. Cheng, J. Wang, P. Wang, and X. Su. Pliocene-pleistocene stable isotope and paleoceanographic changes in the northern south china sea. Palaeogeography, Palaeoclimatology, Palaeoecology, 193(3–4):425–442, 2003.

Read the data


In [2]:
data=np.genfromtxt("ODP1148-BF-18O.txt")
myt=data[:,0]
mydata=data[:,1]

Initialize the class called Wavepal (which is a class of the package wv)


In [3]:
x=wv.Wavepal(myt, mydata, "Age", "$\delta{}^{18}O$", t_units="ka", mydata_units="permil")

To get more info about the inputs at the initialization, use the help:


In [4]:
help(x.__init__)


Help on method __init__ in module wavepal.Wavepal:

__init__(self, t, mydata, t_axis_label='', mydata_axis_label='', t_units=None, mydata_units=None) method of wavepal.Wavepal.Wavepal instance
    Constructor of Wavepal class. It Initializes all the variables of Wavepal class with an access outside Wavepal (the user can access them). The list of available variables is given in this function.
    Required Inputs:
    - t [1-dim numpy array of floats]: the times of the time series, distinct and in ascending order.
    - mydata [1-dim numpy array of floats - size=time.size]: the data at the times given by 't'.
    Optional Inputs:
    - t_axis_label="": label for the time axis in figures
    - mydata_axis_label="": label for the data axis in figures
    - t_units=None: units of 't' (string type)
    - mydata_units=None: units of 'mydata' (string type).
    Outputs:
    /
    -----------------------------
    This is part of WAVEPAL
    (C) 2016 G. Lenoir

Here is the list of all the methods of the Wavepal class:

  • check_data [compulsory]
  • plot_timestep
  • plot_trend
  • choose_trend_degree [compulsory]
  • trend_vectors [compulsory]
  • carma_params [compulsory if you perform a test of significance]
  • freq_analysis [frequency analysis]
  • freq_filtering [filtering in a frequency band]
  • plot_WOSA_segmentation
  • plot_number_WOSA_segments
  • plot_periodogram
  • plot_f_periodogram
  • plot_check_convergence_percentiles
  • plot_pseudo_spectrum
  • plot_variance_anal
  • plot_amplitude
  • plot_amplitude_vs_periodogram
  • timefreq_analysis [time-frequency analysis]
  • timefreq_ridges_filtering [ridges filtering]
  • timefreq_band_filtering [filtering in a frequency band]
  • plot_scalogram
  • plot_check_convergence_percentiles_cwt
  • plot_pseudo_cwtspectrum_anal
  • plot_pseudo_cwtspectrum_mcmc
  • plot_cwt_variance_anal
  • plot_cwtamplitude
  • plot_cwtamplitude_squared
  • plot_global_scalogram
  • plot_check_convergence_percentiles_global_scalogram
  • plot_pseudo_global_spectrum
  • plot_global_cwt_variance_anal
  • plot_global_amplitude
  • plot_global_amplitude_vs_global_scalogram

For each method, you have at your disposal a detailed explanation about what it does and about the inputs and outputs, thanks to "help". Example with freq_analysis method:


In [5]:
help(x.freq_analysis)


Help on method freq_analysis in module wavepal.Wavepal:

freq_analysis(self, freqmin=None, freqmax=None, freqstep=None, dt_GCD=None, freq_min_bound=True, freq_max_bound=True, mywindow=1, D=None, betafact=0.75, coverage=90.0, WOSA_segments=None, percentile=None, weighted_WOSA=True, n_moments=10, MaxFunEvals=100000, algo_moments='gamma-polynomial', computes_amplitude=False) method of wavepal.Wavepal.Wavepal instance
    freq_analysis computes the WOSA periodogram and its confidence levels and the amplitude periodogram.
    Optional Inputs:
    - freqmin=None: minimal frequency. Default value is freqmin=1.0/(t[-1]-t[0]) (where t is the time vector)
    - freqmax=None: maximal frequency. Default value is freqmax=1.0/2.0/dt_GCD
    - freqstep=None: frequency step. Default value is freqstep=(freqmax-freqmin)/t.size (where t is the time vector)
    - dt_GCD=None: the greatest common divisor of the time steps of the time vector. Default value is the smallest time step (which is not exactly dt_GCD; it is an upper bound on the estimation of dt_GCD; but it is very simple to compute). 
    - freq_min_bound=True: limit (if True), or not (if False), the lower bound of the frequency range, for each WOSA segment. More details in
    'A General Theory on Spectral Analysis for Irregularly Sampled Time Series. I. Frequency Analysis', G. Lenoir and M. Crucifix
    - freq_max_bound=True: limit (if True), or not (if False), the upper bound of the frequency range, for each WOSA segment. More details in the above cited article.
    - mywindow=1: window choice for the windowing of the WOSA segments.
            -> 1: Square window
            -> 2: Triangular window
            -> 3: sin window
            -> 4: sin**2 (Hanning) window
            -> 5: sin**3 window
            -> 6: sin**4 window
            -> 7: Hamming window, defined as 0.54-0.46*np.cos(2.0*np.pi*time/D) [D is defined below]
            -> 8: 4-term Blackman-Harris window, with a0=0.35875 and a1=0.48829 and a2=0.14128 and a3=0.01168
            -> 9: Kaiser-Bessel window, with parameter alpha=2.5
            -> 10: Gaussian window, with standard dev. sigma=D/6.0 [D is defined below]
            Terminology and formulas come from:
            F. Harris. On the use of windows for harmonic analysis with the discrete fourier transform. Proceedings of the IEEE, 66(1):51-83, January 1978.
    - D=None: the temporal length of the WOSA segments. Default value is D=(t[-1]-t[0])/10.0 (where t is the time vector).
    - betafact=0.75: overlapping factor for the WOSA segments. Must take a value in [0.,1.[
    - coverage=90.: minimal coverage (in percent) of the data points along the segment length. Below this value, a WOSA segment is not considered. Must take a value between 0. and 100.
    - WOSA_segments=None: Choose the minimal number of WOSA segments to be present at each frequency to take it into account, thus defining the frequency range for the analysis.
            -> WOSA_segments='all': No restrictions on the number of segments per frequency.
            -> WOSA_segments='max': Consider only the frequencies for which the number of WOSA segments is maximal. This is the most restrictive case.
            -> WOSA_segments=None: Consider only the frequencies for which the number of WOSA segments is at least 10, or maximal if there are less than 10 segments.
            -> WOSA_segments=n (n is an integer): Consider only the frequencies for which the number of WOSA segments is at least n.
    - percentile=None: The x^th percentiles for the confidence levels. Must be a 1-dim numpy array. Default is the 95^th percentile (i.e. the 95% confidence level):percentile=np.zeros(1); percentile[0]=95.0
    - weighted_WOSA=True: True to get the weighted periodogram, or False for the classical periodogram.
    - n_moments=10: number of conserved moments for the analytical confidence levels. Must be >= 2. Used if "a" is in signif_level_type (see function 'carma_params')
    - MaxFunEvals=100000: "max_nfev" option for "least_squares" - see python help of "scipy.optimize.least_squares". Used if algo_moments='generalized-gamma-polynomial'.
    - algo_moments='gamma-polynomial': Choice for the algorithm for the computation of analytical confidence levels. Used if "a" is in signif_level_type (see function 'carma_params'). algo_moments='gamma-polynomial' or algo='generalized-gamma-polynomial'. 
    - computes_amplitude=False: computes the amplitude periodogram (if True) or not (if False).
    Outputs:
    /
    -----------------------------
    This is part of WAVEPAL
    (C) 2016 G. Lenoir

N.B.: you can get all of them with: help(x.__module__)

Below is presented an example of spectral analysis using some of those methods.

2. Preliminary analysis

Check the data set


In [6]:
x.check_data()

Figure of the time step in function of time, with an histogram of the distribution of the time steps. If you want to save the figure, use "savefig".


In [7]:
plot_timestep=x.plot_timestep()
plot_timestep.savefig("timestep.pdf")
plot_timestep.show()


Figure of the trend. Try many degrees of the polynomial.


In [8]:
plot_trend=x.plot_trend(pol_degree=-1)    # no trend
plot_trend.show()
plot_trend=x.plot_trend(pol_degree=0)    # constant trend
plot_trend.show()
plot_trend=x.plot_trend(pol_degree=5)    
plot_trend.show()
plot_trend=x.plot_trend(pol_degree=7)   
plot_trend.show()
plot_trend=x.plot_trend(pol_degree=9)    
plot_trend.show()


and choose the degree of the polynomial for the subsequent analyses


In [9]:
x.choose_trend_degree(7)

Compute some variables related to the trend


In [10]:
x.trend_vectors()

3. CARMA(p,q) Background Noise Analysis

Option make_carma_fig=True allows to save some figures related to the analyses of the background noise (made with 'carma pack' package of Kelly & al. - see the reference in the help of carma_params method). They are here saved in the folder "figures_carma", previously created by the user.


In [11]:
x.carma_params(make_carma_fig=True,nbins=20,dpi=400,path_to_figure_folder="figures_carma/")


****************************
*        CARMA PACK        *
****************************

FIRST ROUND (to estimate the number of independent samples): with  10000  samples
**********************************************************************************************************
Calculating sigma...
Calculating log-likelihoods...
Decorrelation length (in number of samples) - Estimation:  15

SECOND ROUND: generates  15000  samples
***************************************
Calculating sigma...
Calculating log-likelihoods...
Plotting parameter summary
Plotting parameter summary
Plotting parameter summary
Plotting parameter summary
Decorrelation length (in number of samples):  15
**************************************
*        BUILD CARMA MATRIX K        *
**************************************
Computing the median parameters of the CAR-1 process from  1000  MCMC samples.
Median parameters:
--------------------
alpha:  0.170285238445
std white noise:  0.14987530053

4. Frequency Analysis

Choose the $\textrm{x}^{\textrm{th}}$ percentiles for significance testing


In [12]:
percentile=np.zeros(2)
percentile[0]=95.
percentile[1]=99.9

N.B.: If you are not interested in the frequency analysis, you can skip the code below and go to section 5.

Run the method for the frequency analysis (do not forget to use help(x.freq_analysis) if needed)


In [13]:
x.freq_analysis(freqstep=0.0001,D=600.,percentile=percentile,n_moments=12,computes_amplitude=True)


100%|██████████| 36/36 [00:00<00:00, 277.71it/s]
  0%|          | 0/532 [00:00<?, ?it/s]
Re-estimated D factor (WOSA):  614.461538462
Preliminary steps for the WOSA periodogram:
Re-estimated frequency range: from  0.00166701633082  to  0.0547705311469 
Main loop, over the frequencies:
100%|██████████| 532/532 [00:20<00:00, 25.81it/s]

Periodogram. This is the central result for the frequency analysis.


In [14]:
plot_periodogram=x.plot_periodogram(fontsize_legend=10)
plot_periodogram.show()


Figure of the WOSA segmentation


In [15]:
plot_WOSA_segmentation=x.plot_WOSA_segmentation()
plot_WOSA_segmentation.show()


Figure of the number of WOSA segments for each frequency


In [16]:
plot_number_WOSA_segments=x.plot_number_WOSA_segments()
plot_number_WOSA_segments.show()


Check the convergence of the analytical confidence levels


In [17]:
plot_check_convergence_percentiles=x.plot_check_convergence_percentiles(fontsize_suptitle=13,fontsize_title=9,fontsize_axes=8,fontsize_ticks=6)
plot_check_convergence_percentiles.show()


Compare the squared amplitude vs the periodogram


In [18]:
plot_amplitude_vs_periodogram=x.plot_amplitude_vs_periodogram(fontsize_legend=10)
plot_amplitude_vs_periodogram.show()


5. Time-frequency Analysis

Define the times at which the CWT (continuous wavelet transform) is to be computed


In [19]:
theta=np.linspace(myt[0],myt[-1],2000)

First analysis

Run the method for the time-frequency analysis. Note that the percentages of the progressing bars are not fully reliable, since the iterations in those loops do not spend equal computing time.


In [20]:
x.timefreq_analysis(theta=theta,w0=5.5,permin=10.,percentile=percentile)


  0%|          | 6/2000 [00:00<00:37, 53.56it/s]
Weights for the scalogram and Shannon-Nyquist exclusion zone:
100%|██████████| 2000/2000 [00:39<00:00, 50.69it/s]
  0%|          | 0/133 [00:00<?, ?it/s]
Re-estimated period range: from  10.0  to  970.058602567
Main loop, over the time-frequency plane:
100%|██████████| 133/133 [10:35<00:00, 12.98s/it]

Set the location of the ticks


In [21]:
time_string=[0., 500., 1000., 1500., 2000., 2500., 3000., 3500., 4000., 4500., 5000., 5500., 6000.]
period_string=[10., 21., 41., 100., 200., 400., 800., 1500.]
dashed_periods=[21., 41., 100.]

Scalogram. This is the central result for the time-frequency analysis. Resizing (with set_size_inches) is better, and is compulsory before saving the figure (with savefig).


In [22]:
plot_scalogram=x.plot_scalogram(color_cl_anal=['g'],color_cl_mcmc=['m'],fontsize_title=30,fontsize_axes=20,fontsize_ticks=20,linewidth_cl=4,global_scal_xlabel_ticks="bottom",decimals=2,linewidth_gscal=2.0,time_string=time_string,period_string=period_string,dashed_periods=dashed_periods,power_string=power_string)
plot_scalogram=x.plot_scalogram(color_cl_anal=['m','g'],fontsize_title=40,fontsize_ticks=20,fontsize_axes=30,time_string=time_string,period_string=period_string,dashed_periods=dashed_periods)
fig = plt.gcf() 
fig.set_size_inches(24,12)
plot_scalogram.show()


Second analysis

Same analysis, with another time-frequency resolution (change the "w0" parameter of the Morlet Wavelet)


In [23]:
y=copy.copy(x)  # optional: in order to keep in memory all what we did up to here (very convenient if you work with ipython)
y.timefreq_analysis(theta=theta,w0=15.0,permin=10.,percentile=percentile)


  0%|          | 7/2000 [00:00<00:32, 61.43it/s]
Weights for the scalogram and Shannon-Nyquist exclusion zone:
100%|██████████| 2000/2000 [00:34<00:00, 57.84it/s]
  0%|          | 0/104 [00:00<?, ?it/s]
Re-estimated period range: from  10.0  to  355.062231062
Main loop, over the time-frequency plane:
100%|██████████| 104/104 [08:18<00:00, 13.20s/it]

In [24]:
plot_scalogram=y.plot_scalogram(color_cl_anal=['m','g'],fontsize_title=40,fontsize_ticks=20,fontsize_axes=30,time_string=time_string,period_string=period_string,dashed_periods=dashed_periods)
fig = plt.gcf()
fig.set_size_inches(24,12)
plot_scalogram.show()


6. Working with the attributes of Wavepal

You may want to access the attributes of the Wavepal class. The list of available attributes is given in the method __init__ of the Wavepal class (open the file Wavepal.py). Most of them are initialized as None. Their values may change when running the methods of Wavepal. Consequently, I recommend to read, save, and possibly modify (with caution) for further use, the attributes of Wavepal after you have run all the desired methods.

Getting the value of an attribute is easy. Example with 'nt' (number of data points):


In [25]:
x.nt


Out[25]:
608

The attributes are listed below, with some details given.

Attributes defined in the initialization of Wavepal class (__init__ method)

  • t [1-D numpy array of floats]: the times of the time series.
  • mydata [1-D numpy array of floats]: the data corresponding to t.
  • t_axis_label [str]: label for the time axis in figures
  • mydata_axis_label [str]: label for the data axis in figures
  • t_units [str]: units of 't'
  • mydata_units [str]: units of 'mydata'
  • t_label [str]: same as t_units, with parentheses
  • mydata_label [str]: same as mydata_units, with parentheses
  • freq_label [str]: $\textrm{t_units}^{-1}$, with parentheses
  • power_label [str]: $\textrm{mydata_units}^{2}$, with parentheses
  • varpow_label [str]: $\textrm{mydata_units}^{4}$, with parentheses

Attributes defined in 'check_data' method

  • nt [int]: number of time/data points, after removing the multiple occurrences of the same times.
  • run_check_data [bool]: True if 'check_data' was run without any trouble. False if not.

Attribute defined in 'plot_timestep' method

  • dt [float]: time step

Attributes defined in 'choose_trend_degree' method

  • pol_degree [int]: degree of the polynomial trend
  • trend [1-D numpy array of floats - size=t.size]: the trend.
  • run_choose_trend_degree [bool]: True if 'choose_trend_degree' was run without any trouble. False if not.

Attributes defined in 'trend_vectors' method

  • Vmat [numpy array of floats - dimension=(nt,pol_degree+3)]: the first (pol_degree+1) columns contain $t^k, \forall k\in[0, ..., \textrm{pol_degree}]$. Vector $t$ was first normalized as $t/\textrm{max}(t)$ to ensure numerical stability. Last two columns contain the weighted cosine and sine, in order to perform the frequency or time-frequency analysis. Those two last columns change at every frequency (with a frequency analysis) or at each couple (theta,period_cwt) (with a time-frequency analysis).
  • myprojvec [numpy array of floats - dimension=(nt,pol_degree+3)]: same as Vmat but with orthonormalized columns (with Gram-Schmidt procedure). Orthonormalization is performed starting with the first column of Vmat. As for Vmat, the last two columns of myprojvec are subject to multiple changes.
  • run_trend_vectors [bool]: True if 'trend_vectors' was run without any trouble. False if not.

Attributes defined in 'carma_params' method

  • p [int]: C-AR order of the CARMA(p,q) process
  • q [int]: C-MA order of the CARMA(p,q) process
  • signif_level_type [str]: "", "a", "n" or "an". Choice made for the type of significance/confidence levels.
  • nmcmc [int]: number of MCMC samples. nmcmc is None if signif_level_type="a" and p=0. See the 'help' of method 'carma_params' for additional details.
  • mylength [int]: lag indicating the decorrelation length for the MCMC samples of the parameters of the CARMA(p,q) process. The value given here is the max. of the decorrelation lengths on all the parameters.
  • beta_gam [float]: used when p=q=0 (white noise). Scale parameter of the gamma distribution. See the formulas of the posterior distribution for the variance of the white noise process.
  • sigwn_unique [float]: "best" standard deviation. If p=q=0 (white noise), this is the value for which the posterior pdf of the white noise variance is maximum. In the other cases, this is the median value of the MCMC distribution. Available when "a" is in signif_level_type.
  • alpha_unique [1-D numpy array of floats - size=p+1]: "best" C-AR coefficients. Each entry of this vector is the median value of the marginal MCMC distribution of the corresponding C-AR parameter. Available when "a" is in signif_level_type.
  • beta_unique [1-D numpy array of floats - size=q+1]: "best" C-MA coefficients. Each entry of this vector is the median value of the marginal MCMC distribution of the corresponding C-MA parameter. Available when "a" is in signif_level_type.
  • ARMA_mat_unique [numpy array of floats - dimension=(nt,nt*p)]: matrix K used for the computation of the analytical confidence levels (see the reference paper). Available when "a" is in signif_level_type.
  • myn [numpy array of floats - dimension=(nt,nmcmc)]: contains the CARMA(p,q) MCMC time series. Available when "n" is in signif_level_type. This is not applicable when p=q=0 (white noise), since in that case MCMC time series are not explicitly computed, and then myn=None.
  • run_carma_params [bool]: True if 'carma_params' was run without any trouble. False if not.

Attributes defined in 'freq_analysis' method

  • freq [1-D numpy array of floats]: the frequencies
  • tau [1-D numpy array of floats]: values of the times at which start the WOSA segments
  • myind_time [numpy array of ints - dim=(tau.size,2)]: min. and max. temporal indices (of the vector 't') for each WOSA segment
  • myind_freq [list of size=tau.size]: Each entry of the list contains an array with the frequency indices (of the vector 'freq') which are taken into account on the WOSA segment
  • myind_Q [1-D numpy array of ints - size=tau.size]: indices of the WOSA segments taken into account, on the basis of a regular set of WOSA segments.
  • D [float]: the temporal length of the WOSA segments.
  • nsmooth_vec [1-D numpy array of ints - size=freq.size]: Number of WOSA segments for each frequency.
  • nsmooth [int]: Number of WOSA segments. Note that nsmooth is not necessarily equal to nsmooth_vec.max(), because each WOSA segment does not necessarily holds all the frequencies.
  • tapwindow [int]: window choice for the windowing of the WOSA segments. It is the same as input variable 'mywindow' in 'freq_analysis'.
  • weighted_WOSA [str]: is True if the periodogram is weighted, or False if not.
  • computes_amplitude [str]: is True if the amplitude periodogram is computed, or False if not.
  • n_moments [int]: number of conserved moments for the analytical confidence levels. Available when "a" is in signif_level_type.
  • percentile [1-D numpy array of floats]: The $\textrm{x}^{\textrm{th}}$ percentiles for the confidence levels.
  • periodogram [1-D numpy array of floats - size=freq.size]: the (WOSA) periodogram.
  • periodogram_cl_mcmc [numpy array of floats - dim=(freq.size,percentile.size)]: MCMC confidence levels for the periodogram. Available when "n" is in signif_level_type.
  • periodogram_cl_anal [numpy array of floats - dim=(freq.size,percentile.size)]: Analytical confidence levels for the periodogram. Available when "a" is in signif_level_type.
  • f_periodogram [1-D numpy array of floats - size=freq.size]: the f-periodogram. Used when p=q=0 (white noise), 1 WOSA segment and no windowing.
  • f_periodogram_cl [numpy array of floats - dim=(freq.size,percentile.size)]: Analytical confidence levels for the f-periodogram. Available when p=q=0 (white noise), 1 WOSA segment and no windowing.
  • amplitude [1-D numpy array of floats - size=freq.size]: the amplitude periodogram. Available when computes_amplitude is True.
  • amplitude_cos [1-D numpy array of floats - size=freq.size]: Amplitude of the cosine part. Used for filtering, which requires only 1 WOSA segment. Available when computes_amplitude is True.
  • amplitude_sin [1-D numpy array of floats - size=freq.size]: Amplitude of the sine part. Used for filtering, which requires only 1 WOSA segment. Available when computes_amplitude is True.
  • pseudo_spectrum_mcmc [1-D numpy array of floats - size=freq.size]: MCMC pseudo-spectrum. Available when "n" is in signif_level_type.
  • pseudo_spectrum_anal [1-D numpy array of floats - size=freq.size]: Analytical pseudo-spectrum. Available when "a" is in signif_level_type.
  • variance_anal [1-D numpy array of floats - size=freq.size]: Analytical variance of the background noise. Available when "a" is in signif_level_type and the periodogram is not weighted (weighted_WOSA is False).
  • periodogram_cl_anal_check_percentile [list]: list of two components. The first contains a numpy array of 6 floats, which are the frequencies at which convergence is checked. The second one contains a numpy array of dim=(6,n_moments-1,percentile.size), which gives the percentiles at those 6 frequencies and for all the moments (start with a number of moments=2).
  • run_freq_analysis [bool]: True if 'freq_analysis' was run without any trouble. False if not.

Attributes defined in 'freq_filtering' method

  • freq_filtered_signal_bounds [list of tuples]: Length of list is equal to the number of frequency bands on which filtering is performed. Each tuple contains the 2 frequency bounds of the band.
  • freq_filtered_signal [numpy array of floats - dim=(nt,len(freq_filtered_signal_bounds))]: filtered signal in each band.
  • run_freq_filtering [bool]: True if 'freq_filtering' was run without any trouble. False if not.

Attributes defined in 'timefreq_analysis' method

  • theta [1-D numpy array of floats]: the times at which the scalogram is computed.
  • period_cwt [1-D numpy array of floats]: the periods at which the scalogram and its relatives are computed.
  • period_ampl [1-D numpy array of floats]: the periods at which the amplitude scalogram (only) is computed.
  • smoothing_coeff [float]: the smoothing coefficient (see inputs of function 'timefreq').
  • weighted_CWT [str]: True if the scalogram is weighted, or False if not.
  • shannonnyquistexclusionzone [str]: the Shannon-Nyquist exclusion zone is activated (if True) or not (if False).
  • coi1 [1-D numpy array of floats - size=period_cwt.size]: cone of influence - left part.
  • coi2 [1-D numpy array of floats - size=period_cwt.size]: cone of influence - right part.
  • coi1_smooth [1-D numpy array of floats - size=period_cwt.size]: border of the forbidden zone on the left side. Used if 'smoothing_type' in the function 'timefreq_analysis' is 'fixed'.
  • coi2_smooth [1-D numpy array of floats - size=period_cwt.size]: border of the forbidden zone on the right side. Used if 'smoothing_type' in the function 'timefreq_analysis' is 'fixed'.
  • perlim1_smooth_cwt [1-D numpy array of floats - size=theta.size]: periods at the border of the Shannon-Nyquist exclusion zone.
  • perlim1_smooth_ampl [1-D numpy array of floats - size=theta.size]: periods at the border of the Shannon-Nyquist exclusion zone, for the amplitude scalogram (only).
  • perlim2_smooth_scal [1-D numpy array of floats - size=theta.size]: periods at the border of the refinement of the Shannon-Nyquist exclusion zone.
  • perlim2_smooth_ampl [1-D numpy array of floats - size=theta.size]: periods at the border of the refinement of the Shannon-Nyquist exclusion zone, for the amplitude scalogram (only).
  • computes_cwtamplitude [str]: True if the amplitude scalogram was computed or False if not.
  • n_moments_cwt [int]: number of conserved moments for the analytical confidence levels. Available when "a" is in signif_level_type.
  • percentile_cwt [1-D numpy array of floats]: The $\textrm{x}^{\textrm{th}}$ percentiles for the confidence levels.
  • scalogram [numpy array of floats - dim=(theta.size,period_cwt.size)]: the (smoothed) scalogram.
  • scalogram_cl_mcmc [numpy array of floats - dim=(theta.size,period_cwt.size,percentile_cwt.size)]: MCMC confidence levels for the scalogram. Available when "n" is in signif_level_type.
  • scalogram_cl_anal [numpy array of floats - dim=(theta.size,period_cwt.size,percentile_cwt.size)]: Analytical confidence levels for the scalogram. Available when "a" is in signif_level_type.
  • cwtamplitude [numpy array of floats - dim=(theta.size,period_cwt.size)]: the amplitude scalogram. Available when computes_cwtamplitude is True
  • cwtamplitude_cos [numpy array of floats - dim=(theta.size,period_cwt.size)]: Amplitude of the cosine part. Used for filtering. Available when computes_cwtamplitude is True.
  • cwtamplitude_sin [numpy array of floats - dim=(theta.size,period_cwt.size)]: Amplitude of the sine part. Used for filtering. Available when computes_cwtamplitude is True.
  • pseudo_cwtspectrum_mcmc [numpy array of floats - dim=(theta.size,period_cwt.size)]: MCMC pseudo-cwtspectrum. Available when "n" is in signif_level_type.
  • pseudo_cwtspectrum_anal [numpy array of floats - dim=(theta.size,period_cwt.size)]: Analytical pseudo-cwtspectrum. Available when "a" is in signif_level_type.
  • cwt_variance_anal [numpy array of floats - dim=(theta.size,period_cwt.size)]: Analytical variance of the scalogram of the background noise. Available when "a" is in signif_level_type and the scalogram is not weighted (weighted_CWT is False).
  • scalogram_cl_anal_check_convergence [list]: list of two components. Let J=period_cwt.size. The first contains a 1-D numpy array of size J, which are the times at which convergence is checked, for a given period (there is one time per period). The second one contains a numpy array of dim=(J,n_moments-1,percentile_cwt.size), which gives the percentiles at those J time-period points and for all the moments (start with a number of moments=2).
  • computes_global_scalogram [str]: True if the global scalogram was computed or False if not.
  • global_scalogram [1-D numpy array of floats - size=period_cwt.size]: the global scalogram.
  • global_scalogram_cl_mcmc [numpy array of floats - dim=(period_cwt.size,percentile.size)]: MCMC confidence levels for the global scalogram. Available when "n" is in signif_level_type.
  • global_scalogram_cl_anal [numpy array of floats - dim=(period_cwt.size,percentile.size)]: Analytical confidence levels for the global scalogram. Available when "a" is in signif_level_type.
  • global_amplitude [1-D numpy array of floats - size=period_cwt.size]: the global amplitude scalogram. Available when computes_cwtamplitude is True.
  • pseudo_global_spectrum_mcmc [1-D numpy array of floats - size=period_cwt.size]: global MCMC pseudo-cwtspectrum. Available when "n" is in signif_level_type.
  • pseudo_global_spectrum_anal [1-D numpy array of floats - size=period_cwt.size]: global analytical pseudo-cwtspectrum. Available when "a" is in signif_level_type.
  • global_scalogram_variance_anal [1-D numpy array of floats - size=period_cwt.size]: global analytical variance of the scalogram of the background noise. Available when "a" is in signif_level_type and the scalogram is not weighted (weighted_CWT is False).
  • global_scalogram_cl_anal_check_convergence [list]: list of two components. The first contains a numpy array of 6 floats, which are the periods at which convergence is checked. The second one contains a numpy array of dim=(6,n_moments-1,percentile_cwt.size), which gives the percentiles at those 6 frequencies and for all the moments (start with a number of moments=2).
  • minscal [float]: min. for the color scale of the scalogram.
  • maxscal [float]: max. for the color scale of the scalogram.
  • minampl [float]: min. for the color scale of the amplitude scalogram.
  • maxampl [float]: max. for the color scale of the amplitude scalogram.
  • minampl_sq [float]: min. for the color scale of the squared amplitude scalogram.
  • maxampl_sq [float]: max. for the color scale of the squared amplitude scalogram.
  • min_pseudo_cwtspectrum_anal [float]: min. for the color scale of the analytical pseudo-cwtspectrum.
  • max_pseudo_cwtspectrum_anal [float]: max. for the color scale of the analytical pseudo-cwtspectrum.
  • min_pseudo_cwtspectrum_mcmc [float]: min. for the color scale of the MCMC pseudo-cwtspectrum.
  • max_pseudo_cwtspectrum_mcmc [float]: max. for the color scale of the MCMC pseudo-cwtspectrum.
  • min_cwt_variance_anal [float]: min. for the color scale of the variance of the analytical background noise.
  • max_cwt_variance_anal [float]: max. for the color scale of the variance of the analytical background noise. N.B.: The above min. and max. for the color scales are taken on the time-frequency points which are outside the forbidden and shaded zones.
  • n_outside_scalelim1 [1-D numpy array of ints - size=period_cwt.size]: number of theta values outside the Shannon-Nyquist exclusion zone, for each scale.
  • weight_cwt [numpy array of floats - dim=(theta.size,period_cwt.size)]: the weights for the weighted scalogram.
  • run_timefreq_analysis [bool]: True if 'timefreq_analysis' was run without any trouble. False if not.

Attributes defined in 'timefreq_ridges_filtering' method

  • skeleton [list]: the skeleton contains the ridges. Let $r$ be the number of ridges. $\forall k\in[0,...,r-1]$, we have:
    • skeleton[k][0] contains the times of the ridge
    • skeleton[k][1] contains the periods along the ridge
    • skeleton[k][2] contains the amplitude of the cosine part along the ridge (see 'cwtamplitude_cos' above)
    • skeleton[k][3] contains the amplitude of the sine part along the ridge (see 'cwtamplitude_sin' above)
    • skeleton[k][4] contains the amplitude along the ridge (see 'cwtamplitude' above)
  • run_timefreq_ridges_filtering [bool]: True if 'timefreq_ridges_filtering' was run without any trouble. False if not.

Attributes defined in 'timefreq_band_filtering' method

  • timefreq_band_filtered_signal_bounds [list of tuples]: Length of list is equal to the number of period bands on which filtering is performed. Each tuple contains the 2 period bounds of the band.
  • timefreq_band_filtered_signal [numpy array of floats - dim=(theta.size,len(timefreq_band_filtered_signal_bounds))]: filtered signal in each band.
  • run_timefreq_band_filtering [bool]: True if 'timefreq_band_filtering' was run without any trouble. False if not.

7. Other Methods

Two methods that are not part of the Wavepal class are also available to the user, in the wv package:

  • dt_GCD: compute the greatest common divisor of the time steps. This is not direct. See also the file example_dt_GCD.py
  • mov_av: moving average. You may use it as an alternative to the polynomial detrending. In that case, inside Wavepal class, choose a degree for the polynomial trend equal to -1 or 0.

In [26]:
help(wv.mov_av)


Help on function mov_av in module wavepal.mov_av:

mov_av(t, x, l, type_av='t')
    mov_av returns the moving average of a time series. 
    If type_av="n":
    For each data point, it makes the average on l points, i.e. enter in the average: the (l-1)/2 data points before, the (l-1)/2 data points after, and the current data point. l must then be odd. On the borders of the time series, the formula is adapted: the average is taken on less data points (all the available ones); see the code for more details.
    If type_av="t":
    For each data point x[k] at time t[k], it makes the average on a fixed time interval l. Enter in the average: all the data points s.t. their time is between max(t[0],t[k]-l/2). and min(t[-1],t[k]+l/2). The time series being possibly irregularly sampled, the number of data points on which the average is performed may differ from one interval to another. See the code for more details.
    Required Inputs:
    - t [1-dim numpy array of floats]: the times of the time series.
    - x [1-dim numpy array of floats - size=t.size]: the data points of the time series
    - l [int or float]: 
    If type_av="n", this the number of points on which the average is performed. If it is not odd, 1 is added to l. l must be of 'int' type.
    If type_av="t", this is the time interval on which tge average is performed. l must be of 'float' type.
    Optional Inputs:
    - type_av="t": is "t" (default) or "n".
    Outputs:
    - mov_av_x [1-dim numpy array of floats - size=t.size]: the moving averaged time series.
    RECOMMENDATION:
    Before running mov_av, run 'check_data' module of the 'Wavepal' class in order to remove the data points having the same times.
    -----------------------------
    This is part of WAVEPAL
    (C) 2016 G. Lenoir


In [27]:
help(wv.dt_GCD)


Help on function dt_GCD in module wavepal.dt_GCD:

dt_GCD(t)
    Computes the greatest common divisor of the time steps of the times in t
    Inputs: 
    - t [1-dim numpy array of ints]: the times.
    WARNING: the times must all be distinct, of INTEGER type, and sorted in ascending order. In principle, the times come from a data file, such that they have a limited precision (in other words, they are rational numbers). Consequently, they can be transformed under integer form (note that doing that automatically can be quite challenging with python).
    Outputs:
    - dt_GCD [int]: the greatest common divisor of the time steps of the times in t
    Example:
    - See example_dt_GCD.py
    -----------------------------
    This is part of WAVEPAL
    (C) 2016 G. Lenoir