Sensor Simulation#
SS#
sensor_simulation.py Module for simulating synthetic brain activity data for sensor-level measurements.
- class calibrain.sensor_simulation.SensorSimulator(logger=None)[source]#
Bases:
objectSimulates synthetic brain activity data for sensor-level measurements.
- __init__(logger=None)[source]#
Initialize the SensorSimulator. :type logger:
Optional[Logger] :param logger: Logger instance for logging messages. If None, a default logger will be created. :type logger: Optional[logging.Logger]
- simulate(x_trials, L, orientation_type='fixed', alpha_SNR=0.5, n_trials=1, global_seed=42)[source]#
Simulate sensor trials by projecting source data to sensor space and adding noise to the clean sensor data.
- Parameters:
x_trials (List[np.ndarray]) – List of source time courses for each trial. Each element should be an array of shape (n_sources, n_times) for fixed orientation or (n_sources, 3, n_times) for free orientation.
L (np.ndarray) – Leadfield matrix (µV / nAm for EEG or fT / nAm for MEG). - ‘fixed’: Shape (n_sensors, n_sources). - ‘free’: Shape (n_sensors, 3, n_sources).
orientation_type (str) – Orientation type of the sources (‘fixed’ or ‘free’).
alpha_SNR (float) – Desired signal-to-noise ratio between 0 and 1. - 0.0 means full noise, no signal. - 1.0 means no noise, only signal.
n_trials (int) – Number of trials to simulate. Default is 1.
global_seed (int) – Global seed for random number generation to ensure reproducibility across trials.
- Returns:
- y_clean_all_trialsnp.ndarray
Clean sensor data for all trials. Shape: (n_trials, n_sensors, n_times).
- y_noisy_all_trialsnp.ndarray
Noisy sensor data for all trials. Shape: (n_trials, n_sensors, n_times).
- noise_all_trialsnp.ndarray
Noise added to the clean sensor data for all trials. Shape: (n_trials, n_sensors, n_times).
- noise_var_all_trialsnp.ndarray
Noise variance for each trial. Shape: (n_trials,).
- Return type:
Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]