Subtract (combine) EvokedArrays

I have two EvokedArray objects and would like to subtract them. However, it seems like mne.combine_evoked() only works with Evoked objects:

TypeError: unsupported operand type(s) for -: 'EvokedArray' and 'EvokedArray'

What are my options? Is it possible to convert EvokedArray to Evoked? Or should mne.combine_evoked() be extended to work with EvokedArray? I don’t even know what the difference between these types is, I thought that both contain evoked data and can be used interchangeably?

I would assume that we simply forgot to explicitly allow EvokedArray in combine_evoked(), and the subtraction should in fact work without any issues.

As to why EvokedArray needs to be a separate class from Evoked, I don’t know. I, too, think it would make sense from a user’s perspective to have EvokedArray either subclass Evoked, or to have a function like evoked_from_data() that would return a proper Evoked object. I always found the differentiation between Evoked and EvokedArray a bit confusing.

OK, I will try that.

Definitely, it is super confusing, especially becaues Epochs.average() seems to produce an EvokedArray object. I thought that this distinction is to differentiate object creation, but the result should really be the same. Maybe a class method for Evoked (and similarly for Raw and Epochs) would make more sense (e.g. Raw.fromarray(), etc.)?

Also, I made a mistake. I accidentally wrote

mne.combine_evoked([evoked1 - evoked2], weights=[1, -1])

instead of

mne.combine_evoked([evoked1, evoked2], weights=[1, -1])

I guess this answers the question because it works as intended. However, we might want to consider adding a __sub__ method to Evoked.

I guess this answers the question because it works as intended. However, we might want to consider adding a __sub__ method to Evoked.

we used to have one but removed it as the behavior was weird for most users. We could reconsider

A

1 Like