eegdash 0.1.0__py3-none-any.whl → 0.2.1.dev178237806__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.

Potentially problematic release.


This version of eegdash might be problematic. Click here for more details.

eegdash/mongodb.py ADDED
@@ -0,0 +1,66 @@
1
+ import threading
2
+
3
+ from pymongo import MongoClient
4
+
5
+ # MongoDB Operations
6
+ # These methods provide a high-level interface to interact with the MongoDB
7
+ # collection, allowing users to find, add, and update EEG data records.
8
+ # - find:
9
+ # - exist:
10
+ # - add_request:
11
+ # - add:
12
+ # - update_request:
13
+ # - remove_field:
14
+ # - remove_field_from_db:
15
+ # - close: Close the MongoDB connection.
16
+ # - __del__: Destructor to close the MongoDB connection.
17
+
18
+
19
+ class MongoConnectionManager:
20
+ """Singleton class to manage MongoDB client connections."""
21
+
22
+ _instances = {}
23
+ _lock = threading.Lock()
24
+
25
+ @classmethod
26
+ def get_client(cls, connection_string: str, is_staging: bool = False):
27
+ """Get or create a MongoDB client for the given connection string and staging flag.
28
+
29
+ Parameters
30
+ ----------
31
+ connection_string : str
32
+ The MongoDB connection string
33
+ is_staging : bool
34
+ Whether to use staging database
35
+
36
+ Returns
37
+ -------
38
+ tuple
39
+ A tuple of (client, database, collection)
40
+
41
+ """
42
+ # Create a unique key based on connection string and staging flag
43
+ key = (connection_string, is_staging)
44
+
45
+ if key not in cls._instances:
46
+ with cls._lock:
47
+ # Double-check pattern to avoid race conditions
48
+ if key not in cls._instances:
49
+ client = MongoClient(connection_string)
50
+ db_name = "eegdashstaging" if is_staging else "eegdash"
51
+ db = client[db_name]
52
+ collection = db["records"]
53
+ cls._instances[key] = (client, db, collection)
54
+
55
+ return cls._instances[key]
56
+
57
+ @classmethod
58
+ def close_all(cls):
59
+ """Close all MongoDB client connections."""
60
+ with cls._lock:
61
+ for client, _, _ in cls._instances.values():
62
+ try:
63
+ client.close()
64
+ except Exception:
65
+ pass
66
+ cls._instances.clear()
@@ -0,0 +1,65 @@
1
+ import logging
2
+
3
+ import mne
4
+ import numpy as np
5
+
6
+ from braindecode.preprocessing import (
7
+ Preprocessor,
8
+ )
9
+
10
+ logger = logging.getLogger("eegdash")
11
+
12
+
13
+ class hbn_ec_ec_reannotation(Preprocessor):
14
+ """Preprocessor to reannotate the raw data for eyes open and eyes closed events.
15
+
16
+ This processor is designed for HBN datasets.
17
+
18
+ """
19
+
20
+ def __init__(self):
21
+ super().__init__(fn=self.transform, apply_on_array=False)
22
+
23
+ def transform(self, raw):
24
+ """Reannotate the raw data to create new events for eyes open and eyes closed
25
+
26
+ This function modifies the raw MNE object by creating new events based on
27
+ the existing annotations for "instructed_toCloseEyes" and "instructed_toOpenEyes".
28
+ It generates new events every 2 seconds within specified time ranges after
29
+ the original events, and replaces the existing annotations with these new events.
30
+
31
+ Parameters
32
+ ----------
33
+ raw : mne.io.Raw
34
+ The raw MNE object containing EEG data and annotations.
35
+
36
+ """
37
+ events, event_id = mne.events_from_annotations(raw)
38
+
39
+ logger.info("Original events found with ids: %s", event_id)
40
+
41
+ # Create new events array for 2-second segments
42
+ new_events = []
43
+ sfreq = raw.info["sfreq"]
44
+ for event in events[events[:, 2] == event_id["instructed_toCloseEyes"]]:
45
+ # For each original event, create events every 2 seconds from 15s to 29s after
46
+ start_times = event[0] + np.arange(15, 29, 2) * sfreq
47
+ new_events.extend([[int(t), 0, 1] for t in start_times])
48
+
49
+ for event in events[events[:, 2] == event_id["instructed_toOpenEyes"]]:
50
+ # For each original event, create events every 2 seconds from 5s to 19s after
51
+ start_times = event[0] + np.arange(5, 19, 2) * sfreq
52
+ new_events.extend([[int(t), 0, 2] for t in start_times])
53
+
54
+ # replace events in raw
55
+ new_events = np.array(new_events)
56
+
57
+ annot_from_events = mne.annotations_from_events(
58
+ events=new_events,
59
+ event_desc={1: "eyes_closed", 2: "eyes_open"},
60
+ sfreq=raw.info["sfreq"],
61
+ )
62
+
63
+ raw.set_annotations(annot_from_events)
64
+
65
+ return raw
eegdash/utils.py ADDED
@@ -0,0 +1,11 @@
1
+ from mne.utils import get_config, set_config, use_log_level
2
+
3
+
4
+ def __init__mongo_client():
5
+ with use_log_level("ERROR"):
6
+ if get_config("EEGDASH_DB_URI") is None:
7
+ set_config(
8
+ "EEGDASH_DB_URI",
9
+ "mongodb+srv://eegdash-user:mdzoMjQcHWTVnKDq@cluster0.vz35p.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0",
10
+ set_env=True,
11
+ )
@@ -1,14 +1,15 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: eegdash
3
- Version: 0.1.0
3
+ Version: 0.2.1.dev178237806
4
4
  Summary: EEG data for machine learning
5
- Author-email: Young Truong <dt.young112@gmail.com>, Arnaud Delorme <adelorme@gmail.com>
5
+ Author-email: Young Truong <dt.young112@gmail.com>, Arnaud Delorme <adelorme@gmail.com>, Bruno Aristimunha <b.aristimunha@gmail.com>
6
6
  License: GNU General Public License
7
7
 
8
8
  Copyright (C) 2024-2025
9
9
 
10
10
  Young Truong, UCSD, dt.young112@gmail.com
11
11
  Arnaud Delorme, UCSD, adelorme@ucsd.edu
12
+ Bruno Aristimunha, b.aristimunha@gmail.com
12
13
 
13
14
  This program is free software; you can redistribute it and/or modify
14
15
  it under the terms of the GNU General Public License as published by
@@ -26,14 +27,27 @@ License: GNU General Public License
26
27
 
27
28
  Project-URL: Homepage, https://github.com/sccn/EEG-Dash-Data
28
29
  Project-URL: Issues, https://github.com/sccn/EEG-Dash-Data/issues
29
- Classifier: Programming Language :: Python :: 3
30
30
  Classifier: License :: OSI Approved :: MIT License
31
31
  Classifier: Operating System :: OS Independent
32
- Requires-Python: >3.10
32
+ Classifier: Intended Audience :: Science/Research
33
+ Classifier: Intended Audience :: Developers
34
+ Classifier: Programming Language :: Python
35
+ Classifier: Topic :: Software Development
36
+ Classifier: Topic :: Scientific/Engineering
37
+ Classifier: Development Status :: 3 - Alpha
38
+ Classifier: Operating System :: Microsoft :: Windows
39
+ Classifier: Operating System :: POSIX
40
+ Classifier: Operating System :: Unix
41
+ Classifier: Operating System :: MacOS
42
+ Classifier: Programming Language :: Python :: 3
43
+ Classifier: Programming Language :: Python :: 3.10
44
+ Classifier: Programming Language :: Python :: 3.11
45
+ Classifier: Programming Language :: Python :: 3.12
46
+ Requires-Python: >=3.10
33
47
  Description-Content-Type: text/markdown
34
48
  License-File: LICENSE
35
- Requires-Dist: braindecode
36
- Requires-Dist: mne_bids
49
+ Requires-Dist: braindecode>=1.0
50
+ Requires-Dist: mne_bids>=0.16.0
37
51
  Requires-Dist: numba
38
52
  Requires-Dist: numpy
39
53
  Requires-Dist: pandas
@@ -44,13 +58,37 @@ Requires-Dist: s3fs
44
58
  Requires-Dist: scipy
45
59
  Requires-Dist: tqdm
46
60
  Requires-Dist: xarray
47
- Requires-Dist: pre-commit
61
+ Provides-Extra: tests
62
+ Requires-Dist: pytest; extra == "tests"
63
+ Requires-Dist: pytest-cov; extra == "tests"
64
+ Requires-Dist: codecov; extra == "tests"
65
+ Requires-Dist: pytest_cases; extra == "tests"
66
+ Requires-Dist: pytest-benchmark; extra == "tests"
67
+ Provides-Extra: dev
68
+ Requires-Dist: pre-commit; extra == "dev"
69
+ Provides-Extra: docs
70
+ Requires-Dist: sphinx; extra == "docs"
71
+ Requires-Dist: sphinx_gallery; extra == "docs"
72
+ Requires-Dist: sphinx_rtd_theme; extra == "docs"
73
+ Requires-Dist: numpydoc; extra == "docs"
74
+ Provides-Extra: all
75
+ Requires-Dist: pytest; extra == "all"
76
+ Requires-Dist: pytest-cov; extra == "all"
77
+ Requires-Dist: codecov; extra == "all"
78
+ Requires-Dist: pytest_cases; extra == "all"
79
+ Requires-Dist: pre-commit; extra == "all"
80
+ Requires-Dist: sphinx; extra == "all"
81
+ Requires-Dist: sphinx_gallery; extra == "all"
82
+ Requires-Dist: sphinx_rtd_theme; extra == "all"
83
+ Requires-Dist: numpydoc; extra == "all"
48
84
  Dynamic: license-file
49
85
 
50
86
  # EEG-Dash
87
+
51
88
  To leverage recent and ongoing advancements in large-scale computational methods and to ensure the preservation of scientific data generated from publicly funded research, the EEG-DaSh data archive will create a data-sharing resource for MEEG (EEG, MEG) data contributed by collaborators for machine learning (ML) and deep learning (DL) applications.
52
89
 
53
90
  ## Data source
91
+
54
92
  The data in EEG-DaSh originates from a collaboration involving 25 laboratories, encompassing 27,053 participants. This extensive collection includes MEEG data, which is a combination of EEG and MEG signals. The data is sourced from various studies conducted by these labs, involving both healthy subjects and clinical populations with conditions such as ADHD, depression, schizophrenia, dementia, autism, and psychosis. Additionally, data spans different mental states like sleep, meditation, and cognitive tasks. In addition, EEG-DaSh will incorporate a subset of the data converted from NEMAR, which includes 330 MEEG BIDS-formatted datasets, further expanding the archive with well-curated, standardized neuroelectromagnetic data.
55
93
 
56
94
  ## Featured data
@@ -70,9 +108,11 @@ The following HBN datasets are currently featured on EEGDash. Documentation abou
70
108
  A total of [246 other datasets](datasets.md) are also available through EEGDash.
71
109
 
72
110
  ## Data format
111
+
73
112
  EEGDash queries return a **Pytorch Dataset** formatted to facilitate machine learning (ML) and deep learning (DL) applications. PyTorch Datasets are the best format for EEGDash queries because they provide an efficient, scalable, and flexible structure for machine learning (ML) and deep learning (DL) applications. They allow seamless integration with PyTorch’s DataLoader, enabling efficient batching, shuffling, and parallel data loading, which is essential for training deep learning models on large EEG datasets.
74
113
 
75
114
  ## Data preprocessing
115
+
76
116
  EEGDash datasets are processed using the popular [BrainDecode](https://braindecode.org/stable/index.html) library. In fact, EEGDash datasets are BrainDecode datasets, which are themselves PyTorch datasets. This means that any preprocessing possible on BrainDecode datasets is also possible on EEGDash datasets. Refer to [BrainDecode](https://braindecode.org/stable/index.html) tutorials for guidance on preprocessing EEG data.
77
117
 
78
118
  ## EEG-Dash usage
@@ -0,0 +1,28 @@
1
+ eegdash/__init__.py,sha256=5WP-O-5EjRXkQ2BZAn_KKMPeMyWezCmWf5sYLb-dihE,245
2
+ eegdash/api.py,sha256=IQ0c26g7TnqzXv6lqlvMB9EHlobiTrK0YpiDa7ShcrE,26786
3
+ eegdash/data_config.py,sha256=OS6ERO-jHrnEOfMJUehY7ieABdsRw_qWzOKJ4pzSfqw,1323
4
+ eegdash/data_utils.py,sha256=mR0TtERYIefakGQ98jwAeeRVKSNDU9eBlUoH1AY9tnc,23663
5
+ eegdash/dataset.py,sha256=NK5CVGtHvGNlhdbZPaRUWtyLBDxUlyiSz-ot3BrxHQE,2443
6
+ eegdash/mongodb.py,sha256=GD3WgA253oFgpzOHrYaj4P1mRjNtDMT5Oj4kVvHswjI,2006
7
+ eegdash/preprocessing.py,sha256=wvqAO8UgDoQQz7xjVykrl4V8AawS4tpKR4Vrr_9BovY,2230
8
+ eegdash/utils.py,sha256=wU9CBQZLW_LIQIBwhgQm5bU4X-rSsVNPdeF2iE4QGJ4,410
9
+ eegdash/features/__init__.py,sha256=484CLxpPifc8ZQfeM8jWZLvtVKljCxn3qqlUCaq-Yxk,1284
10
+ eegdash/features/datasets.py,sha256=kU1DO70ArSIy-LF1hHD2NN4iT-kJrI0mVpSkyV_OSeI,18301
11
+ eegdash/features/decorators.py,sha256=v0qaJz_dcX703p1fvFYbAIXmwK3d8naYGlq7fRVKn_w,1313
12
+ eegdash/features/extractors.py,sha256=H7h6tP3dKoRcjDJpWWAo0ppmokCq5QlhqMcehYwYV9s,6845
13
+ eegdash/features/inspect.py,sha256=PmbWhx5H_WqpnorUpWONUSkUtaIHkZblRa_Xyk7Szyc,1569
14
+ eegdash/features/serialization.py,sha256=pNsTz0EeRPPYE-A61XK7UoMShI9YBEHQqC5STbzUU6A,2861
15
+ eegdash/features/utils.py,sha256=eM6DdyOpdVfNh7dSPykJ0WaTDtaGvkCQWAmW0G8v60Y,3784
16
+ eegdash/features/feature_bank/__init__.py,sha256=BKrM3aaggXrfey1yEjEBYaxOV5e3UK-o8oGeB30epOg,149
17
+ eegdash/features/feature_bank/complexity.py,sha256=Ds1GAXZ0LGM32xB4EZC2jbMljUBv0yicf2SkuyLvN5I,3183
18
+ eegdash/features/feature_bank/connectivity.py,sha256=bQ6KlxWm5GNpCS9ypLqBUr2L171Yq7wpBQT2tRQKTZ4,2159
19
+ eegdash/features/feature_bank/csp.py,sha256=YOzieLnOcqjvfrcjvg8R3S4SWuC1BqK5J5WXVNCCTc0,3304
20
+ eegdash/features/feature_bank/dimensionality.py,sha256=j_Ds71Y1AbV2uLFQj8EuXQ4kzofLBlQtPV5snMkF7i4,3965
21
+ eegdash/features/feature_bank/signal.py,sha256=3Tb8z9gX7iZipxQJ9DSyy30JfdmW58kgvimSyZX74p8,3404
22
+ eegdash/features/feature_bank/spectral.py,sha256=bNB7skusePs1gX7NOU6yRlw_Gr4UOCkO_ylkCgybzug,3319
23
+ eegdash/features/feature_bank/utils.py,sha256=DGh-Q7-XFIittP7iBBxvsJaZrlVvuY5mw-G7q6C-PCI,1237
24
+ eegdash-0.2.1.dev178237806.dist-info/licenses/LICENSE,sha256=KykUD4H3kw3HLz5bZ0kxMWwZotnk8rhkfCCerGyX2sk,855
25
+ eegdash-0.2.1.dev178237806.dist-info/METADATA,sha256=dn351VNZC1rthL5pYZejIE9ouYek-mp6ZbatrBlKm1k,10137
26
+ eegdash-0.2.1.dev178237806.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
+ eegdash-0.2.1.dev178237806.dist-info/top_level.txt,sha256=zavO69HQ6MyZM0aQMR2zUS6TAFc7bnN5GEpDpOpFZzU,8
28
+ eegdash-0.2.1.dev178237806.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.8.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -4,6 +4,7 @@ Copyright (C) 2024-2025
4
4
 
5
5
  Young Truong, UCSD, dt.young112@gmail.com
6
6
  Arnaud Delorme, UCSD, adelorme@ucsd.edu
7
+ Bruno Aristimunha, b.aristimunha@gmail.com
7
8
 
8
9
  This program is free software; you can redistribute it and/or modify
9
10
  it under the terms of the GNU General Public License as published by