-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
example.py
executable file
·49 lines (40 loc) · 2.03 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 24 12:00:16 2017
@author: giulio
"""
###############################################################################
# #
# Libraries #
# #
###############################################################################
import os #used for reading files and directories
import pickle #used to open pickle files.
import matplotlib.pyplot as plt
import pysiology
""" PATHS """
basepath = os.path.dirname(os.path.realpath(__file__)) #This get the basepath of the script
datafolder = basepath+"/data/"
fileECG = "convertedECG.pkl"
fileEDA = "convertedEDA.pkl"
fileEMG = "convertedEMG.pkl"
if(__name__ == "__main__"):
samplerate = 1000 #samplerate of the signals
eventDuration = 8 #event duration in seconds
#First we load our data
with open(datafolder+fileECG,"rb") as f:
rawECGSignal = pickle.load(f)
with open(datafolder+fileEDA,"rb") as f:
rawEDASignal = pickle.load(f)
with open(datafolder+fileEMG,"rb") as f:
rawEMGSignal = pickle.load(f)
#Here we create some fake events
events = [["A",30],["B",60],["C",90]] #id, starttime in seconds
results = {}
for event in events:
startSample = event[1] * samplerate #First sample of the event
endSample = eventDuration*samplerate + startSample #Final sample of the event
results[event[0]] = {} #create a dict for this event results
results[event[0]]["ECG"] = pysiology.electrocardiography.analyzeECG(rawECGSignal[startSample:endSample],samplerate) #analyze the ECG signal
results[event[0]]["EDA"] = pysiology.electrodermalactivity.analyzeGSR(rawEDASignal[startSample:endSample],samplerate) #analyze the GSR signal
results[event[0]]["EMG"] = pysiology.electromyography.analyzeEMG(rawEMGSignal[startSample:endSample],samplerate) #analyze the EMG signal