MCPcopy Index your code
hub / github.com/mne-tools/mne-python / add_data

Method add_data

mne/simulation/source.py:407–451  ·  view source on GitHub ↗

Add data to the simulation. Data should be added in the form of a triplet of Label (Where) - Waveform(s) (What) - Event(s) (When) Parameters ---------- label : instance of Label The label (as created for example by mne.read_label). If the label

(self, label, waveform, events)

Source from the content-addressed store, hash-verified

405 return self.first_samp + self.n_times - 1
406
407 def add_data(self, label, waveform, events):
408 """Add data to the simulation.
409
410 Data should be added in the form of a triplet of
411 Label (Where) - Waveform(s) (What) - Event(s) (When)
412
413 Parameters
414 ----------
415 label : instance of Label
416 The label (as created for example by mne.read_label). If the label
417 does not match any sources in the SourceEstimate, a ValueError is
418 raised.
419 waveform : array, shape (n_times,) or (n_events, n_times) | list
420 The waveform(s) describing the activity on the label vertices.
421 If list, it must have the same length as events.
422 events : array of int, shape (n_events, 3)
423 Events associated to the waveform(s) to specify when the activity
424 should occur.
425 """
426 _validate_type(label, Label, "label")
427
428 # If it is not a list then make it one
429 if not isinstance(waveform, list) and np.ndim(waveform) == 2:
430 waveform = list(waveform)
431 if not isinstance(waveform, list) and np.ndim(waveform) == 1:
432 waveform = [waveform]
433 if len(waveform) == 1:
434 waveform = waveform * len(events)
435 # The length is either equal to the length of events, or 1
436 if len(waveform) != len(events):
437 raise ValueError(
438 "Number of waveforms and events should match or "
439 f"there should be a single waveform ({len(waveform)} != {len(events)})."
440 )
441 events = _ensure_events(events).astype(np.int64)
442 # Update the last sample possible based on events + waveforms
443 self._labels.extend([label] * len(events))
444 self._waveforms.extend(waveform)
445 self._events = np.concatenate([self._events, events])
446 assert self._events.dtype == np.int64
447 # First sample per waveform is the first column of events
448 # Last is computed below
449 self._last_samples = np.array(
450 [self._events[i, 0] + len(w) - 1 for i, w in enumerate(self._waveforms)]
451 )
452
453 def get_stim_channel(self, start_sample=0, stop_sample=None):
454 """Get the stim channel from the provided data.

Callers 2

test_simulate_raw_bemFunction · 0.95
test_source_simulatorFunction · 0.95

Calls 3

_validate_typeFunction · 0.85
_ensure_eventsFunction · 0.85
extendMethod · 0.45

Tested by 2

test_simulate_raw_bemFunction · 0.76
test_source_simulatorFunction · 0.76