DiGyt / asrpy

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

Attribute error in asr_calibrate() #2

Closed sunshineinsandiego closed 11 months ago

sunshineinsandiego commented 2 years ago

Hi there - Thanks again for your directions previously re: running asr_calibrate() on numpy arrays. I tried testing this on a slice of EEG data and am receiving the following error:

Geometric median could converge in 500 iterations with a tolerance of 1e-05
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/bg/b08l9ly13yb_4hsjwlrvx0dm0000gn/T/ipykernel_5374/3832493090.py in <module>
      5 # calibrate
      6 calibration_data = bandpassed_eeg_data[:, start_calibration: end_calibration]
----> 7 M, T = asr_calibrate(X = calibration_data, sfreq = baseline_eeg_srate, cutoff = asr_cutoff, method = 'euclidean')
      8 
      9 # clean

~/Documents/EEGHRV/asr.py in asr_calibrate(X, sfreq, cutoff, blocksize, win_len, win_overlap, max_dropout_fraction, min_clean_fraction, ab, method)
    431     # Uavg = pyriemann.utils.mean_covariance(U, metric='riemann')
    432     Uavg = geometric_median(U.reshape((-1, nc * nc)) / blocksize)
--> 433     Uavg = Uavg.reshape((nc, nc))
    434 
    435     # get the mixing matrix M

AttributeError: 'NoneType' object has no attribute 'reshape'

My guess is that the script output: "Geometric median could converge" actually means the geometric median could "not" converge.

When I run the helper functions in asr_utils.py individually for the calibration data:

U = block_covariance(calibration_data)
print(U.shape)
U = U.reshape((-1, 19 * 19))
print(U.shape)
temp = geometric_median(U)

It seems that the geometric_median() function is returning 'None' because of failure to converge.

Any thoughts on how to fix this? I see in the asr_calibrate() documentation that it expects a "zero-mean array". Does this mean that each channel should be zero-mean'd? Thanks!