memory / storage check
code:size of data
import sys
# Check memory usage of the raw_eeg_data object
print(f"Size of raw_eeg_data: {sys.getsizeof(raw_eeg_data)} bytes")
code: Is Preload
print(f"Is the data preloaded (in memory)? {raw_eeg_data.preload}")
code:memory usage
import psutil
# Get memory usage of current Python process
process = psutil.Process()
memory_info = process.memory_info()
print(f"Memory usage: {memory_info.rss / (1024 ** 2):.2f} MB")
how to conserve memory
1. Stream the Data Directly from GCS:
Instead of downloading large files to your GCP instance, you can stream the data directly from GCS into memory. This reduces the need for local disk space and can help minimize resource usage. The Python gcsfs library allows you to work with files on GCS as if they were local.
code:eg
Install gcsfs
pip install gcsfs
import mne
import gcsfs
# Initialize GCS FileSystem
fs = gcsfs.GCSFileSystem()
# Open the file directly from GCS without downloading
with fs.open(f'gs://{bucket_name}/{vhdr_path}') as f:
raw = mne.io.read_raw_brainvision(f)
4. Optimize Your Data Handling Workflow:
You might consider breaking down your data into smaller chunks if possible, so you're only loading parts of the EEG dataset at a time. This can prevent overwhelming the system's memory.
code:eg
For example:
python
Copy code
# Load EEG data in smaller chunks or segments
raw = mne.io.read_raw_brainvision(local_vhdr, preload=False)
raw.crop(tmin=0, tmax=60) # Load the first 60 seconds of data
5. Mount GCS Bucket to GCP Using gcsfuse:
You can mount your GCS bucket as a file system on your GCP instance using gcsfuse, which allows you to access GCS files as if they were on a local disk. This way, you don't need to explicitly download the files.
Install gcsfuse:
bash
Copy code
sudo apt-get install gcsfuse
Mount the GCS bucket to a directory:
bash
Copy code
mkdir /path/to/mount
gcsfuse your-bucket-name /path/to/mount
Access files in the mounted directory without fully downloading them to local disk.