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

Method crop

mne/annotations.py:1288–1343  ·  view source on GitHub ↗

Remove all annotations that are outside of [tmin, tmax]. The method operates inplace. Parameters ---------- tmin : float | datetime | None Start time of selection in seconds. tmax : float | datetime | None End time of selection in sec

(
        self, tmin=None, tmax=None, emit_warning=False, use_orig_time=True, verbose=None
    )

Source from the content-addressed store, hash-verified

1286
1287 @verbose
1288 def crop(
1289 self, tmin=None, tmax=None, emit_warning=False, use_orig_time=True, verbose=None
1290 ):
1291 """Remove all annotations that are outside of [tmin, tmax].
1292
1293 The method operates inplace.
1294
1295 Parameters
1296 ----------
1297 tmin : float | datetime | None
1298 Start time of selection in seconds.
1299 tmax : float | datetime | None
1300 End time of selection in seconds.
1301 emit_warning : bool
1302 Whether to emit warnings when limiting or omitting annotations.
1303 Defaults to False.
1304 use_orig_time : bool
1305 Whether to use orig_time as an offset.
1306 Defaults to True.
1307 %(verbose)s
1308
1309 Returns
1310 -------
1311 self : instance of HEDAnnotations
1312 The cropped HEDAnnotations object.
1313 """
1314 if len(self) == 0:
1315 return self
1316 offset, absolute_tmin, absolute_tmax = self._get_crop_lims(
1317 tmin, tmax, use_orig_time
1318 )
1319
1320 keep = []
1321 hed_strings = list(self.hed_string)
1322 for idx, (onset, duration) in enumerate(zip(self.onset, self.duration)):
1323 if np.isnan(duration):
1324 duration = 0.0
1325 absolute_onset = timedelta(seconds=onset) + offset
1326 absolute_offset = absolute_onset + timedelta(seconds=duration)
1327 out_of_bounds = (
1328 absolute_onset > absolute_tmax or absolute_offset < absolute_tmin
1329 )
1330 if not out_of_bounds:
1331 keep.append(idx)
1332
1333 super().crop(
1334 tmin=absolute_tmin,
1335 tmax=absolute_tmax,
1336 emit_warning=emit_warning,
1337 use_orig_time=use_orig_time,
1338 verbose=verbose,
1339 )
1340 self.hed_string = _HEDStrings(
1341 [hed_strings[idx] for idx in keep], hed_version=self._hed_version
1342 )
1343 return self
1344
1345 @fill_doc

Callers 1

test_hed_annotationsFunction · 0.95

Calls 4

_HEDStringsClass · 0.85
_get_crop_limsMethod · 0.80
appendMethod · 0.45
cropMethod · 0.45

Tested by 1

test_hed_annotationsFunction · 0.76