Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spectral decomposition and high gamma duplicate code and processing #108

Open
emilyps14 opened this issue Jul 7, 2020 · 0 comments
Open

Comments

@emilyps14
Copy link
Contributor

  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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant