Write a FreeSurfer label. Parameters ---------- filename : str Path to label file to produce. label : Label The label object to save. %(verbose)s See Also -------- write_labels_to_annot Notes ----- Note that due to file specification lim
(filename, label, verbose=None)
| 1177 | |
| 1178 | @verbose |
| 1179 | def write_label(filename, label, verbose=None): |
| 1180 | """Write a FreeSurfer label. |
| 1181 | |
| 1182 | Parameters |
| 1183 | ---------- |
| 1184 | filename : str |
| 1185 | Path to label file to produce. |
| 1186 | label : Label |
| 1187 | The label object to save. |
| 1188 | %(verbose)s |
| 1189 | |
| 1190 | See Also |
| 1191 | -------- |
| 1192 | write_labels_to_annot |
| 1193 | |
| 1194 | Notes |
| 1195 | ----- |
| 1196 | Note that due to file specification limitations, the Label's subject and |
| 1197 | color attributes are not saved to disk. |
| 1198 | """ |
| 1199 | hemi = label.hemi |
| 1200 | path_head, name = op.split(filename) |
| 1201 | if name.endswith(".label"): |
| 1202 | name = name[:-6] |
| 1203 | if not (name.startswith(hemi) or name.endswith(hemi)): |
| 1204 | name += "-" + hemi |
| 1205 | filename = op.join(path_head, name) + ".label" |
| 1206 | |
| 1207 | logger.info(f"Saving label to : {filename}") |
| 1208 | |
| 1209 | with open(filename, "w", encoding="utf-8") as fid: |
| 1210 | n_vertices = len(label.vertices) |
| 1211 | data = np.zeros((n_vertices, 5), dtype=np.float64) |
| 1212 | data[:, 0] = label.vertices |
| 1213 | data[:, 1:4] = 1e3 * label.pos |
| 1214 | data[:, 4] = label.values |
| 1215 | fid.write(f"#{label.comment}\n") |
| 1216 | fid.write(f"{n_vertices}\n") |
| 1217 | for vert, pos, val in zip(label.vertices, 1e3 * label.pos, label.values): |
| 1218 | fid.write(f"{vert} {pos[0]:f} {pos[1]:f} {pos[2]:f} {val:f}\n") |
| 1219 | |
| 1220 | |
| 1221 | def _prep_label_split(label, subject=None, subjects_dir=None): |