|
15 | 15 | import re
|
16 | 16 |
|
17 | 17 | import numpy as np
|
| 18 | +import os.path as op |
18 | 19 |
|
19 | 20 | from ...utils import verbose, logger, warn
|
20 | 21 | from ..utils import _blk_read_lims
|
21 | 22 | from ..base import BaseRaw, _check_update_montage
|
22 | 23 | from ..meas_info import _empty_info, _unique_channel_names, DATE_NONE
|
23 | 24 | from ..constants import FIFF
|
24 | 25 | from ...filter import resample
|
25 |
| -from ...utils import copy_function_doc_to_method_doc |
26 |
| -from ...annotations import Annotations |
| 26 | +from ...utils import copy_function_doc_to_method_doc, deprecated |
| 27 | +from ...annotations import Annotations, events_from_annotations |
| 28 | +from ._utils import _load_gdf_events_lut |
27 | 29 |
|
28 | 30 |
|
| 31 | +GDF_EVENT_ENCODES_FILE = op.join(op.dirname(__file__), 'gdf_encodes.txt') |
| 32 | +GDF_EVENTS_LUT = _load_gdf_events_lut(fname=GDF_EVENT_ENCODES_FILE, |
| 33 | + md5='12134a9be7e0bfa5941e95f8bfd330f7') |
| 34 | + |
| 35 | + |
| 36 | +@deprecated('find_edf_events is deprecated in 0.18, and will be removed' |
| 37 | + ' in 0.19. Please use `mne.events_from_annotations` instead') |
29 | 38 | def find_edf_events(raw):
|
30 | 39 | """Get original EDF events as read from the header.
|
31 | 40 |
|
@@ -65,7 +74,7 @@ def find_edf_events(raw):
|
65 | 74 | events : ndarray
|
66 | 75 | The events as they are in the file header.
|
67 | 76 | """
|
68 |
| - return raw.find_edf_events() |
| 77 | + return events_from_annotations(raw) |
69 | 78 |
|
70 | 79 |
|
71 | 80 | class RawEDF(BaseRaw):
|
@@ -176,34 +185,19 @@ def __init__(self, input_fname, montage, eog=None, misc=None,
|
176 | 185 | verbose=verbose)
|
177 | 186 |
|
178 | 187 | # Read annotations from file and set it
|
179 |
| - annot = None |
| 188 | + onset, duration, desc = list(), list(), list() |
180 | 189 | ext = os.path.splitext(input_fname)[1][1:].lower()
|
181 | 190 | if ext in ('gdf'):
|
182 |
| - events = edf_info.get('events', None) |
183 |
| - # Annotations in GDF: events are stored as the following |
184 |
| - # list: `events = [n_events, pos, typ, chn, dur]` where pos is the |
185 |
| - # latency, dur is the duration in samples. They both are |
186 |
| - # numpy.ndarray |
187 |
| - if events is not None and events[1].shape[0] > 0: |
188 |
| - # For whatever reason, typ has the same content as pos |
189 |
| - # therefore we set an arbitrary description |
190 |
| - desc = 'GDF event' |
191 |
| - annot = Annotations(onset=events[1] / self.info['sfreq'], |
192 |
| - duration=events[4] / self.info['sfreq'], |
193 |
| - description=desc, |
194 |
| - orig_time=None) |
| 191 | + onset, duration, desc = _get_annotations_gdf(edf_info, |
| 192 | + self.info['sfreq']) |
195 | 193 | elif len(edf_info['tal_idx']) > 0:
|
196 | 194 | # Read TAL data exploiting the header info (no regexp)
|
197 | 195 | tal_data = self._read_segment_file([], [], 0, 0, int(self.n_times),
|
198 | 196 | None, None)
|
199 | 197 | onset, duration, desc = _read_annotations_edf(tal_data[0])
|
200 | 198 |
|
201 |
| - # in EDF, annotations are relative to first_samp |
202 |
| - annot = Annotations(onset=onset, duration=duration, |
203 |
| - description=desc, orig_time=None) |
204 |
| - |
205 |
| - if annot is not None: |
206 |
| - self.set_annotations(annot) |
| 199 | + self.set_annotations(Annotations(onset=onset, duration=duration, |
| 200 | + description=desc, orig_time=None)) |
207 | 201 |
|
208 | 202 | @verbose
|
209 | 203 | def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
|
@@ -328,8 +322,10 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
|
328 | 322 | return tal_data
|
329 | 323 |
|
330 | 324 | @copy_function_doc_to_method_doc(find_edf_events)
|
| 325 | + @deprecated('find_edf_events is deprecated in 0.18, and will be removed' |
| 326 | + ' in 0.19. Please use `mne.events_from_annotations` instead') |
331 | 327 | def find_edf_events(self):
|
332 |
| - return self._raw_extras[0]['events'] |
| 328 | + return events_from_annotations(self) |
333 | 329 |
|
334 | 330 |
|
335 | 331 | def _read_ch(fid, subtype, samp, dtype_byte, dtype=None):
|
@@ -1223,3 +1219,20 @@ def _get_edf_default_event_id(descriptions):
|
1223 | 1219 | mapping = dict((a, n) for n, a in
|
1224 | 1220 | enumerate(sorted(set(descriptions)), start=1))
|
1225 | 1221 | return mapping
|
| 1222 | + |
| 1223 | + |
| 1224 | +def _get_annotations_gdf(edf_info, sfreq): |
| 1225 | + onset, duration, desc = list(), list(), list() |
| 1226 | + events = edf_info.get('events', None) |
| 1227 | + # Annotations in GDF: events are stored as the following |
| 1228 | + # list: `events = [n_events, pos, typ, chn, dur]` where pos is the |
| 1229 | + # latency, dur is the duration in samples. They both are |
| 1230 | + # numpy.ndarray |
| 1231 | + if events is not None and events[1].shape[0] > 0: |
| 1232 | + onset = events[1] / sfreq |
| 1233 | + duration = events[4] / sfreq |
| 1234 | + desc = [GDF_EVENTS_LUT[key] |
| 1235 | + if key in GDF_EVENTS_LUT else 'Unknown' |
| 1236 | + for key in events[2]] |
| 1237 | + |
| 1238 | + return onset, duration, desc |
0 commit comments