Issue with Assigning Values to Sub-Epochs in MNE Epochs Object

Dear MNE Experts,

I am working with an EpochsArray object that contains different event_id categories. However, I encountered an issue when trying to apply a z-score transformation to the data corresponding to each specific event_id. Below is a description of the problem:

Epoch Structure

<EpochsArray |  278 events (all good), -0.5 – 2 s, baseline off, ~32.0 MB, data loaded,
 '1': 34
 '2': 34
 '3': 36
 '4': 37
 '5': 33
 '6': 37
 '7': 33
 '8': 34>

Working Example

When applying a moving average transformation across all data in the EpochsArray, it works perfectly:

 for i_shape1 in range(epoch._data.shape[0]): 
        epoch._data[i_shape1,:,:] = JY_basic_func.moving_average(epoch._data[i_shape1,:,:] , np.ones(window) / window)

Problematic Code

However, when I attempt to apply a z-score transformation to each event_id subset using the following code, the data inside epoch[i_key]._data does not update:

for i_key in epoch.event_id.keys():
        if z_type =='channel':
            epoch[i_key]._data = zscore(epoch[i_key]._data,axis=1)

After running this, epoch[i_key]._data remains unchanged.

Question

Is there a convenient way to modify the data corresponding to each event_id within an EpochsArray structure? Any suggestions or guidance would be greatly appreciated.

System Information:

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

Thank you for your time and support!

Best regards,
Jianyang

Hello!

I believe indexing Epochs creates a copy, so you’re modifying a copy and immediately discarding it … I don’t know from the top of my head how you could solve this, but I suppose you could build something with the help of Epochs.apply_function() and take care of the different event types inside the function you call (you’d need to pass the events array for this).

Good luck,
Richard

1 Like

Get it. Now I have created a dictionary to store the z-score data. Thank you very much.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.