Fix apply_function docstring for Epochs #13118#13136
Conversation
|
Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴 |
|
I've made the necessary changes, built the documentation successfully, and verified that the updates are rendering correctly. I've now submitted the pull request for review. Let me know if any further modifications are needed. Thanks! |
| docdict["fun_applyfun"] = applyfun_fun_base.format( | ||
| " if ``channel_wise=True`` and ``(len(picks), n_times)`` otherwise" | ||
| " if ``channel_wise=True`` then a 3D array of shape ``(n_epochs, len(picks), n_times)`` is passed, otherwise a 3D array of shape ``(n_epochs, n_channels, n_times)`` is passed" | ||
| ) |
There was a problem hiding this comment.
This isn't quite right, because this change will be reflected in the documentation for raw.apply_function and evoked.apply_function, but we don't want it to, since those data will never be 3D!
|
Thanks @Imama-Kainat for brining this to attention! Can you help me to better understand the issue, by providing a minimally working example (MWE) of a user-defined function that works with You can start with this: import mne
sample_fpath = mne.datasets.sample.data_path()
fpath = sample_fpath / "MEG" / "sample" / "sample_audvis_raw.fif"
raw = mne.io.read_raw(sample_fpath, preload=True).pick("eeg")
epochs = mne.make_fixed_length_epochs(raw, duration=1, preload=True)
def my_fun(x):
"""My function that works with epoch.apply_function(channel_wise=True)"""
returnIf docdict["fun_applyfun_epochs"] = applyfun_fun_base.format(
" if ``channel_wise=True`` and ``(n_epochs, n_channels, n_times)`` otherwise"
)And then use |
The fun parameter docstring for mne.Epochs.apply_function incorrectly stated that the array passed to the user's function when channel_wise=False has shape (len(picks), n_times). The actual shape is (n_epochs, n_channels, n_times). Adds a new fun_applyfun_epochs docdict entry alongside fun_applyfun_evoked and fun_applyfun_stc, leaving the Raw docstring (where (len(picks), n_times) is correct) untouched. Per scott-huberty's review suggestion on mne-tools#13136. Fixes mne-tools#13118
The current documentation for apply_function in mne.Epochs is misleading, as it does not accurately describe the shape of the epochs data (3D arrays). This can cause confusion about how the function processes the data across different dimensions.
This PR updates the relevant docstrings in mne/utils/docs.py to clearly state how apply_function operates on the epochs data, ensuring users understand the function's behavior when applied to multi-dimensional data structures. The updated documentation improves clarity and consistency with other MNE functions.