pyedfread icon indicating copy to clipboard operation
pyedfread copied to clipboard

Handling flags and time offset (-ftime option) for >1000 Hz data

Open flyingfalling opened this issue 9 months ago • 7 comments

I noticed that the current version has no mechanism for returning appropriate floating point time for sample rates >1000 Hz. Currently it provides the (edf2asc etc.) default of simply doubling up "time", without adding the 0.5 offset that is specified by the "SAMPLE_ADD_OFFSET" bit (SAMPLE_ADD_OFFSET = 0x0002 # if this flag is set for the sample add .5ms to the sample time), see edf_data.pyx.

When running edf2asc for example, the "-ftime" flag causes 0.5 msec to be added to time for every sample with the SAMPLE_ADD_OFFSET flag set (which is for every other sample when recorded at 2000 Hz). And time is returned as a floating point number rather than large integer.

A slightly separate issue: the 'flags' column is returned in the samples dataframe as a floating point column instead of the (16-bit) integer flags it should (and it is shadowing pandas.DataFrame.flags...making things confusing to the casual coder accessing via df.flags attr instead of df['flags']...).

I'm trying to work on a fix for this (and will require adding a default-off option argument in read_edf).

Thoughts?

flyingfalling avatar Apr 09 '25 02:04 flyingfalling