MCPcopy
hub / github.com/mne-tools/mne-python / annotate_movement

Function annotate_movement

mne/preprocessing/artifact_detection.py:152–299  ·  view source on GitHub ↗

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",
)

Source from the content-addressed store, hash-verified

150
151
152def 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])

Calls 13

AnnotationsClass · 0.85
_angle_between_quatsFunction · 0.85
_mask_to_onsets_offsetsFunction · 0.85
_annotations_from_maskFunction · 0.85
apply_transFunction · 0.85
_quat_to_affineFunction · 0.85
_adjust_onset_meas_dateFunction · 0.85
infoMethod · 0.80
normMethod · 0.80
sqrtMethod · 0.80
copyMethod · 0.45