Closed jajcayn closed 4 years ago
Hi @jajcayn! Sorry for the late reply for some reason I didn't get notified. So it seems to me that a quick fix would be to add the following lines in the code, after idx = np.ma.compress_rows(idx_mask)
:
if len(idx) == 0:
warning.warn('warning message bla bla bla...Returning None')
return None # Or empty pandas DataFrame
We can also, as you say, alter the time before and after but I think I'd prefer the more explicit solution of throwing a warning and returning None. At least the user knows that something is wrong.
What do you think? Thanks!
Dear Raphael, thanks for the reply! I agree that explicit is definitely better than implicit, i.e. I would just warn the user and return None. As for the returning, I believe that None is better because then you can simply do something like
time_around = 1. # second
events = None
while events is None:
events = yasa.get_sync_events(..., time_before=time_around, time_after=time_around)
time_around -= 0.1
I already did a small fix, opening a PR now :) Best!
traceback:
happens when there is only one event (in my case spindle, but that doesn't matter) and that one event is at the beginning or at the end, hence
idx_mask = np.ma.mask_rows(np.ma.masked_outside(idx, 0, data.shape[0]))
line actually gets rid of anything andidx = []
for now, I manually solve it in the sense, that I am always centered around
Peak
so I manually check whether myPeak - time_before
orPeak + time_after
exceed limits of the timeseries and if so, I alter thetime_before
ortime_after
.It'd be nice if
yasa
offers such an option, or an option to completely skip would be also nice.