Get a decomposition matrix and pseudoinverse matrices.
(
trans,
*,
all_coils,
cal,
regularize,
exp,
ignore_ref,
coil_scale,
grad_picks,
mag_picks,
good_mask,
mag_or_fine,
bad_condition,
t,
mag_scale,
mult,
)
| 1270 | |
| 1271 | |
| 1272 | def _get_decomp( |
| 1273 | trans, |
| 1274 | *, |
| 1275 | all_coils, |
| 1276 | cal, |
| 1277 | regularize, |
| 1278 | exp, |
| 1279 | ignore_ref, |
| 1280 | coil_scale, |
| 1281 | grad_picks, |
| 1282 | mag_picks, |
| 1283 | good_mask, |
| 1284 | mag_or_fine, |
| 1285 | bad_condition, |
| 1286 | t, |
| 1287 | mag_scale, |
| 1288 | mult, |
| 1289 | ): |
| 1290 | """Get a decomposition matrix and pseudoinverse matrices.""" |
| 1291 | # |
| 1292 | # Fine calibration processing (point-like magnetometers and calib. coeffs) |
| 1293 | # |
| 1294 | S_decomp_full = _get_s_decomp( |
| 1295 | exp, |
| 1296 | all_coils, |
| 1297 | trans, |
| 1298 | coil_scale, |
| 1299 | cal, |
| 1300 | ignore_ref, |
| 1301 | grad_picks, |
| 1302 | mag_picks, |
| 1303 | mag_scale, |
| 1304 | ) |
| 1305 | if mult is not None: |
| 1306 | S_decomp_full = mult @ S_decomp_full |
| 1307 | S_decomp = S_decomp_full[good_mask] |
| 1308 | # |
| 1309 | # Extended SSS basis (eSSS) |
| 1310 | # |
| 1311 | extended_proj = exp.get("extended_proj", ()) |
| 1312 | if len(extended_proj) > 0: |
| 1313 | rcond = 1e-4 |
| 1314 | thresh = 1e-4 |
| 1315 | extended_proj = extended_proj.T * coil_scale[good_mask] |
| 1316 | extended_proj /= np.linalg.norm(extended_proj, axis=0) |
| 1317 | n_int = _get_n_moments(exp["int_order"]) |
| 1318 | if S_decomp.shape[1] > n_int: |
| 1319 | S_ext = S_decomp[:, n_int:].copy() |
| 1320 | S_ext /= np.linalg.norm(S_ext, axis=0) |
| 1321 | S_ext_orth = linalg.orth(S_ext, rcond=rcond) |
| 1322 | assert S_ext_orth.shape[1] == S_ext.shape[1] |
| 1323 | extended_proj -= np.dot(S_ext_orth, np.dot(S_ext_orth.T, extended_proj)) |
| 1324 | scale = np.mean(np.linalg.norm(S_decomp[n_int:], axis=0)) |
| 1325 | else: |
| 1326 | scale = np.mean(np.linalg.norm(S_decomp[:n_int], axis=0)) |
| 1327 | mask = np.linalg.norm(extended_proj, axis=0) > thresh |
| 1328 | extended_remove = list(np.where(~mask)[0] + S_decomp.shape[1]) |
| 1329 | logger.debug(" Reducing %d -> %d", extended_proj.shape[1], mask.sum()) |
nothing calls this directly
no test coverage detected