eegdash 0.3.6__py3-none-any.whl → 0.3.6.dev99__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/__init__.py CHANGED
@@ -7,4 +7,4 @@ __init__mongo_client()
7
7
 
8
8
  __all__ = ["EEGDash", "EEGDashDataset", "EEGChallengeDataset"]
9
9
 
10
- __version__ = "0.3.6"
10
+ __version__ = "0.3.6.dev99"
eegdash/api.py CHANGED
@@ -6,9 +6,11 @@ from typing import Any, Mapping
6
6
 
7
7
  import mne
8
8
  import numpy as np
9
+ import platformdirs
9
10
  import xarray as xr
10
11
  from dotenv import load_dotenv
11
12
  from joblib import Parallel, delayed
13
+ from mne.utils import warn
12
14
  from mne_bids import get_bids_path_from_fname, read_raw_bids
13
15
  from pymongo import InsertOne, UpdateOne
14
16
  from s3fs import S3FileSystem
@@ -693,9 +695,8 @@ class EEGDash:
693
695
  class EEGDashDataset(BaseConcatDataset):
694
696
  def __init__(
695
697
  self,
696
- query: dict | None = None,
697
- cache_dir: str = "~/eegdash_cache",
698
- dataset: str | list[str] | None = None,
698
+ cache_dir: str | Path,
699
+ query: dict[str, Any] = None,
699
700
  description_fields: list[str] = [
700
701
  "subject",
701
702
  "session",
@@ -706,9 +707,9 @@ class EEGDashDataset(BaseConcatDataset):
706
707
  "sex",
707
708
  ],
708
709
  s3_bucket: str | None = None,
709
- data_dir: str | None = None,
710
710
  eeg_dash_instance=None,
711
711
  records: list[dict] | None = None,
712
+ offline_mode: bool = False,
712
713
  **kwargs,
713
714
  ):
714
715
  """Create a new EEGDashDataset from a given query or local BIDS dataset directory
@@ -754,34 +755,36 @@ class EEGDashDataset(BaseConcatDataset):
754
755
  records : list[dict] | None
755
756
  Optional list of pre-fetched metadata records. If provided, the dataset is
756
757
  constructed directly from these records without querying MongoDB.
758
+ offline_mode : bool
759
+ If True, do not attempt to query MongoDB at all. This is useful if you want to
760
+ work with a local cache only, or if you are offline.
757
761
  kwargs : dict
758
762
  Additional keyword arguments to be passed to the EEGDashBaseDataset
759
763
  constructor.
760
764
 
761
765
  """
762
- self.cache_dir = cache_dir
766
+ self.cache_dir = Path(cache_dir or platformdirs.user_cache_dir("EEGDash"))
767
+ if not self.cache_dir.exists():
768
+ warn(f"Cache directory does not exist, creating it: {self.cache_dir}")
769
+ self.cache_dir.mkdir(exist_ok=True, parents=True)
763
770
  self.s3_bucket = s3_bucket
764
771
  self.eeg_dash = eeg_dash_instance
765
- _owns_client = False
766
- if self.eeg_dash is None and records is None:
767
- self.eeg_dash = EEGDash()
768
- _owns_client = True
769
772
 
770
773
  # Separate query kwargs from other kwargs passed to the BaseDataset constructor
771
- query_kwargs = {
772
- k: v for k, v in kwargs.items() if k in EEGDash._ALLOWED_QUERY_FIELDS
773
- }
774
- base_dataset_kwargs = {k: v for k, v in kwargs.items() if k not in query_kwargs}
774
+ self.query = query or {}
775
+ self.query.update(
776
+ {k: v for k, v in kwargs.items() if k in EEGDash._ALLOWED_QUERY_FIELDS}
777
+ )
778
+ base_dataset_kwargs = {k: v for k, v in kwargs.items() if k not in self.query}
779
+ if "dataset" not in self.query:
780
+ raise ValueError("You must provide a 'dataset' argument")
775
781
 
776
- # If user provided a dataset name via the dedicated parameter (and we're not
777
- # loading from a local directory), treat it as a query filter. Accept str or list.
778
- if data_dir is None and dataset is not None:
779
- # Allow callers to pass a single dataset id (str) or a list of them.
780
- # If list is provided, let _build_query_from_kwargs turn it into $in later.
781
- query_kwargs.setdefault("dataset", dataset)
782
+ self.data_dir = self.cache_dir / self.query["dataset"]
782
783
 
783
- # Allow mixing raw DB query with additional keyword filters. Both will be
784
- # merged by EEGDash.find() (logical AND), so we do not raise here.
784
+ _owns_client = False
785
+ if self.eeg_dash is None and records is None:
786
+ self.eeg_dash = EEGDash()
787
+ _owns_client = True
785
788
 
786
789
  try:
787
790
  if records is not None:
@@ -795,42 +798,25 @@ class EEGDashDataset(BaseConcatDataset):
795
798
  )
796
799
  for record in self.records
797
800
  ]
798
- elif data_dir:
799
- # This path loads from a local directory and is not affected by DB query logic
800
- if isinstance(data_dir, (str, Path)):
801
+ elif offline_mode: # only assume local data is complete if in offline mode
802
+ if self.data_dir.exists():
803
+ # This path loads from a local directory and is not affected by DB query logic
801
804
  datasets = self.load_bids_dataset(
802
- dataset=dataset
803
- if isinstance(dataset, str)
804
- else (dataset[0] if dataset else None),
805
- data_dir=data_dir,
805
+ dataset=self.query["dataset"],
806
+ data_dir=self.data_dir,
806
807
  description_fields=description_fields,
807
808
  s3_bucket=s3_bucket,
808
809
  **base_dataset_kwargs,
809
810
  )
810
811
  else:
811
- assert dataset is not None, (
812
- "dataset must be provided when passing multiple data_dir"
813
- )
814
- assert len(data_dir) == len(dataset), (
815
- "Number of datasets and directories must match"
812
+ raise ValueError(
813
+ f"Offline mode is enabled, but local data_dir {self.data_dir} does not exist."
816
814
  )
817
- datasets = []
818
- for i, _ in enumerate(data_dir):
819
- datasets.extend(
820
- self.load_bids_dataset(
821
- dataset=dataset[i],
822
- data_dir=data_dir[i],
823
- description_fields=description_fields,
824
- s3_bucket=s3_bucket,
825
- **base_dataset_kwargs,
826
- )
827
- )
828
- elif query is not None or query_kwargs:
815
+ elif self.query:
829
816
  # This is the DB query path that we are improving
830
- datasets = self.find_datasets(
831
- query=query,
817
+ datasets = self._find_datasets(
818
+ query=self.eeg_dash._build_query_from_kwargs(**self.query),
832
819
  description_fields=description_fields,
833
- query_kwargs=query_kwargs,
834
820
  base_dataset_kwargs=base_dataset_kwargs,
835
821
  )
836
822
  # We only need filesystem if we need to access S3
@@ -860,11 +846,10 @@ class EEGDashDataset(BaseConcatDataset):
860
846
  return result
861
847
  return None
862
848
 
863
- def find_datasets(
849
+ def _find_datasets(
864
850
  self,
865
851
  query: dict[str, Any] | None,
866
852
  description_fields: list[str],
867
- query_kwargs: dict,
868
853
  base_dataset_kwargs: dict,
869
854
  ) -> list[EEGDashBaseDataset]:
870
855
  """Helper method to find datasets in the MongoDB collection that satisfy the
@@ -888,11 +873,7 @@ class EEGDashDataset(BaseConcatDataset):
888
873
  """
889
874
  datasets: list[EEGDashBaseDataset] = []
890
875
 
891
- # Build records using either a raw query OR keyword filters, but not both.
892
- # Note: callers may accidentally pass an empty dict for `query` along with
893
- # kwargs. In that case, treat it as if no query was provided and rely on kwargs.
894
- # Always delegate merging of raw query + kwargs to EEGDash.find
895
- self.records = self.eeg_dash.find(query, **query_kwargs)
876
+ self.records = self.eeg_dash.find(query)
896
877
 
897
878
  for record in self.records:
898
879
  description = {}
@@ -903,8 +884,8 @@ class EEGDashDataset(BaseConcatDataset):
903
884
  datasets.append(
904
885
  EEGDashBaseDataset(
905
886
  record,
906
- self.cache_dir,
907
- self.s3_bucket,
887
+ cache_dir=self.cache_dir,
888
+ s3_bucket=self.s3_bucket,
908
889
  description=description,
909
890
  **base_dataset_kwargs,
910
891
  )
eegdash/dataset.py CHANGED
@@ -335,7 +335,7 @@ class EEGChallengeDataset(EEGDashDataset):
335
335
  s3_bucket = f"{s3_bucket}/{release}_L100_bdf"
336
336
 
337
337
  super().__init__(
338
- dataset=dataset_parameters,
338
+ dataset=RELEASE_TO_OPENNEURO_DATASET_MAP[release],
339
339
  query=query,
340
340
  cache_dir=cache_dir,
341
341
  s3_bucket=s3_bucket,
eegdash/registry.py CHANGED
@@ -57,7 +57,7 @@ def register_openneuro_datasets(
57
57
 
58
58
  init = make_init(dataset_id)
59
59
 
60
- doc = f"""Create an instance for OpenNeuro dataset ``{dataset_id}``.
60
+ doc = f"""OpenNeuro dataset ``{dataset_id}``.
61
61
 
62
62
  {markdown_table(row_series)}
63
63
 
@@ -69,11 +69,15 @@ def register_openneuro_datasets(
69
69
  Extra Mongo query merged with ``{{'dataset': '{dataset_id}'}}``.
70
70
  s3_bucket : str | None
71
71
  Optional S3 bucket name.
72
+ subject : str | None
73
+ Optional subject identifier.
74
+ task : str | None
75
+ Optional task identifier.
72
76
  **kwargs
73
77
  Passed through to {base_class.__name__}.
74
78
  """
75
79
 
76
- init.__doc__ = doc
80
+ # init.__doc__ = doc
77
81
 
78
82
  cls = type(
79
83
  class_name,
@@ -101,6 +105,7 @@ def markdown_table(row_series: pd.Series) -> str:
101
105
  """Create a reStructuredText grid table from a pandas Series."""
102
106
  if row_series.empty:
103
107
  return ""
108
+ dataset_id = row_series["dataset"]
104
109
 
105
110
  # Prepare the dataframe with user's suggested logic
106
111
  df = (
@@ -112,6 +117,7 @@ def markdown_table(row_series: pd.Series) -> str:
112
117
  "n_tasks": "#Classes",
113
118
  "sampling_freqs": "Freq(Hz)",
114
119
  "duration_hours_total": "Duration(H)",
120
+ "size": "Size",
115
121
  }
116
122
  )
117
123
  .reindex(
@@ -122,6 +128,7 @@ def markdown_table(row_series: pd.Series) -> str:
122
128
  "#Classes",
123
129
  "Freq(Hz)",
124
130
  "Duration(H)",
131
+ "Size",
125
132
  ]
126
133
  )
127
134
  .infer_objects(copy=False)
@@ -131,6 +138,9 @@ def markdown_table(row_series: pd.Series) -> str:
131
138
  # Use tabulate for the final rst formatting
132
139
  table = tabulate(df, headers="keys", tablefmt="rst", showindex=False)
133
140
 
141
+ # Add a caption for the table
142
+ caption = f"Short overview of dataset {dataset_id} more details in the `Nemar documentation <https://nemar.org/dataexplorer/detail?dataset_id={dataset_id}>`_."
143
+ # adding caption below the table
134
144
  # Indent the table to fit within the admonition block
135
145
  indented_table = "\n".join(" " + line for line in table.split("\n"))
136
- return f"\n\n{indented_table}"
146
+ return f"\n\n{indented_table}\n\n{caption}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: eegdash
3
- Version: 0.3.6
3
+ Version: 0.3.6.dev99
4
4
  Summary: EEG data for machine learning
5
5
  Author-email: Young Truong <dt.young112@gmail.com>, Arnaud Delorme <adelorme@gmail.com>, Aviv Dotan <avivd220@gmail.com>, Oren Shriki <oren70@gmail.com>, Bruno Aristimunha <b.aristimunha@gmail.com>
6
6
  License-Expression: GPL-3.0-only
@@ -48,6 +48,7 @@ Requires-Dist: pytest_cases; extra == "tests"
48
48
  Requires-Dist: pytest-benchmark; extra == "tests"
49
49
  Provides-Extra: dev
50
50
  Requires-Dist: pre-commit; extra == "dev"
51
+ Requires-Dist: ipykernel; extra == "dev"
51
52
  Provides-Extra: docs
52
53
  Requires-Dist: sphinx; extra == "docs"
53
54
  Requires-Dist: sphinx_design; extra == "docs"
@@ -55,10 +56,12 @@ Requires-Dist: sphinx_gallery; extra == "docs"
55
56
  Requires-Dist: sphinx_rtd_theme; extra == "docs"
56
57
  Requires-Dist: pydata-sphinx-theme; extra == "docs"
57
58
  Requires-Dist: sphinx-autobuild; extra == "docs"
59
+ Requires-Dist: sphinx-sitemap; extra == "docs"
58
60
  Requires-Dist: numpydoc; extra == "docs"
59
61
  Requires-Dist: memory_profiler; extra == "docs"
60
62
  Requires-Dist: ipython; extra == "docs"
61
63
  Requires-Dist: lightgbm; extra == "docs"
64
+ Requires-Dist: plotly; extra == "docs"
62
65
  Provides-Extra: all
63
66
  Requires-Dist: eegdash[docs]; extra == "all"
64
67
  Requires-Dist: eegdash[dev]; extra == "all"
@@ -1,12 +1,12 @@
1
- eegdash/__init__.py,sha256=98fKNGN_Q6JIg7jL9AQtMbxbGDjnzZ8FAroMiRY-7pA,234
2
- eegdash/api.py,sha256=yotN4vqurZAxVA4q_DK4z0mhh9P8sbpxKzvyxuRSkcQ,38538
1
+ eegdash/__init__.py,sha256=XWizORotB9VyXTEYyeojm1OmzCw6OfkT1Em1o1pnA8U,240
2
+ eegdash/api.py,sha256=_7Ne1uo9ozYgDewuNOGmu79600SJoAGXHHDgyD-eDVw,37460
3
3
  eegdash/data_config.py,sha256=OS6ERO-jHrnEOfMJUehY7ieABdsRw_qWzOKJ4pzSfqw,1323
4
4
  eegdash/data_utils.py,sha256=mi9pscui-BPpRH9ovRtGWiSwHG5QN6K_IvJdYaING2I,27679
5
- eegdash/dataset.py,sha256=iGi7m2FNhLgJxxwSsB9JIy01p4tmdlJIPzdL5CDAJU4,9446
5
+ eegdash/dataset.py,sha256=WoKVmPoBIiRNn5h5ICUMMg5uUa2cMrc5ymChdfYV_f4,9469
6
6
  eegdash/dataset_summary.csv,sha256=9Rw9PawiQ9a_OBRJYKarrzb4UFSGpkGULhYB0MYUieE,14740
7
7
  eegdash/mongodb.py,sha256=GD3WgA253oFgpzOHrYaj4P1mRjNtDMT5Oj4kVvHswjI,2006
8
8
  eegdash/preprocessing.py,sha256=7S_TTRKPKEk47tTnh2D6WExBt4cctAMxUxGDjJqq5lU,2221
9
- eegdash/registry.py,sha256=cxqX53GYyDvg5DkiqJkvjqHDPI72JTPlI4qVh2sILu8,3873
9
+ eegdash/registry.py,sha256=jBR2tGE4YJL4yhbZcn2CN4jaC-ttyVN0wmsCR1uWzoU,4329
10
10
  eegdash/utils.py,sha256=wU9CBQZLW_LIQIBwhgQm5bU4X-rSsVNPdeF2iE4QGJ4,410
11
11
  eegdash/features/__init__.py,sha256=BXNhjvL4_SSFAY1lcP9nyGpkbJNtoOMH4AHlF6OyABo,4078
12
12
  eegdash/features/datasets.py,sha256=kU1DO70ArSIy-LF1hHD2NN4iT-kJrI0mVpSkyV_OSeI,18301
@@ -23,8 +23,8 @@ eegdash/features/feature_bank/dimensionality.py,sha256=j_Ds71Y1AbV2uLFQj8EuXQ4kz
23
23
  eegdash/features/feature_bank/signal.py,sha256=3Tb8z9gX7iZipxQJ9DSyy30JfdmW58kgvimSyZX74p8,3404
24
24
  eegdash/features/feature_bank/spectral.py,sha256=bNB7skusePs1gX7NOU6yRlw_Gr4UOCkO_ylkCgybzug,3319
25
25
  eegdash/features/feature_bank/utils.py,sha256=DGh-Q7-XFIittP7iBBxvsJaZrlVvuY5mw-G7q6C-PCI,1237
26
- eegdash-0.3.6.dist-info/licenses/LICENSE,sha256=asisR-xupy_NrQBFXnx6yqXeZcYWLvbAaiETl25iXT0,931
27
- eegdash-0.3.6.dist-info/METADATA,sha256=jxpD8NJMnPwutQKPSXsL9LsBV5_miObbQy-luSTSUwQ,9919
28
- eegdash-0.3.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
29
- eegdash-0.3.6.dist-info/top_level.txt,sha256=zavO69HQ6MyZM0aQMR2zUS6TAFc7bnN5GEpDpOpFZzU,8
30
- eegdash-0.3.6.dist-info/RECORD,,
26
+ eegdash-0.3.6.dev99.dist-info/licenses/LICENSE,sha256=asisR-xupy_NrQBFXnx6yqXeZcYWLvbAaiETl25iXT0,931
27
+ eegdash-0.3.6.dev99.dist-info/METADATA,sha256=EU7-axNmsF0t2UD9MLG-msef0oPZYyvsN5r4_xAWWzc,10052
28
+ eegdash-0.3.6.dev99.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
29
+ eegdash-0.3.6.dev99.dist-info/top_level.txt,sha256=zavO69HQ6MyZM0aQMR2zUS6TAFc7bnN5GEpDpOpFZzU,8
30
+ eegdash-0.3.6.dev99.dist-info/RECORD,,