accusleepy 0.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- accusleepy/__init__.py +0 -0
- accusleepy/__main__.py +4 -0
- accusleepy/bouts.py +142 -0
- accusleepy/brain_state_set.py +89 -0
- accusleepy/classification.py +285 -0
- accusleepy/config.json +24 -0
- accusleepy/constants.py +46 -0
- accusleepy/fileio.py +179 -0
- accusleepy/gui/__init__.py +0 -0
- accusleepy/gui/icons/brightness_down.png +0 -0
- accusleepy/gui/icons/brightness_up.png +0 -0
- accusleepy/gui/icons/double_down_arrow.png +0 -0
- accusleepy/gui/icons/double_up_arrow.png +0 -0
- accusleepy/gui/icons/down_arrow.png +0 -0
- accusleepy/gui/icons/home.png +0 -0
- accusleepy/gui/icons/question.png +0 -0
- accusleepy/gui/icons/save.png +0 -0
- accusleepy/gui/icons/up_arrow.png +0 -0
- accusleepy/gui/icons/zoom_in.png +0 -0
- accusleepy/gui/icons/zoom_out.png +0 -0
- accusleepy/gui/images/primary_window.png +0 -0
- accusleepy/gui/images/viewer_window.png +0 -0
- accusleepy/gui/images/viewer_window_annotated.png +0 -0
- accusleepy/gui/main.py +1494 -0
- accusleepy/gui/manual_scoring.py +1096 -0
- accusleepy/gui/mplwidget.py +386 -0
- accusleepy/gui/primary_window.py +2577 -0
- accusleepy/gui/primary_window.ui +3831 -0
- accusleepy/gui/resources.qrc +16 -0
- accusleepy/gui/resources_rc.py +6710 -0
- accusleepy/gui/text/config_guide.txt +27 -0
- accusleepy/gui/text/main_guide.md +167 -0
- accusleepy/gui/text/manual_scoring_guide.md +23 -0
- accusleepy/gui/viewer_window.py +610 -0
- accusleepy/gui/viewer_window.ui +926 -0
- accusleepy/models.py +108 -0
- accusleepy/multitaper.py +661 -0
- accusleepy/signal_processing.py +469 -0
- accusleepy/temperature_scaling.py +157 -0
- accusleepy-0.6.0.dist-info/METADATA +106 -0
- accusleepy-0.6.0.dist-info/RECORD +42 -0
- accusleepy-0.6.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
This is the current brain state configuration.
|
|
2
|
+
If you make changes, click 'Save' to store them.
|
|
3
|
+
|
|
4
|
+
Each brain state has several attributes:
|
|
5
|
+
|
|
6
|
+
- Digit: how the brain state is represented in label files,
|
|
7
|
+
and the key on the keyboard that, during manual scoring,
|
|
8
|
+
sets an epoch to this brain state.
|
|
9
|
+
|
|
10
|
+
- Enabled: whether a brain state for this digit exists.
|
|
11
|
+
|
|
12
|
+
- Name: unique name of the brain state (e.g., REM).
|
|
13
|
+
|
|
14
|
+
- Scored: whether a classification model should output this
|
|
15
|
+
brain state. If you have a state that corresponds to
|
|
16
|
+
missing or corrupted data, for example, you would
|
|
17
|
+
probably want to uncheck this box.
|
|
18
|
+
|
|
19
|
+
- Frequency: approximate relative frequency of this brain
|
|
20
|
+
state. Does not need to be very accurate, but it can
|
|
21
|
+
influence classification accuracy slightly. The values
|
|
22
|
+
for all scored brain states must sum to 1.
|
|
23
|
+
|
|
24
|
+
Important notes:
|
|
25
|
+
- Changing these settings can invalidate existing label files,
|
|
26
|
+
calibration files, and trained models!
|
|
27
|
+
- Reinstalling AccuSleePy will overwrite this configuration.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Definitions
|
|
2
|
+
- Recording: a table containing one channel of electroencephalogram (EEG)
|
|
3
|
+
data and one channel of electromyogram (EMG) data collected at a
|
|
4
|
+
constant sampling rate.
|
|
5
|
+
- Epoch: the temporal resolution of brain state scoring. If, for example,
|
|
6
|
+
the epoch length is 5 seconds, then a brain state label will be
|
|
7
|
+
assigned to each 5-second segment of a recording.
|
|
8
|
+
- Bout: a contiguous set of epochs with the same brain state.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# 1. Overview of the primary interface
|
|
12
|
+
|
|
13
|
+
The workflow for sleep scoring is as follows:
|
|
14
|
+
1. Set the epoch length
|
|
15
|
+
2. For each of your recordings:
|
|
16
|
+
1. create a new entry in the list of recordings
|
|
17
|
+
2. enter the sampling rate
|
|
18
|
+
3. select the recording file containing the EEG and EMG data
|
|
19
|
+
4. choose a filename for saving the brain state labels,
|
|
20
|
+
or select an existing label file
|
|
21
|
+
|
|
22
|
+
At this point, you can score the recordings manually.
|
|
23
|
+
|
|
24
|
+
3. For each recording, create a calibration file using a small amount
|
|
25
|
+
of labeled data, or choose a calibration file created using
|
|
26
|
+
another recording from the same subject and under the same recording
|
|
27
|
+
conditions
|
|
28
|
+
4. Select a trained classification model file with the correct epoch length
|
|
29
|
+
5. Score all recordings automatically using the classifier
|
|
30
|
+
|
|
31
|
+
By default, there are three brain state options: REM, wake, and NREM.
|
|
32
|
+
If you want to change this configuration, click the "Settings" tab.
|
|
33
|
+
Note that if you change the configuration, you might be unable to load
|
|
34
|
+
existing labels and calibration data, and you may need to train a new
|
|
35
|
+
classification model.
|
|
36
|
+
|
|
37
|
+
Use the "import" and "export" buttons to load or save a list of
|
|
38
|
+
recordings. This can be useful if you need to re-score a set of
|
|
39
|
+
recordings with a new model, or if you want to keep a record of
|
|
40
|
+
the recordings that were used when training a model.
|
|
41
|
+
|
|
42
|
+
# 2. AccuSleePy file types
|
|
43
|
+
There are four types of files associated with AccuSleePy.
|
|
44
|
+
To select a file in the primary interface, you can either use the
|
|
45
|
+
associated button, or drag/drop the file into the empty box adjacent
|
|
46
|
+
to the button.
|
|
47
|
+
- Recording file: a .parquet or .csv file containing one
|
|
48
|
+
column of EEG data and one column of EMG data.
|
|
49
|
+
The column names must be **eeg** and **emg**.
|
|
50
|
+
- Label file: a .csv file with one column titled **brain_state**
|
|
51
|
+
with entries that are either the undefined brain state (by default, this is -1)
|
|
52
|
+
or one of the digits in your brain state configuration.
|
|
53
|
+
By default, these are 1-3 where REM = 1, wake = 2, NREM = 3.
|
|
54
|
+
Optionally, there can be a second column named **confidence_score**
|
|
55
|
+
containing classification confidence scores between 0 and 1.
|
|
56
|
+
- Calibration data file: required for automated scoring. See Section 4
|
|
57
|
+
for details. These have .csv format.
|
|
58
|
+
- Trained classification model: required for automated scoring. See
|
|
59
|
+
Section 4 for details. These have .pth format.
|
|
60
|
+
|
|
61
|
+
# 3. Manually assigning brain state labels
|
|
62
|
+
1. Select the recording you wish to modify from the recording list, or
|
|
63
|
+
add a new one.
|
|
64
|
+
2. Click the "Select recording file" button to set the location of the
|
|
65
|
+
EEG/EMG data, or drag/drop the recording file into the box next
|
|
66
|
+
to the button.
|
|
67
|
+
3. Click the "Select" label file button (or drag/drop) to choose an
|
|
68
|
+
existing label file, or click the "create" label file button to
|
|
69
|
+
enter the filename for a new label file.
|
|
70
|
+
4. Click "Score manually" to launch an interactive window for manual
|
|
71
|
+
brain state scoring. When you are finished, save your changes and
|
|
72
|
+
close the window.
|
|
73
|
+
|
|
74
|
+
The manual scoring interface has many useful keyboard shortcuts,
|
|
75
|
+
so please consult its user manual by clicking the question mark icon.
|
|
76
|
+
|
|
77
|
+
# 4. Automatically scoring recordings with a classification model
|
|
78
|
+
Automatic brain state scoring requires the inputs described in
|
|
79
|
+
Section 3, as well as calibration data files and a trained classification
|
|
80
|
+
model.
|
|
81
|
+
If you already have all of these files, proceed to Section 4C.
|
|
82
|
+
Models trained on the AccuSleep dataset are provided at
|
|
83
|
+
https://osf.io/py5eb under /python_format/models/ for epoch lengths of
|
|
84
|
+
2.5, 4, 5, and 10 seconds. These models are the "default" type, in that
|
|
85
|
+
they use several epochs of data before and after any given epoch when
|
|
86
|
+
scoring that epoch. (The other model type, called "real-time", only
|
|
87
|
+
uses data from the current epoch and several preceding epochs.)
|
|
88
|
+
|
|
89
|
+
## 4A. Creating calibration data files
|
|
90
|
+
|
|
91
|
+
In order to perform automated sleep scoring,
|
|
92
|
+
each recording must have a calibration file assigned to it.
|
|
93
|
+
This file lets AccuSleep transform features of the EEG and EMG data so
|
|
94
|
+
that they are in the same range as the classifier's training data.
|
|
95
|
+
You can use the same calibration file for multiple recordings, as long
|
|
96
|
+
as they come from the same subject and were collected under the same
|
|
97
|
+
recording conditions (i.e., the same recording equipment was used).
|
|
98
|
+
|
|
99
|
+
To create a calibration data file:
|
|
100
|
+
|
|
101
|
+
1. Ensure you have a file containing brain state labels. You can create
|
|
102
|
+
this file by following the steps in Section 3, or select an
|
|
103
|
+
existing label file.
|
|
104
|
+
2. The label file must contain at least some labels for each sleep
|
|
105
|
+
stage (e.g., REM, wakefulness, and NREM). It is recommended to
|
|
106
|
+
label at least several minutes of each stage, and more labels can
|
|
107
|
+
improve classification accuracy.
|
|
108
|
+
3. Click "Create calibration file".
|
|
109
|
+
4. Enter a filename for the calibration data file.
|
|
110
|
+
5. The calibration file will automatically be assigned to the currently
|
|
111
|
+
selected recording.
|
|
112
|
+
|
|
113
|
+
Note that epoch length can affect the calibration process. If you make
|
|
114
|
+
a calibration file for a subject using one epoch length, but want to
|
|
115
|
+
score another recording from the same subject with a different epoch
|
|
116
|
+
length, it's best to create a new calibration file.
|
|
117
|
+
|
|
118
|
+
## 4B. Training your own classification model
|
|
119
|
+
|
|
120
|
+
To train a new model on your own data:
|
|
121
|
+
|
|
122
|
+
1. Add your scored recordings to the recording list. Make sure the
|
|
123
|
+
sampling rate, recording file, and label file are set for each
|
|
124
|
+
recording. Calibration files are not required.
|
|
125
|
+
2. Click the "Model training" tab
|
|
126
|
+
3. Choose the number of epochs to consider when scoring each epoch.
|
|
127
|
+
This will be the "width" of the training images. For "default"
|
|
128
|
+
type models, this must be an odd number. In general, about 30
|
|
129
|
+
seconds worth of data is enough.
|
|
130
|
+
4. Choose whether the images used to train the model should be
|
|
131
|
+
deleted once training is complete. It's generally best to
|
|
132
|
+
leave this box checked. A (temporary) folder for these files
|
|
133
|
+
will be created in the same location as the trained model.
|
|
134
|
+
5. Choose whether to create a "default" or "real-time"-type model.
|
|
135
|
+
Note that scoring recordings in the primary interface requires
|
|
136
|
+
a default-type model.
|
|
137
|
+
6. Choose whether to calibrate the model. This process uses part
|
|
138
|
+
of the training data to make the model's confidence scores
|
|
139
|
+
more accurately reflect the probability that the output
|
|
140
|
+
labels are accurate. If using calibration, choose what percent
|
|
141
|
+
of the training data to set aside for calibration.
|
|
142
|
+
7. Click "Train classification model" and enter a
|
|
143
|
+
filename for the trained model. Training can take some time.
|
|
144
|
+
The console will display progress updates.
|
|
145
|
+
|
|
146
|
+
## 4C. Automatic scoring
|
|
147
|
+
|
|
148
|
+
Instructions for automatic scoring using this interface are below.
|
|
149
|
+
|
|
150
|
+
1. Set the epoch length for all recordings.
|
|
151
|
+
2. Select the recording file, label file, and calibration file to use
|
|
152
|
+
for each recording. See section 4A for instructions on creating
|
|
153
|
+
calibration files.
|
|
154
|
+
3. Click "Load classification model" to load the trained classification
|
|
155
|
+
model. It's important that the epoch length used when training this
|
|
156
|
+
model is the same as the current epoch length.
|
|
157
|
+
4. If you wish to preserve any existing labels in the label file, and
|
|
158
|
+
only overwrite undefined epochs, check the box labeled
|
|
159
|
+
"Only overwrite undefined epochs".
|
|
160
|
+
5. Choose whether to save confidence scores to the label files.
|
|
161
|
+
6. Set the minimum bout length, in seconds. A typical value could be 5.
|
|
162
|
+
Following automatic labeling, any brain state bout shorter than this
|
|
163
|
+
duration will be reassigned to the surrounding state (if the states
|
|
164
|
+
on either side of the bout are the same).
|
|
165
|
+
7. Click "Score all automatically" to score all recordings in the
|
|
166
|
+
recording list. To inspect the results, select a recording
|
|
167
|
+
in the list and click "Score manually".
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Manual scoring interface
|
|
2
|
+
|
|
3
|
+
Keyboard shortcuts:
|
|
4
|
+
- Mouse click on the upper 3 plots: jump to epoch
|
|
5
|
+
- Ctrl + S: save labels to file
|
|
6
|
+
- Right / left arrow: move one epoch forward / backward in time
|
|
7
|
+
- Numbers 0-9: set current epoch to this brain state
|
|
8
|
+
- Backspace: set current epoch to the undefined state
|
|
9
|
+
- Ctrl + Z: undo last change to brain state labels
|
|
10
|
+
- Ctrl + Y: redo last change to brain state labels
|
|
11
|
+
- Shift + (number 0-9, or backspace):
|
|
12
|
+
After pressing this combination, click and drag on the upper plot of brain
|
|
13
|
+
state labels to set the selected epochs
|
|
14
|
+
to this brain state. Press Escape to cancel.
|
|
15
|
+
- Plus (+): zoom in (upper panel x-axis)
|
|
16
|
+
- Minus (-): zoom out (upper panel x-axis)
|
|
17
|
+
- Shift + right / left arrow: jump to the next / previous epoch with a different brain state
|
|
18
|
+
than the current epoch
|
|
19
|
+
- Spacebar: equivalent to shift + right arrow
|
|
20
|
+
- Ctrl + right / left arrow: jump to the next / preceding undefined epoch
|
|
21
|
+
- Ctrl + W: quit
|
|
22
|
+
|
|
23
|
+

|