Extension Modules

C/C++ extension modules, for accelerated calculations.

ptsa.extensions.circular_stat

ptsa.extensions.circular_stat.circ_diff(X, Y, Z)

Computes the angular difference of the complex arrays X and Y, storing the value in Z

Parameters:

X,Y,Z – np.array[np.complex]

ptsa.extensions.circular_stat.circ_diff_par(X, Y, Z, n_threads)

Computes the angular difference of the complex arrays X and Y, storing the value in Z. The computation is performed in parallel over n_threads threads

Parameters:
  • X,Y,Z – np.array[np.complex]

  • n_threads – int

ptsa.extensions.circular_stat.circ_mean(Z)

Returns the average angle of a vector of complex numbers, weighted by the magnitude of each number. Thus, circ_mean([1+0j, 1+0j, 0+1j]) == circ_mean([2+0j, 0+1j])

ptsa.extensions.circular_stat.circ_diff_time_bins(c1, c2, c_diff, cdiff_means)

Computes the circular difference of c1 and c2, stores the result in c_diff, then fills cdiff_means with the average binned differences.

len(cdiff_means) must divide len(c1)

Returns:

None

ptsa.extensions.circular_stat.compute_f_stat(phase_diffs, classes, f_stat)

Performs an F-test, i.e. a circular ANOVA, comparing the variance of phase_diffs when partitioned into two classes, and stores the results in fstat.

Parameters:
  • phase_diffs – A matrix of phase differences

  • classes – A boolean vector indicating which observation belongs in which class Should be the same length as the first dimension of phase_diffs

  • f_stat – An empty vector the same length as the second dimension of phase_diffs

ptsa.extensions.circular_stat.compute_z_scores(m, n_perms)
ptsa.extensions.circular_stat.single_trial_ppc_all_features(recalls, wavelets, ppc_output, theta_sum_recalls, theta_sum_non_recalls, n_freqs, n_bps, n_threads)
ptsa.extensions.circular_stat.single_trial_ppc_all_features(wavelets, theta_avg_recalls, theta_avg_non_recalls, outsample_features, n_freqs, n_bps, n_threads)

ptsa.extensions.morlet

Low-level extension module for quickly computing Morlet wavelet decompositions.

This module uses the following wavelet for frequency \(f\) and Gaussian width \(w\):

\[\Phi(t) = \sigma^{-\frac{1}{2}} \pi^{-\frac{1}{4}} e^{\frac{-t^2}{{2 \sigma^2}}} e^{\frac{iwt}{\sigma}}\]

where

\[\sigma = \frac{w}{2\pi f}\]

The Gaussian envelope is only computed to a width of \(3.5\sigma\) on each side of the peak. Any points beyond that are rounded to 0.

The convolution of a signal \(\Psi\) with a wavelet \(\Phi\) is computed using the identity

\[\Psi * \Phi = N^{-1} \big(\widehat{\hat{\Psi} \cdot \hat \Phi }\big)\]

where \(N\) is the number of samples in the the signal \(\Psi\), in order to take advantage of the speed provided by the FFTW library.

Example:
signal = #... A 1D array
n_freqs = 10
pow_mat = np.empty(shape=n_freqs*len(signal),dtype=float)
transform = MorletWaveletTransform(width=4,
                                   low_freq=3,
                                   high_freq=100,
                                   nf=n_freqs,
                                   sample_freq=1000,
                                   signal_len = len(signal)
                                   )
transformed_signal = transform.multiphasevec(signal,pow_mat).reshape((n_freqs,-1))

ptsa.extensions.edf

File-like wrapper around parts of EDFlib to provide an interface for reading the EDF+ family of EEG formats. ptsa.data.readers.EDFRawReader provides a slightly higher-level interface for doing the same thing.

class ptsa.extensions.morlet.ChannelInfo

Channel data including label, number of samples, etc. These objects are returned by EDFFile.get_channel_info(), and have the following read-only attributes:

Variables:
  • label (str) – The name of the channel

  • smp_in_file (int) – Number of samples in file

  • phys_max (float) – Maximum representable value in physical units

  • phys_min (float) – Minimum representable value in physical units

  • dig_max (int) – Maximum representable value in digital units

  • dig_min (int) – Minimum representable value in digital units

  • smp_in_datarecord (int) – Number of samples stored in one record

  • physdimension (str) – Dimension of physical units

  • prefilter (str) – Type of prefiltering performed on signal

  • transducer (str) – Transducer type (e.g. ‘AgAgCl electrode’)

class ptsa.extensions.morlet.EDFFile

Reads the EDF family of files.

This class utilizes EDFlib to read EDF/BDF/EDF+/BDF+ files.

__init__(filename)
Parameters:

filename (str) –

get_channel_info(channel)

Return the information on a given channel

Parameters:

channel – int

get_channel_numbers(channel_names)
get_samplerate(channel)
read_samples(channels, samples, offset)

Read samples from a list of channels. Channels can be specified by either a list of numbers or a list of labels.