mne-python icon indicating copy to clipboard operation
mne-python copied to clipboard

Fix apply_function docstring for Epochs #13118

Open Imama-Kainat opened this issue 9 months ago • 3 comments

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.

Imama-Kainat avatar Mar 01 '25 10:03 Imama-Kainat

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

welcome[bot] avatar Mar 01 '25 10:03 welcome[bot]

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!

Imama-Kainat avatar Mar 01 '25 10:03 Imama-Kainat

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 epochs.apply_function(channel_wise=True) but fails with epochs.apply_function(channel_wise=False)?

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)"""
   return

If epoch.apply_function(channel_wise=False) requires the user to pass a 3D array, then I think we'll likely want to add another doc_dict entry like the one below, here

docdict["fun_applyfun_epochs"] = applyfun_fun_base.format(
    " if ``channel_wise=True`` and ``(n_epochs, n_channels, n_times)`` otherwise"
)

And then use %fun_applyfun_epochs here

scott-huberty avatar Mar 10 '25 20:03 scott-huberty