mne-tools / mne-connectivity

Connectivity algorithms that leverage the MNE-Python API.
https://mne.tools/mne-connectivity/dev/index.html
BSD 3-Clause "New" or "Revised" License
68 stars 34 forks source link

[MAINT] Add logic for handling AverageTFRArray in old MNE versions #185

Closed tsbinns closed 4 months ago

tsbinns commented 4 months ago

Problem

Since MNE-Python v1.7 the API of time_frequency.AverageTFR has been changed. The old API from <= v1.6 is now available in the new class time_frequency.AverageTFRArray.

The example cwt_sensor_connectivity.py uses AverageTFR with the old API, causing documentation building to fail when using MNE-Python >= v1.7.

Solution

One possibility is to check whether the new class AverageTFRArray is available and import this (for >= v1.7), otherwise use the old AverageTFR (for v <= 1.6):

https://github.com/mne-tools/mne-connectivity/blob/397d6d737a09ee976f8814c7ad90ded1ea9c8609/examples/cwt_sensor_connectivity.py#L19-L28

Also necessary to explicitly set the nave parameter, as the new AverageTFRArray does not support this as a positional argument:

https://github.com/mne-tools/mne-connectivity/blob/397d6d737a09ee976f8814c7ad90ded1ea9c8609/examples/cwt_sensor_connectivity.py#L100

Very open to other ideas for implementing such a logic. Cheers!

tsbinns commented 4 months ago

Again some strange MacOS-specific runtime errors for code not touched by this PR like in #184.

tsbinns commented 4 months ago

Unrelated spelling mistake just now being caught with updated codespell version addressed in #186.

larsoner commented 4 months ago

Looks like comments have been address so I'll mark for merge-when-green, thanks @tsbinns !