Convert forward solution between different source orientations. Parameters ---------- fwd : Forward The forward solution to modify. surf_ori : bool, optional (default False) Use surface-based source coordinate system? Note that force_fixed=True implies surf_o
(
fwd, surf_ori=False, force_fixed=False, copy=True, use_cps=True, *, verbose=None
)
| 716 | |
| 717 | @verbose |
| 718 | def convert_forward_solution( |
| 719 | fwd, surf_ori=False, force_fixed=False, copy=True, use_cps=True, *, verbose=None |
| 720 | ): |
| 721 | """Convert forward solution between different source orientations. |
| 722 | |
| 723 | Parameters |
| 724 | ---------- |
| 725 | fwd : Forward |
| 726 | The forward solution to modify. |
| 727 | surf_ori : bool, optional (default False) |
| 728 | Use surface-based source coordinate system? Note that force_fixed=True |
| 729 | implies surf_ori=True. |
| 730 | force_fixed : bool, optional (default False) |
| 731 | If True, force fixed source orientation mode. |
| 732 | copy : bool |
| 733 | Whether to return a new instance or modify in place. |
| 734 | %(use_cps)s |
| 735 | %(verbose)s |
| 736 | |
| 737 | Returns |
| 738 | ------- |
| 739 | fwd : Forward |
| 740 | The modified forward solution. |
| 741 | """ |
| 742 | fwd = fwd.copy() if copy else fwd |
| 743 | |
| 744 | if force_fixed is True: |
| 745 | surf_ori = True |
| 746 | |
| 747 | if any([src["type"] == "vol" for src in fwd["src"]]) and force_fixed: |
| 748 | raise ValueError( |
| 749 | "Forward operator was generated with sources from a " |
| 750 | "volume source space. Conversion to fixed orientation is not " |
| 751 | "possible. Consider using a discrete source space if you have " |
| 752 | "meaningful normal orientations." |
| 753 | ) |
| 754 | |
| 755 | if surf_ori and use_cps: |
| 756 | if any(s.get("patch_inds") is not None for s in fwd["src"]): |
| 757 | logger.info( |
| 758 | " Average patch normals will be employed in " |
| 759 | "the rotation to the local surface coordinates.." |
| 760 | ".." |
| 761 | ) |
| 762 | else: |
| 763 | use_cps = False |
| 764 | logger.info( |
| 765 | " No patch info available. The standard source " |
| 766 | "space normals will be employed in the rotation " |
| 767 | "to the local surface coordinates...." |
| 768 | ) |
| 769 | |
| 770 | # We need to change these entries (only): |
| 771 | # 1. source_nn |
| 772 | # 2. sol['data'] |
| 773 | # 3. sol['ncol'] |
| 774 | # 4. sol_grad['data'] |
| 775 | # 5. sol_grad['ncol'] |