accusleepy 0.1.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.
@@ -0,0 +1,24 @@
1
+ This is the current brain state configuration.
2
+
3
+ Each brain state has several attributes:
4
+
5
+ - Digit: how the brain state is represented in label files,
6
+ and the key on the keyboard that, during manual scoring,
7
+ sets an epoch to this brain state.
8
+
9
+ - Enabled: whether a brain state for this digit exists.
10
+
11
+ - Name: unique name of the brain state (e.g., REM).
12
+
13
+ - Scored: whether a classification model should output this
14
+ brain state. If you have a state that corresponds to
15
+ missing or corrupted data, for example, you would
16
+ probably want to uncheck this box.
17
+
18
+ - Frequency: approximate relative frequency of this brain
19
+ state. Does not need to be very accurate, but it can
20
+ influence classification accuracy slightly. The values
21
+ for all scored brain states must sum to 1.
22
+
23
+ Note that changing these settings can invalidate existing
24
+ label files, calibration files, and trained models!
@@ -0,0 +1,142 @@
1
+ Section 1: Overview of the GUI
2
+ Section 2: AccuSleePy file types
3
+ Section 3: Manually assigning brain state labels
4
+ Section 4: Automatically assigning brain state labels
5
+
6
+ -----------------------------------------------------------------------
7
+ Section 1: Overview of the primary interface
8
+ -----------------------------------------------------------------------
9
+ This interface allows a user to assign brain state labels to 1-channel
10
+ electroencephalogram (EEG) and electromyogram (EMG) data.
11
+ The overall workflow looks like this:
12
+ 1. Enter the epoch length for all recordings. This determines the time
13
+ resolution of the brain state labels.
14
+ 2. For each of your recordings, add to the recording list, enter its
15
+ sampling rate, load the EEG/EMG data, and determine where to save
16
+ the brain state labels (or load the labels if they already exist)
17
+ At this point, you can score the recordings manually.
18
+ 3. For each recording, create a calibration file using a small amount
19
+ of labeled data, or choose a calibration file created using
20
+ another recording from the same subject and under the same recording
21
+ conditions (i.e., equipment)
22
+ 4. Choose a trained classification model file with a matching epoch size
23
+ 5. Score all recordings automatically using the classifier
24
+
25
+ By default, there are three brain state options: REM, wake, and NREM.
26
+ If you want to change this configuration, click the "Settings" tab.
27
+ Note that if you change the configuration, you might be unable to load
28
+ existing labels and calibration data, and you may need to train a new
29
+ classification model.
30
+
31
+ Use the "import" and "export" buttons to load or save a list of
32
+ recordings. This can be useful if you need to re-score a set of
33
+ recordings with a different model, or if you want to keep a record of
34
+ the recordings that were used when training your model.
35
+
36
+ -----------------------------------------------------------------------
37
+ Section 2: AccuSleePy file types
38
+ -----------------------------------------------------------------------
39
+ There are four types of files associated with AccuSleePy.
40
+ To select a file in the primary interface, you can either use the
41
+ associated button, or drag/drop the file into the empty box adjacent
42
+ to the button.
43
+ Recording file: a .csv or .parquet file containing one column of EEG
44
+ data and one column of EMG data. The column names must match the
45
+ ones listed in constants.py (EEG_COL, EMG_COL).
46
+ Label file: a .csv file with one column whose title matches
47
+ BRAIN_STATE_COL in config.py, with entries that are either the
48
+ undefined brain state (UNDEFINED_LABEL) or one of the valid
49
+ "digit" attributes of your brain states. By default, these are 1-3
50
+ and REM = 1, wake = 2, NREM = 3.
51
+ Calibration data file: required for automatic labeling. See Section 4
52
+ for details.
53
+ Trained classification model: required for automatic labeling. See
54
+ Section 4 for details.
55
+
56
+ -----------------------------------------------------------------------
57
+ Section 3: Manually assigning brain state labels
58
+ -----------------------------------------------------------------------
59
+ 1. Select the recording you wish to modify from the recording list, or
60
+ add a new one.
61
+ 2. Click the 'Select recording file' button to set the location of the
62
+ EEG/EMG data, or drag/drop the recording file into the box next
63
+ to the button.
64
+ 3. Click the 'Select' label file button (or drag/drop) to choose an
65
+ existing label file, or click the 'create' label file button to
66
+ enter the filename for a new label file.
67
+ 4. Click 'Score manually' to launch an interactive window for manual
68
+ brain state labeling. Close the window when you are finished.
69
+ This interface has many useful keyboard shortcuts, so it's recommended
70
+ to consult its user manual.
71
+
72
+ -----------------------------------------------------------------------
73
+ Section 4: Automatically scoring recordings with a classification model
74
+ -----------------------------------------------------------------------
75
+ Automatic brain state scoring requires the inputs described in
76
+ Section 3, as well as calibration data files and a trained classifier.
77
+ If you already have all of these files, proceed to Section 4C.
78
+
79
+ --- Section 4A: Creating calibration data files ---
80
+ Each recording must have a calibration file assigned to it.
81
+ This file lets AccuSleep transform features of the EEG and EMG data so
82
+ that they are in the same range as the classifier's training data.
83
+ You can use the same calibration file for multiple recordings, as long
84
+ as they come from the same subject and were collected under the same
85
+ recording conditions (i.e., the same recording equipment was used).
86
+ To create a calibration data file:
87
+ 1. Ensure you have a file containing brain state labels. You can create
88
+ this file by following the steps in Section 3, or select an
89
+ existing label file.
90
+ 2. The label file must contain at least some labels for each sleep
91
+ stage (e.g., REM, wakefulness, and NREM). It is recommended to
92
+ label at least several minutes of each stage, and more labels can
93
+ improve classification accuracy.
94
+ 3. Click 'Create calibration file'.
95
+ 4. Enter a filename for the calibration data file.
96
+ 5. The calibration file will automatically be assigned to the currently
97
+ selected recording.
98
+
99
+ --- Section 4B: Training your own classification model ---
100
+ Pre-trained classification models are provided with AccuSleePy for
101
+ epoch lengths of 2.5, 4, 5, and 10 seconds. These models are the
102
+ "default" type, in that they use several epochs of data before and
103
+ after any given epoch when scoring that epoch. (The other model type,
104
+ called "real-time", only uses data from the current epoch and several
105
+ preceding epochs.
106
+ To train a new model on your own data:
107
+ 1. Add your scored recordings to the recording list. Make sure the
108
+ sampling rate, recording file, and label file are set for each
109
+ recording.
110
+ 2. Click the "Model training" tab
111
+ 3. Choose the number of epochs to consider when scoring each epoch.
112
+ This will be the "width" of the training images. For "default"
113
+ type models, this must be an odd number. In general, about 30
114
+ seconds worth of data is enough.
115
+ 4. Choose whether the images used to train the model should be
116
+ deleted once training is complete.
117
+ 5. Select a directory where the training images will be saved. A
118
+ new directory with an automatically generated name will be
119
+ created inside the directory you choose.
120
+ 6. Click the "Train classification model" button and enter a
121
+ filename for the trained model. Training can take some time.
122
+
123
+ --- Section 4C: Automatic labeling ---
124
+ Instructions for automatic labeling using this GUI are below.
125
+ 1. Set the epoch length for all recordings.
126
+ 2. Select the recording file, label file, and calibration file to use
127
+ for each recording. See section 4A for instructions on creating
128
+ calibration files.
129
+ 3. Click 'Load classification model' to load the trained classification
130
+ model. The epoch length used when training this network should be
131
+ the same as the current epoch length.
132
+ 4. If you wish to preserve any existing labels in the label file, and
133
+ only overwrite undefined epochs, check the box labeled
134
+ 'Only overwrite undefined epochs'.
135
+ 5. Set the minimum bout length, in seconds. A typical value could be 5.
136
+ Following automatic labeling, any brain state bout shorter than this
137
+ duration will be reassigned to the surrounding stage (if the stages
138
+ on either side of the bout match).
139
+ 6. Click 'Score all automatically' to score all recordings in the
140
+ recording list. Labels will be saved to the file specified by
141
+ the 'Select or create label file' field of each recording. You can
142
+ click 'Score manually' to visualize the results.
@@ -0,0 +1,28 @@
1
+ The lower panel shows a zoomed-in subset of the epochs shown in the upper panel.
2
+ The red diamond in the upper panel and the red lines in the lower panel
3
+ mark the currently selected epoch.
4
+ The red horizontal line in the upper panel indicates the epochs shown in the lower panel.
5
+ Click a location on the upper panel to jump to that epoch.
6
+ The buttons next to the spectrogram control the zoom level and intensity.
7
+ The buttons next to the EEG and EMG plots control the zoom level and y-axis offset.
8
+ If "auto-scroll" is enabled, modifying the brain state of the current epoch
9
+ will automatically select the next epoch.
10
+
11
+ Keyboard shortcuts:
12
+ Ctrl + S: save labels to file
13
+ Right arrow: move one epoch forward in time
14
+ Left arrow: move one epoch backward in time
15
+ Numbers 0-9: set current epoch to this brain state
16
+ Backspace: set current epoch to undefined
17
+ Ctrl + Z: undo last change to brain state labels
18
+ Ctrl + Y: redo last change to brain state labels
19
+ Shift + (number 0-9, or backspace):
20
+ Click and drag on the upper plot of brain state labels to set the selected epochs
21
+ to the desired brain state. Press Esc to cancel.
22
+ +: zoom in (upper panel x-axis)
23
+ -: zoom out (upper panel x-axis)
24
+ Shift + right arrow, or space: jump to the next epoch of a different state
25
+ than the current epoch
26
+ Shift + left arrow: jump to the preceding epoch of a different state than the current epoch
27
+ Ctrl + right/left arrow: jump to the next/preceding undefined epoch
28
+ Ctrl + W: quit