fooof-tools / fooof

Parameterizing neural power spectra into periodic & aperiodic components.
https://fooof-tools.github.io/
Apache License 2.0
358 stars 97 forks source link

get_params not working due to inhomogeneities in FOOOFGroup #313

Closed maschpall closed 6 months ago

maschpall commented 7 months ago

I am using version 1.0.0 and when fitting with FOOOFGroup, when using fg.get_params('peak_params') I get an error:

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (1165,) + inhomogeneous part.

It appears to have an issue if each PSD has a different number of peaks. I have checked all tutorials and examples and having a variable number of fitted peaks should not be a problem, so any help in that matter would be really helpfull.

Thanks!

Camilo-Castelblanco commented 7 months ago

I am experiencing the same issue! First, I tried using my data, and that yielded the error. Then, using the example code and data, I observed the same issue. The aperiodic and goodness of fit are estimated with my data, but the peak centers are not.

image

Thank you!

Full Error:

image
TomDonoghue commented 7 months ago

@maschpall and/or @Camilo-Castelblanco - could you check what version of fooof and numpy you are running, and let me know? I have a feeling this is a change in how numpy handles certain arrays, and you will likely have to update fooof and/or downgrade numpy to avoid this error. If you are not already on fooof 1.1, try updating to that - I have a feeling I fixed this at some point, though I don't remember / can't quickly find exactly when / where.

maschpall commented 7 months ago

Hi @TomDonoghue and thanks for the answer! I did try with both fooof 1.0 and 1.1.0 and had the same result. The version of numpy I am using is 1.24.4

TomDonoghue commented 7 months ago

@maschpall - ahh, okay, it's still an issue up until 1.1, I'll have to check if I changed anything relevant in the development version, and/or if it's still an issue everywhere, and then see what I can do to update and fix, and backport this is fix to 1.1.

In the meantime, from some quick checks, I think this changed in numpy as of 1.24 (which you are on), so I believe if you drop your numpy version to be prior to 1.24 (so <= 1.23), I think this should work. This should be the quickest way to get things moving (and unless you need anything in particular from the newest numpy for other stuff, shouldn't change things otherwise), so this should get things up and running until it gets fixed more generally.

TomDonoghue commented 7 months ago

Also, @maschpall - do you have a minimal example of some data that leads to this problem for you? I'm not immediately replicating this error with newer numpy - so I'm not sure if there is some particular details of the pattern(s) of peaks across models that leads to this issue

maschpall commented 7 months ago

I double checked and it seems I did not update correctly to 1.1. Now when I redid it, it works correctly! I'm sorry for the inconvenience and thanks a lot for your time and help!

TomDonoghue commented 7 months ago

@maschpall - no worries, that's actually great news, as it means this is already fixed hahaha! It sounded familiar - I must not have looked far back enough to find the change for this - I'll keep a note on this so that we can have a clearer recommendation for addressing this, as more people might encounter it if they update numpy without also updating fooof.

@Camilo-Castelblanco - if you see this, could you also check and confirm that everything works if you update to fooof v1.1? If so, we should be all good on this!

Camilo-Castelblanco commented 7 months ago

Thank you for the info! Indeed, I have fooof 1.0.0. Probably, I am making a silly mistake when trying to upload fooof. I tried following the website and also conda install fooof=1.1.0 (from the link). However, it is not updating for me. I will keep working on this. I appreciate your help!

TomDonoghue commented 7 months ago

hey @Camilo-Castelblanco - I just realized version 1.1 doesn't seem to have been updated on conda-forge yet, so you won't be able to update through conda just yet - i've opened an issue at #315 to get check in on getting this updated, so hopefully this will be fixed soon.

In the meantime, you should still be able to update using pip (in your conda environment) if you want to try that.

TomDonoghue commented 6 months ago

As far as I can tell - everything here is fixed in the 1.1 release, so I'm going to close this now!

For anyone finding this issue - if you see a similar error on 1.0, try updating to 1.1! If that doesn't fix it, please add a comment and/or add a new issue!