Open jonahpearl opened 2 months ago
Hey @jonahpearl thanks for this, so to be sure I understand correctly:
1) plot_traces()
is getting the times 25.5 - 25.6 into the recording, irregardless of what the actual start time is.
2) the expected behaviour is that plot_traces()
displays the actual 25.5 - 25.6 second range. So for example, if the recording was from ground-truth times 20 to 50 seconds, you would expect the time slice you used (25.5, 25.6) to display 5.5 to 5.6 seconds into the recording (25.5-25.6 true time). But, it is giving 25.5 to 25.6 seconds into the recording (which is 45.5 to 45.6 seconds true time).
I think this is because the plot_traces()
code you linked is looking for a time_vector but ignoring any t_start
set on the recording. Presumably if you do recording_car.has_time_vector()
you will get False
? Could you do recording_cmr.set_times(recording_cmr.get_times())
and check if that fixes the problem? (otherwise I've misunderstood something).
Now, this conditional is outdated as get_times()
will generate times on the fly even if no time vector is found. This is better as it will use any t_start
on the recording. I think conditional block in plot_traces
linked above can now be replaced with just the second part of the conditional:
times = rec0.get_times(segment_index=segment_index)
t_start = times[0]
t_end = times[-1]
@alejoe91 @samuelgarcia do you agree? In practice, can we deprecate has_time_vector()
as one is always generated now, and it will use t_start
if available whereas legacy code that uses this conditional check may not?
Hi @JoeZiminski — yes, running recording_cmr.set_times(recording_cmr.get_times())
aligns the two behaviors, as you expected :) thanks!
One other note, if I run that fix, and then "naively" ask for a time segment outside the start of the recording with the plot_traces function, I get a fairly cryptic ValueError because it's trying to run operations on an empty array, it might be worth checking for this and raising a user-readable error, since I imagine some people will just instinctively try to plot the first few seconds of their recording. recording.time_slice()
gives an AssertionError which is clear from context if you look at the traceback, but it wouldn't be hard to add a simple message giving the user feedback.
I think this should be fixed if we use time_slice
in plot_traces
, since it seems to handle correctly all cases. Will make a PR
@jonahpearl could you test this? https://github.com/SpikeInterface/spikeinterface/pull/3393
Also improved error messages in that PR
@jonahpearl could you test this? #3393
Actually doesn't seem to work for me — when I subselect my one channel, I just get an empty plot, even without passing any time_range. If I don't subselect the channels it works. And you can see that channel has data b/c if i pull it out directly it's fine.
Hi all — I was doing some manual digging around to deal with artifacts caused by some custom lighting in our rigs, and I wanted to find the moment in the recording where the artifacts began. I noticed that depending on whether I used
recording.time_slice()
orrecording.plot_traces
, there are two different behaviors for dealing with the case where t0 != 0 (this is coming from open ephys, so it's often the case that the first timestamp isn't 0 in the recording).Case 1: the "give me X many seconds into the recording" strategy. This appears to be used by
recording.plot_traces
, and I think is a bug.Case 2: the "give me the data where the timestamps equal this value" strategy. This appears to be used by
recording.time_slice
, and I think is the correct way (?).For example, here is the plot from
plot_traces
for the time range (25.5, 26.5): you can see the artifacts start ~halfway through the window.Now if I run this code to try to show the same thing but with
recording.time_slice()
, we instead get a different moment:If we adjust the time slicing to account for the inconsistent behavior, we recover the same moment in the data:
You can see the behavior in the code. time_slice ultimately relies on this logic (at least in my case, it seems that self.t_start is assigned automatically when reading from OE folders):
sample_index = (time_s - self.t_start) * self.sampling_frequency
, which means that, say, if t0 were 10, and the user requested t=20, the code would correctly give the user the data from 10 seconds into the recording.However the plot/get_traces functions don't appear to do this correction, as seen here and down on L145 below that, and then the helper function just inherits that time range directly.
Hopefully fixing the behavior in
plot_traces
is easy enough and won't hurt anyone's workflow — I imagine that may be why the bug still exists :)