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

Function _read_one

mne/forward/forward.py:326–372  ·  view source on GitHub ↗

Read all interesting stuff for one forward solution.

(fid, node)

Source from the content-addressed store, hash-verified

324
325
326def _read_one(fid, node):
327 """Read all interesting stuff for one forward solution."""
328 # This function assumes the fid is open as a context manager
329 if node is None:
330 return None
331
332 one = Forward()
333 one["source_ori"] = _get_tag_int(
334 fid, node, "Source orientation", FIFF.FIFF_MNE_SOURCE_ORIENTATION
335 )
336 one["coord_frame"] = _get_tag_int(
337 fid, node, "Coordinate frame", FIFF.FIFF_MNE_COORD_FRAME
338 )
339 one["nsource"] = _get_tag_int(
340 fid, node, "Number of sources", FIFF.FIFF_MNE_SOURCE_SPACE_NPOINTS
341 )
342 one["nchan"] = _get_tag_int(fid, node, "Number of channels", FIFF.FIFF_NCHAN)
343 try:
344 one["sol"] = _read_named_matrix(
345 fid, node, FIFF.FIFF_MNE_FORWARD_SOLUTION, transpose=True
346 )
347 one["_orig_sol"] = one["sol"]["data"].copy()
348 except Exception:
349 logger.error("Forward solution data not found")
350 raise
351
352 try:
353 fwd_type = FIFF.FIFF_MNE_FORWARD_SOLUTION_GRAD
354 one["sol_grad"] = _read_named_matrix(fid, node, fwd_type, transpose=True)
355 one["_orig_sol_grad"] = one["sol_grad"]["data"].copy()
356 except Exception:
357 one["sol_grad"] = None
358
359 if one["sol"]["data"].shape[0] != one["nchan"] or (
360 one["sol"]["data"].shape[1] != one["nsource"]
361 and one["sol"]["data"].shape[1] != 3 * one["nsource"]
362 ):
363 raise ValueError("Forward solution matrix has wrong dimensions")
364
365 if one["sol_grad"] is not None:
366 if one["sol_grad"]["data"].shape[0] != one["nchan"] or (
367 one["sol_grad"]["data"].shape[1] != 3 * one["nsource"]
368 and one["sol_grad"]["data"].shape[1] != 3 * 3 * one["nsource"]
369 ):
370 raise ValueError("Forward solution gradient matrix has wrong dimensions")
371
372 return one
373
374
375@fill_doc

Callers 1

read_forward_solutionFunction · 0.85

Calls 4

ForwardClass · 0.85
_get_tag_intFunction · 0.85
_read_named_matrixFunction · 0.85
copyMethod · 0.45

Tested by

no test coverage detected