yasa icon indicating copy to clipboard operation
yasa copied to clipboard

plot_average plots all channels, not only indicated ones

Open skjerns opened this issue 1 year ago • 3 comments

I'm running the following code


raw = mne.io.read_raw(edf_file, preload=True)
hypno = sleep_utils.read_hypno(hypno_file, verbose=False)
hypno_upsampled = yasa.hypno_upsample_to_data(hypno, sf_hypno=1/30, data=raw)
assert len(raw)//raw.info['sfreq']//30==len(hypno)
chs = ['Fz'] 

sp = yasa.spindles_detect(raw, hypno=hypno_upsampled, ch_names=chs, include=[2,3])
ax = sp.plot_average()

I would expect that in the resulting figure only the channel indicated in chs is plotted. However, all the channels of the raw are plotted. Is that the indention?

PS Once again thanks for the library! Amazing for quickly analyzing a dataset

skjerns avatar Feb 01 '24 16:02 skjerns

Hi Simon,

ch_names only indicates the channel names, not the channels that should be included in the analysis. Furthermore, ch_names is actually discarded if the input data is a mne.Raw instance, since the channel names can be extracted automatically from the Raw object:

https://github.com/raphaelvallat/yasa/blob/ae9ccc7fc5fd31ea0618bec59fed6b2dbf3edff7/yasa/detection.py#L57

Therefore, you need to update your code to:

raw.pick(["Fz"])
sp = yasa.spindles_detect(raw, hypno=hypno_upsampled, include=[2,3])
ax = sp.plot_average()

I think that the current documentation of ch_names is somewhat misleading and should be clarified.

Hope this helps! Raphael

raphaelvallat avatar Feb 03 '24 14:02 raphaelvallat

Hi Simon,

ch_names only indicates the channel names, not the channels that should be included in the analysis. Furthermore, ch_names is actually discarded if the input data is a mne.Raw instance, since the channel names can be extracted automatically from the Raw object:

https://github.com/raphaelvallat/yasa/blob/ae9ccc7fc5fd31ea0618bec59fed6b2dbf3edff7/yasa/detection.py#L57

Therefore, you need to update your code to:

raw.pick(["Fz"])
sp = yasa.spindles_detect(raw, hypno=hypno_upsampled, include=[2,3])
ax = sp.plot_average()

I think that the current documentation of ch_names is somewhat misleading and should be clarified.

Hope this helps! Raphael

Right! Now I understand. Would it be an idea to give a warning/assertion if ch_names is indicated and a raw object is provided?

skjerns avatar Feb 07 '24 13:02 skjerns

Yes we probably should — the current implementation is confusing!

raphaelvallat avatar Feb 07 '24 14:02 raphaelvallat