Skip to content

Proj id and proj name access #13261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

LaurentLM
Copy link

Reference issue

Fixes #13252.

What does this implement/fix?

Allows user to set proj_idand proj_name through direct dict access.
Ensures that proj_id is either an integer or None.
Ensures that proj_name is either a string or None.

Additional information

Example:


import mne
info = mne.create_info(
    ch_names=['EEG 001', 'EEG 002'],
    sfreq=1000,
    ch_types='eeg',
)

info['proj_name'] = None
info['proj_name'] = 123 #TypeError: 123 is not a string
info['proj_name'] = 'test' 

info['proj_id'] = None
info['proj_id'] = 123
info['proj_id'] = '123' #TypeError: '123' is not an int

Copy link

welcome bot commented May 23, 2025

Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴

@larsoner
Copy link
Member

This looks like it's headed in the right direction!

If you look at one CI failure, you'll see:

________________ ERROR collecting mne/stats/tests/test_erp.py _________________
mne\stats\tests\test_erp.py:14: in <module>
    raw = read_raw_fif(base_dir / "test_raw.fif")
mne\io\fiff\raw.py:543: in read_raw_fif
    return Raw(
<decorator-gen-364>:12: in __init__
    ???
mne\io\fiff\raw.py:103: in __init__
    raw, next_fname, buffer_size_sec = self._read_raw_file(
<decorator-gen-365>:12: in _read_raw_file
    ???
mne\io\fiff\raw.py:209: in _read_raw_file
    info, meas = read_meas_info(fid, tree, clean_bads=True)
<decorator-gen-31>:12: in read_meas_info
    ???
mne\_fiff\meas_info.py:2540: in read_meas_info
    info["proj_id"] = proj_id
mne\_fiff\meas_info.py:960: in __setitem__
    val = self._attributes[key](
mne\_fiff\meas_info.py:1008: in _check_types
    _validate_type(x, types, name)
mne\utils\check.py:640: in _validate_type
    raise TypeError(
E   TypeError: proj_id must be an instance of int or None, got <class 'numpy.ndarray'> instead.

I would suggest to modify mne\_fiff\meas_info.py:2540: in read_meas_info to have a .item() to get it to be a float rather than an ndarray with one element.

Any new change would ideally include some changed test, could you modify mne/_fiff/tests/test_meas_info.py somewhere to make sure you can set these two new values? And maybe even a couple with pytest.raises(TypeError, match="...") that you can't set them to something of the wrong type?

Finally, we'll need a doc/changes/devel/13261.newfeature.rst that mentions the ability to set these values. In there you should use the :newcontrib: directive with your name and add a link to doc/changes/names.inc as well.

@LaurentLM
Copy link
Author

Hi @larsoner,

Thanks for your guidance, I'm very new to this.

Still a bit confused as to why the test failed. proj_id should be either an int or None. It makes sense to me that an error is returned if someone tries to set proj_id with a numpy.ndarray.
Having said that, I made the change you suggested and it seems to work fine.

I have added tests and contribution information, hopefully it's all in the right place and the right format. Let me know if not :-)

@LaurentLM
Copy link
Author

LaurentLM commented May 25, 2025

I think I am a bit stuck with this. I fail to understand why info["proj_id"] is converted into an ndarray here:

info["proj_id"] = np.zeros_like(info["proj_id"])

It would make more sense to me to set it as 0 (as an integer), the same way as subject_info["id"] is anonymized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fields proj_id, proj_name
2 participants