coganlab / IEEG_Pipelines

A repo of current preprocessing methods for the Cogan Lab
https://ieeg-pipelines.readthedocs.io/en/latest/
MIT License
4 stars 2 forks source link

wavelet_scaleogram ifft shape errors #86

Closed jimzhang629 closed 9 months ago

jimzhang629 commented 1 year ago

CODE:

import mne.time_frequency
import mne
from ieeg.io import get_data, raw_from_layout
from ieeg.navigate import trial_ieeg, channel_outlier_marker, crop_empty_data, outliers_to_nan
from ieeg.calc.scaling import rescale
import os
from ieeg.timefreq.utils import wavelet_scaleogram, crop_pad
import numpy as np

from misc_functions import calculate_RTs

HOME = os.path.expanduser("~")

# get box directory depending on OS
if os.name == 'nt': # windows
    LAB_root = os.path.join(HOME, "Box", "CoganLab")
else: # mac
    LAB_root = os.path.join(HOME, "Library", "CloudStorage", "Box-Box", "CoganLab")

layout = get_data("GlobalLocal", root=LAB_root)

layout = get_data("GlobalLocal", root=LAB_root)
subjects = layout.get(return_type="id", target="subject")

print(subjects)
# for sub in subjects:

sub='D0057' #why does this not work in the for loop???
# Load the data
filt = raw_from_layout(layout.derivatives['derivatives/clean'], subject=sub,
                        extension='.edf', desc='clean', preload=False) #get line-noise filtered data
print(filt)

## Crop raw data to minimize processing time
good = crop_empty_data(filt)

# good.drop_channels(good.info['bads'])
good.info['bads'] = channel_outlier_marker(good, 3, 2)
good.drop_channels(good.info['bads'])
# good.info['bads'] += channel_outlier_marker(good, 4, 2)
# good.drop_channels(good.info['bads'])
good.load_data()

ch_type = filt.get_channel_types(only_data_chs=True)[0]
good.set_eeg_reference(ref_channels="average", ch_type=ch_type)

# Remove intermediates from mem
good.plot()

## epoching and trial outlier removal

save_dir = os.path.join(layout.root, 'derivatives', 'spec', 'wavelet', sub)
if not os.path.exists(save_dir):
        os.makedirs(save_dir)

RTs, skipped = calculate_RTs(good)
avg_RT = np.median(RTs)
print(avg_RT)
# make stimulus baseline EpochsTFR
times=[-1.5, avg_RT+1.3+0.5] #this is for 0.5 sec of padding on each side
print("times: " + str(times))
trials = trial_ieeg(good, "Stimulus", times, preload=True)

# print("base trials shape is: " + str(trials._data.shape))
outliers_to_nan(trials, outliers=10)
base = wavelet_scaleogram(trials, n_jobs=-2, decim=int(good.info['sfreq'] / 100))

ERROR:


_RemoteTraceback                          Traceback (most recent call last)
_RemoteTraceback: 
"""
Traceback (most recent call last):
  File "c:\Users\jz421\AppData\Local\anaconda3\envs\ieeg\Lib\site-packages\joblib\_parallel_backends.py", line 272, in _wrap_func_call
    return func()
           ^^^^^^
  File "c:\Users\jz421\AppData\Local\anaconda3\envs\ieeg\Lib\site-packages\joblib\parallel.py", line 580, in __call__
    return [func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\jz421\AppData\Local\anaconda3\envs\ieeg\Lib\site-packages\joblib\parallel.py", line 580, in 
    return [func(*args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users/jz421/Desktop/GlobalLocal/IEEG_Pipelines\ieeg\timefreq\utils.py", line 179, in _ifft_abs
    np.abs(np.fft.ifft(x * np.tile(daughter, (
                       ^^^^^^^^^^^^^^^^^^^^^^^
ValueError: operands could not be broadcast together with shapes (448,1,8942) (448,46,8943) 
"""

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
Cell In[3], line 10
      8 # print("base trials shape is: " + str(trials._data.shape))
...
--> 745         raise self._result
    746     return self._result
    747 finally:

ValueError: operands could not be broadcast together with shapes (448,1,8942) (448,46,8943)