Create ECG signal from cross channel average.
(inst, start, stop, reject_by_annotation=False, verbose=None)
| 484 | |
| 485 | @verbose |
| 486 | def _make_ecg(inst, start, stop, reject_by_annotation=False, verbose=None): |
| 487 | """Create ECG signal from cross channel average.""" |
| 488 | if not any(c in inst for c in ["mag", "grad"]): |
| 489 | raise ValueError( |
| 490 | "Generating an artificial ECG channel can only be done for MEG data." |
| 491 | ) |
| 492 | for ch in ["mag", "grad"]: |
| 493 | if ch in inst: |
| 494 | break |
| 495 | logger.info( |
| 496 | "Reconstructing ECG signal from {}".format( |
| 497 | {"mag": "Magnetometers", "grad": "Gradiometers"}[ch] |
| 498 | ) |
| 499 | ) |
| 500 | picks = pick_types(inst.info, meg=ch, eeg=False, ref_meg=False) |
| 501 | |
| 502 | # Handle start/stop |
| 503 | msg = ( |
| 504 | "integer arguments for the start and stop parameters are " |
| 505 | "not supported for Epochs and Evoked objects. Please " |
| 506 | "consider using float arguments specifying start and stop " |
| 507 | "time in seconds." |
| 508 | ) |
| 509 | begin_param_name = "tmin" |
| 510 | if isinstance(start, int_like): |
| 511 | if isinstance(inst, BaseRaw): |
| 512 | # Raw has start param, can just use int |
| 513 | begin_param_name = "start" |
| 514 | else: |
| 515 | raise ValueError(msg) |
| 516 | |
| 517 | end_param_name = "tmax" |
| 518 | if isinstance(start, int_like): |
| 519 | if isinstance(inst, BaseRaw): |
| 520 | # Raw has stop param, can just use int |
| 521 | end_param_name = "stop" |
| 522 | else: |
| 523 | raise ValueError(msg) |
| 524 | |
| 525 | kwargs = {begin_param_name: start, end_param_name: stop} |
| 526 | |
| 527 | if isinstance(inst, BaseRaw): |
| 528 | reject_by_annotation = "omit" if reject_by_annotation else None |
| 529 | ecg, times = inst.get_data( |
| 530 | picks, |
| 531 | return_times=True, |
| 532 | **kwargs, |
| 533 | reject_by_annotation=reject_by_annotation, |
| 534 | ) |
| 535 | elif isinstance(inst, BaseEpochs): |
| 536 | ecg = np.hstack(inst.copy().get_data(picks, **kwargs)) |
| 537 | times = inst.times |
| 538 | elif isinstance(inst, Evoked): |
| 539 | ecg = inst.get_data(picks, **kwargs) |
| 540 | times = inst.times |
| 541 | return ecg.mean(0, keepdims=True), times |
no test coverage detected