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

Function get_meg_helmet_surf

mne/surface.py:176–266  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

174
175@verbose
176def 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])

Callers 5

test_make_field_map_megFunction · 0.90
test_helmetFunction · 0.90
make_field_mapFunction · 0.85
plot_head_positionsFunction · 0.85
_plot_helmetFunction · 0.85

Calls 14

_validate_typeFunction · 0.85
_get_meg_systemFunction · 0.85
read_bem_surfacesFunction · 0.85
_scale_helmet_to_sensorsFunction · 0.85
pick_typesFunction · 0.85
_fit_sphereFunction · 0.85
_cart_to_sphFunction · 0.85
_pol_to_cartFunction · 0.85
_reorder_ccwFunction · 0.85
_soft_importFunction · 0.85
complete_surface_infoFunction · 0.85
TransformClass · 0.85

Tested by 2

test_make_field_map_megFunction · 0.72
test_helmetFunction · 0.72