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)
| 160 | |
| 161 | |
| 162 | def _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 | |
| 202 | def _write_3(fid, val): |
no test coverage detected