Skip to content

Spectral decomposition and high gamma duplicate code and processing #108

@emilyps14

Description

@emilyps14
  1. processing_data.high_gamma_estimation recomputes the spectral decomposition bands, even if they have already been computed in processing_data.spectral_decomposition. It would be nice if the code would check to see if they have been run already, and use the precomputed bands if possible. If it is computing new bands, it would make sense to append these to the existing decomposition table (or make a new decomposition table?) to save the processing.

  2. The spectral decomposition code is copy and pasted between processing_data.spectral_decomposition and processing_data.high_gamma_estimation:

    nBands = len(band_param_0)
    nSamples = lfp.data.shape[0]
    nChannels = lfp.data.shape[1]
    Xp = np.zeros((nBands, nChannels, nSamples)) # power (nBands,nChannels,nSamples)
    # Apply Hilbert transform ---------------------------------------------
    print('Running Spectral Decomposition...')
    start = time.time()
    for ch in np.arange(nChannels):
    Xch = lfp.data[:, ch] * 1e6 # 1e6 scaling helps with numerical accuracy
    Xch = Xch.reshape(1, -1)
    Xch = Xch.astype('float32') # signal (nChannels,nSamples)
    X_fft_h = None
    for ii, (bp0, bp1) in enumerate(zip(band_param_0, band_param_1)):
    kernel = gaussian(Xch.shape[-1], rate, bp0, bp1)
    X_analytic, X_fft_h = hilbert_transform(Xch, rate, kernel, phase=None, X_fft_h=X_fft_h)
    Xp[ii, ch, :] = abs(X_analytic).astype('float32')
    print('Spectral Decomposition finished in {} seconds'.format(time.time() - start))
    # data: (ndarray) dims: num_times * num_channels * num_bands
    Xp = np.swapaxes(Xp, 0, 2)

    nBands = len(band_param_0)
    nSamples = lfp.data.shape[0]
    nChannels = lfp.data.shape[1]
    Xp = np.zeros((nBands, nChannels, nSamples)) # power (nBands,nChannels,nSamples)
    # Apply Hilbert transform ---------------------------------------------
    print('Running High Gamma estimation...')
    start = time.time()
    for ch in np.arange(nChannels):
    Xch = lfp.data[:, ch] * 1e6 # 1e6 scaling helps with numerical accuracy
    Xch = Xch.reshape(1, -1)
    Xch = Xch.astype('float32') # signal (nChannels,nSamples)
    X_fft_h = None
    for ii, (bp0, bp1) in enumerate(zip(band_param_0, band_param_1)):
    kernel = gaussian(Xch.shape[-1], rate, bp0, bp1)
    X_analytic, X_fft_h = hilbert_transform(
    Xch, rate, kernel, phase=None, X_fft_h=X_fft_h)
    Xp[ii, ch, :] = abs(X_analytic).astype('float32')
    print('High Gamma estimation finished in {} seconds'.format(time.time() - start))
    # data: (ndarray) dims: num_times * num_channels * num_bands
    Xp = np.swapaxes(Xp, 0, 2)

(I can look into writing a PR for this when I have some time)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions