Wavelet Transform

class process_nwb.wavelet_transform.ChannelBandIterator(X, rate, filters='rat', npad=None, hg_only=True, post_resample_rate=None, precision='single')[source]

Class for iterative write over channels and bands.

Parameters
  • X (ndarray (n_time, n_channels)) – Data array.

  • filters (str (optional)) – Which type of filters to use. Options are ‘rat’: center frequencies spanning 2-1200 Hz, constant Q, 54 bands ‘human’: center frequencies spanning 4-200 Hz, constant Q, 40 bands ‘changlab’: center frequencies spanning 4-200 Hz, variable Q, 40 bands

  • npad (int) – Padding to add to beginning and end of timeseries. Default 0.

  • hg_only (bool) – If True, only the amplitudes in the high gamma range [70-150 Hz] is computed.

  • post_resample_rate (float) – If not None, resample the computed wavelet amplitudes to this rate.

  • precision (str) – Either single for float32/complex64 or double for float/complex.

property dtype

Define the data type of the array

Returns

NumPy style dtype or otherwise compliant dtype string

property maxshape

Property describing the maximum shape of the data array that is being iterated over

Returns

NumPy-style shape tuple indicating the maxiumum dimensions up to which the dataset may be resized. Axes with None are unlimited.

next()

Return the next data chunk or raise a StopIteration exception if all chunks have been retrieved.

HINT: numpy.s_ provides a convenient way to generate index tuples using standard array slicing. This is often useful to define the DataChunk.selection of the current chunk

Returns

DataChunk object with the data and selection of the current chunk

Return type

DataChunk

recommended_chunk_shape()[source]

Recommend the chunk shape for the data array.

Returns

NumPy-style shape tuple describing the recommended shape for the chunks of the target array or None. This may or may not be the same as the shape of the chunks returned in the iteration process.

recommended_data_shape()[source]

Recommend the initial shape for the data array.

This is useful in particular to avoid repeated resized of the target array when reading from this data iterator. This should typically be either the final size of the array or the known minimal shape of the array.

Returns

NumPy-style shape tuple indicating the recommended initial shape for the target array. This may or may not be the final full shape of the array, i.e., the array is allowed to grow. This should not be None.

process_nwb.wavelet_transform.gaussian(n_time, rate, center, sd, precision='single')[source]

Generates a normalized gaussian kernel.

Parameters
  • n_time (int) – Number of samples

  • rate (float) – Sampling rate of kernel (Hz).

  • center (float) – Center frequency (Hz).

  • sd (float) – Bandwidth (Hz).

  • precision (str) – Either single for float32/complex64 or double for float/complex.

process_nwb.wavelet_transform.get_filterbank(filters, n_time, rate, hg_only, precision='single')[source]

Get the filterbank and parameters.

Parameters
  • filters (str or list) – Which type of filters to use. Options are ‘rat’: center frequencies spanning 2-1200 Hz, constant Q, 54 bands ‘human’: center frequencies spanning 4-200 Hz, constant Q, 40 bands ‘changlab’: center frequencies spanning 4-200 Hz, variable Q, 40 bands Note - calculating center frequencies above rate/2 raises a ValueError If filters is a list, it is assumed to already be correctly formatted.

  • n_time (int) – Input data time dimension.

  • rate (float) – Number of samples per second.

  • hg_only (bool) – If True, only the amplitudes in the high gamma range [70-150 Hz] is computed.

  • precision (str) – Either single for float32/complex64 or double for float/complex.

Returns

  • filters (list of ndarrays) – List of filters to apply.

  • cfs (ndarray) – Center frequencies used.

  • sds (ndarray) – Bandwidths used.

process_nwb.wavelet_transform.hamming(n_time, rate, min_freq, max_freq, precision='single')[source]

Generates a normalized Hamming kernel.

Parameters
  • n_time (int) – Number of samples

  • rate (float) – Sampling rate of kernel (Hz).

  • min_freq (float) – Band minimum frequency (Hz).

  • max_freq (float) – Band maximum frequency (Hz).

  • precision (str) – Either single for float32/complex64 or double for float/complex.

process_nwb.wavelet_transform.store_wavelet_transform(elec_series, processing, filters='rat', hg_only=True, abs_only=True, npad='fast', post_resample_rate=None, chunked=True, precision='single', source_series=None)[source]

Apply a wavelet transform using a prespecified set of filters. Results are stored in the NWB file as a DecompositionSeries.

Calculates the center frequencies and bandwidths for the wavelets and applies them along with a heavyside function to the fft of the signal before performing an inverse fft. The center frequencies and bandwidths are also stored in the NWB file.

Parameters
  • elec_series (ElectricalSeries) – ElectricalSeries to process.

  • processing (Processing module) – NWB Processing module to save processed data.

  • filters (str (optional)) – Which type of filters to use. Options are ‘rat’: center frequencies spanning 2-1200 Hz, constant Q, 54 bands ‘human’: center frequencies spanning 4-200 Hz, constant Q, 40 bands ‘changlab’: center frequencies spanning 4-200 Hz, variable Q, 40 bands

  • hg_only (bool) – If True, only the amplitudes in the high gamma range [70-150 Hz] is computed.

  • abs_only (bool) – If True, only the amplitude is stored.

  • npad (int) – Padding to add to beginning and end of timeseries. Default ‘fast’, which pads to the next fastest length.

  • post_resample_rate (float) – If not None, resample the computed wavelet amplitudes to this rate.

  • chunked (bool) – If True, calculate wavelet transform one channel and band at a time and store iteratively into nwb. Default True

  • precision (str) – Either single for float32/complex64 or double for float/complex. Default single.

  • source_series (ElectricalSeries) – If not None, this series gets used as the source rather than elec_series. Can be used if not all intermediate series are being stored in the NWB during preprocessing.

Returns

  • X_wvlt (ndarray, complex) – Complex wavelet coefficients.

  • series (list of DecompositionSeries) – List of NWB objects.

process_nwb.wavelet_transform.wavelet_transform(X, rate, filters='rat', hg_only=True, X_fft_h=None, npad='fast', to_removes=None, precision='single')[source]

Apply a wavelet transform using a prespecified set of filters.

Calculates the center frequencies and bandwidths for the wavelets and applies them along with a heavyside function to the fft of the signal before performing an inverse fft. Here are additional details:

1. Computes the FFT of the signal and applies 2u(f), where u(f) = heaviside function necessary for calculating analytic signal

2. Filters in the frequency domain by multiplying with a gaussian kernel (or equivalently a complex morlet wavelet in the time domain). The gaussian kernel location = the center frequency and the standard deviation = the center frequency / Q. For the ‘rat’ and ‘human’ filters, Q is constant with a default value of 8

3. Computes the IFFT returning the analytic bandpassed (via a complex morlet wavelet) signal for each filter

Parameters
  • X (ndarray (n_time, n_channels)) – Input data, dimensions

  • rate (float) – Number of samples per second.

  • filters (str (optional)) – Which type of filters to use. Options are ‘rat’: center frequencies spanning 2-1200 Hz, constant Q, 54 bands ‘human’: center frequencies spanning 4-200 Hz, constant Q, 40 bands ‘changlab’: center frequencies spanning 4-200 Hz, variable Q, 40 bands Note - calculating center frequencies above rate/2 raises a ValueError

  • hg_only (bool) – If True, only the amplitudes in the high gamma range [70-150 Hz] is computed.

  • X_fft_h (ndarray (n_time, n_channels)) – Precomputed product of X_fft and heavyside. Useful for when bands are computed independently.

  • npad (int) – Padding to add to beginning and end of timeseries. Default ‘fast’, which pads to the next fastest length.

  • to_removes (int) – Number of samples to remove at the beginning and end of the timeseries. Default None. Only used if X_fft_h is not None.

  • precision (str) – Either single for float32/complex64 or double for float/complex.

Returns

  • Xh (ndarray, complex) – Bandpassed analytic signal

  • X_fft_h (ndarray, complex) – Product of X_fft and heavyside.

  • cfs (ndarray) – Center frequencies used.

  • sds (ndarray) – Bandwidths used.