Detect segments with NaN and return a new Annotations instance. Parameters ---------- raw : instance of Raw Data to find segments with NaN values. %(verbose)s Returns ------- annot : instance of Annotations New channel-specific annotations for the data.
(raw, *, verbose=None)
| 11 | |
| 12 | @verbose |
| 13 | def annotate_nan(raw, *, verbose=None): |
| 14 | """Detect segments with NaN and return a new Annotations instance. |
| 15 | |
| 16 | Parameters |
| 17 | ---------- |
| 18 | raw : instance of Raw |
| 19 | Data to find segments with NaN values. |
| 20 | %(verbose)s |
| 21 | |
| 22 | Returns |
| 23 | ------- |
| 24 | annot : instance of Annotations |
| 25 | 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 annot |