From ede5bd66b2f9221ebaa180d4f15b424555ecceb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=B6ll=C5=91d=20Csaba?= <kollod.csaba@itk.ppke.hu> Date: Fri, 6 Jan 2023 12:57:40 +0100 Subject: [PATCH] Update: adding unit constants - merge_records.py --- mcc-flow/merge_records.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/mcc-flow/merge_records.py b/mcc-flow/merge_records.py index 0e5e106..40a6e8c 100644 --- a/mcc-flow/merge_records.py +++ b/mcc-flow/merge_records.py @@ -23,6 +23,10 @@ EEG_EMG_SCALE = 0.04470348358154 # (uV) GYRO_SCALE = 0.0152587890625 # (deg/sec) ACC_SCALE = 0.00006103515625 # (g) +EEG_EMG_UNIT = 'uV' +GYRO_UNIT = 'deg/sec' +ACC_UNIT = 'g' + @dataclass class PacketData: @@ -92,7 +96,13 @@ class FlowPacket: self._plot(self.eeg_giro, 'EEG Gyroscope') self._plot(self.eeg_acc, 'EEG Accelerometer') self._plot(self.emg, 'EMG') - # self._plot(self.spo2, 'SPO2') + self._plot(self.emg_giro, 'EMG Gyroscope') + self._plot(self.emg_acc, 'EMG Accelerometer') + self._plot(self.flow, 'flow') + self._plot(self.hr, 'HR') + self._plot(self.spo2, 'SPO2') + self._plot(self.sound, 'Sound') + self._plot(self.gsr, 'GSR') plt.show() def to_edf(self, filename): @@ -108,8 +118,6 @@ class FlowPacket: # print(sig) edf.setPhysicalMaximum(sig, max(ch_dat.max(), 1)) edf.setPhysicalMinimum(sig, min(ch_dat.min(), -1)) - # edf.setDigitalMaximum(sig, 2**7) - # edf.setDigitalMinimum(sig, -2**7) edf.setPhysicalDimension(sig, pkt.unit) edf.setSamplefrequency(sig, pkt.fs) edf.setLabel(sig, f'{pkt.type}{i}') @@ -167,6 +175,7 @@ def read_packet(file): except ValueError as e: print(f'\033[91mERROR\033[0m Corrupted header in file \'{file.name}\'. Process aborted.') exit(12) + spo2 /= 10. flow = PacketData(np.array([[flow]]), 'flow', 'unit', HEADER_FS) hr = PacketData(np.array([[hr]]), 'hr', 'unit', HEADER_FS) @@ -177,18 +186,18 @@ def read_packet(file): eeg = _read_block_data(file, (250, 4), 'i', 4).T * EEG_EMG_SCALE eeg_giro = _read_block_data(file, (50, 3), 'h', 2).T * GYRO_SCALE eeg_acc = _read_block_data(file, (50, 3), 'h', 2).T * ACC_SCALE - eeg = PacketData(eeg, 'eeg', 'uV', EEG_EMG_FS) - eeg_giro = PacketData(eeg_giro, 'eeg_giro', 'unit', GYRO_ACC_FS) - eeg_acc = PacketData(eeg_acc, 'eeg_acc', 'unit', GYRO_ACC_FS) + eeg = PacketData(eeg, 'eeg', EEG_EMG_UNIT, EEG_EMG_FS) + eeg_giro = PacketData(eeg_giro, 'eeg_giro', GYRO_UNIT, GYRO_ACC_FS) + eeg_acc = PacketData(eeg_acc, 'eeg_acc', ACC_UNIT, GYRO_ACC_FS) # print(eeg, eeg_giro, eeg_acc) # emg emg = _read_block_data(file, (250, 6), 'i', 4).T * EEG_EMG_SCALE emg_giro = _read_block_data(file, (50, 3), 'h', 2).T * GYRO_SCALE emg_acc = _read_block_data(file, (50, 3), 'h', 2).T * ACC_SCALE - emg = PacketData(emg, 'emg', 'uV', EEG_EMG_FS) - emg_giro = PacketData(emg_giro, 'emg_giro', 'unit', GYRO_ACC_FS) - emg_acc = PacketData(emg_acc, 'emg_acc', 'unit', GYRO_ACC_FS) + emg = PacketData(emg, 'emg', EEG_EMG_UNIT, EEG_EMG_FS) + emg_giro = PacketData(emg_giro, 'emg_giro', GYRO_UNIT, GYRO_ACC_FS) + emg_acc = PacketData(emg_acc, 'emg_acc', ACC_UNIT, GYRO_ACC_FS) # print(emg, emg_giro, emg_acc) # extra -- GitLab