`time_as_index` counter-part: `index_as_time`

Does the counterpart to time_as_index exist? The event array returned by mne.find_events returns the position in samples and I want to add events with make_fixed_length_events while providing the argument start and stop based on my events. Is there a convenience function to convert from sample to time somewhere in MNE?

Not to my knowledge; I think in all examples, we’d do something like

t = sample_index / info['sfreq']

That’s what I thought. I do get that there is some error checking/tricks in the conversion from time to index that has to be covered in time_as_index; but I’m not sure if it doesn’t apply also to the conversion in the other direction, especially with the origin/first_samp/meas_date system.

Actually I don’t think so, therefore the example I showed should do the Right Thing ™

But for sake of consistency, sure, why not add index_as_time? :slight_smile: Even though maybe sample_index_as_time() would be more explicit?

Ok, thanks. I’m not familiar enough with the system of origin/first_samp/meas_date for now to make sure there isn’t some hidden logic somewhere and to add this. I’ll keep it in mind for a future me.

Same :sweat_smile::sweat_smile::see_no_evil: And I think 99% of our users would agree :see_no_evil:

1 Like

reminds me of a PR when I needed “index_as_time” as well and it wasn’t there :smiley:

I had a brief discussion with @larsoner on this: [MRG] ENH, FIX: Add tmin/tmax parameters to get_data methods, fix bug in find_bads_ecg by sappelhoff · Pull Request #9556 · mne-tools/mne-python · GitHub

In that PR it turned out that “index_as_time” wasn’t needed, so we didn’t add it.

1 Like