beacon-biosignals / AlignedSpans.jl

Helpers for continuous <-> discrete indexing
MIT License
4 stars 0 forks source link

Discrete back to continuous #7

Closed ericphanson closed 2 years ago

ericphanson commented 2 years ago

I bailed on this in #2 since I wanted to think about it more and wasn’t sure it was needed. I think there are times it’s pretty useful, and that there’s a simple thing we can do:

We define the start as time_from_index(sample_rate, span.first_index) and the stop as time_from_index(sample_rate, span.last_index + 1). In other words, if we had sample rate 1 and indices 5:10, we have AlignedSpan(1, 5, 10) which we would map to TimeSpan(Second(5), Second(11)).

In other words, we’re saying that 1 sample is associated to the time of the sample (inclusive) to the time of the next sample (exclusive).

Why?

Why do we ever need to go back to continuous time? All the cases I’ve found have essentially been to allow interop with code that expects TimeSpans-compatible spans. For example, for use with the Legolas schema for Onda Annotations. I think we should try to avoid mapping back and forth too much, but it’s nice if we can in a principled way.

To close this: