freesurfer-stats
Python Library to Read FreeSurfer’s Cortical Parcellation Anatomical Statistics subject/stats/[rl]h.aparc.*.stats
Freesurfer https://surfer.nmr.mgh.harvard.edu/
Install
pip3 install --user freesurfer-stats
Releases follow the semantic versioning <https://semver.org/> scheme.
Usage
>>> from freesurfer_stats import CorticalParcellationStats
>>> stats = CorticalParcellationStats.read('tests/subjects/fabian/stats/lh.aparc.DKTatlas.stats')
>>> stats.headers['subjectname']
'fabian'
>>> stats.headers['CreationTime'].isoformat()
'2019-05-09T21:05:54+00:00'
>>> stats.headers['cvs_version']
'Id: mris_anatomical_stats.c,v 1.79 2016/03/14 15:15:34 greve Exp'
>>> stats.headers['cmdline'][:64]
'mris_anatomical_stats -th3 -mgz -cortex ../label/lh.cortex.label'
>>> stats.hemisphere
'left'
>>> stats.whole_brain_measurements['estimated_total_intracranial_volume_mm^3']
0 1.670487e+06
Name: estimated_total_intracranial_volume_mm^3, dtype: float64
>>> stats.whole_brain_measurements['white_surface_total_area_mm^2']
0 98553
Name: white_surface_total_area_mm^2, dtype: int64
>>> stats.structural_measurements[['structure_name', 'surface_area_mm^2',
... 'gray_matter_volume_mm^3']].head()
structure_name surface_area_mm^2 gray_matter_volume_mm^3
0 caudalanteriorcingulate 1472 4258
1 caudalmiddlefrontal 3039 8239
2 cuneus 2597 6722
3 entorhinal 499 2379
4 fusiform 3079 9064
Load Multiple Stats Files
>>> import glob, pandas
>>> from freesurfer_stats import CorticalParcellationStats
>>> def load_whole_brain_measurements(stats_path) -> pandas.DataFrame:
... stats = CorticalParcellationStats.read(stats_path)
... stats.whole_brain_measurements['subject'] = stats.headers['subjectname']
... stats.whole_brain_measurements['source_basename'] = os.path.basename(stats_path)
... stats.whole_brain_measurements['hemisphere'] = stats.hemisphere
... return stats.whole_brain_measurements
...
>>> whole_brain_measurements = pandas.concat(
... map(load_whole_brain_measurements, glob.glob('tests/subjects/fabian/stats/*h.aparc*.stats')),
... sort=False)
>>> whole_brain_measurements.reset_index(drop=True, inplace=True)
>>> whole_brain_measurements[['subject', 'source_basename', 'hemisphere',
... 'white_surface_total_area_mm^2', 'pial_surface_total_area_mm^2']]
subject source_basename hemisphere white_surface_total_area_mm^2 pial_surface_total_area_mm^2
0 fabian lh.aparc.DKTatlas.stats left 98553.0 NaN
1 fabian rh.aparc.stats right 99468.9 NaN
2 fabian rh.aparc.a2009s.stats right 99494.9 NaN
3 fabian rh.aparc.DKTatlas.stats right 99494.9 NaN
4 fabian lh.aparc.stats left 98536.5 NaN
5 fabian lh.aparc.pial.stats left NaN 118601.0
6 fabian rh.aparc.pial.stats right NaN 121260.0
7 fabian lh.aparc.a2009s.stats left 98553.0 NaN
Load Stats File From Webserver, Amazon S3 or Google Cloud Storage
>>> from freesurfer_stats import CorticalParcellationStats
>>> stats = CorticalParcellationStats.read('https://[...]/stats/rh.aparc.stats')
>>> stats.whole_brain_measurements['total_cortical_gray_matter_volume_mm^3']
0 553998.311189
Name: total_cortical_gray_matter_volume_mm^3, dtype: float64
Replace https:// with s3:// or gcs://.
Credentials for S3 may be provided in ~/.aws/credentials or via environment variables. See S3Fs docs.
Tests
pip3 install --user pipenv
git clone https://github.com/fphammerle/freesurfer-stats.git
cd freesurfer-stats
pipenv sync --dev
pipenv run pylint freesurfer_stats
pipenv run pytest
Metadata
Release files for freesurfer-stats 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| freesurfer-stats-1.2.1.tar.gz | 79.7 kB | Without provenance | Details for freesurfer-stats-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| freesurfer_stats-1.2.1-py3-none-any.whl | Python 3 | none | any | Details for freesurfer_stats-1.2.1-py3-none-any.whl |
Total release size: 99.0 kB
Release files / freesurfer-stats-1.2.1.tar.gz
| Download URL | freesurfer-stats-1.2.1.tar.gz |
|---|---|
| Size | 79.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f9922b5320bf75677fe8fd2acfd2f456505c870a9072e07fb1cc9c188b242cc1
|
|
BLAKE2b-256 checksum How to use checksums |
c37ac6392b68eaa8f6d8e6313204dc840ff1a0bd9a37e097db58415678f25274
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5
|
Release files / freesurfer_stats-1.2.1-py3-none-any.whl
| Download URL | freesurfer_stats-1.2.1-py3-none-any.whl |
|---|---|
| Size | 19.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7699db95042e9aa10ff761a97aa303f99a50e2ab68e94c01b01d213cdf05a079
|
|
BLAKE2b-256 checksum How to use checksums |
b1d7d864bafdf129afee114a5fa5279e6c5e2b85d3e52e86c5504332ae742430
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5
|
Security for freesurfer-stats 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.