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

Function _read_w

mne/source_estimate.py:162–199  ·  view source on GitHub ↗

Read a w file. w files contain activations or source reconstructions for a single time point. Parameters ---------- filename : path-like The name of the w file. Returns ------- data: dict The w structure. It has the following keys: vertic

(filename)

Source from the content-addressed store, hash-verified

160
161
162def _read_w(filename):
163 """Read a w file.
164
165 w files contain activations or source reconstructions for a single time
166 point.
167
168 Parameters
169 ----------
170 filename : path-like
171 The name of the w file.
172
173 Returns
174 -------
175 data: dict
176 The w structure. It has the following keys:
177 vertices vertex indices (0 based)
178 data The data matrix (nvert long)
179 """
180 with open(filename, "rb", buffering=0) as fid: # buffering=0 for np bug
181 # skip first 2 bytes
182 fid.read(2)
183
184 # read number of vertices/sources (3 byte integer)
185 vertices_n = int(_read_3(fid))
186
187 vertices = np.zeros((vertices_n), dtype=np.int32)
188 data = np.zeros((vertices_n), dtype=np.float32)
189
190 # read the vertices and data
191 for i in range(vertices_n):
192 vertices[i] = _read_3(fid)
193 data[i] = np.fromfile(fid, dtype=">f4", count=1).item()
194
195 w = dict()
196 w["vertices"] = vertices
197 w["data"] = data
198
199 return w
200
201
202def _write_3(fid, val):

Callers 1

read_source_estimateFunction · 0.85

Calls 2

_read_3Function · 0.85
readMethod · 0.80

Tested by

no test coverage detected