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)[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.

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

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

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

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.head_pos_to_csv(file_name_prefix, head_pos)[source]

Save head positions to csv file for future visualization.

Parameters:
  • file_name_prefix (str) – Prefix for the file name. Example: ‘Head’.

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

Returns:

df_deriv – QC derivative with head positions.

Return type:

QC_derivative

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