Detect segments with movement. Detects segments periods further from rotation_velocity_limit, translation_velocity_limit and mean_distance_limit. It returns an annotation with the bad segments. Parameters ---------- raw : instance of Raw Data to compute head positio
(
raw,
pos,
rotation_velocity_limit=None,
translation_velocity_limit=None,
mean_distance_limit=None,
use_dev_head_trans="average",
)
| 150 | |
| 151 | |
| 152 | def annotate_movement( |
| 153 | raw, |
| 154 | pos, |
| 155 | rotation_velocity_limit=None, |
| 156 | translation_velocity_limit=None, |
| 157 | mean_distance_limit=None, |
| 158 | use_dev_head_trans="average", |
| 159 | ): |
| 160 | """Detect segments with movement. |
| 161 | |
| 162 | Detects segments periods further from rotation_velocity_limit, |
| 163 | translation_velocity_limit and mean_distance_limit. It returns an |
| 164 | annotation with the bad segments. |
| 165 | |
| 166 | Parameters |
| 167 | ---------- |
| 168 | raw : instance of Raw |
| 169 | Data to compute head position. |
| 170 | pos : array, shape (N, 10) |
| 171 | The position and quaternion parameters from cHPI fitting. Obtained |
| 172 | with `mne.chpi` functions. |
| 173 | rotation_velocity_limit : float |
| 174 | Head rotation velocity limit in degrees per second. |
| 175 | translation_velocity_limit : float |
| 176 | Head translation velocity limit in meters per second. |
| 177 | mean_distance_limit : float |
| 178 | Head position limit from mean recording in meters. |
| 179 | use_dev_head_trans : 'average' (default) | 'info' |
| 180 | Identify the device to head transform used to define the |
| 181 | fixed HPI locations for computing moving distances. |
| 182 | If ``average`` the average device to head transform is |
| 183 | computed using ``compute_average_dev_head_t``. |
| 184 | If ``info``, ``raw.info['dev_head_t']`` is used. |
| 185 | |
| 186 | Returns |
| 187 | ------- |
| 188 | annot : mne.Annotations |
| 189 | Periods with head motion. |
| 190 | hpi_disp : array |
| 191 | Head position over time with respect to the mean head pos. |
| 192 | |
| 193 | See Also |
| 194 | -------- |
| 195 | compute_average_dev_head_t |
| 196 | """ |
| 197 | sfreq = raw.info["sfreq"] |
| 198 | hp_ts = pos[:, 0].copy() - raw.first_time |
| 199 | dt = np.diff(hp_ts) |
| 200 | hp_ts = np.concatenate([hp_ts, [hp_ts[-1] + 1.0 / sfreq]]) |
| 201 | orig_time = raw.info["meas_date"] |
| 202 | annot = Annotations([], [], [], orig_time=orig_time) |
| 203 | |
| 204 | # Annotate based on rotational velocity |
| 205 | t_tot = raw.times[-1] |
| 206 | if rotation_velocity_limit is not None: |
| 207 | assert rotation_velocity_limit > 0 |
| 208 | # Rotational velocity (radians / s) |
| 209 | r = _angle_between_quats(pos[:-1, 1:4], pos[1:, 1:4]) |