From b1e53e51773fae93eaebbe260cf9b45810626120 Mon Sep 17 00:00:00 2001 From: Luke Bloy Date: Wed, 20 Jan 2021 14:40:21 -0500 Subject: [PATCH 1/2] add option to penalized large rotations --- mne/chpi.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mne/chpi.py b/mne/chpi.py index 92f68d8c86e..132b5eb0385 100644 --- a/mne/chpi.py +++ b/mne/chpi.py @@ -491,7 +491,7 @@ def _fit_chpi_quat(coil_dev_rrs, coil_head_rrs): return quat, gof -def _fit_coil_order_dev_head_trans(dev_pnts, head_pnts): +def _fit_coil_order_dev_head_trans(dev_pnts, head_pnts, pen_large_rots=True): """Compute Device to Head transform allowing for permutiatons of points.""" id_quat = np.zeros(6) best_order = None @@ -501,11 +501,14 @@ def _fit_coil_order_dev_head_trans(dev_pnts, head_pnts): head_pnts_tmp = head_pnts[np.array(this_order)] this_quat, g = _fit_chpi_quat(dev_pnts, head_pnts_tmp) assert np.linalg.det(quat_to_rot(this_quat[:3])) > 0.9999 - # For symmetrical arrangements, flips can produce roughly - # equivalent g values. To avoid this, heavily penalize - # large rotations. - rotation = _angle_between_quats(this_quat[:3], np.zeros(3)) - check_g = g * max(1. - rotation / np.pi, 0) ** 0.25 + if pen_large_rots: + # For symmetrical arrangements, flips can produce roughly + # equivalent g values. To avoid this, heavily penalize + # large rotations. + rotation = _angle_between_quats(this_quat[:3], np.zeros(3)) + check_g = g * max(1. - rotation / np.pi, 0) ** 0.25 + else: + check_g = g if check_g > best_g: out_g = g best_g = check_g From 6fbade5e38ca053ab8c08da7f70ad7297216ad02 Mon Sep 17 00:00:00 2001 From: Luke Bloy Date: Fri, 26 Feb 2021 12:40:45 -0500 Subject: [PATCH 2/2] Use Bias --- mne/chpi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mne/chpi.py b/mne/chpi.py index 132b5eb0385..7bcbb80913c 100644 --- a/mne/chpi.py +++ b/mne/chpi.py @@ -491,7 +491,7 @@ def _fit_chpi_quat(coil_dev_rrs, coil_head_rrs): return quat, gof -def _fit_coil_order_dev_head_trans(dev_pnts, head_pnts, pen_large_rots=True): +def _fit_coil_order_dev_head_trans(dev_pnts, head_pnts, bias=True): """Compute Device to Head transform allowing for permutiatons of points.""" id_quat = np.zeros(6) best_order = None @@ -501,7 +501,7 @@ def _fit_coil_order_dev_head_trans(dev_pnts, head_pnts, pen_large_rots=True): head_pnts_tmp = head_pnts[np.array(this_order)] this_quat, g = _fit_chpi_quat(dev_pnts, head_pnts_tmp) assert np.linalg.det(quat_to_rot(this_quat[:3])) > 0.9999 - if pen_large_rots: + if bias: # For symmetrical arrangements, flips can produce roughly # equivalent g values. To avoid this, heavily penalize # large rotations.