MEGAP
ArticleGitHubLinkedin
  • Bridging the MEG Gap
  • Basic information
    • Core Features
    • Folder Structure
    • BIDS Format
  • Getting Started
    • Installation
    • Flat sensors
    • Extraneous Data
    • Head Position
      • Movement Check
    • Filter cHPI
    • Line noise
      • Zapline_Plus
      • Regression
    • Muscle Artifact
    • Bad Sensors
    • Squid Jumps
    • Environment Noise
    • Artifacts Removal
Powered by GitBook
On this page
  1. Getting Started

Flat sensors

PreviousInstallationNextExtraneous Data

Last updated 6 months ago

CtrlK

Flat sensors can dampen graphs by exhibiting abnormal amplitudes when autoscaling is applied to the signal power spectrum. To ensure accurate visualization, MEGAP first detects and excludes these flat sensors. By detecting them rather than merely adjusting the y-axis, MEGAP can display a warning message ("flat sensor excluded") on the plots. It should be noted that the comprehensive detection of all bad sensors is deferred to later steps.

data.compute_psd().plot()
Damped power spectrum with one flat sensor

The MNE library's function for plotting PSD does not include built-in parameters to disable autoscaling or manually rescale the y-axis.

MEGAP output power spectrum with warning massage

To identify flat sensors based on PREP, the code first detects channels containing NaN values, which indicate missing or corrupted data. It then flags channels with flat signals by evaluating two criteria: Median Absolute Deviation (MAD) and Standard Deviation (STD). Channels with MAD or STD values below a predefined threshold (flat_threshold = 1e-18 T or T/m) are considered flat, as they exhibit no meaningful signal variation.

meg_picks_diff =  mne.pick_types(raw_meg.info, meg=True, ref_meg=False)
meg_data = raw_meg.get_data(picks=meg_picks_diff)
ch_names = [raw_meg.ch_names[i] for i in meg_picks_diff]
# Detect channels containing any NaN values
nan_channel_mask = np.isnan(np.sum(meg_data, axis=1))
nan_channels = np.array(ch_names)[nan_channel_mask]
flat_threshold=1e-18
# Detect channels with flat signals
flat_by_mad = median_abs_deviation(meg_data, axis=1) < flat_threshold
flat_by_std = np.std(meg_data, axis=1) < flat_threshold
flat_channel_mask = flat_by_mad | flat_by_std
flat_channels = np.array(ch_names)[flat_channel_mask]

flat_channel_indices=[]
flat_channel_indices.extend(meg_ch_idx[flat_channel_mask])
flat_channel_indices.extend(meg_ch_idx[nan_channel_mask])
Example of Flat sensors on PSD plot