braindecode 1.8.1.dev180667301__tar.gz → 1.8.1.dev180679353__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 (212) hide show
  1. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/NOTICE.txt +22 -2
  2. {braindecode-1.8.1.dev180667301/braindecode.egg-info → braindecode-1.8.1.dev180679353}/PKG-INFO +1 -1
  3. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/augmentation/__init__.py +2 -0
  4. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/augmentation/functional.py +6 -2
  5. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/augmentation/transforms.py +185 -0
  6. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/classifier.py +6 -5
  7. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/base.py +228 -11
  8. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/tuh.py +20 -13
  9. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datautil/serialization.py +10 -6
  10. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/eegneuralnet.py +7 -2
  11. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/functional/__init__.py +6 -0
  12. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/functional/_real_dft.py +55 -0
  13. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/functional/functions.py +174 -16
  14. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/__init__.py +35 -14
  15. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/attn_sleep.py +9 -15
  16. braindecode-1.8.1.dev180679353/braindecode/models/axon.py +557 -0
  17. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/barista.py +6 -2
  18. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/base.py +136 -20
  19. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/bendr.py +73 -63
  20. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/biot.py +57 -70
  21. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/brainbert.py +10 -11
  22. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/brainmodule.py +19 -12
  23. braindecode-1.8.1.dev180679353/braindecode/models/brainomni.py +962 -0
  24. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/brant.py +17 -14
  25. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/cbramod.py +64 -26
  26. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/codebrain.py +133 -79
  27. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/config.py +1 -2
  28. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/contrawr.py +26 -4
  29. braindecode-1.8.1.dev180679353/braindecode/models/csbrain.py +767 -0
  30. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/ctnet.py +9 -1
  31. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/dance.py +1 -1
  32. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/deep4.py +22 -5
  33. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/dgcnn.py +10 -1
  34. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/diver1.py +55 -60
  35. braindecode-1.8.1.dev180679353/braindecode/models/eeg_clip.py +307 -0
  36. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/eegconformer.py +19 -3
  37. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/eegdino.py +32 -16
  38. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/eeginception_mi.py +48 -17
  39. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/eegnex.py +20 -1
  40. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/eegpt.py +66 -109
  41. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/eegsym.py +102 -24
  42. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/emg2qwerty.py +19 -2
  43. braindecode-1.8.1.dev180679353/braindecode/models/epint.py +311 -0
  44. braindecode-1.8.1.dev180679353/braindecode/models/gcnsnet.py +338 -0
  45. braindecode-1.8.1.dev180679353/braindecode/models/guetschel2026.py +775 -0
  46. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/labram.py +294 -222
  47. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/luna.py +86 -44
  48. braindecode-1.8.1.dev180679353/braindecode/models/mapa.py +905 -0
  49. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/medformer.py +68 -33
  50. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/meta_neuromotor.py +102 -55
  51. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/mirepnet.py +38 -6
  52. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/msvtnet.py +127 -8
  53. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/mvpformer.py +178 -192
  54. braindecode-1.8.1.dev180679353/braindecode/models/neurorvq.py +626 -0
  55. braindecode-1.8.1.dev180679353/braindecode/models/neurorvq_tokenizer.py +627 -0
  56. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/patchedtransformer.py +3 -8
  57. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/popt.py +4 -0
  58. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/reve.py +76 -58
  59. braindecode-1.8.1.dev180679353/braindecode/models/seizure_transformer.py +407 -0
  60. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/sensingdynamics.py +10 -5
  61. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/shallow_fbcsp.py +15 -8
  62. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/signal_jepa.py +153 -39
  63. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/sinc_shallow.py +2 -1
  64. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/sleep_stager_blanco_2020.py +13 -6
  65. braindecode-1.8.1.dev180679353/braindecode/models/sleepfm.py +776 -0
  66. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/sstdpn.py +13 -10
  67. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/steegformer.py +10 -4
  68. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/summary.csv +16 -5
  69. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/syncnet.py +2 -2
  70. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/tcformer.py +30 -52
  71. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/tcn.py +5 -0
  72. braindecode-1.8.1.dev180679353/braindecode/models/tfm_tokenizer.py +450 -0
  73. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/tidnet.py +18 -1
  74. braindecode-1.8.1.dev180679353/braindecode/models/tmsanet.py +233 -0
  75. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/usleep.py +3 -2
  76. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/util.py +318 -85
  77. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/zuna.py +38 -21
  78. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/modules/__init__.py +6 -2
  79. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/modules/attention.py +91 -10
  80. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/modules/blocks.py +18 -5
  81. braindecode-1.8.1.dev180679353/braindecode/modules/channels.py +459 -0
  82. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/modules/convolution.py +10 -9
  83. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/modules/dance_modules.py +48 -27
  84. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/modules/filter.py +93 -66
  85. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/modules/layers.py +53 -23
  86. braindecode-1.8.1.dev180679353/braindecode/modules/linear_attention.py +128 -0
  87. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/modules/parametrization.py +29 -0
  88. braindecode-1.8.1.dev180679353/braindecode/modules/quantization.py +422 -0
  89. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/modules/stats.py +6 -1
  90. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/preprocessing/preprocess.py +28 -0
  91. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/preprocessing/windowers.py +5 -4
  92. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/regressor.py +6 -5
  93. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/samplers/base.py +60 -61
  94. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/training/losses.py +5 -4
  95. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/training/scoring.py +6 -5
  96. braindecode-1.8.1.dev180679353/braindecode/version.py +1 -0
  97. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/visualization/topology.py +1 -1
  98. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353/braindecode.egg-info}/PKG-INFO +1 -1
  99. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode.egg-info/SOURCES.txt +19 -3
  100. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/api.rst +48 -7
  101. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/index.rst +1 -0
  102. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/models/models_categorization.rst +10 -3
  103. braindecode-1.8.1.dev180679353/docs/user_guide/channel_strategies.rst +59 -0
  104. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/whats_new.rst +440 -1
  105. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/pyproject.toml +3 -0
  106. braindecode-1.8.1.dev180667301/braindecode/models/interpolated.py +0 -185
  107. braindecode-1.8.1.dev180667301/braindecode/modules/interpolation.py +0 -201
  108. braindecode-1.8.1.dev180667301/braindecode/version.py +0 -1
  109. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/LICENSE.txt +0 -0
  110. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/MANIFEST.in +0 -0
  111. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/README.rst +0 -0
  112. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/__init__.py +0 -0
  113. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/augmentation/base.py +0 -0
  114. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/__init__.py +0 -0
  115. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/_notebook_viewer.py +0 -0
  116. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/bbci.py +0 -0
  117. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/bcicomp.py +0 -0
  118. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/bids/__init__.py +0 -0
  119. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/bids/datasets.py +0 -0
  120. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/bids/format.py +0 -0
  121. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/bids/hub.py +0 -0
  122. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/bids/hub_format.py +0 -0
  123. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/bids/hub_io.py +0 -0
  124. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/bids/hub_validation.py +0 -0
  125. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/bids/iterable.py +0 -0
  126. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/chb_mit.py +0 -0
  127. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/collate.py +0 -0
  128. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/mne.py +0 -0
  129. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/moabb.py +0 -0
  130. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/nmt.py +0 -0
  131. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/registry.py +0 -0
  132. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/siena.py +0 -0
  133. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/sleep_physio_challe_18.py +0 -0
  134. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/sleep_physionet.py +0 -0
  135. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/utils.py +0 -0
  136. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datasets/xy.py +0 -0
  137. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datautil/__init__.py +0 -0
  138. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datautil/channel_utils.py +0 -0
  139. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datautil/hub_formats.py +0 -0
  140. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/datautil/util.py +0 -0
  141. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/functional/initialization.py +0 -0
  142. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/atcnet.py +0 -0
  143. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/attentionbasenet.py +0 -0
  144. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/deepsleepnet.py +0 -0
  145. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/eeginception_erp.py +0 -0
  146. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/eegitnet.py +0 -0
  147. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/eegminer.py +0 -0
  148. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/eegnet.py +0 -0
  149. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/eegsimpleconv.py +0 -0
  150. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/eegtcnet.py +0 -0
  151. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/fbcnet.py +0 -0
  152. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/fblightconvnet.py +0 -0
  153. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/fbmsnet.py +0 -0
  154. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/hybrid.py +0 -0
  155. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/ifnet.py +0 -0
  156. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/mscformer.py +0 -0
  157. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/neuropose.py +0 -0
  158. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/sccnet.py +0 -0
  159. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/sleep_stager_chambon_2018.py +0 -0
  160. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/sparcnet.py +0 -0
  161. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/tsinception.py +0 -0
  162. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/models/vemg2pose.py +0 -0
  163. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/modules/activation.py +0 -0
  164. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/modules/linear.py +0 -0
  165. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/modules/popt_modules.py +0 -0
  166. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/modules/util.py +0 -0
  167. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/modules/wrapper.py +0 -0
  168. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/preprocessing/__init__.py +0 -0
  169. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/preprocessing/eegprep_preprocess.py +0 -0
  170. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/preprocessing/mne_preprocess.py +0 -0
  171. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/preprocessing/util.py +0 -0
  172. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/samplers/__init__.py +0 -0
  173. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/samplers/ssl.py +0 -0
  174. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/training/__init__.py +0 -0
  175. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/training/callbacks.py +0 -0
  176. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/util.py +0 -0
  177. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/visualization/__init__.py +0 -0
  178. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/visualization/activations.py +0 -0
  179. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/visualization/attribution.py +0 -0
  180. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/visualization/confusion_matrices.py +0 -0
  181. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/visualization/frequency.py +0 -0
  182. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/visualization/metrics.py +0 -0
  183. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode/visualization/sanity.py +0 -0
  184. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode.egg-info/dependency_links.txt +0 -0
  185. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode.egg-info/requires.txt +0 -0
  186. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/braindecode.egg-info/top_level.txt +0 -0
  187. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/Makefile +0 -0
  188. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/_templates/autosummary/class.rst +0 -0
  189. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/_templates/autosummary/class_in_subdir.rst +0 -0
  190. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/_templates/autosummary/function.rst +0 -0
  191. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/_templates/autosummary/function_in_subdir.rst +0 -0
  192. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/agent_docs.rst +0 -0
  193. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/cite.rst +0 -0
  194. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/conf.py +0 -0
  195. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/help.rst +0 -0
  196. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/install/install.rst +0 -0
  197. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/install/install_pip.rst +0 -0
  198. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/install/install_source.rst +0 -0
  199. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/models/categorization/attention.rst +0 -0
  200. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/models/categorization/channel.rst +0 -0
  201. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/models/categorization/convolution.rst +0 -0
  202. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/models/categorization/filterbank.rst +0 -0
  203. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/models/categorization/gnn.rst +0 -0
  204. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/models/categorization/interpretable.rst +0 -0
  205. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/models/categorization/lbm.rst +0 -0
  206. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/models/categorization/recurrent.rst +0 -0
  207. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/models/categorization/spd.rst +0 -0
  208. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/models/models.rst +0 -0
  209. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/models/models_table.rst +0 -0
  210. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/models/models_visualization.rst +0 -0
  211. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/docs/sg_execution_times.rst +0 -0
  212. {braindecode-1.8.1.dev180667301 → braindecode-1.8.1.dev180679353}/setup.cfg +0 -0
@@ -13,9 +13,10 @@ The following components are licensed under the Creative Commons Attribution-Non
13
13
 
14
14
  - `braindecode/models/eegminer.py`
15
15
  - `braindecode/models/meta_neuromotor.py`
16
+ - `braindecode/models/sleepfm.py`
16
17
  - `braindecode/models/brainmodule.py`
17
-
18
- As well as class later imported into the `braindecode.models.module` named as GeneralizedGaussianFilter.
18
+ - `braindecode/models/neurorvq.py`
19
+ - `braindecode/models/neurorvq_tokenizer.py`
19
20
 
20
21
  The `meta_neuromotor.py` file is a derivative of
21
22
  `facebookresearch/generic-neuromotor-interface`, released by Meta Platforms,
@@ -44,15 +45,34 @@ The following components are licensed under the MIT License:
44
45
  - `braindecode/models/ifnet.py`
45
46
  - `braindecode/models/mirepnet.py`
46
47
  - `braindecode/models/popt.py`
48
+ - `braindecode/models/tfm_tokenizer.py`
47
49
  - `braindecode/modules/popt_modules.py`
50
+ - `braindecode/models/brainomni.py`
51
+ - `braindecode/modules/quantization.py`
52
+ - `braindecode/modules/linear_attention.py`
53
+ - `braindecode/models/seizure_transformer.py`
54
+ - `docs/_static/model/seizure_transformer_arch.png`
55
+ - `braindecode/models/guetschel2026.py`
56
+ - `braindecode/models/tmsanet.py`
57
+ - `braindecode/models/epint.py`
58
+ - `braindecode/models/gcnsnet.py`
59
+
60
+ The `brainomni.py` file is a derivative of `OpenTSLab/BrainOmni` (MIT), whose
61
+ SEANet codec derives from Meta's `facebookresearch/encodec` (MIT). The
62
+ `quantization.py` module holds the residual vector quantization derived from
63
+ `lucidrains/vector-quantize-pytorch` (MIT) and the BrainOmni port.
64
+ The `linear_attention.py` module is the part of
65
+ `lucidrains/linear-attention-transformer` (MIT) that BIOT and TFMTokenizer run.
48
66
 
49
67
  ### Apache-2.0 Licensed Files
50
68
 
51
69
  The following components are licensed under the Apache License 2.0:
52
70
 
71
+ - `braindecode/models/axon.py`
53
72
  - `braindecode/models/mvpformer.py`
54
73
  - `braindecode/models/zuna.py`
55
74
  - `braindecode/models/luna.py`
75
+ - `braindecode/models/mapa.py`
56
76
  - `braindecode/models/brant.py`
57
77
  - `braindecode/models/diver1.py`
58
78
  - `braindecode/models/mscformer.py`
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: braindecode
3
- Version: 1.8.1.dev180667301
3
+ Version: 1.8.1.dev180679353
4
4
  Summary: Deep learning software to decode EEG, ECG or MEG signals
5
5
  Author-email: Robin Tibor Schirrmeister <robintibor@gmail.com>, Bruno Aristimunha Pinto <b.aristimunha@gmail.com>, Alexandre Gramfort <agramfort@meta.com>
6
6
  Maintainer-email: Alexandre Gramfort <agramfort@meta.com>, Bruno Aristimunha Pinto <b.aristimunha@gmail.com>, Robin Tibor Schirrmeister <robintibor@gmail.com>
@@ -23,6 +23,7 @@ from .transforms import (
23
23
  SignFlip,
24
24
  SmoothTimeMask,
25
25
  TimeReverse,
26
+ TrivialAugment,
26
27
  )
27
28
 
28
29
  __all__ = [
@@ -30,6 +31,7 @@ __all__ = [
30
31
  "IdentityTransform",
31
32
  "Compose",
32
33
  "AugmentedDataLoader",
34
+ "TrivialAugment",
33
35
  "TimeReverse",
34
36
  "SignFlip",
35
37
  "FTSurrogate",
@@ -3,6 +3,7 @@
3
3
  # Gustavo Rodrigues <gustavenrique01@gmail.com>
4
4
  # Bruna Lopes <brunajaflopes@gmail.com>
5
5
  # Sarthak Tayal <sarthaktayal2@gmail.com>
6
+ # Anton Soloviev <anton@praviel.com>
6
7
  #
7
8
  # License: BSD (3-clause)
8
9
 
@@ -931,7 +932,7 @@ def _rotate_signals(
931
932
  transformed_X = X.clone()
932
933
  sensors_positions = list(sensors_positions_matrix)
933
934
  for s, rot_sensors_matrix in enumerate(rot_sensors_matrices):
934
- rot_sensors_positions = list(rot_sensors_matrix.T)
935
+ rot_sensors_positions = list(rot_sensors_matrix)
935
936
  for time in range(X.shape[-1]):
936
937
  interpolator_t = Rbf(*sensors_positions, X[s, :, time])
937
938
  transformed_X[s, :, time] = torch.from_numpy(
@@ -1093,7 +1094,8 @@ def segmentation_reconstruction(
1093
1094
  y : torch.Tensor
1094
1095
  EEG labels for the example or batch.
1095
1096
  n_segments : int
1096
- Number of segments to use in the batch.
1097
+ Number of segments to use in the batch. Any remaining samples are
1098
+ included in the last segment.
1097
1099
  data_classes : list[tuple[int, torch.Tensor]]
1098
1100
  List of tuples. Each tuple contains the class index and the corresponding EEG data.
1099
1101
  rand_indices : array-like
@@ -1133,6 +1135,8 @@ def segmentation_reconstruction(
1133
1135
  for idx_segment in range(n_segments):
1134
1136
  start = idx_segment * segment_size
1135
1137
  end = (idx_segment + 1) * segment_size
1138
+ if idx_segment == n_segments - 1:
1139
+ end = window_size
1136
1140
 
1137
1141
  # Perform the data augmentation
1138
1142
  X_aug[np.arange(n_trials), :, start:end] = X_class[
@@ -1457,3 +1457,188 @@ class BandRotation(Transform):
1457
1457
  "circular_jitter": self.circular_jitter,
1458
1458
  "random_state": self.rng,
1459
1459
  }
1460
+
1461
+
1462
+ class TrivialAugment(Transform):
1463
+ """Apply one randomly sampled label-preserving augmentation per example.
1464
+
1465
+ For every example, independently samples one transform from the pool
1466
+ below and one of ``num_bins`` strengths evenly spaced between that
1467
+ transform's bounds, as in TrivialAugment [1]_. Examples that draw the
1468
+ same transform and strength are transformed in one call; each pooled
1469
+ transform still draws its own randomness per example.
1470
+
1471
+ Default pool (no assumption on the signal's unit, sampling frequency or
1472
+ montage):
1473
+
1474
+ * :class:`TimeReverse` — no strength parameter.
1475
+ * :class:`SignFlip` — no strength parameter.
1476
+ * :class:`FTSurrogate` — phase noise magnitude, 0.2 to 1.
1477
+ * :class:`ChannelsDropout` — channel drop probability, 0.05 to 0.4.
1478
+ * :class:`ChannelsShuffle` — shuffle probability, 0.1 to 0.75.
1479
+ * :class:`SmoothTimeMask` — mask length as a fraction of the window
1480
+ length, 0.05 to 0.25.
1481
+ * :class:`GaussianNoise` — noise standard deviation as a fraction of the
1482
+ sub-batch standard deviation (volts or microvolts alike), 0.02 to 0.3.
1483
+ * :class:`AmplitudeScale` — scale interval ``(1/s, s)``, ``s`` from 1.25
1484
+ to 2.5.
1485
+
1486
+ ``sfreq`` adds :class:`BandstopFilter` (bandwidth 0.5 to 4 Hz, capped
1487
+ 2.5 Hz below Nyquist) and :class:`FrequencyShift` (maximum shift 0.5 to
1488
+ 2 Hz); ``sensors_positions_matrix`` adds :class:`SensorsRotation` around
1489
+ the z axis (5 to 25 degrees).
1490
+
1491
+ Parameters
1492
+ ----------
1493
+ probability : float, optional
1494
+ Probability of augmenting each example. Defaults to 1.0.
1495
+ sfreq : float | None, optional
1496
+ Sampling frequency of the signals, in Hz. Defaults to None.
1497
+ sensors_positions_matrix : array-like | None, optional
1498
+ Sensor positions of shape ``(3, n_channels)`` (see
1499
+ :class:`SensorsRotation`). Defaults to None.
1500
+ num_bins : int, optional
1501
+ Number of strength levels per transform. Defaults to 10.
1502
+ random_state : int | numpy.random.RandomState, optional
1503
+ Seed shared by the per-example sampler and every pooled transform.
1504
+ Defaults to None.
1505
+
1506
+ Attributes
1507
+ ----------
1508
+ op_names : list of str
1509
+ Names of the transforms in the pool, in sampling order.
1510
+
1511
+ References
1512
+ ----------
1513
+ .. [1] Müller, S. G., & Hutter, F. (2021). TrivialAugment:
1514
+ Tuning-free Yet State-of-the-Art Data Augmentation. Proceedings of
1515
+ the IEEE/CVF International Conference on Computer Vision (ICCV),
1516
+ pp. 774-782.
1517
+ """
1518
+
1519
+ def __init__(
1520
+ self,
1521
+ probability=1.0,
1522
+ sfreq=None,
1523
+ sensors_positions_matrix=None,
1524
+ num_bins=10,
1525
+ random_state=None,
1526
+ ):
1527
+ super().__init__(probability=probability, random_state=random_state)
1528
+ if not isinstance(num_bins, (int, np.integer)) or num_bins < 1:
1529
+ raise ValueError(f"num_bins must be a positive integer, got {num_bins}")
1530
+ self.num_bins = int(num_bins)
1531
+ rng = self.rng
1532
+ # (name, strength bounds or None, make(strength) or None: built per call)
1533
+ specs = [
1534
+ ("TimeReverse", None, lambda s: TimeReverse(1.0, random_state=rng)),
1535
+ ("SignFlip", None, lambda s: SignFlip(1.0, random_state=rng)),
1536
+ (
1537
+ "FTSurrogate",
1538
+ (0.2, 1.0),
1539
+ lambda s: FTSurrogate(1.0, phase_noise_magnitude=s, random_state=rng),
1540
+ ),
1541
+ (
1542
+ "ChannelsDropout",
1543
+ (0.05, 0.4),
1544
+ lambda s: ChannelsDropout(1.0, p_drop=s, random_state=rng),
1545
+ ),
1546
+ (
1547
+ "ChannelsShuffle",
1548
+ (0.1, 0.75),
1549
+ lambda s: ChannelsShuffle(1.0, p_shuffle=s, random_state=rng),
1550
+ ),
1551
+ ("SmoothTimeMask", (0.05, 0.25), None),
1552
+ ("GaussianNoise", (0.02, 0.3), None),
1553
+ (
1554
+ "AmplitudeScale",
1555
+ (1.25, 2.5),
1556
+ lambda s: AmplitudeScale(1.0, interval=(1.0 / s, s), random_state=rng),
1557
+ ),
1558
+ ]
1559
+ if sfreq is not None:
1560
+ nyquist = sfreq / 2.0
1561
+ # BandstopFilter needs bandwidth < nyquist - 2; keep a margin
1562
+ max_bandwidth = min(4.0, nyquist - 2.5)
1563
+ if max_bandwidth <= 0.5:
1564
+ raise ValueError(
1565
+ f"sfreq={sfreq} is too small to sample valid band-stop "
1566
+ "bandwidths (needs at least 6.0 Hz)."
1567
+ )
1568
+ specs += [
1569
+ (
1570
+ "BandstopFilter",
1571
+ (0.5, max_bandwidth),
1572
+ lambda s: BandstopFilter(
1573
+ 1.0,
1574
+ sfreq=sfreq,
1575
+ bandwidth=s,
1576
+ max_freq=nyquist,
1577
+ random_state=rng,
1578
+ ),
1579
+ ),
1580
+ (
1581
+ "FrequencyShift",
1582
+ (0.5, 2.0),
1583
+ lambda s: FrequencyShift(
1584
+ 1.0, sfreq=sfreq, max_delta_freq=s, random_state=rng
1585
+ ),
1586
+ ),
1587
+ ]
1588
+ if sensors_positions_matrix is not None:
1589
+ specs.append(
1590
+ (
1591
+ "SensorsRotation",
1592
+ (5.0, 25.0),
1593
+ lambda s: SensorsRotation(
1594
+ 1.0,
1595
+ sensors_positions_matrix=sensors_positions_matrix,
1596
+ max_degrees=s,
1597
+ random_state=rng,
1598
+ ),
1599
+ )
1600
+ )
1601
+
1602
+ self._pool = []
1603
+ for name, bounds, make in specs:
1604
+ if bounds is None:
1605
+ strengths = [None]
1606
+ else:
1607
+ strengths = np.linspace(*bounds, self.num_bins).tolist()
1608
+ variants = None if make is None else [make(s) for s in strengths]
1609
+ self._pool.append((name, strengths, variants))
1610
+ # pre-built transforms as submodules (pickle, ``.to()``)
1611
+ self._static_transforms = torch.nn.ModuleList(
1612
+ v for _, _, variants in self._pool if variants for v in variants
1613
+ )
1614
+ self.op_names = [name for name, _, _ in self._pool]
1615
+
1616
+ def operation(self, X, y):
1617
+ """Apply one sampled transform and strength to each example of X."""
1618
+ n_strengths = np.array([len(strengths) for _, strengths, _ in self._pool])
1619
+ op_ids = self.rng.randint(0, len(self._pool), size=X.shape[0])
1620
+ bin_ids = self.rng.randint(0, self.num_bins, size=X.shape[0])
1621
+ # magnitude-free transforms collapse all examples onto bin 0
1622
+ bin_ids[n_strengths[op_ids] == 1] = 0
1623
+ keys = op_ids * self.num_bins + bin_ids
1624
+
1625
+ out_X, out_y = X.clone(), y.clone()
1626
+ for key in np.unique(keys):
1627
+ group = torch.from_numpy(np.flatnonzero(keys == key)).to(X.device)
1628
+ op_i, bin_j = divmod(int(key), self.num_bins)
1629
+ name, strengths, variants = self._pool[op_i]
1630
+ X_sub = X[group]
1631
+ if variants is not None:
1632
+ transform = variants[bin_j]
1633
+ elif name == "SmoothTimeMask":
1634
+ n_mask = max(1, int(round(strengths[bin_j] * X.shape[-1])))
1635
+ transform = SmoothTimeMask(
1636
+ 1.0, mask_len_samples=n_mask, random_state=self.rng
1637
+ )
1638
+ else: # GaussianNoise, std relative to the sub-batch (unit-free)
1639
+ std = strengths[bin_j] * X_sub.std().item()
1640
+ transform = GaussianNoise(1.0, std=std, random_state=self.rng)
1641
+ tr_X, tr_y = transform(X_sub, y[group])
1642
+ out_X[group] = tr_X.to(out_X.dtype)
1643
+ out_y[group] = tr_y
1644
+ return out_X, out_y
@@ -212,11 +212,12 @@ class EEGClassifier(_EEGNeuralNet, NeuralNetClassifier):
212
212
  the number of predictions depend on the chosen window size and the
213
213
  receptive field of the network. If trials have different lengths,
214
214
  a list with one (n_classes x n_predictions) array per trial.
215
- trial_targets : np.ndarray
216
- Ground-truth targets from the dataset in a 2-dimensional array
217
- (n_trials x n_targets). Only returned when ``return_targets=True``.
218
- The number of targets depends on the decoding paradigm and can be
219
- either a single value, multiple values, or a sequence.
215
+ trial_targets : np.ndarray | list of np.ndarray
216
+ Ground-truth targets from the dataset. Only returned when
217
+ ``return_targets=True``. An ``np.ndarray`` with a leading trial
218
+ dimension: ``(n_trials,)`` for scalar targets, with further
219
+ dimensions for multi-value or equal-length sequence targets. If
220
+ trial lengths differ, a list with one target array per trial.
220
221
  """
221
222
  if not self.cropped:
222
223
  warnings.warn(
@@ -14,13 +14,16 @@ from __future__ import annotations
14
14
  import bisect
15
15
  import html as _html
16
16
  import json
17
+ import mmap
17
18
  import os
18
19
  import shutil
19
20
  import warnings
20
21
  from abc import abstractmethod
21
22
  from collections import Counter
22
- from collections.abc import Callable, Hashable
23
+ from collections.abc import Callable, Hashable, Sequence
23
24
  from glob import glob
25
+ from itertools import chain
26
+ from operator import attrgetter
24
27
  from pathlib import Path
25
28
  from typing import Any, Generic, Iterable, no_type_check
26
29
 
@@ -28,6 +31,7 @@ import mne
28
31
  import mne.io
29
32
  import numpy as np
30
33
  import pandas as pd
34
+ from mne.io.constants import FIFF
31
35
  from mne.utils import _soft_import
32
36
  from mne.utils.docs import deprecated
33
37
  from torch.utils.data import ConcatDataset, Dataset, IterableDataset
@@ -220,6 +224,125 @@ def _compute_ch_pos(info, targets_from):
220
224
  return pos
221
225
 
222
226
 
227
+ _TAG_ROW = attrgetter("kind", "type", "size", "next", "pos")
228
+
229
+
230
+ def _tag_rows(tags):
231
+ """(kind, type, size, next, pos) of FIF tags as an int64 array (n, 5)."""
232
+ flat = chain.from_iterable(map(_TAG_ROW, tags))
233
+ return np.fromiter(flat, np.int64, 5 * len(tags)).reshape(-1, 5)
234
+
235
+
236
+ class _FifTagTable(Sequence):
237
+ """The data-buffer tags of a lazy FIF raw as one int64 array.
238
+
239
+ mne's FIF reader keeps one ``Tag`` object per data buffer in
240
+ ``raw._raw_extras[i]["ent"]`` (one per second of signal with mne's default
241
+ buffers), each with its attribute dict and integers once unpickled. A lazy
242
+ dataset of many recordings holds millions of them in RAM, and every forked
243
+ DataLoader worker copies the memory pages of those it reads (reference
244
+ counts). This holds the same fields in 40 bytes per buffer and returns an
245
+ equal ``Tag`` on access, so mne's own reads are unchanged.
246
+ """
247
+
248
+ def __init__(self, tags):
249
+ self.tag_class = type(tags[0])
250
+ self.table = _tag_rows(tags)
251
+
252
+ def __len__(self):
253
+ return len(self.table)
254
+
255
+ def __getitem__(self, i):
256
+ if isinstance(i, slice):
257
+ return [self.tag_class(*row) for row in self.table[i].tolist()]
258
+ return self.tag_class(*self.table[i].tolist())
259
+
260
+
261
+ _TAG_FIELDS = ("kind", "type", "size", "next", "pos", "data")
262
+
263
+
264
+ def _compact_fif_tags(inst):
265
+ """Swap the ``Tag`` lists of a FIF raw for `_FifTagTable` (in place).
266
+
267
+ Only gap-free lists of directory tags (no ``None``, no ``data``) with mne's
268
+ ``Tag`` fields are swapped; anything else is left as mne built it.
269
+ """
270
+ for extra in getattr(inst, "_raw_extras", ()):
271
+ tags = extra.get("ent")
272
+ if not isinstance(tags, list) or not tags:
273
+ continue
274
+ cls = type(tags[0])
275
+ if tuple(getattr(cls, "__dataclass_fields__", ())) == _TAG_FIELDS and all(
276
+ type(t) is cls and t.data is None for t in tags
277
+ ):
278
+ extra["ent"] = _FifTagTable(tags)
279
+ return inst
280
+
281
+
282
+ def _read_fif_window(raw, start, stop, willneed=False):
283
+ """Samples ``start:stop`` of a lazy FIF raw, copied from the file in one go.
284
+
285
+ mne reads, casts and calibrates the FIF data buffers of a range one at a
286
+ time (60 Python steps for a 60-s window saved with 1-s buffers, each through
287
+ a buffered file whose buffer is 4 MB on network file systems). Here one
288
+ slice of the memory-mapped file holds the bytes of every buffer in the
289
+ range and one multiply calibrates them, with mne's arithmetic (float64 data
290
+ times ``raw._cals``), so the values equal ``raw._getitem``'s. Returns None
291
+ (the caller uses mne) unless ``raw`` is a lazy, single-file, uncompressed
292
+ FIF raw of float32 buffers without projector, compensation or gaps.
293
+
294
+ With ``willneed=True`` nothing is read and None is returned: the OS is
295
+ only asked to start reading the window's bytes into the page cache in the
296
+ background (``posix_fadvise(POSIX_FADV_WILLNEED)``).
297
+ """
298
+ if (
299
+ not isinstance(raw, mne.io.Raw)
300
+ or raw.preload
301
+ or len(raw._raw_extras) != 1
302
+ or raw._projector is not None
303
+ or raw._comp is not None
304
+ ):
305
+ return None
306
+ extra = raw._raw_extras[0]
307
+ fname, bounds = extra["filename"], extra["bounds"]
308
+ if not isinstance(fname, Path) or fname.suffix == ".gz":
309
+ return None
310
+ start, stop = start + raw._first_samps[0], stop + raw._first_samps[0]
311
+ first = np.searchsorted(bounds, start, side="right") - 1
312
+ tags = extra["ent"]
313
+ if isinstance(tags, _FifTagTable):
314
+ rows = tags.table[first : np.searchsorted(bounds, stop)]
315
+ else:
316
+ tags = tags[first : np.searchsorted(bounds, stop)]
317
+ if any(t is None for t in tags):
318
+ return None
319
+ rows = _tag_rows(tags)
320
+ if not len(rows) or (rows[:, 1] != FIFF.FIFFT_FLOAT).any():
321
+ return None
322
+ size, pos = rows[:, 2].tolist(), rows[:, 4].tolist()
323
+ if willneed: # only a hint: any error is left to the read itself
324
+ try:
325
+ with open(fname, "rb") as f:
326
+ os.posix_fadvise(
327
+ f.fileno(),
328
+ pos[0],
329
+ pos[-1] + 16 + size[-1] - pos[0],
330
+ os.POSIX_FADV_WILLNEED,
331
+ )
332
+ except OSError:
333
+ pass
334
+ return None
335
+ # mmap: no copy through a 4 MB read buffer, and a cold file is read around
336
+ # the window by the kernel (as mne's 4 MB reads did), not window by window
337
+ with open(fname, "rb") as f, mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as m:
338
+ buf = m[pos[0] : pos[-1] + 16 + size[-1]]
339
+ one = np.concatenate(
340
+ [np.frombuffer(buf, ">f4", s // 4, p + 16 - pos[0]) for s, p in zip(size, pos)]
341
+ ).reshape(-1, extra["orig_nchan"])[start - bounds[first] : stop - bounds[first]]
342
+ picked = one[:, raw._read_picks[0]].T
343
+ return np.multiply(picked, raw._cals[:, np.newaxis], order="C")
344
+
345
+
223
346
  def _window_info(crop_inds, sfreq):
224
347
  """Extract window size from crop indices.
225
348
 
@@ -823,9 +946,11 @@ class EEGWindowsDataset(_ZarrMixin, RecordDataset):
823
946
  if self._zarr_data is not None:
824
947
  X = self._zarr_data[:, i_start:i_stop]
825
948
  else:
826
- X = self.raw._getitem(
827
- (slice(None), slice(i_start, i_stop)), return_times=False
828
- )
949
+ X = _read_fif_window(self.raw, i_start, i_stop)
950
+ if X is None:
951
+ X = self.raw._getitem(
952
+ (slice(None), slice(i_start, i_stop)), return_times=False
953
+ )
829
954
  X = np.array(X, dtype="float32")
830
955
  if self.transform is not None:
831
956
  X = self.transform(X)
@@ -1156,6 +1281,49 @@ class WindowsDataset(_ZarrMixin, RecordDataset):
1156
1281
  )
1157
1282
 
1158
1283
 
1284
+ def _lazy_source_files(ds) -> list:
1285
+ """Return the files ``ds`` still reads its signal from (none once preloaded)."""
1286
+ signal = ds.raw if hasattr(ds, "raw") else getattr(ds, "windows", None)
1287
+ if signal is None or getattr(signal, "preload", True):
1288
+ return []
1289
+ files = list(
1290
+ getattr(signal, "filenames", None) or [getattr(signal, "filename", None)]
1291
+ )
1292
+ raw = getattr(signal, "_raw", None)
1293
+ if isinstance(raw, mne.io.BaseRaw) and not raw.preload:
1294
+ files += raw.filenames # mne.Epochs of a lazily read Raw read through it
1295
+ return [f for f in files if f is not None]
1296
+
1297
+
1298
+ def _dir_key(directory):
1299
+ """Identify a directory by device and inode, whatever its spelling."""
1300
+ stat = os.stat(directory)
1301
+ return stat.st_dev, stat.st_ino
1302
+
1303
+
1304
+ def _overwrite_conflicts(datasets, path, offset):
1305
+ """Yield ``(i_ds, i_target, target_dir)`` for each dataset ``i_ds`` that
1306
+ lazily reads from inside ``target_dir = path/<i_target + offset>``, which
1307
+ ``save(overwrite=True)`` deletes before writing dataset ``i_target``.
1308
+ """
1309
+ targets = {}
1310
+ for i in range(len(datasets)):
1311
+ target_dir = os.path.join(path, str(i + offset))
1312
+ if os.path.isdir(target_dir):
1313
+ targets[_dir_key(target_dir)] = (i, target_dir)
1314
+ if not targets:
1315
+ return
1316
+ for i_ds, ds in enumerate(datasets):
1317
+ for file in _lazy_source_files(ds):
1318
+ # ancestors of the name and of the file it links to (DataLad)
1319
+ parents = {
1320
+ *Path(os.path.abspath(file)).parents,
1321
+ *Path(os.path.realpath(file)).parents,
1322
+ }
1323
+ for key in {_dir_key(p) for p in parents if p.is_dir()} & targets.keys():
1324
+ yield (i_ds, *targets[key])
1325
+
1326
+
1159
1327
  @register_dataset
1160
1328
  class BaseConcatDataset(ConcatDataset, HubDatasetMixin, Generic[T]):
1161
1329
  """A base class for concatenated datasets.
@@ -1253,7 +1421,8 @@ class BaseConcatDataset(ConcatDataset, HubDatasetMixin, Generic[T]):
1253
1421
  def __len__(self):
1254
1422
  return self._ensure_cumulative_sizes()[-1]
1255
1423
 
1256
- def _get_single_item(self, idx: int):
1424
+ def _locate(self, idx: int):
1425
+ """The dataset that holds item ``idx`` and the item's index in it."""
1257
1426
  if idx < 0:
1258
1427
  if -idx > len(self):
1259
1428
  raise ValueError(
@@ -1267,7 +1436,33 @@ class BaseConcatDataset(ConcatDataset, HubDatasetMixin, Generic[T]):
1267
1436
  sample_idx = idx
1268
1437
  else:
1269
1438
  sample_idx = idx - cumulative_sizes[dataset_idx - 1]
1270
- return self.datasets[dataset_idx][sample_idx]
1439
+ return self.datasets[dataset_idx], sample_idx
1440
+
1441
+ def _get_single_item(self, idx: int):
1442
+ ds, i = self._locate(idx)
1443
+ return ds[i]
1444
+
1445
+ def __getitems__(self, indices):
1446
+ """Items ``indices``, as ``[self[i] for i in indices]``.
1447
+
1448
+ A :class:`~torch.utils.data.DataLoader` fetches each batch through
1449
+ this. The lazy FIF windows of the batch are first requested from the
1450
+ OS all at once (``posix_fadvise(POSIX_FADV_WILLNEED)``, where it
1451
+ exists), so their reads from disk overlap instead of running one after
1452
+ another: on a network file system a batch read from cold files then
1453
+ costs about one round trip, not one per window.
1454
+ """
1455
+ # ponytail: advises the whole batch at once; chunk it if a batch's
1456
+ # windows ever outgrow the page cache
1457
+ if hasattr(os, "posix_fadvise"):
1458
+ for idx in indices:
1459
+ if not isinstance(idx, (int, np.integer)):
1460
+ continue # e.g. a SequenceSampler tuple: read, not advised
1461
+ ds, i = self._locate(idx)
1462
+ if isinstance(ds, EEGWindowsDataset) and ds._zarr_data is None:
1463
+ _, start, stop = ds.crop_inds[i].tolist()
1464
+ _read_fif_window(ds.raw, start, stop, willneed=True)
1465
+ return [self[idx] for idx in indices]
1271
1466
 
1272
1467
  def __getitem__(self, idx: int | list):
1273
1468
  """
@@ -1366,7 +1561,9 @@ class BaseConcatDataset(ConcatDataset, HubDatasetMixin, Generic[T]):
1366
1561
  metadata : pd.DataFrame
1367
1562
  DataFrame containing as many rows as there are windows in the
1368
1563
  BaseConcatDataset, with the metadata and description information
1369
- for each window.
1564
+ for each window, and an ``i_dataset`` column giving the position
1565
+ in ``datasets`` of the dataset (recording) each window comes from.
1566
+ Samplers use it to keep recordings apart.
1370
1567
  """
1371
1568
  if not all(
1372
1569
  [
@@ -1392,9 +1589,15 @@ class BaseConcatDataset(ConcatDataset, HubDatasetMixin, Generic[T]):
1392
1589
  "Dataset descriptions cannot contain the reserved window "
1393
1590
  "metadata key 'i_trial_in_dataset'."
1394
1591
  )
1592
+ if "i_dataset" in df.columns or "i_dataset" in ds.description:
1593
+ raise ValueError(
1594
+ "Window metadata and dataset descriptions cannot contain the "
1595
+ "key 'i_dataset', which get_metadata() reserves for the "
1596
+ "position of the dataset each window comes from. Rename it."
1597
+ )
1395
1598
 
1396
1599
  all_dfs = list()
1397
- for ds in self.datasets:
1600
+ for i_ds, ds in enumerate(self.datasets):
1398
1601
  if hasattr(ds, "_windows") and ds._windows is not None:
1399
1602
  df = ds._windows.metadata
1400
1603
  else:
@@ -1404,6 +1607,7 @@ class BaseConcatDataset(ConcatDataset, HubDatasetMixin, Generic[T]):
1404
1607
  df = df.copy()
1405
1608
  for k, v in ds.description.items():
1406
1609
  df[k] = v
1610
+ df["i_dataset"] = i_ds
1407
1611
  all_dfs.append(df)
1408
1612
 
1409
1613
  return pd.concat(all_dfs)
@@ -1672,7 +1876,8 @@ class BaseConcatDataset(ConcatDataset, HubDatasetMixin, Generic[T]):
1672
1876
  kwargs_path = os.path.join(path, ".".join([kwarg_name, "json"]))
1673
1877
  kwargs = getattr(self, kwarg_name)
1674
1878
  if kwargs is not None:
1675
- json.dump(kwargs, open(kwargs_path, "w"))
1879
+ with open(kwargs_path, "w") as f:
1880
+ json.dump(kwargs, f)
1676
1881
 
1677
1882
  @property
1678
1883
  def description(self) -> pd.DataFrame:
@@ -1725,7 +1930,9 @@ class BaseConcatDataset(ConcatDataset, HubDatasetMixin, Generic[T]):
1725
1930
  -raw.fif | -epo.fif and .json files to.
1726
1931
  overwrite : bool
1727
1932
  Whether to delete old subdirectories that will be saved to in this
1728
- call.
1933
+ call. If a dataset still reads its data lazily from one of them, a
1934
+ ``ValueError`` is raised before anything is deleted: load the data
1935
+ into memory first (``preload=True``) or save to another directory.
1729
1936
  offset : int
1730
1937
  If provided, the integer is added to the id of the dataset in the
1731
1938
  concat. This is useful in the setting of very large datasets, where
@@ -1738,11 +1945,21 @@ class BaseConcatDataset(ConcatDataset, HubDatasetMixin, Generic[T]):
1738
1945
  hasattr(self.datasets[0], "raw") or hasattr(self.datasets[0], "windows")
1739
1946
  ):
1740
1947
  raise ValueError("dataset should have either raw or windows attribute")
1948
+ if overwrite:
1949
+ for _, _, target_dir in _overwrite_conflicts(self.datasets, path, offset):
1950
+ raise ValueError(
1951
+ f"Saving with overwrite=True would delete {target_dir} while "
1952
+ "a dataset still reads its data from it. Load the data into "
1953
+ "memory first (preload=True) or save to another directory."
1954
+ )
1741
1955
 
1742
1956
  # Create path if it doesn't exist
1743
1957
  os.makedirs(path, exist_ok=True)
1744
1958
 
1745
- path_contents = os.listdir(path)
1959
+ # With an offset the caller fills one directory piece by piece (preprocess
1960
+ # saves each recording at its index), so the other entries are expected:
1961
+ # skip the scan that would stat them all on every call and list them in a warning.
1962
+ path_contents = os.listdir(path) if offset == 0 else []
1746
1963
  n_sub_dirs = len(
1747
1964
  [e for e in path_contents if os.path.isdir(os.path.join(path, e))]
1748
1965
  )