Aluode/PerceptionLabPortable
0
1# Authors: The MNE-Python contributors.2# License: BSD-3-Clause3# Copyright the MNE-Python contributors.4 5import numpy as np6 7from ..annotations import Annotations, _adjust_onset_meas_date8from ..utils import verbose9from .artifact_detection import _annotations_from_mask10 11 12@verbose13def annotate_nan(raw, *, verbose=None):14 """Detect segments with NaN and return a new Annotations instance.15 16 Parameters17 ----------18 raw : instance of Raw19 Data to find segments with NaN values.20 %(verbose)s21 22 Returns23 -------24 annot : instance of Annotations25 New channel-specific annotations for the data.26 """27 data, times = raw.get_data(return_times=True)28 onsets, durations, ch_names = list(), list(), list()29 for row, ch_name in zip(data, raw.ch_names):30 annot = _annotations_from_mask(times, np.isnan(row), "BAD_NAN")31 onsets.extend(annot.onset)32 durations.extend(annot.duration)33 ch_names.extend([[ch_name]] * len(annot))34 annot = Annotations(35 onsets, durations, "BAD_NAN", ch_names=ch_names, orig_time=raw.info["meas_date"]36 )37 _adjust_onset_meas_date(annot, raw)38 return annot39 