DiGyt / asrpy

Artifact Subspace Reconstruction for Python
BSD 3-Clause "New" or "Revised" License
41 stars 14 forks source link

block_covariance(X, window=blocksize) function reshape has an error. #10

Closed JLULijh closed 6 months ago

JLULijh commented 6 months ago

Hello, I greatly appreciate your code. I encountered the following error with some local EEG files while using your code, which might be related to block_covariance(X, window=blocksize). I'm not sure if you have experienced this issue during your usage. Thank you very much for your time and assistance. Below is the error message:

`

ValueError Traceback (most recent call last) Cell In[109], line 1 ----> 1 asr.fit(raw)

File F:\anaconda\lib\site-packages\asrpy\asr.py:233, in ASR.fit(self, raw, picks, start, stop, return_clean_window) 223 clean, sample_mask = clean_windows( 224 X, 225 sfreq=self.sfreq, (...) 229 min_clean_fraction=self.min_clean_fraction, 230 max_dropout_fraction=self.max_dropout_fraction) 232 # Perform calibration --> 233 self.M, self.T = asr_calibrate( 234 clean, 235 sfreq=self.sfreq, 236 cutoff=self.cutoff, 237 blocksize=self.blocksize, 238 win_len=self.win_len, 239 win_overlap=self.win_overlap, 240 max_dropout_fraction=self.max_dropout_fraction, 241 min_clean_fraction=self.min_clean_fraction, 242 ab=(self.A, self.B), 243 method=self.method) 245 self._fitted = True 247 # return data if required

File F:\anaconda\lib\site-packages\asrpy\asr.py:431, in asr_calibrate(X, sfreq, cutoff, blocksize, win_len, win_overlap, max_dropout_fraction, min_clean_fraction, ab, method) 428 N = int(np.round(win_len sfreq)) 430 # get block covariances --> 431 U = block_covariance(X, window=blocksize) 433 # get geometric median for each block 434 # Note: riemann mode is not yet supported, else this could be: 435 # Uavg = pyriemann.utils.mean_covariance(U, metric='riemann') 436 Uavg = geometric_median(U.reshape((-1, nc nc)) / blocksize)

File F:\anaconda\lib\site-packages\asrpy\asr_utils.py:509, in block_covariance(data, window) 506 for k in range(0, window): 507 idx_range = np.minimum(n_times - 1, 508 np.arange(k, n_times + k - 2, window)) --> 509 U = U + np.reshape(data[idx_range].reshape([-1, 1, n_ch]) * 510 data[idx_range].reshape(-1, n_ch, 1), U.shape) 512 return np.array(U)

File <__array_function__ internals>:180, in reshape(*args, **kwargs)

File F:\anaconda\lib\site-packages\numpy\core\fromnumeric.py:298, in reshape(a, newshape, order) 198 @array_function_dispatch(_reshape_dispatcher) 199 def reshape(a, newshape, order='C'): 200 """ 201 Gives a new shape to an array without changing its data. 202 (...) 296 [5, 6]]) 297 """ --> 298 return _wrapfunc(a, 'reshape', newshape, order=order)

File F:\anaconda\lib\site-packages\numpy\core\fromnumeric.py:57, in _wrapfunc(obj, method, *args, kwds) 54 return _wrapit(obj, method, *args, *kwds) 56 try: ---> 57 return bound(args, kwds) 58 except TypeError: 59 # A TypeError occurs if the object does have such a method in its 60 # class, but its signature is not identical to that of NumPy's. This (...) 64 # Call _wrapit from within the except clause to ensure a potential 65 # exception has a traceback chain. 66 return _wrapit(obj, method, *args, **kwds)

ValueError: cannot reshape array of size 10820304 into shape (75142,144) `

aliosia commented 5 months ago

I cropped the raw data to have integer seconds and it works: raw.crop(tmin=0, tmax=int(raw.times[-1]))