(self, data, vertices, tmin, tstep, subject=None, verbose=None)
| 497 | |
| 498 | @verbose |
| 499 | def __init__(self, data, vertices, tmin, tstep, subject=None, verbose=None): |
| 500 | assert hasattr(self, "_data_ndim"), self.__class__.__name__ |
| 501 | assert hasattr(self, "_src_type"), self.__class__.__name__ |
| 502 | assert hasattr(self, "_src_count"), self.__class__.__name__ |
| 503 | kernel, sens_data = None, None |
| 504 | if isinstance(data, tuple): |
| 505 | if len(data) != 2: |
| 506 | raise ValueError("If data is a tuple it has to be length 2") |
| 507 | kernel, sens_data = data |
| 508 | data = None |
| 509 | if kernel.shape[1] != sens_data.shape[0]: |
| 510 | raise ValueError( |
| 511 | f"kernel ({kernel.shape}) and sens_data ({sens_data.shape}) " |
| 512 | "have invalid dimensions" |
| 513 | ) |
| 514 | if sens_data.ndim != 2: |
| 515 | raise ValueError( |
| 516 | "The sensor data must have 2 dimensions, got {sens_data.ndim}" |
| 517 | ) |
| 518 | |
| 519 | _validate_type(vertices, list, "vertices") |
| 520 | if self._src_count is not None: |
| 521 | if len(vertices) != self._src_count: |
| 522 | raise ValueError( |
| 523 | f"vertices must be a list with {self._src_count} entries, " |
| 524 | f"got {len(vertices)}." |
| 525 | ) |
| 526 | vertices = [np.array(v, np.int64) for v in vertices] # makes copy |
| 527 | if any(np.any(np.diff(v) <= 0) for v in vertices): |
| 528 | raise ValueError("Vertices must be ordered in increasing order.") |
| 529 | |
| 530 | n_src = sum([len(v) for v in vertices]) |
| 531 | |
| 532 | # safeguard the user against doing something silly |
| 533 | if data is not None: |
| 534 | if data.ndim not in (self._data_ndim, self._data_ndim - 1): |
| 535 | raise ValueError( |
| 536 | f"Data (shape {data.shape}) must have {self._data_ndim} " |
| 537 | f"dimensions for {self.__class__.__name__}" |
| 538 | ) |
| 539 | if data.shape[0] != n_src: |
| 540 | raise ValueError( |
| 541 | f"Number of vertices ({n_src}) and stc.data.shape[0] " |
| 542 | f"({data.shape[0]}) must match" |
| 543 | ) |
| 544 | if self._data_ndim == 3: |
| 545 | if data.shape[1] != 3: |
| 546 | raise ValueError( |
| 547 | "Data for VectorSourceEstimate must have " |
| 548 | f"shape[1] == 3, got shape {data.shape}" |
| 549 | ) |
| 550 | if data.ndim == self._data_ndim - 1: # allow upbroadcasting |
| 551 | data = data[..., np.newaxis] |
| 552 | |
| 553 | self._data = data |
| 554 | self._tmin = tmin |
| 555 | self._tstep = tstep |
| 556 | self.vertices = vertices |
no test coverage detected