Info does not support directly setting the key 'gdf_events'.

error: Info does not support directly setting the key ‘gdf_events’.
MNE version: 1.1.0
operating system: Windows 10

code:

class BCICompetition4Set2A(object):
    def __init__(self, filename, load_sensor_names=None, labels_filename=None):
        assert load_sensor_names is None
        self.__dict__.update(locals())
        del self.self

    def load(self):
        cnt = self.extract_data()
        events, artifact_trial_mask = self.extract_events(cnt)
        cnt.info["events"] = events
        cnt.info["artifact_trial_mask"] = artifact_trial_mask
        return cnt

    def extract_data(self):
        raw_gdf = mne.io.read_raw_gdf(self.filename, stim_channel="auto")
        raw_gdf.load_data()

        data = raw_gdf.get_data()

        for i_chan in range(data.shape[0]):
            this_chan = data[i_chan]
            data[i_chan] = np.where(
                this_chan == np.min(this_chan), np.nan, this_chan
            )
            mask = np.isnan(data[i_chan])
            chan_mean = np.nanmean(data[i_chan])
            data[i_chan, mask] = chan_mean

        gdf_events = mne.events_from_annotations(raw_gdf)
        raw_gdf = mne.io.RawArray(data, raw_gdf.info, verbose="WARNING")
        raw_gdf.info["gdf_events"] = gdf_events
        return raw_gdf

run code ,error:
RuntimeError: Info does not support directly setting the key ‘gdf_events’. You can set info[‘temp’] to store temporary objects in an Info instance, but these will not survive an I/O round-trip.

I want to put multiple values in ‘info’(‘events’ and ‘artifact_trial_mask’), but can only use ‘temp’. What should I do?

Hello,

The Info object is restricted and the key 'gdf_events' is not among the expected values.
You can use the key 'temp' to store whatever you want, but it will not survive the I/O roundtrip, meaning that if you save an object with this Info and load it back, any information in the key 'temp' will be lost.

raw_gdf.info["temp"] = gdf_events

Mathieu

1 Like

Thanks for your reply. Due to the need for multiple values, I cannot use temp, because it can only be used once. Is there any other method? I think it’s the version number of mne.

It was restricted in version 1.0 or 1.1, but it was restricted for a reason. I do not suggest to go around that. On the contrary, I would suggest to use the latest version of MNE-Python as many improvements and bugfixes are continuously added.

Other methods are:

  • Don’t store additional metadata in inst.info but in separate variables
  • Use a dictionary
raw_gdf.info["temp"] = dict()
raw_gdf.info["temp"]["gdf_events"] = gdf_events

Thank you. This has solved my problem successfully

hello,could you tell me how do you solved this problem? I aslo meet it.
thanks!

Please see the accepted answer above. You should use the info["temp"] variable.

Mathieu

1 Like