README.rst 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. freesurfer-stats
  2. ================
  3. TODO add badges
  4. Python Library to Read FreeSurfer's cortical parcellation anatomical statistics
  5. Freesurfer https://surfer.nmr.mgh.harvard.edu/
  6. Install
  7. -------
  8. .. code:: sh
  9. pip3 install --user freesurfer-stats
  10. Releases follow the `semantic versioning <https://semver.org/>` scheme.
  11. Usage
  12. -----
  13. .. code:: python
  14. >>> from freesurfer_stats import CorticalParcellationStats
  15. >>> stats = CorticalParcellationStats.read('tests/subjects/fabian/stats/lh.aparc.DKTatlas.stats')
  16. >>> stats.headers['CreationTime'].isoformat()
  17. '2019-05-09T21:05:54+00:00'
  18. >>> stats.headers['cvs_version']
  19. 'Id: mris_anatomical_stats.c,v 1.79 2016/03/14 15:15:34 greve Exp'
  20. >>> stats.headers['cmdline'][:64]
  21. 'mris_anatomical_stats -th3 -mgz -cortex ../label/lh.cortex.label'
  22. >>> stats.hemisphere
  23. 'left'
  24. >>> stats.whole_brain_measurements['estimated_total_intracranial_volume_mm^3']
  25. 0 1.670487e+06
  26. Name: estimated_total_intracranial_volume_mm^3, dtype: float64
  27. >>> stats.whole_brain_measurements['white_surface_total_area_mm^2']
  28. 0 98553
  29. Name: white_surface_total_area_mm^2, dtype: int64
  30. >>> stats.structure_measurements[['Structure Name', 'Surface Area (mm^2)',
  31. ... 'Gray Matter Volume (mm^3)']].head()
  32. Structure Name Surface Area (mm^2) Gray Matter Volume (mm^3)
  33. 0 caudalanteriorcingulate 1472 4258
  34. 1 caudalmiddlefrontal 3039 8239
  35. 2 cuneus 2597 6722
  36. 3 entorhinal 499 2379
  37. 4 fusiform 3079 9064
  38. Load Multiple Stats Files
  39. ~~~~~~~~~~~~~~~~~~~~~~~~~
  40. .. code:: python
  41. >>> import glob, pandas
  42. >>> from freesurfer_stats import CorticalParcellationStats
  43. >>> def load_whole_brain_measurements(stats_path) -> pandas.DataFrame:
  44. ... stats = CorticalParcellationStats.read(stats_path)
  45. ... stats.whole_brain_measurements['subject'] = stats.headers['subjectname']
  46. ... stats.whole_brain_measurements['source_basename'] = os.path.basename(stats_path)
  47. ... stats.whole_brain_measurements['hemisphere'] = stats.hemisphere
  48. ... return stats.whole_brain_measurements
  49. ...
  50. >>> whole_brain_measurements = pandas.concat(
  51. ... map(load_whole_brain_measurements, glob.glob('tests/subjects/fabian/stats/*h.aparc*.stats')),
  52. ... sort=False)
  53. >>> whole_brain_measurements.reset_index(drop=True, inplace=True)
  54. >>> whole_brain_measurements[['subject', 'source_basename', 'hemisphere',
  55. ... 'white_surface_total_area_mm^2', 'pial_surface_total_area_mm^2']]
  56. subject source_basename hemisphere white_surface_total_area_mm^2 pial_surface_total_area_mm^2
  57. 0 fabian lh.aparc.DKTatlas.stats left 98553.0 NaN
  58. 1 fabian rh.aparc.stats right 99468.9 NaN
  59. 2 fabian rh.aparc.a2009s.stats right 99494.9 NaN
  60. 3 fabian rh.aparc.DKTatlas.stats right 99494.9 NaN
  61. 4 fabian lh.aparc.stats left 98536.5 NaN
  62. 5 fabian lh.aparc.pial.stats left NaN 118601.0
  63. 6 fabian rh.aparc.pial.stats right NaN 121260.0
  64. 7 fabian lh.aparc.a2009s.stats left 98553.0 NaN
  65. >>>