Convert a set of labels and values to a STC. This function is meant to work like the opposite of `extract_label_time_course`. Parameters ---------- %(labels_eltc)s values : ndarray, shape (n_labels, ...) The values in each label. Can be 1D or 2D. tmin : float
(
labels, values, tmin=0, tstep=1, subject=None, src=None, verbose=None
)
| 2471 | |
| 2472 | @verbose |
| 2473 | def labels_to_stc( |
| 2474 | labels, values, tmin=0, tstep=1, subject=None, src=None, verbose=None |
| 2475 | ): |
| 2476 | """Convert a set of labels and values to a STC. |
| 2477 | |
| 2478 | This function is meant to work like the opposite of |
| 2479 | `extract_label_time_course`. |
| 2480 | |
| 2481 | Parameters |
| 2482 | ---------- |
| 2483 | %(labels_eltc)s |
| 2484 | values : ndarray, shape (n_labels, ...) |
| 2485 | The values in each label. Can be 1D or 2D. |
| 2486 | tmin : float |
| 2487 | The tmin to use for the STC. |
| 2488 | tstep : float |
| 2489 | The tstep to use for the STC. |
| 2490 | %(subject)s |
| 2491 | %(src_eltc)s |
| 2492 | Can be omitted if using a surface source space, in which case |
| 2493 | the label vertices will determine the output STC vertices. |
| 2494 | Required if using a volumetric source space. |
| 2495 | |
| 2496 | .. versionadded:: 0.22 |
| 2497 | %(verbose)s |
| 2498 | |
| 2499 | Returns |
| 2500 | ------- |
| 2501 | stc : instance of SourceEstimate | instance of VolSourceEstimate |
| 2502 | The values-in-labels converted to a STC. |
| 2503 | |
| 2504 | See Also |
| 2505 | -------- |
| 2506 | extract_label_time_course |
| 2507 | |
| 2508 | Notes |
| 2509 | ----- |
| 2510 | Vertices that appear in more than one label will be averaged. |
| 2511 | |
| 2512 | .. versionadded:: 0.18 |
| 2513 | """ |
| 2514 | values = np.array(values, float) |
| 2515 | if values.ndim == 1: |
| 2516 | values = values[:, np.newaxis] |
| 2517 | if values.ndim != 2: |
| 2518 | raise ValueError(f"values must have 1 or 2 dimensions, got {values.ndim}") |
| 2519 | _validate_type(src, (SourceSpaces, None)) |
| 2520 | if src is None: |
| 2521 | data, vertices, subject = _labels_to_stc_surf( |
| 2522 | labels, values, tmin, tstep, subject |
| 2523 | ) |
| 2524 | klass = SourceEstimate |
| 2525 | else: |
| 2526 | kind = src.kind |
| 2527 | subject = _check_subject( |
| 2528 | src._subject, subject, first_kind="source space subject", raise_error=False |
| 2529 | ) |
| 2530 | _check_option("source space kind", kind, ("surface", "volume")) |