physioex 1.0.0.dev4__tar.gz → 1.0.5__tar.gz

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 (162) hide show
  1. physioex-1.0.5/PKG-INFO +156 -0
  2. physioex-1.0.5/README.md +89 -0
  3. {physioex-1.0.0.dev4/docs/api → physioex-1.0.5/physioex}/__init__.py +0 -0
  4. physioex-1.0.5/physioex/data/datamodule.py +109 -0
  5. physioex-1.0.5/physioex/data/datareader.py +455 -0
  6. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/data/dataset.py +4 -2
  7. {physioex-1.0.0.dev4/physioex → physioex-1.0.5/physioex/preprocess}/__init__.py +0 -0
  8. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/preprocess/bin/main.py +32 -20
  9. physioex-1.0.0.dev4/physioex/preprocess/mros.py → physioex-1.0.5/physioex/preprocess/hpap.py +12 -17
  10. physioex-1.0.5/physioex/preprocess/kornum.py +149 -0
  11. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/preprocess/mesa.py +2 -3
  12. physioex-1.0.5/physioex/preprocess/mros.py +118 -0
  13. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/preprocess/preprocessor.py +5 -9
  14. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/preprocess/shhs.py +55 -33
  15. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/preprocess/sleepedf.py +49 -27
  16. physioex-1.0.5/physioex/preprocess/utils/mousedata.py +211 -0
  17. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/preprocess/utils/signal.py +17 -9
  18. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/preprocess/utils/sleepdata.py +4 -2
  19. physioex-1.0.5/physioex/preprocess/wsc.py +306 -0
  20. {physioex-1.0.0.dev4/physioex/preprocess/.future/dreem → physioex-1.0.5/physioex/train/bin}/__init__.py +0 -0
  21. physioex-1.0.5/physioex/train/bin/dist_train.py +100 -0
  22. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/bin/finetune.py +3 -0
  23. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/bin/parser.py +41 -12
  24. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/bin/test.py +5 -0
  25. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/bin/train.py +6 -0
  26. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/models/load.py +12 -2
  27. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/networks/__init__.py +3 -4
  28. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/networks/base.py +38 -21
  29. physioex-1.0.5/physioex/train/networks/prototype.py +263 -0
  30. physioex-1.0.5/physioex/train/networks/seqsexnet.py +412 -0
  31. physioex-1.0.5/physioex/train/networks/sleeptransformer.py +248 -0
  32. physioex-1.0.5/physioex/train/networks/utils/layers.py +158 -0
  33. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/networks/utils/loss.py +33 -7
  34. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/utils/test.py +27 -5
  35. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/utils/train.py +48 -32
  36. physioex-1.0.5/physioex.egg-info/PKG-INFO +156 -0
  37. physioex-1.0.5/physioex.egg-info/SOURCES.txt +57 -0
  38. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex.egg-info/requires.txt +2 -0
  39. {physioex-1.0.0.dev4 → physioex-1.0.5}/pyproject.toml +4 -2
  40. physioex-1.0.5/setup.py +40 -0
  41. physioex-1.0.0.dev4/.DS_Store +0 -0
  42. physioex-1.0.0.dev4/.github/workflows/black.yml +0 -15
  43. physioex-1.0.0.dev4/.github/workflows/ci.yml +0 -44
  44. physioex-1.0.0.dev4/.gitignore +0 -184
  45. physioex-1.0.0.dev4/PKG-INFO +0 -124
  46. physioex-1.0.0.dev4/README.md +0 -60
  47. physioex-1.0.0.dev4/docs/api/bin.py +0 -251
  48. physioex-1.0.0.dev4/docs/api/concept_learning.py +0 -0
  49. physioex-1.0.0.dev4/docs/api/data.py +0 -162
  50. physioex-1.0.0.dev4/docs/api/network.py +0 -132
  51. physioex-1.0.0.dev4/docs/api/preprocessor.py +0 -80
  52. physioex-1.0.0.dev4/docs/api/train.py +0 -92
  53. physioex-1.0.0.dev4/docs/assets/images/data/sequence_viz.png +0 -0
  54. physioex-1.0.0.dev4/docs/assets/images/logo.psd +0 -0
  55. physioex-1.0.0.dev4/docs/assets/images/logo.svg +0 -9
  56. physioex-1.0.0.dev4/docs/assets/images/logo_bar.svg +0 -11
  57. physioex-1.0.0.dev4/docs/css/custom.css +0 -12
  58. physioex-1.0.0.dev4/docs/examples/latent_space_visualization.md +0 -301
  59. physioex-1.0.0.dev4/docs/examples/latent_space_visualization_files/latent_space_visualization_11_1.png +0 -0
  60. physioex-1.0.0.dev4/docs/examples/latent_space_visualization_files/latent_space_visualization_12_1.png +0 -0
  61. physioex-1.0.0.dev4/docs/examples/latent_space_visualization_files/latent_space_visualization_6_0.png +0 -0
  62. physioex-1.0.0.dev4/docs/examples/latent_space_visualization_files/latent_space_visualization_8_1.png +0 -0
  63. physioex-1.0.0.dev4/docs/index.md +0 -60
  64. physioex-1.0.0.dev4/docs/javascript/extra.js +0 -1
  65. physioex-1.0.0.dev4/docs/pages/contribute.md +0 -81
  66. physioex-1.0.0.dev4/docs/pages/data.md +0 -138
  67. physioex-1.0.0.dev4/docs/pages/preprocess.md +0 -289
  68. physioex-1.0.0.dev4/docs/pages/train/cli.md +0 -34
  69. physioex-1.0.0.dev4/docs/pages/train/networks/chambon2018.md +0 -24
  70. physioex-1.0.0.dev4/docs/pages/train/networks.md +0 -79
  71. physioex-1.0.0.dev4/docs/pages/train/train.md +0 -171
  72. physioex-1.0.0.dev4/docs/pages/unavailable.md +0 -1
  73. physioex-1.0.0.dev4/docs/stylesheets/extra.css +0 -3
  74. physioex-1.0.0.dev4/examples/basic_usage.ipynb +0 -1040
  75. physioex-1.0.0.dev4/examples/spectral_gradients.ipynb +0 -572
  76. physioex-1.0.0.dev4/examples/tesi_sostegni.ipynb +0 -332
  77. physioex-1.0.0.dev4/examples/utils.py +0 -24
  78. physioex-1.0.0.dev4/examples/visualize_data.ipynb +0 -143
  79. physioex-1.0.0.dev4/mkdocs.yml +0 -102
  80. physioex-1.0.0.dev4/physioex/data/datamodule.py +0 -108
  81. physioex-1.0.0.dev4/physioex/data/datareader.py +0 -242
  82. physioex-1.0.0.dev4/physioex/explain/ari_explainer.py +0 -260
  83. physioex-1.0.0.dev4/physioex/explain/base.py +0 -71
  84. physioex-1.0.0.dev4/physioex/explain/freq_bands_explainer.py +0 -865
  85. physioex-1.0.0.dev4/physioex/explain/metrics/__init__.py +0 -2
  86. physioex-1.0.0.dev4/physioex/explain/metrics/base.py +0 -0
  87. physioex-1.0.0.dev4/physioex/explain/metrics/infidelity.py +0 -130
  88. physioex-1.0.0.dev4/physioex/explain/metrics/sensitivity.py +0 -0
  89. physioex-1.0.0.dev4/physioex/explain/spectralgradients/__init__.py +0 -3
  90. physioex-1.0.0.dev4/physioex/explain/spectralgradients/explainer.py +0 -198
  91. physioex-1.0.0.dev4/physioex/explain/spectralgradients/importance.py +0 -203
  92. physioex-1.0.0.dev4/physioex/explain/spectralgradients/spectral_gradients.py +0 -111
  93. physioex-1.0.0.dev4/physioex/explain/spectralgradients/utils.py +0 -19
  94. physioex-1.0.0.dev4/physioex/explain/spectralgradients/viz.py +0 -249
  95. physioex-1.0.0.dev4/physioex/preprocess/.future/cap/preprocessing.py +0 -226
  96. physioex-1.0.0.dev4/physioex/preprocess/.future/config/create_dreem.py +0 -55
  97. physioex-1.0.0.dev4/physioex/preprocess/.future/config/dreem.yaml +0 -899
  98. physioex-1.0.0.dev4/physioex/preprocess/.future/config/mit-bih.yaml +0 -71
  99. physioex-1.0.0.dev4/physioex/preprocess/.future/config/sleep-edf.yaml +0 -40
  100. physioex-1.0.0.dev4/physioex/preprocess/.future/dreem/dreem.py +0 -54
  101. physioex-1.0.0.dev4/physioex/preprocess/.future/dreem/preprocess.py +0 -158
  102. physioex-1.0.0.dev4/physioex/preprocess/.future/dreem/utils.py +0 -59
  103. physioex-1.0.0.dev4/physioex/preprocess/.future/isruc/isruc.py +0 -52
  104. physioex-1.0.0.dev4/physioex/preprocess/.future/isruc/preprocess.py +0 -231
  105. physioex-1.0.0.dev4/physioex/preprocess/.future/mitdb.py +0 -236
  106. physioex-1.0.0.dev4/physioex/preprocess/.future/physio2018/checksum.csv +0 -2982
  107. physioex-1.0.0.dev4/physioex/preprocess/.future/physio2018/download.py +0 -147
  108. physioex-1.0.0.dev4/physioex/preprocess/.future/physio2018/physio2018.py +0 -53
  109. physioex-1.0.0.dev4/physioex/preprocess/.future/physio2018/preprocess.py +0 -158
  110. physioex-1.0.0.dev4/physioex/preprocess/.future/sleep_edf/constant.py +0 -95
  111. physioex-1.0.0.dev4/physioex/preprocess/.future/sleep_edf/preprocess.py +0 -162
  112. physioex-1.0.0.dev4/physioex/preprocess/.future/sleep_edf/sleep_edf.py +0 -52
  113. physioex-1.0.0.dev4/physioex/preprocess/.future/sleep_edf/subjects.xls +0 -0
  114. physioex-1.0.0.dev4/physioex/preprocess/.future/svuh/constant.py +0 -6
  115. physioex-1.0.0.dev4/physioex/preprocess/.future/svuh/preprocess.py +0 -222
  116. physioex-1.0.0.dev4/physioex/preprocess/.future/svuh/svuh.py +0 -54
  117. physioex-1.0.0.dev4/physioex/preprocess/__init__.py +0 -0
  118. physioex-1.0.0.dev4/physioex/train/bin/__init__.py +0 -0
  119. physioex-1.0.0.dev4/physioex/train/models/backup/chambon-EEG-EOG-EMG-L=21-test_acc=0.867.ckpt +0 -0
  120. physioex-1.0.0.dev4/physioex/train/models/backup/chambon-EEG-L=21-test_acc=0.843.ckpt +0 -0
  121. physioex-1.0.0.dev4/physioex/train/models/backup/seqsleepnet-EEG-EOG-EMG-L=21-test_acc=0.877.ckpt +0 -0
  122. physioex-1.0.0.dev4/physioex/train/models/backup/seqsleepnet-EEG-L=21-test_acc=0.864.ckpt +0 -0
  123. physioex-1.0.0.dev4/physioex/train/models/backup/tiny-EEG-EOG-EMG-L=21-test_acc=0.885.ckpt +0 -0
  124. physioex-1.0.0.dev4/physioex/train/models/backup/tiny-EEG-L=21-test_acc=0.871.ckpt +0 -0
  125. physioex-1.0.0.dev4/physioex/train/models/check_table.csv +0 -7
  126. physioex-1.0.0.dev4/physioex/train/models/checkpoints/chambon-EEG-EOG-EMG-L=21-test_acc=0.867.ckpt +0 -0
  127. physioex-1.0.0.dev4/physioex/train/models/checkpoints/chambon-EEG-L=21-test_acc=0.843.ckpt +0 -0
  128. physioex-1.0.0.dev4/physioex/train/models/checkpoints/seqsleepnet-EEG-EOG-EMG-L=21-test_acc=0.877.ckpt +0 -0
  129. physioex-1.0.0.dev4/physioex/train/models/checkpoints/seqsleepnet-EEG-L=21-test_acc=0.864.ckpt +0 -0
  130. physioex-1.0.0.dev4/physioex/train/models/checkpoints/tiny-EEG-EOG-EMG-L=21-test_acc=0.885.ckpt +0 -0
  131. physioex-1.0.0.dev4/physioex/train/models/checkpoints/tiny-EEG-L=21-test_acc=0.871.ckpt +0 -0
  132. physioex-1.0.0.dev4/physioex/train/networks/config/chambon2018.yaml +0 -11
  133. physioex-1.0.0.dev4/physioex/train/networks/config/finetuned.yaml +0 -2
  134. physioex-1.0.0.dev4/physioex/train/networks/config/multisource.yaml +0 -2
  135. physioex-1.0.0.dev4/physioex/train/networks/config/seqecgnet.yaml +0 -12
  136. physioex-1.0.0.dev4/physioex/train/networks/config/seqsleepnet.yaml +0 -22
  137. physioex-1.0.0.dev4/physioex/train/networks/config/sleeptransformer.yaml +0 -22
  138. physioex-1.0.0.dev4/physioex/train/networks/config/tinysleepnet.yaml +0 -22
  139. physioex-1.0.0.dev4/physioex/train/networks/config.yaml +0 -34
  140. physioex-1.0.0.dev4/physioex/train/networks/utils/filterbank_shape.py +0 -107
  141. physioex-1.0.0.dev4/physioex.egg-info/PKG-INFO +0 -124
  142. physioex-1.0.0.dev4/physioex.egg-info/SOURCES.txt +0 -144
  143. physioex-1.0.0.dev4/requirements.txt +0 -31
  144. {physioex-1.0.0.dev4 → physioex-1.0.5}/LICENSE +0 -0
  145. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/data/__init__.py +0 -0
  146. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/explain/__init__.py +0 -0
  147. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/preprocess/bin/compress_datasets.py +0 -0
  148. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/preprocess/dcsm.py +0 -0
  149. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/preprocess/hmc.py +0 -0
  150. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/preprocess/mass.py +0 -0
  151. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/__init__.py +0 -0
  152. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/models/__init__.py +0 -0
  153. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/networks/chambon2018.py +0 -0
  154. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/networks/seqsleepnet.py +0 -0
  155. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/networks/tinysleepnet.py +0 -0
  156. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/networks/utils/target_transform.py +0 -0
  157. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/utils/__init__.py +0 -0
  158. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex/train/utils/finetune.py +0 -0
  159. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex.egg-info/dependency_links.txt +0 -0
  160. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex.egg-info/entry_points.txt +0 -0
  161. {physioex-1.0.0.dev4 → physioex-1.0.5}/physioex.egg-info/top_level.txt +0 -0
  162. {physioex-1.0.0.dev4 → physioex-1.0.5}/setup.cfg +0 -0
@@ -0,0 +1,156 @@
1
+ Metadata-Version: 2.4
2
+ Name: physioex
3
+ Version: 1.0.5
4
+ Summary: A python package for explainable sleep staging via deep learning
5
+ Author-email: Guido Gagliardi <guido.gagliardi@phd.unipi.it>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2023 Guido Gagliardi
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/guidogagl/physioex
29
+ Project-URL: Documentation, https://guidogagl.github.io/physioex
30
+ Project-URL: Repository, https://github.com/guidogagl/physioex
31
+ Project-URL: Issues, https://github.com/guidogagl/physioex/issues
32
+ Description-Content-Type: text/markdown
33
+ License-File: LICENSE
34
+ Requires-Dist: tensorboard
35
+ Requires-Dist: boto3
36
+ Requires-Dist: botocore
37
+ Requires-Dist: braindecode
38
+ Requires-Dist: captum
39
+ Requires-Dist: dirhash
40
+ Requires-Dist: h5py
41
+ Requires-Dist: joblib
42
+ Requires-Dist: lightning
43
+ Requires-Dist: loguru
44
+ Requires-Dist: matplotlib
45
+ Requires-Dist: npy_append_array
46
+ Requires-Dist: numpy
47
+ Requires-Dist: pandas
48
+ Requires-Dist: paramiko
49
+ Requires-Dist: psg_utils
50
+ Requires-Dist: pyEDFlib
51
+ Requires-Dist: pytorch_lightning
52
+ Requires-Dist: pytorch_metric_learning
53
+ Requires-Dist: pyunpack
54
+ Requires-Dist: PyYAML
55
+ Requires-Dist: rarfile
56
+ Requires-Dist: requests
57
+ Requires-Dist: scikit_learn
58
+ Requires-Dist: scipy
59
+ Requires-Dist: seaborn
60
+ Requires-Dist: setuptools
61
+ Requires-Dist: torch
62
+ Requires-Dist: torchmetrics
63
+ Requires-Dist: tqdm
64
+ Requires-Dist: wfdb
65
+ Requires-Dist: gdown
66
+ Dynamic: license-file
67
+
68
+ <div style = "text-align: center;">
69
+ <img src="https://raw.githubusercontent.com/guidogagl/physioex/refs/heads/main/docs/assets/images/logo.svg" width = "250px", alt="PhysioEx Logo">
70
+
71
+ <h1> PhysioEx </h1>
72
+ </div>
73
+
74
+ ![Python Version](https://img.shields.io/badge/python-3.7%2B-blue)
75
+ ![PyPI Version](https://badge.fury.io/py/physioex.svg)
76
+
77
+ **PhysioEx ( Physiological Signal Explainer )** is a versatile python library tailored for building, training, and explaining deep learning models for physiological signal analysis.
78
+
79
+ The main purpose of the library is to propose a standard and fast methodology to train and evalutate state-of-the-art deep learning architectures for physiological signal analysis, to shift the attention from the architecture building task to the explainability task.
80
+
81
+ With PhysioEx you can simulate a state-of-the-art experiment just running the `train`, `test_model` and `finetune` commands; evaluating and saving the trained model; and start focusing on the explainability task!
82
+
83
+ ## Supported deep learning architectures
84
+
85
+ - [Chambon2018](https://ieeexplore.ieee.org/document/8307462) model for sleep stage classification ( raw time series as input).
86
+ - [TinySleepNet](https://github.com/akaraspt/tinysleepnet) model for sleep stage classification (raw time series as input).
87
+ - [SeqSleepNet](https://arxiv.org/pdf/1809.10932.pdf) model for sleep stage classification (time-frequency images as input).
88
+ - [SleepTransformer](https://arxiv.org/pdf/2105.11043) model for sleep stage classification (time-frequency images as input).
89
+
90
+ ## Supported datasets
91
+
92
+ ### Publicly Available:
93
+
94
+ For these datasets PhysioEx will take also to download the data with the `preprocess` command.
95
+
96
+ - [Sleep-EDF(78)](https://physionet.org/content/sleep-edfx/1.0.0/), The sleep-edf database contains 197 whole-night PolySomnoGraphic sleep recordings, containing EEG, EOG, chin EMG, and event markers.
97
+ - [HMC (Haaglanden Medisch Centrum)](https://physionet.org/content/hmc-sleep-staging/1.1/), is a collection of 151 whole-night PSG recordings from 85 men and 66 women, gathered at the Haaglanden Medisch Centrum sleep center. The PSG data includes 4 EEG channels (F4/M1, C4/M1, O2/M1, and C3/M2), two EOG channels (E1/M2 and E2/M2), and one bipolar chin EMG, with all signals sampled at 256 Hz.
98
+ - [DCSM (Danish Center for Sleep Medicine)](https://erda.ku.dk/public/archives/db553715ecbe1f3ac66c1dc569826eef/published-archive.html), is a collection of 255 randomly selected and fully anonymized overnight lab-based PSG recordings from patients seeking diagnosis for non-specific sleep-related disorders at the DCSM. The PSG setup included EEG, EOG, and EMG channels, all sampled at 256 Hz.
99
+
100
+
101
+ ### [NSSR](https://sleepdata.org) Datasets
102
+
103
+ These datasets can be easily get from the NSSR archive. Once downloaded in your `data_folder`, place them into the folder `data_folder/dataset_name/` directory with name `dataset_raw`. Then you can run the `preprocess -d dataset_name -df data_folder` command to make the data readable by PhysioEx.
104
+
105
+ - [SHHS (Sleep Heart Health Study)](https://sleepdata.org/datasets/shhs), is a multi-center cohort study designed to investigate the cardiovascular and other consequences of sleep-disordered breathing. At visit 1, it included 5,793 participants aged 40 years or older. PSG recordings were typically conducted in the subjects' homes by trained and certified technicians. The recording montage included C3/A2 and C4/A1 EEGs sampled at 125 Hz, right and left EOGs sampled at 50 Hz, and a bipolar submental EMG sampled at 125 Hz.
106
+ - [MESA (Multi-Ethnic Study of Atherosclerosis)](https://sleepdata.org/datasets/mesa), is a multi-center prospective study of 2.237 ethnically diverse men and women aged 45-84 from six communities in the United States. PSGs recordings were obtained using in-home settings including central C4-M1 EEG, bilateral EOG and chin EMG sampled at 256Hz. PSGs were scored by one of 3 MESA certified, registered polysomnologists.
107
+ - [MrOS (The Osteoporotic Fractures in Men Study)](https://sleepdata.org/datasets/mros), is a multicenter study comprising 2,911 PSG recordings from men aged 65 years or older, enrolled at six clinical centers. PSG recordings were conducted in home settings and included C3/A2 and C4/A1 EEGs, chin EMG, and left-right EOG, all sampled at 256 Hz.
108
+ - [WSC (The Wisconsin Sleep Cohort)](https://sleepdata.org/datasets/wsc) A longitudinal study of the causes, consequences, and natural history of sleep disorders using overnight in-laboratory sleep recordings gathered at the University of Wisconsin, United States, with a baseline sample of 1,500 subjects assessed at four-year intervals. The study consists of multiple visits with overnight PSG data acquisition. PSG recordings included C3/M2 EEG, EMG, and left-right EOG, all sampled at 200 Hz.
109
+
110
+ ### Others
111
+
112
+ - [MASS (Montreal Archive of Sleep Studies)](http://ceams-carsm.ca/mass/), is an open-access collaborative database containing laboratory-based PSG recordings. It includes 200 complete nights recorded from 97 men and 103 women, aged 18 to 76 years. All recordings have a sampling frequency of 256 Hz and feature an EEG montage of 4–20 channels, along with standard EOG and EMG
113
+
114
+
115
+ ## Installation guidelines
116
+
117
+ ### Create a Virtual Environment (Optional but Recommended)
118
+
119
+ ```bash
120
+ $ conda create -n physioex python==3.10
121
+ $ conda activate physioex
122
+ $ conda install pip
123
+ $ pip install --upgrade pip # On Windows, use `venv\Scripts\activate`
124
+ ```
125
+
126
+ ### Install from source ( Recommended )
127
+ 1. **Clone the Repository:**
128
+ ```bash
129
+ $ git clone https://github.com/guidogagl/physioex.git
130
+ $ cd physioex
131
+ ```
132
+
133
+ 2. **Install Dependencies and Package in Development Mode**
134
+ ```bash
135
+ $ pip install -e .
136
+ ```
137
+
138
+ ### Install via pip
139
+
140
+ 1. **Install PhysioEx from PyPI:**
141
+ ```bash
142
+ $ pip install physioex
143
+ ```
144
+
145
+ Note: the github version of the library is kept updated weekly, the PiPy version may be outdated depending on the last commit of the github version. We recommend to use the github version if possible.
146
+
147
+ ## Cite Us!
148
+ ```bib
149
+ @article{10.1088/1361-6579/adaf73,
150
+ author={Gagliardi, Guido and Alfeo, Luca and Cimino, Mario G C A and Valenza, Gaetano and De Vos, Maarten},
151
+ title={PhysioEx, a new Python library for explainable sleep staging through deep learning},
152
+ journal={Physiological Measurement},
153
+ url={http://iopscience.iop.org/article/10.1088/1361-6579/adaf73},
154
+ year={2025},
155
+ }
156
+ ```
@@ -0,0 +1,89 @@
1
+ <div style = "text-align: center;">
2
+ <img src="https://raw.githubusercontent.com/guidogagl/physioex/refs/heads/main/docs/assets/images/logo.svg" width = "250px", alt="PhysioEx Logo">
3
+
4
+ <h1> PhysioEx </h1>
5
+ </div>
6
+
7
+ ![Python Version](https://img.shields.io/badge/python-3.7%2B-blue)
8
+ ![PyPI Version](https://badge.fury.io/py/physioex.svg)
9
+
10
+ **PhysioEx ( Physiological Signal Explainer )** is a versatile python library tailored for building, training, and explaining deep learning models for physiological signal analysis.
11
+
12
+ The main purpose of the library is to propose a standard and fast methodology to train and evalutate state-of-the-art deep learning architectures for physiological signal analysis, to shift the attention from the architecture building task to the explainability task.
13
+
14
+ With PhysioEx you can simulate a state-of-the-art experiment just running the `train`, `test_model` and `finetune` commands; evaluating and saving the trained model; and start focusing on the explainability task!
15
+
16
+ ## Supported deep learning architectures
17
+
18
+ - [Chambon2018](https://ieeexplore.ieee.org/document/8307462) model for sleep stage classification ( raw time series as input).
19
+ - [TinySleepNet](https://github.com/akaraspt/tinysleepnet) model for sleep stage classification (raw time series as input).
20
+ - [SeqSleepNet](https://arxiv.org/pdf/1809.10932.pdf) model for sleep stage classification (time-frequency images as input).
21
+ - [SleepTransformer](https://arxiv.org/pdf/2105.11043) model for sleep stage classification (time-frequency images as input).
22
+
23
+ ## Supported datasets
24
+
25
+ ### Publicly Available:
26
+
27
+ For these datasets PhysioEx will take also to download the data with the `preprocess` command.
28
+
29
+ - [Sleep-EDF(78)](https://physionet.org/content/sleep-edfx/1.0.0/), The sleep-edf database contains 197 whole-night PolySomnoGraphic sleep recordings, containing EEG, EOG, chin EMG, and event markers.
30
+ - [HMC (Haaglanden Medisch Centrum)](https://physionet.org/content/hmc-sleep-staging/1.1/), is a collection of 151 whole-night PSG recordings from 85 men and 66 women, gathered at the Haaglanden Medisch Centrum sleep center. The PSG data includes 4 EEG channels (F4/M1, C4/M1, O2/M1, and C3/M2), two EOG channels (E1/M2 and E2/M2), and one bipolar chin EMG, with all signals sampled at 256 Hz.
31
+ - [DCSM (Danish Center for Sleep Medicine)](https://erda.ku.dk/public/archives/db553715ecbe1f3ac66c1dc569826eef/published-archive.html), is a collection of 255 randomly selected and fully anonymized overnight lab-based PSG recordings from patients seeking diagnosis for non-specific sleep-related disorders at the DCSM. The PSG setup included EEG, EOG, and EMG channels, all sampled at 256 Hz.
32
+
33
+
34
+ ### [NSSR](https://sleepdata.org) Datasets
35
+
36
+ These datasets can be easily get from the NSSR archive. Once downloaded in your `data_folder`, place them into the folder `data_folder/dataset_name/` directory with name `dataset_raw`. Then you can run the `preprocess -d dataset_name -df data_folder` command to make the data readable by PhysioEx.
37
+
38
+ - [SHHS (Sleep Heart Health Study)](https://sleepdata.org/datasets/shhs), is a multi-center cohort study designed to investigate the cardiovascular and other consequences of sleep-disordered breathing. At visit 1, it included 5,793 participants aged 40 years or older. PSG recordings were typically conducted in the subjects' homes by trained and certified technicians. The recording montage included C3/A2 and C4/A1 EEGs sampled at 125 Hz, right and left EOGs sampled at 50 Hz, and a bipolar submental EMG sampled at 125 Hz.
39
+ - [MESA (Multi-Ethnic Study of Atherosclerosis)](https://sleepdata.org/datasets/mesa), is a multi-center prospective study of 2.237 ethnically diverse men and women aged 45-84 from six communities in the United States. PSGs recordings were obtained using in-home settings including central C4-M1 EEG, bilateral EOG and chin EMG sampled at 256Hz. PSGs were scored by one of 3 MESA certified, registered polysomnologists.
40
+ - [MrOS (The Osteoporotic Fractures in Men Study)](https://sleepdata.org/datasets/mros), is a multicenter study comprising 2,911 PSG recordings from men aged 65 years or older, enrolled at six clinical centers. PSG recordings were conducted in home settings and included C3/A2 and C4/A1 EEGs, chin EMG, and left-right EOG, all sampled at 256 Hz.
41
+ - [WSC (The Wisconsin Sleep Cohort)](https://sleepdata.org/datasets/wsc) A longitudinal study of the causes, consequences, and natural history of sleep disorders using overnight in-laboratory sleep recordings gathered at the University of Wisconsin, United States, with a baseline sample of 1,500 subjects assessed at four-year intervals. The study consists of multiple visits with overnight PSG data acquisition. PSG recordings included C3/M2 EEG, EMG, and left-right EOG, all sampled at 200 Hz.
42
+
43
+ ### Others
44
+
45
+ - [MASS (Montreal Archive of Sleep Studies)](http://ceams-carsm.ca/mass/), is an open-access collaborative database containing laboratory-based PSG recordings. It includes 200 complete nights recorded from 97 men and 103 women, aged 18 to 76 years. All recordings have a sampling frequency of 256 Hz and feature an EEG montage of 4–20 channels, along with standard EOG and EMG
46
+
47
+
48
+ ## Installation guidelines
49
+
50
+ ### Create a Virtual Environment (Optional but Recommended)
51
+
52
+ ```bash
53
+ $ conda create -n physioex python==3.10
54
+ $ conda activate physioex
55
+ $ conda install pip
56
+ $ pip install --upgrade pip # On Windows, use `venv\Scripts\activate`
57
+ ```
58
+
59
+ ### Install from source ( Recommended )
60
+ 1. **Clone the Repository:**
61
+ ```bash
62
+ $ git clone https://github.com/guidogagl/physioex.git
63
+ $ cd physioex
64
+ ```
65
+
66
+ 2. **Install Dependencies and Package in Development Mode**
67
+ ```bash
68
+ $ pip install -e .
69
+ ```
70
+
71
+ ### Install via pip
72
+
73
+ 1. **Install PhysioEx from PyPI:**
74
+ ```bash
75
+ $ pip install physioex
76
+ ```
77
+
78
+ Note: the github version of the library is kept updated weekly, the PiPy version may be outdated depending on the last commit of the github version. We recommend to use the github version if possible.
79
+
80
+ ## Cite Us!
81
+ ```bib
82
+ @article{10.1088/1361-6579/adaf73,
83
+ author={Gagliardi, Guido and Alfeo, Luca and Cimino, Mario G C A and Valenza, Gaetano and De Vos, Maarten},
84
+ title={PhysioEx, a new Python library for explainable sleep staging through deep learning},
85
+ journal={Physiological Measurement},
86
+ url={http://iopscience.iop.org/article/10.1088/1361-6579/adaf73},
87
+ year={2025},
88
+ }
89
+ ```
@@ -0,0 +1,109 @@
1
+ import os
2
+ from typing import Callable, List, Union
3
+
4
+ import pytorch_lightning as pl
5
+ from torch.utils.data import DataLoader, DistributedSampler, Subset, SubsetRandomSampler
6
+
7
+ from physioex.data.dataset import PhysioExDataset
8
+
9
+
10
+ class PhysioExDataModule(pl.LightningDataModule):
11
+ def __init__(
12
+ self,
13
+ datasets: Union[List[str], PhysioExDataset],
14
+ batch_size: int = 32,
15
+ preprocessing: str = "raw",
16
+ selected_channels: List[int] = ["EEG"],
17
+ sequence_length: int = 21,
18
+ target_transform: Callable = None,
19
+ task: str = "sleep",
20
+ folds: Union[int, List[int]] = -1,
21
+ data_folder: str = None,
22
+ evaluate_on_whole_night: bool = False,
23
+ num_nodes : int = 1,
24
+ num_workers: int = os.cpu_count(),
25
+ ):
26
+ super().__init__()
27
+
28
+ self.datasets_id = datasets
29
+ self.num_workers = num_workers
30
+
31
+ if isinstance(datasets, list):
32
+ self.dataset = PhysioExDataset(
33
+ datasets=datasets,
34
+ preprocessing=preprocessing,
35
+ selected_channels=selected_channels,
36
+ sequence_length=sequence_length,
37
+ target_transform=target_transform,
38
+ data_folder=data_folder,
39
+ task=task,
40
+ )
41
+
42
+ if evaluate_on_whole_night:
43
+ self.eval_dataset = PhysioExDataset(
44
+ datasets=datasets,
45
+ preprocessing=preprocessing,
46
+ selected_channels=selected_channels,
47
+ sequence_length=-1,
48
+ target_transform=target_transform,
49
+ data_folder=data_folder,
50
+ task=task,
51
+ )
52
+ else:
53
+ self.eval_dataset = self.dataset
54
+
55
+ elif isinstance(datasets, PhysioExDataset):
56
+ self.dataset = datasets
57
+ self.eval_dataset = datasets
58
+ else:
59
+ raise ValueError("ERR: datasets should be a list or a PhysioExDataset")
60
+
61
+ self.batch_size = batch_size
62
+
63
+ if isinstance(folds, int):
64
+ self.dataset.split(folds)
65
+ else:
66
+ assert len(folds) == len(
67
+ datasets
68
+ ), "ERR: folds and datasets should have the same length"
69
+ for i, fold in enumerate(folds):
70
+ self.dataset.split(fold, i)
71
+
72
+ train_idx, _, _ = self.dataset.get_sets()
73
+ _, valid_idx, test_idx = self.eval_dataset.get_sets()
74
+
75
+ self.train_dataset = Subset(self.dataset, train_idx)
76
+ self.valid_dataset = Subset(self.eval_dataset, valid_idx)
77
+ self.test_dataset = Subset(self.eval_dataset, test_idx)
78
+
79
+ self.eown = evaluate_on_whole_night
80
+
81
+ def train_dataloader(self):
82
+ """
83
+ Returns the DataLoader for the training dataset.
84
+
85
+ Returns:
86
+ DataLoader: DataLoader for the training dataset.
87
+ """
88
+ return DataLoader(
89
+ self.train_dataset,
90
+ batch_size=self.batch_size,
91
+ shuffle=True,
92
+ num_workers=self.num_workers,
93
+ )
94
+
95
+ def val_dataloader(self):
96
+ return DataLoader(
97
+ self.valid_dataset,
98
+ batch_size=self.batch_size if not self.eown else 1,
99
+ shuffle=False,
100
+ num_workers=self.num_workers,
101
+ )
102
+
103
+ def test_dataloader(self):
104
+ return DataLoader(
105
+ self.test_dataset,
106
+ batch_size=self.batch_size if not self.eown else 1,
107
+ shuffle=False,
108
+ num_workers=self.num_workers,
109
+ )