misleep 0.3.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.
Files changed (94) hide show
  1. misleep/__init__.py +111 -0
  2. misleep/__main__.py +16 -0
  3. misleep/analysis/__init__.py +23 -0
  4. misleep/analysis/auto_stage.py +158 -0
  5. misleep/analysis/detection.py +198 -0
  6. misleep/analysis/features.py +131 -0
  7. misleep/analysis/models/P30_EEG_F_lightgbm.pkl +0 -0
  8. misleep/analysis/models/P30_EEG_P_lightgbm.pkl +0 -0
  9. misleep/analysis/models/__init__.py +0 -0
  10. misleep/analysis/models/ado_EEG_F_lightgbm.pkl +0 -0
  11. misleep/analysis/models/ado_EEG_P_lightgbm.pkl +0 -0
  12. misleep/analysis/models/adult_EEG_F_lightgbm.pkl +0 -0
  13. misleep/analysis/models/adult_EEG_P_lightgbm.pkl +0 -0
  14. misleep/analysis/transformer/__init__.py +46 -0
  15. misleep/analysis/transformer/checkpoints/CausalTransformer_best.pt +0 -0
  16. misleep/analysis/transformer/checkpoints/__init__.py +0 -0
  17. misleep/analysis/transformer/configs.py +52 -0
  18. misleep/analysis/transformer/data.py +362 -0
  19. misleep/analysis/transformer/inference.py +328 -0
  20. misleep/analysis/transformer/models.py +220 -0
  21. misleep/analysis/transformer/preprocessing.py +105 -0
  22. misleep/config/__init__.py +105 -0
  23. misleep/config/default_config.ini +38 -0
  24. misleep/data/__init__.py +13 -0
  25. misleep/data/annotation.py +114 -0
  26. misleep/data/midata.py +387 -0
  27. misleep/gui/__init__.py +23 -0
  28. misleep/gui/app.py +183 -0
  29. misleep/gui/config_dialog.py +429 -0
  30. misleep/gui/dialogs.py +1107 -0
  31. misleep/gui/event_filters.py +26 -0
  32. misleep/gui/main_window.py +2699 -0
  33. misleep/gui/qt_utils.py +277 -0
  34. misleep/gui/resources/__init__.py +9 -0
  35. misleep/gui/resources/entire_logo.png +0 -0
  36. misleep/gui/resources/logo.png +0 -0
  37. misleep/gui/resources/misleep.ico +0 -0
  38. misleep/gui/resources/misleep.qrc +7 -0
  39. misleep/gui/resources/misleep_rc.py +1324 -0
  40. misleep/gui/spec_window.py +187 -0
  41. misleep/gui/style.py +994 -0
  42. misleep/gui/uis/SWA_detect_dialog.ui +181 -0
  43. misleep/gui/uis/SWA_detect_dialog_ui.py +176 -0
  44. misleep/gui/uis/__init__.py +6 -0
  45. misleep/gui/uis/about.ui +88 -0
  46. misleep/gui/uis/about_ui.py +80 -0
  47. misleep/gui/uis/auto_stage_causalTransformer_dialog.ui +77 -0
  48. misleep/gui/uis/auto_stage_causalTransformer_dialog_ui.py +90 -0
  49. misleep/gui/uis/auto_stage_lightGBM_dialog.ui +124 -0
  50. misleep/gui/uis/auto_stage_lightGBM_dialog_ui.py +124 -0
  51. misleep/gui/uis/horizontal_line_dialog.ui +166 -0
  52. misleep/gui/uis/horizontal_line_dialog_ui.py +157 -0
  53. misleep/gui/uis/label_dialog.ui +65 -0
  54. misleep/gui/uis/label_dialog_ui.py +72 -0
  55. misleep/gui/uis/main_window.ui +871 -0
  56. misleep/gui/uis/main_window_ui.py +616 -0
  57. misleep/gui/uis/save_data_dialog.ui +95 -0
  58. misleep/gui/uis/save_data_dialog_ui.py +98 -0
  59. misleep/gui/uis/spec_window.ui +109 -0
  60. misleep/gui/uis/spec_window_ui.py +103 -0
  61. misleep/gui/uis/spindle_detect_dialog.ui +202 -0
  62. misleep/gui/uis/spindle_detect_dialog_ui.py +194 -0
  63. misleep/gui/uis/state_spectral_dialog.ui +240 -0
  64. misleep/gui/uis/state_spectral_dialog_ui.py +204 -0
  65. misleep/gui/uis/transfer_result_dialog.ui +104 -0
  66. misleep/gui/uis/transfer_result_dialog_ui.py +94 -0
  67. misleep/gui/workers.py +69 -0
  68. misleep/io/__init__.py +68 -0
  69. misleep/io/annotation.py +367 -0
  70. misleep/io/array.py +209 -0
  71. misleep/io/base.py +174 -0
  72. misleep/io/edf.py +109 -0
  73. misleep/io/mat.py +189 -0
  74. misleep/logger.py +79 -0
  75. misleep/preprocessing/__init__.py +23 -0
  76. misleep/preprocessing/artifacts.py +76 -0
  77. misleep/preprocessing/filtering.py +94 -0
  78. misleep/preprocessing/segment.py +59 -0
  79. misleep/preprocessing/spectral.py +169 -0
  80. misleep/utils/__init__.py +45 -0
  81. misleep/utils/annotation.py +130 -0
  82. misleep/utils/entropy.py +135 -0
  83. misleep/utils/misc.py +69 -0
  84. misleep/utils/time_utils.py +61 -0
  85. misleep/viz/__init__.py +12 -0
  86. misleep/viz/hypnogram.py +48 -0
  87. misleep/viz/signals.py +51 -0
  88. misleep/viz/spectral.py +98 -0
  89. misleep-0.3.0.dist-info/METADATA +249 -0
  90. misleep-0.3.0.dist-info/RECORD +94 -0
  91. misleep-0.3.0.dist-info/WHEEL +5 -0
  92. misleep-0.3.0.dist-info/entry_points.txt +15 -0
  93. misleep-0.3.0.dist-info/licenses/LICENSE +29 -0
  94. misleep-0.3.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,104 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ui version="4.0">
3
+ <class>TransferResultDialog</class>
4
+ <widget class="QDialog" name="TransferResultDialog">
5
+ <property name="geometry">
6
+ <rect>
7
+ <x>0</x>
8
+ <y>0</y>
9
+ <width>271</width>
10
+ <height>216</height>
11
+ </rect>
12
+ </property>
13
+ <property name="windowTitle">
14
+ <string>Dialog</string>
15
+ </property>
16
+ <property name="windowIcon">
17
+ <iconset resource="../resources/misleep.qrc">
18
+ <normaloff>:/logo/logo.png</normaloff>:/logo/logo.png</iconset>
19
+ </property>
20
+ <layout class="QGridLayout" name="gridLayout_2">
21
+ <item row="1" column="0">
22
+ <widget class="QPushButton" name="OKBt">
23
+ <property name="text">
24
+ <string>OK</string>
25
+ </property>
26
+ </widget>
27
+ </item>
28
+ <item row="1" column="1">
29
+ <widget class="QPushButton" name="CancelBt">
30
+ <property name="text">
31
+ <string>Cancel</string>
32
+ </property>
33
+ </widget>
34
+ </item>
35
+ <item row="0" column="0" colspan="2">
36
+ <widget class="QGroupBox" name="groupBox">
37
+ <property name="title">
38
+ <string>Transfer result options</string>
39
+ </property>
40
+ <layout class="QGridLayout" name="gridLayout">
41
+ <item row="3" column="0">
42
+ <widget class="QDateTimeEdit" name="TransferStartTimeEdit">
43
+ <property name="displayFormat">
44
+ <string>yyyy/MM/dd HH:mm:ss</string>
45
+ </property>
46
+ </widget>
47
+ </item>
48
+ <item row="0" column="0">
49
+ <widget class="QCheckBox" name="ResetTimeCheckBox">
50
+ <property name="text">
51
+ <string>Reset acquisition time</string>
52
+ </property>
53
+ </widget>
54
+ </item>
55
+ <item row="1" column="1">
56
+ <spacer name="horizontalSpacer">
57
+ <property name="orientation">
58
+ <enum>Qt::Horizontal</enum>
59
+ </property>
60
+ <property name="sizeHint" stdset="0">
61
+ <size>
62
+ <width>40</width>
63
+ <height>20</height>
64
+ </size>
65
+ </property>
66
+ </spacer>
67
+ </item>
68
+ <item row="1" column="0">
69
+ <widget class="QDateTimeEdit" name="ACTimeEditor">
70
+ <property name="displayFormat">
71
+ <string>yyyy/MM/dd HH:mm:ss</string>
72
+ </property>
73
+ </widget>
74
+ </item>
75
+ <item row="3" column="1">
76
+ <spacer name="horizontalSpacer_2">
77
+ <property name="orientation">
78
+ <enum>Qt::Horizontal</enum>
79
+ </property>
80
+ <property name="sizeHint" stdset="0">
81
+ <size>
82
+ <width>40</width>
83
+ <height>20</height>
84
+ </size>
85
+ </property>
86
+ </spacer>
87
+ </item>
88
+ <item row="2" column="0">
89
+ <widget class="QCheckBox" name="ResetTransferStartTimeCheckBox">
90
+ <property name="text">
91
+ <string>Reset transfer start time</string>
92
+ </property>
93
+ </widget>
94
+ </item>
95
+ </layout>
96
+ </widget>
97
+ </item>
98
+ </layout>
99
+ </widget>
100
+ <resources>
101
+ <include location="../resources/misleep.qrc"/>
102
+ </resources>
103
+ <connections/>
104
+ </ui>
@@ -0,0 +1,94 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ################################################################################
4
+ ## Form generated from reading UI file 'transfer_result_dialog.ui'
5
+ ##
6
+ ## Created by: Qt User Interface Compiler version 6.11.1
7
+ ##
8
+ ## WARNING! All changes made in this file will be lost when recompiling UI file!
9
+ ################################################################################
10
+
11
+ from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
12
+ QMetaObject, QObject, QPoint, QRect,
13
+ QSize, QTime, QUrl, Qt)
14
+ from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
15
+ QFont, QFontDatabase, QGradient, QIcon,
16
+ QImage, QKeySequence, QLinearGradient, QPainter,
17
+ QPalette, QPixmap, QRadialGradient, QTransform)
18
+ from PySide6.QtWidgets import (QApplication, QCheckBox, QDateTimeEdit, QDialog,
19
+ QGridLayout, QGroupBox, QPushButton, QSizePolicy,
20
+ QSpacerItem, QWidget)
21
+ from misleep.gui.resources import misleep_rc
22
+
23
+ class Ui_TransferResultDialog(object):
24
+ def setupUi(self, TransferResultDialog):
25
+ if not TransferResultDialog.objectName():
26
+ TransferResultDialog.setObjectName(u"TransferResultDialog")
27
+ TransferResultDialog.resize(271, 216)
28
+ icon = QIcon()
29
+ icon.addFile(u":/logo/logo.png", QSize(), QIcon.Mode.Normal, QIcon.State.Off)
30
+ TransferResultDialog.setWindowIcon(icon)
31
+ self.gridLayout_2 = QGridLayout(TransferResultDialog)
32
+ self.gridLayout_2.setObjectName(u"gridLayout_2")
33
+ self.OKBt = QPushButton(TransferResultDialog)
34
+ self.OKBt.setObjectName(u"OKBt")
35
+
36
+ self.gridLayout_2.addWidget(self.OKBt, 1, 0, 1, 1)
37
+
38
+ self.CancelBt = QPushButton(TransferResultDialog)
39
+ self.CancelBt.setObjectName(u"CancelBt")
40
+
41
+ self.gridLayout_2.addWidget(self.CancelBt, 1, 1, 1, 1)
42
+
43
+ self.groupBox = QGroupBox(TransferResultDialog)
44
+ self.groupBox.setObjectName(u"groupBox")
45
+ self.gridLayout = QGridLayout(self.groupBox)
46
+ self.gridLayout.setObjectName(u"gridLayout")
47
+ self.TransferStartTimeEdit = QDateTimeEdit(self.groupBox)
48
+ self.TransferStartTimeEdit.setObjectName(u"TransferStartTimeEdit")
49
+
50
+ self.gridLayout.addWidget(self.TransferStartTimeEdit, 3, 0, 1, 1)
51
+
52
+ self.ResetTimeCheckBox = QCheckBox(self.groupBox)
53
+ self.ResetTimeCheckBox.setObjectName(u"ResetTimeCheckBox")
54
+
55
+ self.gridLayout.addWidget(self.ResetTimeCheckBox, 0, 0, 1, 1)
56
+
57
+ self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)
58
+
59
+ self.gridLayout.addItem(self.horizontalSpacer, 1, 1, 1, 1)
60
+
61
+ self.ACTimeEditor = QDateTimeEdit(self.groupBox)
62
+ self.ACTimeEditor.setObjectName(u"ACTimeEditor")
63
+
64
+ self.gridLayout.addWidget(self.ACTimeEditor, 1, 0, 1, 1)
65
+
66
+ self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)
67
+
68
+ self.gridLayout.addItem(self.horizontalSpacer_2, 3, 1, 1, 1)
69
+
70
+ self.ResetTransferStartTimeCheckBox = QCheckBox(self.groupBox)
71
+ self.ResetTransferStartTimeCheckBox.setObjectName(u"ResetTransferStartTimeCheckBox")
72
+
73
+ self.gridLayout.addWidget(self.ResetTransferStartTimeCheckBox, 2, 0, 1, 1)
74
+
75
+
76
+ self.gridLayout_2.addWidget(self.groupBox, 0, 0, 1, 2)
77
+
78
+
79
+ self.retranslateUi(TransferResultDialog)
80
+
81
+ QMetaObject.connectSlotsByName(TransferResultDialog)
82
+ # setupUi
83
+
84
+ def retranslateUi(self, TransferResultDialog):
85
+ TransferResultDialog.setWindowTitle(QCoreApplication.translate("TransferResultDialog", u"Dialog", None))
86
+ self.OKBt.setText(QCoreApplication.translate("TransferResultDialog", u"OK", None))
87
+ self.CancelBt.setText(QCoreApplication.translate("TransferResultDialog", u"Cancel", None))
88
+ self.groupBox.setTitle(QCoreApplication.translate("TransferResultDialog", u"Transfer result options", None))
89
+ self.TransferStartTimeEdit.setDisplayFormat(QCoreApplication.translate("TransferResultDialog", u"yyyy/MM/dd HH:mm:ss", None))
90
+ self.ResetTimeCheckBox.setText(QCoreApplication.translate("TransferResultDialog", u"Reset acquisition time", None))
91
+ self.ACTimeEditor.setDisplayFormat(QCoreApplication.translate("TransferResultDialog", u"yyyy/MM/dd HH:mm:ss", None))
92
+ self.ResetTransferStartTimeCheckBox.setText(QCoreApplication.translate("TransferResultDialog", u"Reset transfer start time", None))
93
+ # retranslateUi
94
+
misleep/gui/workers.py ADDED
@@ -0,0 +1,69 @@
1
+ # -*- coding: UTF-8 -*-
2
+ """Background worker threads for the GUI.
3
+
4
+ These QThread subclasses keep file I/O off the UI thread so the interface
5
+ stays responsive while saving large files.
6
+ """
7
+
8
+ from PySide6.QtCore import QThread
9
+
10
+ from misleep.io.annotation import save_misleep_anno
11
+ from misleep.io.base import write_signal
12
+ from misleep.io.mat import load_mat
13
+
14
+
15
+ class SaveThread(QThread):
16
+ """Save files (annotation, data, configuration) in a background thread.
17
+
18
+ Parameters
19
+ ----------
20
+ parent : QObject, optional
21
+ file : ANY, optional
22
+ Object to save: a ``[mianno, midata]`` pair for annotations, a
23
+ ``MiData`` for data, or a ConfigParser for configuration.
24
+ file_path : str, optional
25
+ Destination path.
26
+ """
27
+
28
+ def __init__(self, parent=None, file=None, file_path=None):
29
+ super().__init__(parent)
30
+ self.file = file
31
+ self.file_path = file_path
32
+
33
+ def save_config(self):
34
+ """Save a ConfigParser to ``self.file_path``."""
35
+ with open(self.file_path, "w", encoding="utf-8") as config_file:
36
+ self.file.write(config_file)
37
+
38
+ def save_anno(self):
39
+ """Save an annotation; ``self.file`` must be ``[mianno, midata]``."""
40
+ mianno, midata = self.file
41
+ return save_misleep_anno(mianno, midata, self.file_path)
42
+
43
+ def save_data(self):
44
+ """Save a :class:`MiData` through the registered format writer."""
45
+ midata = self.file
46
+ if midata is None:
47
+ return False
48
+
49
+ write_signal(midata, self.file_path)
50
+ return True
51
+
52
+
53
+ class LoadThread(QThread):
54
+ """Load data in a background thread.
55
+
56
+ Parameters
57
+ ----------
58
+ parent : QObject, optional
59
+ file_path : str, optional
60
+ File to load.
61
+ """
62
+
63
+ def __init__(self, parent=None, file_path=None):
64
+ super().__init__(parent)
65
+ self.file_path = file_path
66
+
67
+ def load_mat_data(self):
68
+ """Load data from a ``.mat`` file."""
69
+ return load_mat(data_path=self.file_path)
misleep/io/__init__.py ADDED
@@ -0,0 +1,68 @@
1
+ # -*- coding: UTF-8 -*-
2
+ """Input/output module.
3
+
4
+ Public API:
5
+
6
+ * :func:`misleep.io.mat.load_mat` / :func:`misleep.io.mat.write_mat`
7
+ * :func:`misleep.io.edf.load_edf` / :func:`misleep.io.edf.write_edf`
8
+ * :func:`misleep.io.annotation.load_misleep_anno` / ``save_misleep_anno``
9
+ * :func:`misleep.io.annotation.transfer_result`
10
+ * :func:`misleep.io.base.load_signal` / ``write_signal`` -- extension dispatch
11
+ """
12
+
13
+ from .base import (
14
+ MiData,
15
+ MiAnnotation,
16
+ register_signal_reader,
17
+ register_signal_writer,
18
+ load_signal,
19
+ write_signal,
20
+ available_readers,
21
+ available_writers,
22
+ )
23
+ from .mat import load_mat, write_mat
24
+ from .edf import load_edf, write_edf
25
+ from .array import load_npy, load_npz, load_csv, load_tsv, write_npz
26
+ from .annotation import (
27
+ available_annotation_readers,
28
+ load_annotation,
29
+ load_bio_anno,
30
+ load_json_anno,
31
+ load_misleep_anno,
32
+ load_table_anno,
33
+ save_misleep_anno,
34
+ transfer_result,
35
+ )
36
+
37
+ # Register built-in formats
38
+ from . import mat as _mat # noqa: F401 (triggers register_signal_*)
39
+ from . import edf as _edf # noqa: F401
40
+ from . import array as _array # noqa: F401
41
+
42
+ __all__ = [
43
+ "MiData",
44
+ "MiAnnotation",
45
+ "load_mat",
46
+ "write_mat",
47
+ "load_edf",
48
+ "write_edf",
49
+ "load_npy",
50
+ "load_npz",
51
+ "load_csv",
52
+ "load_tsv",
53
+ "write_npz",
54
+ "load_misleep_anno",
55
+ "save_misleep_anno",
56
+ "load_bio_anno",
57
+ "transfer_result",
58
+ "load_annotation",
59
+ "load_json_anno",
60
+ "load_table_anno",
61
+ "available_annotation_readers",
62
+ "load_signal",
63
+ "write_signal",
64
+ "register_signal_reader",
65
+ "register_signal_writer",
66
+ "available_readers",
67
+ "available_writers",
68
+ ]