Difficulty Indexing EpochsTFR Object with Boolean Mask

Dear MNE-Python Community,

I am currently working with an EpochsTFR object and encountering challenges when attempting to select specific epochs using a boolean mask. Below are the details of my setup and the issue:

  • MNE Version: 1.9.0
  • Operating System: Ubuntu 20.04

Code Snippet:

import numpy as np
import mne

# Assuming 'power_epochs' is an existing EpochsTFR object
valid_idx = [
    False, True, False, True, False, True, False, True,
    False, False, True, False, False, True, True, False,
    True, True, False, True, True, False, True, True,
    True, True, True, True, True, False
]

# Attempting to select epochs using the boolean mask
matching_epochs = power_epochs[valid_idx]

Issue:

When executing the above code, I encounter the following error:

IndexError: list assignment index out of range

Observations:

  • The length of valid_idx matches the number of epochs in power_epochs.
  • Using integer indices instead of a boolean mask does not resolve the issue.
  • Accessing power_epochs.selection[valid_idx] returns the expected array of selected indices.

Request:

I am seeking guidance on the correct method to index or select specific epochs from an EpochsTFR object using a boolean mask or an alternative approach. Any insights or suggestions to resolve this issue would be greatly appreciated.

Thank you for your assistance.

Best regards,

Hironobu Nakamura

Hello,

Could you please share some more info from the error traceback? Does it happen to look like this?

If so, this is a bug that was recently fixed and is available in the development version of MNE. If you don’t want to use the development version, a workaround is to initialise the drop log in the EpochsTFRArray object as drop_log=tuple([() for _ in range(n_epochs)]) instead of the default None.

If it’s not the same error, would you be able to share the EpochsTFR object you are having issues with and we can look into it.

Best,
Thomas

Dear Thomas,

Thank you for your prompt response.

The error message I encountered is indeed identical to the one you described. Therefore, I plan to try the MNE development version to see if it resolves the issue.

For your reference, here is the basic information of the EpochsTFR object I’m working with:

  • Type: <class 'mne.time_frequency.tfr.EpochsTFR'>
  • Data shape: (30, 66, 30, 1501) (epochs, channels, frequencies, time points)
  • Number of epochs: 30
  • Number of channels: 66
  • Number of frequencies: 30
  • Number of time points: 1501
  • Time range: 7.0 to 10.0 seconds
  • Frequency range: 2.0 to 200.0 Hz
  • Channels: [‘eega1-ref’, ‘eega2-ref’, ‘pola4-pola3’, ‘pola5-pola4’, ‘pola6-pola5’, ‘pola3-pola6’, ‘pola8-pola7’, ‘pola9-pola8’, ‘pola10-pola9’, ‘pola11-pola10’, ‘pola12-pola11’, ‘pola13-pola12’, ‘pola14-pola13’, ‘pola15-pola14’, ‘pola16-pola15’, ‘pola17-pola16’, ‘pola18-pola17’, ‘pola7-pola18’, ‘pola20-pola19’, ‘pola21-pola20’, ‘pola22-pola21’, ‘pola23-pola22’, ‘pola24-pola23’, ‘pola19-pola24’, ‘pola26-pola25’, ‘pola27-pola26’, ‘pola28-pola27’, ‘pola29-pola28’, ‘pola30-pola29’, ‘pola25-pola30’, ‘pola32-pola31’, ‘pola33-pola32’, ‘pola34-pola33’, ‘pola35-pola34’, ‘pola36-pola35’, ‘pola31-pola36’, ‘pola38-pola37’, ‘pola39-pola38’, ‘pola40-pola39’, ‘pola41-pola40’, ‘pola42-pola41’, ‘pola37-pola42’, ‘pola44-pola43’, ‘pola45-pola44’, ‘pola46-pola45’, ‘pola47-pola46’, ‘pola48-pola47’, ‘pola43-pola48’, ‘pola50-pola49’, ‘pola51-pola50’, ‘pola52-pola51’, ‘pola53-pola52’, ‘pola54-pola53’, ‘pola55-pola54’, ‘pola56-pola55’, ‘pola57-pola56’, ‘pola58-pola57’, ‘pola59-pola58’, ‘pola60-pola59’, ‘pola49-pola60’, ‘polb2-polb1’, ‘polb3-polb2’, ‘polb4-polb3’, ‘polb5-polb4’, ‘polb6-polb5’, ‘polb1-polb6’]
  • Channel types: [‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’]
  • Metadata columns: Index([‘time’, ‘cue’, ‘valence’, ‘vividness’, ‘valence_RT’, ‘vividness_RT’], dtype=‘object’)

I hope this information is helpful. Thank you again for your assistance.

Best regards,

Hironobu Nakamura

1 Like

In theory using a list of indices should work.

Depending on what you need to do afterward a workaround could be to use the .get_data() method to keep the data as a numpy array. Then you could work directly on that or create an EpochsTFRArray object.

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