Load the MEG helmet associated with the MEG sensors. Parameters ---------- %(info_not_none)s trans : dict The head<->MRI transformation, usually obtained using read_trans(). Can be None, in which case the surface will be in head coordinates instead of MRI coo
(info, trans=None, *, upsampling=1, verbose=None)
| 174 | |
| 175 | @verbose |
| 176 | def get_meg_helmet_surf(info, trans=None, *, upsampling=1, verbose=None): |
| 177 | """Load the MEG helmet associated with the MEG sensors. |
| 178 | |
| 179 | Parameters |
| 180 | ---------- |
| 181 | %(info_not_none)s |
| 182 | trans : dict |
| 183 | The head<->MRI transformation, usually obtained using |
| 184 | read_trans(). Can be None, in which case the surface will |
| 185 | be in head coordinates instead of MRI coordinates. |
| 186 | %(helmet_upsampling)s |
| 187 | %(verbose)s |
| 188 | |
| 189 | Returns |
| 190 | ------- |
| 191 | surf : dict |
| 192 | The MEG helmet as a surface. |
| 193 | |
| 194 | Notes |
| 195 | ----- |
| 196 | A built-in helmet is loaded if possible. If not, a helmet surface |
| 197 | will be approximated based on the sensor locations. |
| 198 | """ |
| 199 | from .bem import _fit_sphere, read_bem_surfaces |
| 200 | from .channels.channels import _get_meg_system |
| 201 | |
| 202 | _validate_type(upsampling, "int", "upsampling") |
| 203 | |
| 204 | system, have_helmet = _get_meg_system(info) |
| 205 | incomplete = False |
| 206 | if have_helmet: |
| 207 | logger.info(f"Getting helmet for system {system}") |
| 208 | fname = _helmet_path / f"{system}.fif.gz" |
| 209 | surf = read_bem_surfaces( |
| 210 | fname, False, FIFF.FIFFV_MNE_SURF_MEG_HELMET, verbose=False |
| 211 | ) |
| 212 | surf = _scale_helmet_to_sensors(system, surf, info) |
| 213 | else: |
| 214 | rr = np.array( |
| 215 | [ |
| 216 | info["chs"][pick]["loc"][:3] |
| 217 | for pick in pick_types(info, meg=True, ref_meg=False, exclude=()) |
| 218 | ] |
| 219 | ) |
| 220 | logger.info( |
| 221 | "Getting helmet for system %s (derived from %d MEG channel locations)", |
| 222 | system, |
| 223 | len(rr), |
| 224 | ) |
| 225 | hull = ConvexHull(rr) |
| 226 | rr = rr[np.unique(hull.simplices)] |
| 227 | R, center = _fit_sphere(rr) |
| 228 | sph = _cart_to_sph(rr - center)[:, 1:] |
| 229 | # add a point at the front of the helmet (where the face should be): |
| 230 | # 90 deg az and maximal el (down from Z/up axis) |
| 231 | front_sph = [[np.pi / 2.0, sph[:, 1].max()]] |
| 232 | sph = np.concatenate((sph, front_sph)) |
| 233 | xy = _pol_to_cart(sph[:, ::-1]) |