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

Method get_stc

mne/simulation/source.py:498–576  ·  view source on GitHub ↗

Simulate a SourceEstimate from the provided data. Returns a SourceEstimate object constructed according to the simulation parameters which should be added through function add_data. If both start_sample and stop_sample are not specified, the entire duration is used.

(self, start_sample=None, stop_sample=None)

Source from the content-addressed store, hash-verified

496 return stim_data
497
498 def get_stc(self, start_sample=None, stop_sample=None):
499 """Simulate a SourceEstimate from the provided data.
500
501 Returns a SourceEstimate object constructed according to the simulation
502 parameters which should be added through function add_data. If both
503 start_sample and stop_sample are not specified, the entire duration is
504 used.
505
506 Parameters
507 ----------
508 start_sample : int | None
509 First sample in chunk. If ``None`` the value of the ``first_samp``
510 attribute is used. Defaults to ``None``.
511 stop_sample : int | None
512 The final sample of the returned STC. If ``None``, then all samples
513 past ``start_sample`` are returned.
514
515 Returns
516 -------
517 stc : SourceEstimate object
518 The generated source time courses.
519 """
520 if len(self._labels) == 0:
521 raise ValueError(
522 "No simulation parameters were found. Please use "
523 "function add_data to add simulation parameters."
524 )
525 if start_sample is None:
526 start_sample = self.first_samp
527 if stop_sample is None:
528 stop_sample = start_sample + self.n_times - 1
529 elif stop_sample < start_sample:
530 raise ValueError("start_sample must be >= stop_sample.")
531 n_samples = stop_sample - start_sample + 1
532
533 # Initialize the stc_data array to span all possible samples
534 stc_data = np.zeros((len(self._labels), n_samples))
535
536 # Select only the events that fall within the span
537 ind = np.where(
538 np.logical_and(
539 self._last_samples >= start_sample, self._events[:, 0] <= stop_sample
540 )
541 )[0]
542
543 # Loop only over the items that are in the time span
544 subset_waveforms = [self._waveforms[i] for i in ind]
545 for i, (waveform, event) in enumerate(zip(subset_waveforms, self._events[ind])):
546 # We retrieve the first and last sample of each waveform
547 # According to the corresponding event
548 wf_start = event[0]
549 wf_stop = self._last_samples[ind[i]]
550
551 # Recover the indices of the event that should be in the chunk
552 waveform_ind = np.isin(
553 np.arange(wf_start, wf_stop + 1),
554 np.arange(start_sample, stop_sample + 1),
555 )

Callers 4

__iter__Method · 0.95
test_source_simulatorFunction · 0.95

Calls 1

simulate_stcFunction · 0.85

Tested by 1

test_source_simulatorFunction · 0.76