MCPcopy
hub / github.com/mne-tools/mne-python / fit

Method fit

mne/transforms.py:1105–1202  ·  view source on GitHub ↗

Fit the warp from source points to destination points. Parameters ---------- source : array, shape (n_src, 3) The source points. destination : array, shape (n_dest, 3) The destination points. order : int Order of the spheri

(
        self,
        source,
        destination,
        order=4,
        reg=1e-5,
        center=True,
        match="oct5",
        verbose=None,
    )

Source from the content-addressed store, hash-verified

1103
1104 @verbose
1105 def fit(
1106 self,
1107 source,
1108 destination,
1109 order=4,
1110 reg=1e-5,
1111 center=True,
1112 match="oct5",
1113 verbose=None,
1114 ):
1115 """Fit the warp from source points to destination points.
1116
1117 Parameters
1118 ----------
1119 source : array, shape (n_src, 3)
1120 The source points.
1121 destination : array, shape (n_dest, 3)
1122 The destination points.
1123 order : int
1124 Order of the spherical harmonic fit.
1125 reg : float
1126 Regularization of the TPS warp.
1127 center : bool
1128 If True, center the points by fitting a sphere to points
1129 that are in a reasonable region for head digitization.
1130 match : str
1131 The uniformly-spaced points to match on the two surfaces.
1132 Can be "ico#" or "oct#" where "#" is an integer.
1133 The default is "oct5".
1134 %(verbose)s
1135
1136 Returns
1137 -------
1138 inst : instance of SphericalSurfaceWarp
1139 The warping object (for chaining).
1140 """
1141 from .bem import _fit_sphere
1142 from .source_space._source_space import _check_spacing
1143
1144 match_rr = _check_spacing(match, verbose=False)[2]["rr"]
1145 logger.info("Computing TPS warp")
1146 src_center = dest_center = np.zeros(3)
1147 if center:
1148 logger.info(" Centering data")
1149 hsp = np.array([p for p in source if not (p[2] < -1e-6 and p[1] > 1e-6)])
1150 src_center = _fit_sphere(hsp)[1]
1151 source = source - src_center
1152 hsp = np.array([p for p in destination if not (p[2] < 0 and p[1] > 0)])
1153 dest_center = _fit_sphere(hsp)[1]
1154 destination = destination - dest_center
1155 logger.info(
1156 " Using centers {np.array_str(src_center, None, 3)} -> "
1157 "{np.array_str(dest_center, None, 3)}"
1158 )
1159 self._fit_params = dict(
1160 n_src=len(source),
1161 n_dest=len(destination),
1162 match=match,

Callers

nothing calls this directly

Calls 9

_check_spacingFunction · 0.85
_fit_sphereFunction · 0.85
_cart_to_sphFunction · 0.85
_compute_sph_harmFunction · 0.85
_sph_to_cartFunction · 0.85
_TPSWarpClass · 0.85
infoMethod · 0.80
copyMethod · 0.45
fitMethod · 0.45

Tested by

no test coverage detected