How change (update) info items?

  • MNE version: e.g. 0.24.0
  • operating system: Windows 10

Dear Sr,

I dont want to create a new raw.info. I want to update some info from file without destroying the rest.

Problem: mne.Info quote:
" This class should not be instantiated directly. To create a measurement information structure, use mne.create_info()."

can’t I just:

raw.info[‘description’] = ‘My custom dataset’
?

Besides
how to update multiple fields in subject_info:

Last name.
First name.
Middle name.
Birthday in (year, month, day) format.
Subject sex (0=unknown, 1=male, 2=female).
Handedness (1=right, 2=left, 3=ambidextrous).

Is it something like
raw.create_info(“Last name” = Kanda)
?

One last question: how long can be the text in cases as →
Pages.EEG_raw.info[‘description’] = “a small string the size of a book…”

Could you show me a code example. I couldn’t find any.

Thanks in advance.

Paulo Kanda

Did you read the rest of the mne.Info docstring? It says, among other things:

The only entries that should be manually changed by the user are info['bads'], info['description'], info['device_info'], info['dev_head_t'], info['experimenter'], info['helium_info'], info['line_freq'], info['temp'] and info['subject_info']. All other entries should be considered read-only, though they can be modified by various MNE-Python functions or methods (which have safeguards to ensure all fields remain in sync).

So you can certainly do things like raw.info['description'] = 'whatever'. I don’t know if the length of the string is limited; we don’t limit it in our code but it might be constrained by the .fif file format when saving the info, or when saving a data object with that info attached to it. @larsoner probably knows that answer.

subject_info is also in the above list of entries that may be changed by the user. So raw.info['subject_info'] = some_dict is fine, as is raw.info['subject_info'].update(last_name='Kanda', first_name='Paolo', ...)

To further clarify: what this means

is that you should not do my_new_info = mne.Info(...) (that would be “direct class instantiation”) but instead you should do my_new_info = mne.create_info(...) (using our function to create an instance of the Info class). The function is preferred because it has lots of built-in safety checks to make sure your Info object is consistent / has everything it needs to work properly with our data classes like Raw, Epochs, etc. But both of these possibilities apply when you want a new Info object, not when you want to update fields in an existing Info object. For that, see my prior answer above.

AFAIK there isn’t any real limit on the str size. I think in practice you’re going to hit problems as you get close to 2GB, but hopefully your info['description'] doesn’t get close to this :slight_smile:

Did you read the rest of the mne.Info docstring? It says, among other things…

Yes, I read that. My doubt was about having to update all the dic.

All that info was enlightening!!

Thank you again.

Just in case it can help anyone else:

    Pages.EEG_raw.info['subject_info'] = {"last_name":"Kanda",
                                          "first_name":"Paolo",
                                          "middle_name":"Medeiros",
                                           "birthday":(1971,9,10),
                                           "sex":1,
                                           "hand":1}
    print(Pages.EEG_raw.info['subject_info'])

{‘last_name’: ‘Kanda’, ‘first_name’: ‘Paolo’, ‘middle_name’: ‘Medeiros’, ‘birthday’: (1971, 9, 10), ‘sex’: 1, ‘hand’: 1}

and to get info back:

    print(Pages.EEG_raw.info['subject_info']['last_name'])

kanda