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

Merged
merged 34 commits into from
Jun 25, 2025

Conversation

LaurentLM
Copy link
Contributor

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
Contributor 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
Contributor 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.

@larsoner
Copy link
Member

larsoner commented Jun 2, 2025

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

Agreed, I think you can make this change

@LaurentLM LaurentLM requested a review from larsoner June 20, 2025 15:14
Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me, marking for merge when green, thanks in advance @LaurentLM !

@larsoner larsoner enabled auto-merge (squash) June 23, 2025 16:37
@larsoner larsoner merged commit 99275fa into mne-tools:main Jun 25, 2025
32 checks passed
Copy link

welcome bot commented Jun 25, 2025

🎉 Congrats on merging your first pull request! 🥳 Looking forward to seeing more from you in the future! 💪

larsoner added a commit to larsoner/mne-python that referenced this pull request Jun 26, 2025
* upstream/main: (55 commits)
  doc: fix rendering typo rst docstr (mne-tools#13301)
  DOC: fix docstrs around layout functions (mne-tools#13300)
  MAINT: Fix doc build failure due to deprecation (mne-tools#13299)
  Birthday input cast to datetime.date (mne-tools#13284)
  DOC: fix missing space, use f-strings, structure->object (mne-tools#13291)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13290)
  ENH: channel_indices_by_type now has an exclude param (mne-tools#13293)
  Proj id and proj name access (mne-tools#13261)
  Fix: nearly invisible traces with spatial_colors=True (mne-tools#13286)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13283)
  Bump autofix-ci/action from 551dded8c6cc8a1054039c8bc0b8b48c51dfc6ef to 635ffb0c9798bd160680f18fd73371e355b85f27 in the actions group (mne-tools#13282)
  fix Maxwell bads filtering (mne-tools#13280)
  fix actionable linkcheck errors (mne-tools#13273)
  MAINT: Use radius keyword with PyVista tube (mne-tools#13277)
  BUG: Fix bug with simulating head pos and BEM (mne-tools#13276)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13274)
  MAINT: Update code credit (mne-tools#13267)
  Annotations extras (mne-tools#13228)
  Tidy up the directory reading (mne-tools#13268)
  FIX, DOC: Drop bad channel in 10_publication_figure.py (mne-tools#13266)
  ...
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
3 participants