Fill the surface between sources for a source space label. Parameters ---------- src : SourceSpaces Source space in which the label was defined. If a source space is provided, the label is expanded to fill in surface vertices that lie betw
(self, src, name=None)
| 454 | return cp.deepcopy(self) |
| 455 | |
| 456 | def fill(self, src, name=None): |
| 457 | """Fill the surface between sources for a source space label. |
| 458 | |
| 459 | Parameters |
| 460 | ---------- |
| 461 | src : SourceSpaces |
| 462 | Source space in which the label was defined. If a source space is |
| 463 | provided, the label is expanded to fill in surface vertices that |
| 464 | lie between the vertices included in the source space. For the |
| 465 | added vertices, ``pos`` is filled in with positions from the |
| 466 | source space, and ``values`` is filled in from the closest source |
| 467 | space vertex. |
| 468 | name : None | str |
| 469 | Name for the new Label (default is self.name). |
| 470 | |
| 471 | Returns |
| 472 | ------- |
| 473 | label : Label |
| 474 | The label covering the same vertices in source space but also |
| 475 | including intermediate surface vertices. |
| 476 | |
| 477 | See Also |
| 478 | -------- |
| 479 | Label.restrict |
| 480 | Label.smooth |
| 481 | """ |
| 482 | # find source space patch info |
| 483 | if len(self.vertices) == 0: |
| 484 | return self.copy() |
| 485 | hemi_src = _get_label_src(self, src) |
| 486 | |
| 487 | if not np.all(np.isin(self.vertices, hemi_src["vertno"])): |
| 488 | msg = "Source space does not contain all of the label's vertices" |
| 489 | raise ValueError(msg) |
| 490 | |
| 491 | if hemi_src["nearest"] is None: |
| 492 | warn( |
| 493 | "Source space is being modified in place because patch " |
| 494 | "information is needed. To avoid this in the future, run " |
| 495 | "mne.add_source_space_distances() on the source space " |
| 496 | "and save it to disk." |
| 497 | ) |
| 498 | dist_limit = 0 |
| 499 | add_source_space_distances(src, dist_limit=dist_limit) |
| 500 | nearest = hemi_src["nearest"] |
| 501 | |
| 502 | # find new vertices |
| 503 | include = np.isin(nearest, self.vertices, False) |
| 504 | vertices = np.nonzero(include)[0] |
| 505 | |
| 506 | # values |
| 507 | nearest_in_label = np.digitize(nearest[vertices], self.vertices, True) |
| 508 | values = self.values[nearest_in_label] |
| 509 | # pos |
| 510 | pos = hemi_src["rr"][vertices] |
| 511 | |
| 512 | name = self.name if name is None else name |
| 513 | label = Label( |