'AverageTFR' object has no attribute '_times_readonly'

MNE version: 1.3.1
operating system: macOS 12.0.1

I updated mne python to version 3.10.9. When I now try to simply print a previously saved AverageTFR object (named “power”) or try to modify it in either the time or frequency domain with e.g power.crop(fmin = 5, max = 12) I receive the following error:

‘AverageTFR’ object has no attribute ‘_times_readonly’

Before updating mne python I had no problem with this command. I am happy for any help or solution. Thanks in advance :slight_smile:

Hello @lucinda and welcome to the forum!

Something like this should not happen and I suspect it’s a bug we need to fix.

@drammock What’s your thought on this?

Best wishes,
Richard

it’s possible our reader is not backward compatible

can you share an old file?

A

looks like _times_readonly was added in [ENH, MRG] Add decimate to EpochsTFR object by alexrockhill · Pull Request #10940 · mne-tools/mne-python · GitHub by @alexrockhill. @alexrockhill do you have time to take a look at this one?

I can look later today

Hmmm I did the following with mne 1.0

import numpy as np
import mne
from mne.datasets import sample

data_path = sample.data_path()
raw_fname = data_path / 'MEG' / 'sample' / 'sample_audvis_raw.fif'
raw = mne.io.read_raw_fif(raw_fname)
events = mne.find_events(raw)
epochs = mne.Epochs(raw, events)
ave = mne.time_frequency.tfr_morlet(epochs.average(), [50], [5], return_itc=False)
ave.save('tmp-tfr.h5')

and then this with the current mne dev version it works just fine

ave2 = mne.time_frequency.read_tfrs('tmp-tfr.h5')[0]
ave2.crop(tmin=0)

It appears I’ll need more version information in order to properly diagnose what’s going on (i.e. which version were they made with and I assume 1.3.1 is what they were read in with).

EDIT: I also tried with 1.2.0 and dev and it also worked
EDIT2: 0.24 and 1.3.1 also worked

Hi, sorry for the late reply and thanks for your effort already.

I created it in mne version 0.24 (python 3.8.0) and then I try to read it with mne version 1.3.1(python 3.10.1) . When I rerun my script in mne version 1.3.1 and save it it works. I also did not save the AverageTFR object directly but appended it to a list and saved it with pickle, previously it worked like this. I can share a snipped of my code later today.

Thank you again :slight_smile:

ah if you used pickle to save your object there is not much we can do about it.

pickle is not a good format to keep your files between versions.

you should use what the .save methods of mne offer (ie. .fif, .h5 etc.)

so to me there is no bug on our side

Alex

1 Like

You should read back the pickle with the version of MNE that was used to create it; and then use our .save() methods to write the data to disk, like @agramfort suggested.

Best wishes,
Richard