No feature to save an MNE.decoding.SSD/SPoC object?

  • MNE version: 1.9.0
  • operating system: Ubuntu 24.04.2

Is there a way to save an MNE.decoding.SSD or an MNE.decoding.SPoC object?
For example, it exists for MNE.preprocessing.ICA (save() method).
It would be very practical and avoid rerunning SSD and then SPoC each time!

It is possible to save/read these objects as pickle files (see below for an example).

I agree though that having some native save (and read) functionality could be helpful. What do you think @drammock?

import pickle
import mne

ssd = mne.decoding.SSD(...)

# Saving
with open("my\\file\\path", "wb") as file:
    pickle.dump(ssd, file)

# Reading
with open("my\\file\\path", "rb") as file:
    ssd = pickle.load(file)
1 Like

With the caveat that I’m answering from a phone so I haven’t reviewed the implementation of SPoC/SSD, I think it ought to be fairly straightforward to add this, preferably using __setstate__ and __getstate__ like we do for e.g. spectrum objects or TFRs. The fact that pickling already works suggests it should be straightforward.

3 Likes

I opened this issue as a reminder.

@emile Is this something you would be interested in submitting a PR for? If not I could try to work on this in the coming weeks. The pickling workaround can be used meanwhile.

Yes I’d be interested, I can do that.
Where do I submit the Pull Request?

pull requests should go against the main MNE-Python repository: GitHub - mne-tools/mne-python: MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python

The change would go in mne/decoding/ssd.py and mne/decoding/csp.py; you can use __getstate__ and __setstate__ definitions from mne/time_frequency/tfr.py (mne/label.py also has examples) as inspiration. Will need to add or update some tests too, to make sure the save/load round-trip preserves all the relevant information.

2 Likes