holgern / pyedflib

pyedflib is a python library to read/write EDF+/BDF+ files based on EDFlib.
http://pyedflib.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
209 stars 121 forks source link

Minor Visual/Text bug related to a 'physical max/min' error #258

Closed canhotuctor closed 1 week ago

canhotuctor commented 1 week ago

When trying to write a DataFrame to an EDF file, with physical maximums/minimums in precisions over 16 bits, the text defaults to something like 'Physical minimum for channel xx...' even when it should be 'Physical maximum for channel xx...'.

An example of the error

/home/grey/.local/lib/python3.10/site-packages/pyedflib/edfwriter.py:124: UserWarning: Physical minimum for channel 30 (EEG P10) is -37.96628460442817, which has 18 chars, however, EDF+ can only save 8 chars, will be truncated to -37.9662, some loss of precision is to be expected
  warnings.warn('Physical minimum for channel {} ({}) is {}, which has {} chars, '\
/home/grey/.local/lib/python3.10/site-packages/pyedflib/edfwriter.py:131: UserWarning: Physical minimum for channel 30 (EEG P10) is 34.704298604236044, which has 18 chars, however, EDF+ can only save 8 chars, will be truncated to 34.70429, some loss of precision is to be expected.
  warnings.warn('Physical minimum for channel {} ({}) is {}, which has {} chars, '\

when using this as the channel info for each of the signal headers:

for label in channel_labels:
  chan_dict = {
    'label': label,
    'sample_rate': sfreq,
    'dimension': 'uV',
    'physical_min': norm_df[label].min(),
    'physical_max': norm_df[label].max(),
    'digital_min': -32768,
    'digital_max': 32767,
    'transducer': '',
    'prefilter': ''
  }
...
skjerns commented 1 week ago

thanks! fixed in https://github.com/holgern/pyedflib/commit/168ae654f0c975b4436f6b452f3164a7104d8f56