fooof icon indicating copy to clipboard operation
fooof copied to clipboard

Python Error: TypeError: 'NoneType' object is not iterable

Open 4srihy opened this issue 3 years ago • 2 comments

While working in matlab, for some data, I am getting 'Python Error: TypeError: 'NoneType' object is not iterable' with the aperiodic_mode = 'knee'. This issue is sometimes specific to certain frequency range. How to resolve it? Code stops running when this error is thrown. Can we give any condition in matlab, so that code continues to run even after the error?

I have attaching the sample data of matlab NoneTypeError.zip

4srihy avatar Jul 13 '22 06:07 4srihy

Hey @4srihy - I don't use Matlab, so I can't rerun the file you provided, and I can't see the trace of the error you mention. Can you write a copy of the command you are using the run fooof, and a screenshot of the error?

TomDonoghue avatar Jul 13 '22 12:07 TomDonoghue

Dear Donogue,

Here is the command

fooof_ind = fooof(freqVals,SpecPower(1,:)',freq_range,settings,true);

Please note that the same command gives error for first series but works fine for second series. Screenshot (84)

When I load the file with python and then run the following commands, it works there.

import numpy as np from scipy.io import loadmat, savemat

from fooof import FOOOFGroup

Load the mat file

data = loadmat('abc.mat')

Unpack data from dictionary, and squeeze numpy arrays

freqs = np.squeeze(data['freqVals']).astype('double') psds = np.squeeze(data['SpecPower']).astype('double')

fg = FOOOF(peak_width_limits=[4, 8], max_n_peaks=5, aperiodic_mode='knee')

Fit the FOOOF model on all PSDs, and report

fg.fit(freqs, psds[1,:], [20, 44])

4srihy avatar Jul 23 '22 11:07 4srihy

Hey @4srihy - sorry for dropping off / slow reply here.

Since this relates to Matlab, and the Matlab wrapper, then this issue would be better placed over on the fooof_mat repo: https://github.com/fooof-tools/fooof_mat/

On the fooof_mat issues page (https://github.com/fooof-tools/fooof_mat/issues) there is quite a lot of discussion of how to address issues with using FOOOF in Matlab. I think, for example, that your error might relate to this issue: https://github.com/fooof-tools/fooof_mat/issues/18

Basically, when the model fails to fit (as happens in that particular example), the Matlab wrapper fails. That's an issue with the Matlab wrapper. In general, model failing is pretty uncommon, and you should be able to avoid this by tweaking the settings. If you are getting models that fail, you should be able to just ignore these models and continue.

Since this issue is about fooof_mat, I'm going to close this issue here - but feel free to add any comments, and/or re-open this issue over on fooof_mat if you want to follow up / have more questions!

TomDonoghue avatar Jun 29 '23 20:06 TomDonoghue