NeuroTechX / EEG-ExPy

EEG Experiments in Python
https://neurotechx.github.io/EEG-ExPy/
BSD 3-Clause "New" or "Revised" License
418 stars 124 forks source link

Fix plot conditions #257

Closed JohnGriffiths closed 4 months ago

JohnGriffiths commented 6 months ago

addressing plot_conditions issue noted in #246

JohnGriffiths commented 5 months ago

This PR has one important change from the prior code:

conditions for the difference wave plotting are specified by the condition name strings, not the integer values

for example, in the visual p300 example,

conditions = OrderedDict()
conditions['non-target'] = [1]
conditions['target'] = ['2]
diffwav = ["non-target", "target"]

has changed to

conditions = OrderedDict()
conditions['non-target'] = ['non-target']
conditions['target'] = ['target']
diffwav = ["non-target", "target"]

This perhaps does a little odd in that the keys in conditions are identical to the values, but bear in mind that it allows groupings of condition labels, as was previously done with groupings of the integer values.

So, for example, in the visual cueing example,

events = find_events(raw)
event_id = {'InvalidTarget_Left': 11, 'InvalidTarget_Right': 12,
                   'ValidTarget_Left': 21,'ValidTarget_Right': 11}
...
conditions = OrderedDict()
conditions['ValidTarget'] = [21,22]
conditions['InvalidTarget'] = [11,12]

has now become

events = find_events(raw)
event_id = {'InvalidTarget_Left': 11, 'InvalidTarget_Right': 12,
                   'ValidTarget_Left': 21,'ValidTarget_Right': 11}
...
conditions = OrderedDict()
conditions['ValidTarget'] = ['ValidTarget_Left', 'ValidTarget_Right']
conditions['InvalidTarget'] = ['InvalidTarget_Left', 'InvalidTarget_Right']
diffwave = ('ValidTarget', 'InvalidTarget')

The reason for doing this is that the epochs.to_dataframe() method returns a dataframe with a column that has the condition label text strings (i.e. the keys in event_id), but not the integer id values. Moreover, between the two, it is preferable to use text strings than integers to define things as they are more expressive and easier to work with correctly / avoid mis-specification errors.

oreHGA commented 4 months ago

Docs build works, merging to develop