mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.7k stars 1.31k forks source link

something weird with time_as_index #5541

Closed massich closed 6 years ago

massich commented 6 years ago

Describe the bug

Reviewing this line raw.first_time should not be necessary since #5524.

    inds = raw.time_as_index(annotations.onset, use_rounding=True,
                             origin=annotations.orig_time) + raw.first_samp

Steps and/or code to reproduce

#       sec  0        1        2        3
#       raw  .        |--------XXXXXXXXX
#     onset  .        |--------|
#   latency  .        0        1        2
#            .                 0        0
from mne import create_info
from mne.io import RawArray
info = create_info(ch_names=10, sfreq=10.)
raw = RawArray(data=np.empty((10, 10)), info=info, first_samp=10)
raw.info['meas_date'] = 1
onsets = [1.]
inds = raw.time_as_index(onsets,
                            use_rounding=True,
                            origin=raw.info['meas_date'])
assert inds[0] == 10

Expected results

no error thrown / raw.time_as_index returned 10

massich commented 6 years ago

That is a misstatement. time_as_index allows for arbitrary reference of the input times. But the results are always relateive to first_samp.

massich commented 6 years ago

Closing this issue. If someone thinks that is worth to have an arbitrary output reference, be my gest to reopen it.