forked from PIA-Group/BioSPPy
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathconfig.py
More file actions
190 lines (144 loc) · 8.53 KB
/
config.py
File metadata and controls
190 lines (144 loc) · 8.53 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# -*- coding: utf-8 -*-
"""
biosppy.inter_plotting.ecg
-------------------
This module provides configuration functions and variables for the Biosignal Annotator.
:copyright: (c) 2015-2023 by Instituto de Telecomunicacoes
:license: BSD 3-clause, see LICENSE for more details.
"""
from matplotlib.backend_bases import MouseButton
import matplotlib.colors as mcolors
from ..signals import eda
from ..signals import ecg
from ..signals import abp
from ..signals import emg
from ..signals import pcg
from ..signals import ppg
def UI_intention(event, var_edit_plots=None, var_toggle_Ctrl=None, var_zoomed_in=None, window_in_border=None,
closest_event=False):
"""Returns the user intention and action given an event.
Parameters
----------
var_edit_plots : None
Enables (if set to 1) or disables (if set to 0) annotation editing.
var_toggle_Ctrl : None
Stores whether currently zoomed-in (if set to 1) or zoomed-out (if set to 0) in amplitude.
var_zoomed_in : None
Stores whether currently zoomed-in (if true) or zoomed-out (if false) in time.
window_in_border: None
Stores whether the current zoomed-in window is in the borders of the time range (x-scale).
closest_event : None
Stores whether closest event is within defined range (if true) or not (false).
Returns
-------
return_dict : dict
The returned dictionary with keys 'triggered_intention' and 'triggered_action'.
"""
triggered_intention = None
triggered_action = None
if hasattr(event, 'inaxes'):
if event.inaxes is not None and not event.dblclick: # and var_edit_plots.get() == 1
if event.button == MouseButton.RIGHT:
triggered_intention = "rmv_annotation"
if var_edit_plots is not None:
if var_edit_plots.get() == 1 and closest_event:
triggered_action = "rmv_annotation"
elif var_edit_plots.get() == 1 and not closest_event:
triggered_action = "rmv_annotation_not_close"
# else the action remain None
elif event.button == MouseButton.LEFT:
triggered_intention = "add_annotation"
if var_edit_plots is not None:
if var_edit_plots.get() == 1:
triggered_action = "add_annotation"
elif hasattr(event, 'keysym'):
# Moving to the Right (right arrow)
if event.keysym == 'Right':
triggered_intention = "move_right"
if window_in_border is not None:
if not window_in_border:
triggered_action = "move_right"
# else, window doesn't move to the right (stays the same)
# Moving to the left (left arrow)
elif event.keysym == 'Left':
triggered_intention = "move_left"
if window_in_border is not None:
if not window_in_border:
triggered_action = "move_left"
# else, window doesn't move to the left (stays the same)
# Zooming out to original xlims or to previous zoomed in lims
elif event.keysym == 'Shift_L':
triggered_intention = "adjust_in_time"
if var_zoomed_in is not None:
# if the window was not zoomed in, it should zoom in
if not var_zoomed_in:
triggered_action = "zooming_in"
# else, it should zoom out
else:
triggered_action = "zooming_out"
# if Left Control is pressed
elif event.keysym == 'Control_L':
triggered_intention = "adjust_in_amplitude"
if var_toggle_Ctrl is not None:
# if the window was not zoomed in, it should zoom in
if var_toggle_Ctrl.get() == 0:
triggered_action = "zooming_in"
# else, it should zoom out
else:
triggered_action = "zooming_out"
elif event.keysym == 'Escape':
triggered_intention = "quit_ui"
return_dict = {'triggered_intention': triggered_intention, 'triggered_action': triggered_action}
return return_dict
# possible intentions and actions
UI_intentions_actions = {
"adjust_in_amplitude": {None: "Error", "zooming_in": "Amplitude Zoom-in", "zooming_out": "Amplitude Zoom-out"},
"adjust_in_time": {None: "Error", "zooming_in": "Time zoom-in", "zooming_out": "Time zoom-out"},
"move_right": {None: "Cannot move further to the right (signal ends there).", "move_right": "Moving right"},
"move_left": {None: "Cannot move further to the left (signal ends there).", "move_left": "Moving left"},
"add_annotation": {None: "Click on \'Edit Annotations\' checkbox", "add_annotation": "Adding Annotation"},
"rmv_annotation": {None: "Click on \'Edit Annotations\' checkbox", "rmv_annotation": "Removing Annotation",
"rmv_annotation_not_close": "Click closer to the annotation."},
}
# listed BioSPPy default filtering methods and main feature extraction methods.
list_functions = {'EDA': {
'Basic SCR Extractor - Onsets': {'preprocess': eda.preprocess_eda, 'function': eda.basic_scr,
'template_key': 'onsets'},
'Basic SCR Extractor - Peaks': {'preprocess': eda.preprocess_eda, 'function': eda.basic_scr,
'template_key': 'onsets'},
'KBK SCR Extractor - Onsets': {'preprocess': eda.preprocess_eda, 'function': eda.kbk_scr,
'template_key': 'peaks'},
'KBK SCR Extractor - Peaks': {'preprocess': eda.preprocess_eda, 'function': eda.kbk_scr,
'template_key': 'peaks'}},
'ECG': {'R-peak Hamilton Segmenter': {'preprocess': ecg.preprocess_ecg,
'function': ecg.hamilton_segmenter, 'template_key': 'rpeaks'},
'R-peak SSF Segmenter': {'preprocess': ecg.preprocess_ecg, 'function': ecg.ssf_segmenter,
'template_key': 'rpeaks'},
'R-peak Christov Segmenter': {'preprocess': ecg.preprocess_ecg,
'function': ecg.christov_segmenter, 'template_key': 'rpeaks'},
'R-peak Engzee Segmenter': {'preprocess': ecg.preprocess_ecg,
'function': ecg.engzee_segmenter, 'template_key': 'rpeaks'},
'R-peak Gamboa Segmenter': {'preprocess': ecg.preprocess_ecg,
'function': ecg.gamboa_segmenter, 'template_key': 'rpeaks'},
'R-peak ASI Segmenter': {'preprocess': ecg.preprocess_ecg, 'function': ecg.ASI_segmenter,
'template_key': 'rpeaks'}},
'ABP': {'Onset Extractor': {'preprocess': abp.preprocess_abp, 'function': abp.find_onsets_zong2003,
'template_key': 'onsets'}},
'EMG': {'Basic Onset Finder': {'preprocess': emg.preprocess_emg, 'function': emg.find_onsets,
'template_key': 'onsets'}},
# 'Hodges Onset Finder': {'preprocess': emg.preprocess_emg,'function': emg.hodges_bui_onset_detector, 'template_key': 'onsets'},
# 'Bonato Onset Finder': {'preprocess': emg.preprocess_emg,'function': emg.bonato_onset_detector, 'template_key': 'onsets'},
# 'Lidierth Onset Finder': {'preprocess': emg.preprocess_emg,'function': emg.lidierth_onset_detector, 'template_key': 'onsets'},
# 'Abbink Onset Finder': {'preprocess': emg.preprocess_emg,'function': emg.abbink_onset_detector, 'template_key': 'onsets'},
# 'Solnik Onset Finder': {'preprocess': emg.preprocess_emg,'function': emg.solnik_onset_detector, 'template_key': 'onsets'},
# 'Silva Onset Finder': {'preprocess': emg.preprocess_emg,'function': emg.silva_onset_detector, 'template_key': 'onsets'},
# 'londral_onset_detector': {'preprocess': emg.preprocess_emg,'function': emg.londral_onset_detector, 'template_key': 'onsets'}},
'PCG': {
'Basic Peak Finger': {'preprocess': None, 'function': pcg.find_peaks, 'template_key': 'peaks'}},
'PPG': {'Elgendi Onset Finder': {'preprocess': ppg.preprocess_ppg,
'function': ppg.find_onsets_elgendi2013, 'template_key': 'onsets'},
'Kavsaoglu Onset Finder': {'preprocess': ppg.preprocess_ppg,
'function': ppg.find_onsets_kavsaoglu2016,
'template_key': 'onsets'}}
}
plot_colors = list(mcolors.TABLEAU_COLORS.values())