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

Function _read_stc

mne/source_estimate.py:71–119  ·  view source on GitHub ↗

Aux Function.

(filename)

Source from the content-addressed store, hash-verified

69
70
71def _read_stc(filename):
72 """Aux Function."""
73 with open(filename, "rb") as fid:
74 buf = fid.read()
75
76 stc = dict()
77 offset = 0
78 num_bytes = 4
79
80 # read tmin in ms
81 stc["tmin"] = (
82 float(np.frombuffer(buf, dtype=">f4", count=1, offset=offset).item()) / 1000.0
83 )
84 offset += num_bytes
85
86 # read sampling rate in ms
87 stc["tstep"] = (
88 float(np.frombuffer(buf, dtype=">f4", count=1, offset=offset).item()) / 1000.0
89 )
90 offset += num_bytes
91
92 # read number of vertices/sources
93 vertices_n = int(np.frombuffer(buf, dtype=">u4", count=1, offset=offset).item())
94 offset += num_bytes
95
96 # read the source vector
97 stc["vertices"] = np.frombuffer(buf, dtype=">u4", count=vertices_n, offset=offset)
98 offset += num_bytes * vertices_n
99
100 # read the number of timepts
101 data_n = int(np.frombuffer(buf, dtype=">u4", count=1, offset=offset).item())
102 offset += num_bytes
103
104 if (
105 vertices_n
106 and ( # vertices_n can be 0 (empty stc)
107 (len(buf) // 4 - 4 - vertices_n) % (data_n * vertices_n)
108 )
109 != 0
110 ):
111 raise ValueError("incorrect stc file size")
112
113 # read the data matrix
114 stc["data"] = np.frombuffer(
115 buf, dtype=">f4", count=vertices_n * data_n, offset=offset
116 )
117 stc["data"] = stc["data"].reshape([data_n, vertices_n]).T
118
119 return stc
120
121
122def _write_stc(filename, tmin, tstep, vertices, data):

Callers 1

read_source_estimateFunction · 0.85

Calls 1

readMethod · 0.80

Tested by

no test coverage detected