__main__.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import argparse
  2. import csv
  3. import sys
  4. from freesurfer_surface import Annotation, Surface
  5. def annotation_labels():
  6. """
  7. List Labels Stored in Freesurfer's Annotation File
  8. (i.e., label/lh.aparc.annot)
  9. """
  10. argparser = argparse.ArgumentParser(
  11. description=annotation_labels.__doc__.strip())
  12. argparser.add_argument('--delimiter', default='\t',
  13. help='default: %(default)r')
  14. argparser.add_argument('annotation_file_path')
  15. args = argparser.parse_args()
  16. annotation = Annotation.read(args.annotation_file_path)
  17. csv_writer = csv.writer(sys.stdout, delimiter=args.delimiter)
  18. csv_writer.writerow(('index', 'color', 'name'))
  19. labels = sorted(annotation.labels.values(), key=lambda l: l.index)
  20. csv_writer.writerows((l.index, l.hex_color_code, l.name,) for l in labels)
  21. def unite_surfaces():
  22. """
  23. Unite Multiple Surfaces in Freesurfer's TriangularSurface Format
  24. Into a Single TriangularSurface File (i.e., lh.pial, lh.white)
  25. """
  26. argparser = argparse.ArgumentParser(
  27. description=unite_surfaces.__doc__.strip())
  28. argparser.add_argument('--output',
  29. metavar='OUTPUT_PATH',
  30. dest='output_path',
  31. required=True)
  32. argparser.add_argument('input_paths',
  33. metavar='INPUT_PATH',
  34. nargs='+')
  35. args = argparser.parse_args()
  36. union = Surface.unite(Surface.read_triangular(p)
  37. for p in args.input_paths)
  38. union.write_triangular(args.output_path)