Check or auto-determine the origin.
(origin, info, coord_frame="head", disp=False)
| 1119 | |
| 1120 | |
| 1121 | def _check_origin(origin, info, coord_frame="head", disp=False): |
| 1122 | """Check or auto-determine the origin.""" |
| 1123 | if isinstance(origin, str): |
| 1124 | if origin != "auto": |
| 1125 | raise ValueError( |
| 1126 | f'origin must be a numerical array, or "auto", not {origin}' |
| 1127 | ) |
| 1128 | if coord_frame == "head": |
| 1129 | R, origin = fit_sphere_to_headshape( |
| 1130 | info, verbose=_verbose_safe_false(), units="m" |
| 1131 | )[:2] |
| 1132 | logger.info(f" Automatic origin fit: head of radius {R * 1000:0.1f} mm") |
| 1133 | del R |
| 1134 | else: |
| 1135 | origin = (0.0, 0.0, 0.0) |
| 1136 | origin = np.array(origin, float) |
| 1137 | if origin.shape != (3,): |
| 1138 | raise ValueError("origin must be a 3-element array") |
| 1139 | if disp: |
| 1140 | origin_str = ", ".join([f"{o * 1000:0.1f}" for o in origin]) |
| 1141 | msg = f" Using origin {origin_str} mm in the {coord_frame} frame" |
| 1142 | if coord_frame == "meg" and info["dev_head_t"] is not None: |
| 1143 | o_dev = apply_trans(info["dev_head_t"], origin) |
| 1144 | origin_str = ", ".join(f"{o * 1000:0.1f}" for o in o_dev) |
| 1145 | msg += f" ({origin_str} mm in the head frame)" |
| 1146 | logger.info(msg) |
| 1147 | return origin |
| 1148 | |
| 1149 | |
| 1150 | # ############################################################################ |
no test coverage detected