generate_edf+C.py 1.0 KB

1234567891011121314151617181920212223242526272829
  1. """
  2. Generate minimal EDF+C file.
  3. See also pyedflib and format specifications
  4. https://github.com/holgern/pyedflib
  5. https://www.edfplus.info/
  6. Author: Julia Sprenger
  7. """
  8. from pyedflib import highlevel
  9. import numpy as np
  10. # write an edf file with 5 channels á 265 samples (1 second)
  11. signals = np.random.rand(5, 256) * 200
  12. channel_names = ['ch1', 'ch2', 'ch3', 'ch4', 'ch5']
  13. dimensions = ['mV', 'uV', 'pA', 'dimensionless', 'C']
  14. transducer = ['unknown', 'A', 'B', '', 'Z']
  15. prefilter = ['true', 'false', 'false', 'true', 'true']
  16. signal_headers = highlevel.make_signal_headers(list_of_labels=channel_names, sample_rate=256)
  17. for i in range(len(signal_headers)):
  18. signal_headers[i]['dimension'] = dimensions[i]
  19. signal_headers[i]['transducer'] = transducer[i]
  20. signal_headers[i]['prefilter'] = prefilter[i]
  21. header = highlevel.make_header(patientname='patient_x', gender='Female')
  22. highlevel.write_edf('edf+C.edf', signals, signal_headers, header)
  23. # export plain signal also as txt file (transposed for compatiblity with AnalogSignal)
  24. np.savetxt('edf+C.txt', signals.T)