You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For my applications, I need sample precision when I extract subsets of the data at a given time using the get_waveforms method of an ASDFDataSet instance. However, I observed discrepancies of up to 1 sample between the start time I requested and the start time that was returned.
I tracked the issue down to _get_idx_and_size_estimate of asdf_data_set.py. The line:
produces an undesirable output when (starttime - data_starttime) / dt = X + 0.999999. Instead of returning offset = X + 1 samples, it returns offset = X samples due to the floating point number imprecision. This happens of course because of the behavior of int, which rounds to the nearest lower integer number.
A solution that works for me is to add a number a < 1 to (starttime - data_starttime) / dt before converting it to an integer. If this number is a = 0.5, the following line:
actually rounds the time to the nearest (lower or upper) integer number. See this commit: ebeauce@4437051
I guess that some people would want to be able to always round to the nearest upper or the nearest lower integer, so it may be worth adding a key-word argument to get_waveforms similarly to the slice method of Obspy Stream. My opinion is that rounding to the nearest sample would be the preferable default behavior.
Thank you,
Eric
The text was updated successfully, but these errors were encountered:
Hi,
For my applications, I need sample precision when I extract subsets of the data at a given time using the
get_waveforms
method of anASDFDataSet
instance. However, I observed discrepancies of up to 1 sample between the start time I requested and the start time that was returned.I tracked the issue down to
_get_idx_and_size_estimate
of asdf_data_set.py. The line:produces an undesirable output when
(starttime - data_starttime) / dt = X + 0.999999
. Instead of returningoffset = X + 1
samples, it returnsoffset = X
samples due to the floating point number imprecision. This happens of course because of the behavior ofint
, which rounds to the nearest lower integer number.A solution that works for me is to add a number
a < 1
to(starttime - data_starttime) / dt
before converting it to an integer. If this number isa = 0.5
, the following line:actually rounds the time to the nearest (lower or upper) integer number. See this commit: ebeauce@4437051
I guess that some people would want to be able to always round to the nearest upper or the nearest lower integer, so it may be worth adding a key-word argument to
get_waveforms
similarly to theslice
method of ObspyStream
. My opinion is that rounding to the nearest sample would be the preferable default behavior.Thank you,
Eric
The text was updated successfully, but these errors were encountered: