Head movement artifacts

UML diagrams presenting the flow of the analysis for each module are available here: https://github.com/ANCPLabOldenburg/MEG-QC-code/tree/main/diagrams

meg_qc.calculation.metrics.Head_meg_qc.HEAD_movement_meg_qc(raw: Raw, verbose_plots: bool, plot_annotations: bool = False)[source]

Main function for head movement. Calculates:

  • head positions (x, y, z) and rotations (q1, q2, q3)

  • maximum amplitude of positions and rotations

  • std of positions and rotations over whole time series:
    1. calculate 1 value for positions and 1 value for rotations using Pythagorean theorem - for each time point.

    2. calculate std of these values and get 1 std for positions and 1 std for rotations over whole time series.

Parameters:
  • raw (mne.io.Raw) – Raw data.

  • verbose_plots (bool) – True for showing plot in notebook.

  • plot_with_lines (bool) – If True, plot head movement with lines.

  • plot_annotations (bool) – If True, plot head movement with annotations.

Returns:

  • head_derivs (list) – List of QC derivatives with figures.

  • simple_metrics_head (dict) – Dictionary with simple metrics for head movement.

  • head_str (str) – String with information about head positions if they were not calculated, otherwise empty. For report

meg_qc.calculation.metrics.Head_meg_qc.compute_head_pos_std_and_max_rotation_movement(head_pos: ndarray)[source]

Compute the standard deviation of the movement of the head over time and the maximum rotation and movement in 3 directions.

Parameters:

head_pos (np.ndarray) – Head positions as numpy array calculated by MNE. The shape of the array should be (n_timepoints, 10).

Returns:

  • std_head_pos (float) – Standard deviation of the movement of the head over time: X, Y, Z coordinates are calculated using Pythagorean theorem to get 1 float value.

  • std_head_rotations (float) – Standard deviation of the rotation of the head over time: Q1, Q2, Q3 coordinates are calculated using Pythagorean theorem to get 1 float value.

  • max_movement_xyz (list) – Maximum movement amplitude in 3 directions: X, Y, Z coordinates.

  • max_rotation_q (list) – Maximum rotation amplitude in 3 directions: Q1, Q2, Q3 coordinates.

  • df_head_pos (pandas dataframe) – Head positions as pandas dataframe just for visualization and check.

meg_qc.calculation.metrics.Head_meg_qc.get_head_positions(raw: Raw)[source]

Get head positions and rotations using MNE

Parameters:

raw (mne.io.Raw) – Raw data.

Returns:

  • head_pos (np.ndarray) – Head positions and rotations calculated by MNE.

  • no_head_pos_str (str) – String with information about head positions if they were not calculated, otherwise empty.

meg_qc.calculation.metrics.Head_meg_qc.make_head_annots_plot(raw: Raw, head_pos: ndarray)[source]

Plot raw data with annotated head movement. Currently not used.

Parameters:
  • raw (mne.io.Raw) – Raw data.

  • head_pos (np.ndarray) – Head positions and rotations.

Returns:

head_derivs – List of QC derivatives with annotated figures.

Return type:

list

meg_qc.calculation.metrics.Head_meg_qc.make_head_pos_plot(raw: Raw, head_pos: ndarray, verbose_plots: bool)[source]

Plot positions and rotations of the head.

Parameters:
  • raw (mne.io.Raw) – Raw data.

  • head_pos (np.ndarray) – Head positions and rotations.

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

  • head_derivs (list) – List of QC_derivative objects containing figures with head positions and rotations.

  • head_pos_baselined (np.ndarray) – Head positions and rotations starting from 0 instead of the mne detected starting point. Can be used for plotting.

meg_qc.calculation.metrics.Head_meg_qc.make_simple_metric_head(std_head_pos: float, std_head_rotations: float, max_movement_xyz: list, max_rotation_q: list)[source]

Make simple metric for head positions.

Parameters:
  • std_head_pos (float) – Standard deviation of the movement of the head over time.

  • std_head_rotations (float) – Standard deviation of the rotation of the head over time.

  • max_movement_xyz (list) – Maximum movement amplitude in 3 directions: X, Y, Z coordinates.

  • max_rotation_q (list) – Maximum rotation amplitude in 3 directions: Q1, Q2, Q3 coordinates.

Returns:

simple_metric – Simple metric for head positions.

Return type:

dict