### Setup and Run Pre-commit Hooks Source: https://github.com/sccn/eegdash/blob/develop/DevNotes.md Installs the pre-commit framework and then installs the git hooks. It also shows how to run all pre-commit hooks on the entire codebase. ```shell pip install pre-commit pre-commit install pre-commit run --all-files ``` -------------------------------- ### Test EEGdash Installation Source: https://github.com/sccn/eegdash/blob/develop/DevNotes.md Verifies that the EEGdash package is installed correctly and can be imported by running a simple Python command. ```python python -c "from eegdash import EEGDashDataset; print(EEGDashDataset)" ``` -------------------------------- ### Install EEGdash Locally using Pip Source: https://github.com/sccn/eegdash/blob/develop/DevNotes.md Installs the EEGdash package and its dependencies from a requirements file. It also shows how to uninstall and then reinstall the package in editable mode for development. ```shell pip install -r requirements.txt pip uninstall eegdash -y python -m pip install --editable . ``` -------------------------------- ### Install Preview EEGDash using Pip Source: https://github.com/sccn/eegdash/blob/develop/docs/source/install/install_source.rst Installs the preview version of EEGDash from PyPI, which is the version currently under development on the main branch and may not be stable. ```shell pip install --pre eegdash ``` -------------------------------- ### Verify EEGDash Installation Source: https://github.com/sccn/eegdash/blob/develop/docs/source/install/install_source.rst Runs a Python command to check if EEGDash is installed correctly and to display its current version. This is a simple verification step after installation. ```shell python -m "import eegdash; eegdash.__version__" ``` -------------------------------- ### Install EEGDash via pip Source: https://github.com/sccn/eegdash/blob/develop/docs/source/install/install.rst This command installs the EEGDash package from the Python Package Index (PyPI) using pip. It is the recommended method for beginners as it automatically handles dependencies. This is a shell command. ```shell pip install eegdash ``` -------------------------------- ### Clone EEGDash Repository and Navigate Source: https://github.com/sccn/eegdash/blob/develop/docs/source/install/install_source.rst Clones the EEGDash repository from GitHub to your local machine and changes the current directory to the root of the cloned repository, preparing for source installation. ```shell git clone https://github.com/sccn/EEGDash && cd EEGDash ``` -------------------------------- ### Install EEGDash with Optional Dependencies (Test, Docs, Dev) using Pip Source: https://github.com/sccn/eegdash/blob/develop/docs/source/install/install_source.rst Installs EEGDash from the local source in editable mode, including optional dependencies required for testing, documentation, and general development workflows. ```shell pip install -e .[test,docs,dev] ``` -------------------------------- ### Install EEGDash from GitHub using Pip Source: https://github.com/sccn/eegdash/blob/develop/docs/source/install/install_source.rst Installs the latest development version of EEGDash directly from its GitHub repository using pip, suitable for users who want the newest features without local cloning. ```shell pip install git+https://github.com/sccn/EEGDash.git ``` -------------------------------- ### Populate Database with EEGdash Data Source: https://github.com/sccn/eegdash/blob/develop/DevNotes.md Instructions for logging into a MongoDB database and running a Python script to ingest data for the EEGdash project. Requires database credentials and modification of a configuration file. ```python # Change eegdash or eegdashstaging in main.py script/data_ingest.py ``` -------------------------------- ### Install EEGDash with All Optional Dependencies using Pip Source: https://github.com/sccn/eegdash/blob/develop/docs/source/install/install_source.rst Installs EEGDash from the local source in editable mode, including all available optional dependencies. This is useful for comprehensive testing and documentation building if you plan to contribute to EEGDash. ```shell pip install -e .[all] ``` -------------------------------- ### Initialize EEGDash Client Source: https://github.com/sccn/eegdash/blob/develop/docs/source/user_guide.rst Connects to the public metadata database using the EEGDash client. This is the first step to interacting with the metadata. ```python from eegdash import EEGDash # Connect to the public database eegdash = EEGDash() ``` -------------------------------- ### Build and Upload EEGdash Package to PyPI Source: https://github.com/sccn/eegdash/blob/develop/DevNotes.md Commands to build the Python package for distribution and upload it to PyPI. This includes updating the version number and using twine for the upload process. ```shell # Update version in pyproject.toml python -m build python -m twine upload --repository testpypi dist/* # OR python -m twine upload dist/* ``` -------------------------------- ### Install EEGDash from Local Source with Pip (Editable Mode) Source: https://github.com/sccn/eegdash/blob/develop/docs/source/install/install_source.rst Installs EEGDash from a local clone of the repository in editable mode using pip. This allows direct use of source code changes in Python without reinstallation. ```shell pip install -e . ``` -------------------------------- ### Verify EEG-Dash Installation in Python Source: https://github.com/sccn/eegdash/blob/develop/README.md This Python code snippet verifies the installation of the eegdash package by attempting to import the EEGDash class. A successful import indicates the package is installed correctly. ```python from eegdash import EEGDash ``` -------------------------------- ### Initialize EEGDashDataset Source: https://github.com/sccn/eegdash/blob/develop/docs/source/user_guide.rst Initializes the EEGDashDataset for a specific dataset, specifying a cache directory for downloaded data. This object is used to load EEG recordings. ```python from eegdash import EEGDashDataset # Initialize the dataset for ds002718 dataset = EEGDashDataset( cache_dir="./eeg_data", dataset="ds002718", ) print(f"Found {len(dataset)} recordings in the dataset.") ``` -------------------------------- ### Remount Remote File System using SSHFS Source: https://github.com/sccn/eegdash/blob/develop/DevNotes.md Command to mount a remote directory from an SDSC Expanse server to a local directory using SSHFS. This requires SSH access and appropriate file system permissions. ```shell sudo sshfs -o allow_other,IdentityFile=/home/dung/.ssh/id_rsa arno@login.expanse.sdsc.edu:/expanse/projects/nemar /mnt/nemar/ ``` -------------------------------- ### Access and Load EEG Data from EEGDashDataset - Python Source: https://github.com/sccn/eegdash/blob/develop/docs/source/user_guide.rst Demonstrates how to access individual recordings from an EEGDashDataset object and load the EEG data using MNE-Python. It retrieves the first recording, loads it into an MNE Raw object, and prints metadata such as subject, sampling frequency, and number of channels. ```python from eegdash.api import EEGDashDataset # Assuming 'dataset' is an initialized EEGDashDataset object # dataset = EEGDashDataset(...) if len(dataset) > 0: # Get the first recording recording = dataset[0] # Load the EEG data as a raw MNE object raw = recording.load() print(f"Loaded recording for subject: {recording.description['subject']}") print(f"Sampling frequency: {raw.info['sfreq']} Hz") print(f"Number of channels: {len(raw.ch_names)}") ``` -------------------------------- ### Filter EEGDashDataset by Subject Source: https://github.com/sccn/eegdash/blob/develop/docs/source/user_guide.rst Initializes an EEGDashDataset instance filtered to include recordings from a specific subject or a list of subjects. ```python # Filter by a single subject subject_dataset = EEGDashDataset( cache_dir="./eeg_data", dataset="ds002718", subject="012" ) print(f"Found {len(subject_dataset)} recordings for subject 012.") # Filter by a list of subjects multi_subject_dataset = EEGDashDataset( cache_dir="./eeg_data", dataset="ds002718", subject=["012", "013", "014"] ) print(f"Found {len(multi_subject_dataset)} recordings for subjects 012, 013, and 014.") ``` -------------------------------- ### Filter EEGDashDataset by Task Source: https://github.com/sccn/eegdash/blob/develop/docs/source/user_guide.rst Initializes an EEGDashDataset instance filtered to include only recordings associated with a specific experimental task, such as 'RestingState'. ```python # Filter by a single task resting_state_dataset = EEGDashDataset( cache_dir="./eeg_data", dataset="ds002718", task="RestingState" ) print(f"Found {len(resting_state_dataset)} resting-state recordings.") ``` -------------------------------- ### Find Records with EEGDash Source: https://github.com/sccn/eegdash/blob/develop/docs/source/user_guide.rst Queries the metadata database for records matching specific criteria. Supports simple keyword arguments or complex MongoDB query dictionaries. ```python # Find records for a specific dataset and subject records = eegdash.find(dataset="ds002718", subject="012") print(f"Found {len(records)} records.") # You can also use more complex queries query = {"dataset": "ds002718", "subject": {"$in": ["012", "013"]}} records_advanced = eegdash.find(query) print(f"Found {len(records_advanced)} records with advanced query.") ``` -------------------------------- ### Initialize EEGDashDataset in Offline Mode - Python Source: https://github.com/sccn/eegdash/blob/develop/docs/source/user_guide.rst Shows how to initialize the EEGDashDataset in offline mode by setting 'download=False'. This enables the library to use locally stored BIDS-compliant data instead of accessing remote resources. The code specifies the cache directory and dataset name, then prints the number of local recordings found. ```python from eegdash.api import EEGDashDataset # Initialize in offline mode local_dataset = EEGDashDataset( cache_dir="./eeg_data", dataset="ds002718", download=False ) print(f"Found {len(local_dataset)} local recordings.") ``` -------------------------------- ### Download EEG Files Directly from S3 Source: https://context7.com/sccn/eegdash/llms.txt This Python code illustrates how to download EEG files from S3 storage using EEGDash's downloader module. It includes steps to get the S3 filesystem object, construct the S3 path, and specify the local destination for the downloaded file. ```python from eegdash.downloader import ( get_s3_filesystem, download_s3_file, get_s3path ) from pathlib import Path # Get S3 filesystem fs = get_s3_filesystem() # Construct S3 path s3_bucket = "s3://openneuro.org" file_path = "ds002718/sub-012/eeg/sub-012_task-RestingState_eeg.set" s3_path = get_s3path(s3_bucket, file_path) # Download file local_path = Path.home() / "eegdash" / "downloads" / "sub-012_task-RestingState_eeg.set" local_path.parent.mkdir(parents=True, exist_ok=True) downloaded_file = download_s3_file( s3_path=s3_path, local_path=local_path, s3_open_neuro=True ) print(f"Downloaded to: {downloaded_file}") print(f"File exists: {downloaded_file.exists()}") ``` -------------------------------- ### Advanced EEG Queries with MongoDB Syntax - Python Source: https://github.com/sccn/eegdash/blob/develop/docs/source/user_guide.rst Illustrates using a MongoDB-style query dictionary with the 'query' parameter for advanced filtering of EEG data. This method supports operators like '$in' for flexible querying. The code initializes EEGDashDataset with a custom query and prints the count of matching recordings. ```python from eegdash.api import EEGDashDataset # Use a MongoDB-style query query = { "dataset": "ds002718", "subject": {"$in": ["012", "013"]}, "task": "RestingState" } advanced_dataset = EEGDashDataset(cache_dir="./eeg_data", query=query) print(f"Found {len(advanced_dataset)} recordings using an advanced query.") ``` -------------------------------- ### Combine Filters for Specific EEG Queries - Python Source: https://github.com/sccn/eegdash/blob/develop/docs/source/user_guide.rst Demonstrates combining subject and task filters to create a specific query for EEG recordings. This requires the EEGDashDataset class and specifies the cache directory, dataset name, subject list, and task type as parameters. It outputs the number of recordings found matching the criteria. ```python from eegdash.api import EEGDashDataset # Combine subject and task filters combined_filter_dataset = EEGDashDataset( cache_dir="./eeg_data", dataset="ds002718", subject=["012", "013"], task="RestingState" ) print(f"Found {len(combined_filter_dataset)} recordings matching the criteria.") ``` -------------------------------- ### Create ML Training Windows from EEG Data Source: https://context7.com/sccn/eegdash/llms.txt This Python script demonstrates how to load and preprocess EEG data using EEGDash, create time windows from events, split the data into training and testing sets, and prepare PyTorch DataLoaders for machine learning. ```python from eegdash import EEGDashDataset from eegdash.hbn.preprocessing import hbn_ec_ec_reannotation from braindecode.preprocessing import preprocess, Preprocessor, create_windows_from_events from pathlib import Path import numpy as np import torch from sklearn.model_selection import train_test_split from torch.utils.data import DataLoader, TensorDataset cache_dir = Path.home() / "eegdash" # Load and preprocess dataset dataset = EEGDashDataset( cache_dir=cache_dir, dataset="ds005514", subject="NDARDB033FW5", task="RestingState" ) preprocessors = [ hbn_ec_ec_reannotation(), Preprocessor("pick_channels", ch_names=["E22", "E9", "E33", "Cz"]), Preprocessor("resample", sfreq=128), Preprocessor("filter", l_freq=1, h_freq=55) ] preprocess(dataset, preprocessors) # Create 2-second windows from events windows_ds = create_windows_from_events( dataset, trial_start_offset_samples=0, trial_stop_offset_samples=256, # 2 seconds at 128 Hz preload=True ) # Extract labels labels = np.array([ds[1] for ds in windows_ds]) print(f"Total windows: {len(windows_ds)}") print(f"Labels: {np.unique(labels)}") # Split into train/test train_idx, test_idx = train_test_split( range(len(windows_ds)), test_size=0.2, stratify=labels, random_state=42 ) # Convert to PyTorch tensors X_train = torch.FloatTensor(np.array([windows_ds[i][0] for i in train_idx])) X_test = torch.FloatTensor(np.array([windows_ds[i][0] for i in test_idx])) y_train = torch.LongTensor(labels[train_idx]) y_test = torch.LongTensor(labels[test_idx]) # Create DataLoaders train_loader = DataLoader( TensorDataset(X_train, y_train), batch_size=32, shuffle=True ) test_loader = DataLoader( TensorDataset(X_test, y_test), batch_size=32, shuffle=False ) print(f"Training batches: {len(train_loader)}") print(f"Test batches: {len(test_loader)}") print(f"Input shape: {X_train.shape}") ``` -------------------------------- ### Add Custom BIDS Dataset to MongoDB Source: https://context7.com/sccn/eegdash/llms.txt This Python script demonstrates how to add a local BIDS dataset to a private MongoDB instance using the EEGDash library. It requires environment variables for the database connection and includes steps for connecting, adding the dataset, verifying the insertion, and closing the database connection. ```python from eegdash import EEGDash from dotenv import load_dotenv # Load environment variables with DB_CONNECTION_STRING load_dotenv() # Connect to private database eegdash = EEGDash(is_public=False) # Add BIDS dataset from local directory eegdash.add_bids_dataset( dataset="ds999999", data_dir="/path/to/local/bids/dataset", overwrite=True ) # Verify insertion records = eegdash.find(dataset="ds999999") print(f"Inserted {len(records)} records") # Close connections EEGDash.close_all_connections() ``` -------------------------------- ### Apply Braindecode Preprocessing Pipelines Source: https://context7.com/sccn/eegdash/llms.txt Applies preprocessing pipelines to EEG data using braindecode integration. Defines a sequence of preprocessing steps, including channel selection, resampling, and filtering, and applies them to an EEGDashDataset. Returns preprocessed data loaded as an mne.io.Raw object. ```python from eegdash import EEGDashDataset from eegdash.hbn.preprocessing import hbn_ec_ec_reannotation from braindecode.preprocessing import preprocess, Preprocessor from pathlib import Path cache_dir = Path.home() / "eegdash" # Load resting state dataset dataset = EEGDashDataset( cache_dir=cache_dir, dataset="ds005514", subject="NDARDB033FW5", task="RestingState" ) # Define preprocessing pipeline preprocessors = [ hbn_ec_ec_reannotation(), # HBN-specific event reannotation Preprocessor( "pick_channels", ch_names=["E22", "E9", "E33", "E24", "E11", "E124", "E122", "E29", "E6", "E111", "E45", "E36", "E104", "E108", "E42", "E55", "E93", "E58", "E52", "E62", "E92", "E96", "E70", "Cz"] ), Preprocessor("resample", sfreq=128), Preprocessor("filter", l_freq=1, h_freq=55) ] # Apply preprocessing preprocess(dataset, preprocessors) # Access preprocessed data raw = dataset[0].load() print(f"Preprocessed sampling rate: {raw.info['sfreq']} Hz") print(f"Channels after selection: {len(raw.ch_names)}") ``` -------------------------------- ### Load EEG Recordings as PyTorch Dataset Source: https://context7.com/sccn/eegdash/llms.txt Loads EEG recordings into a PyTorch-compatible dataset with automatic S3 downloading and local caching. Supports filtering by dataset, subject, and task. Can operate in offline mode by setting download=False. Returns an EEGDashDataset object. ```python from eegdash import EEGDashDataset from pathlib import Path cache_dir = Path.home() / "eegdash" # Load dataset with simple filters dataset = EEGDashDataset( cache_dir=cache_dir, dataset="ds002718", subject="012" ) # Multiple subjects and task filtering dataset = EEGDashDataset( cache_dir=cache_dir, dataset="ds002718", subject=["012", "013", "014"], task="RestingState" ) # Access recordings print(f"Number of recordings: {len(dataset)}") if len(dataset) > 0: recording = dataset[0] raw = recording.load() # Returns mne.io.Raw object print(f"Sampling rate: {raw.info['sfreq']} Hz") print(f"Channels: {len(raw.ch_names)}") print(f"Duration: {raw.times[-1]:.1f} seconds") # Offline mode - use local data only dataset = EEGDashDataset( cache_dir=cache_dir, dataset="ds002718", subject="012", download=False ) ``` -------------------------------- ### Load EEG 2025 Challenge Data Source: https://context7.com/sccn/eegdash/llms.txt Specialized dataset loader for the EEG 2025 Challenge, providing access to preprocessed data. Supports loading full or mini releases, filtering by subjects, and applying additional queries. Returns an EEGChallengeDataset object. ```python from eegdash import EEGChallengeDataset from pathlib import Path cache_dir = Path.home() / "eegdash" # Load mini release for challenge dataset = EEGChallengeDataset( release="R1", cache_dir=cache_dir, mini=True ) # Load full release dataset = EEGChallengeDataset( release="R1", cache_dir=cache_dir, mini=False ) # Filter specific subjects in mini release dataset = EEGChallengeDataset( release="R1", cache_dir=cache_dir, mini=True, subject=["NDARAA536PTU", "NDARAB793GL3"] ) # Additional filtering with query dataset = EEGChallengeDataset( release="R2", cache_dir=cache_dir, mini=True, query={"task": "RestingState"} ) ``` -------------------------------- ### Query EEGDash MongoDB Metadata Source: https://context7.com/sccn/eegdash/llms.txt High-level client for querying the EEGDash metadata database. Supports simple filters, multiple subjects, raw MongoDB queries, and checks for dataset existence. Returns a list of matching records or a boolean. ```python from eegdash import EEGDash # Connect to public database eegdash = EEGDash() # Find recordings with simple filters records = eegdash.find(dataset="ds002718", subject="012") # Find with multiple subjects (converts to $in query) records = eegdash.find(dataset="ds002718", subject=["012", "013", "014"]) # Use raw MongoDB queries records = eegdash.find({ "dataset": "ds002718", "subject": {"$in": ["012", "013"]}, "task": "RestingState" }) # Combine raw query with keyword filters records = eegdash.find( {"dataset": "ds002718"}, subject=["012", "013"] ) # Check if dataset exists exists = eegdash.exist({"dataset": "ds002718"}) print(f"Dataset exists: {exists}") ``` -------------------------------- ### Extract Spectral Features from EEG Data Source: https://context7.com/sccn/eegdash/llms.txt This Python script shows how to use the EEGDash FeatureExtractor to compute spectral features like entropy, moment, and Hjorth activity from simulated EEG data. It initializes the extractor with a dictionary of feature functions and sampling parameters. ```python from eegdash.features import FeatureExtractor from eegdash.features.feature_bank.spectral import ( spectral_entropy, spectral_moment, spectral_hjorth_activity ) import numpy as np # Create feature extractor feature_dict = { "entropy": spectral_entropy, "moment": spectral_moment, "hjorth": spectral_hjorth_activity } extractor = FeatureExtractor( feature_dict, fs=128, # Sampling frequency f_min=1, f_max=50 ) # Simulate EEG data (batch_size=10, channels=4, samples=256) batch_size = 10 n_channels = 4 n_samples = 256 x = np.random.randn(batch_size, n_channels, n_samples) channel_names = ["Ch1", "Ch2", "Ch3", "Ch4"] # Fit if trainable (not needed for spectral features) if extractor._is_trainable: extractor.partial_fit(x) extractor.fit() # Extract features features = extractor(x, _batch_size=batch_size, _ch_names=channel_names) print(f"Extracted features: {list(features.keys())}") for name, values in features.items(): print(f"{name}: shape {values.shape}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.