Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reading freesurfer stats files correctly#1152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
simkarwin wants to merge7 commits intonipy:master
base:master
Choose a base branch
Loading
fromsimkarwin:master
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletionnibabel/freesurfer/io.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
"""Read / write FreeSurfer geometry, morphometry, label, annotation formats"""
"""Read / write FreeSurfer geometry, morphometry, label, stats, annotation formats"""
from __future__importannotations

importgetpass
importtime
Expand DownExpand Up@@ -617,3 +618,50 @@
val=volume_info[key]
strings.append(f'{key:6s} ={val[0]:.10g}{val[1]:.10g}{val[2]:.10g}\n'.encode())
returnb''.join(strings)

defread_stats_file(file_path):
"""Extracts stats from stats files except '*curv.stats' files
Parameters
----------
file_path: str, required
Examples
--------
>>> stats_a2009, column_names = read_stats_file(r'lh.aparc.a2009s.stats')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If we're going to have example code, it needs to run. We could drop an example file innibabel/tests/data/ and access it with

fromnibabel.testingimporttest_datastats_a2009=read_stats_file(test_data(fname='lh.aparc.a2009s.stats'))

"""
withopen(file_path,'r')asf:
forlineinf:
ifline.startswith('# ColHeaders '):
columns=line.split()[2:]
break
returnnp.genfromtxt(f,dtype=None,names=columns,encoding='utf-8')

Check warning on line 639 in nibabel/freesurfer/io.py

View check run for this annotation

Codecov/ codecov/patch

nibabel/freesurfer/io.py#L637-L639

Added lines #L637 - L639 were not covered by tests


defread_stats_file_both_hemispheres(file_path:str):
"""Extracts stats data of both hemispheres and merges them
Parameters
----------
file_path: str, required
Path of the stats file belong to left (lh) or right(rh) hemisphere
Returns
-------
stats_both_hemispheres: ndarray
Stats data of both hemisphers
column_naems: ndarray
Name of columns
Examples
--------
>>> stats_a2009, column_names = read_stats_file_both_hemispheres(r'lh.aparc.a2009s.stats')
"""
stats_left,columns_left=read_stats_file(file_path.replace('rh','lh'))
stats_right,columns_right=read_stats_file(file_path.replace('lh','rh'))
stats_both_hemispheres=np.concatenate((stats_left,stats_right[:,1:]),axis=1)

Check warning on line 664 in nibabel/freesurfer/io.py

View check run for this annotation

Codecov/ codecov/patch

nibabel/freesurfer/io.py#L663-L664

Added lines #L663 - L664 were not covered by tests
column_names= [col_name+'_left'forcol_nameincolumns_left]+ [col_name+'_right'forcol_namein
columns_right[1:]]
Comment on lines +662 to +666
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You're no longer returning column names. I think you can usenumpy.lib.recfunctions.join_by to do what you want.

I would also use the following pattern for doctests:

    ..testsetup::        >>>import os        >>>from nibabel.testingimport get_test_data        >>>cwd= os.getcwd()        >>>os.chdir(get_test_data())    >>>stats_a2009= read_stats_file_both_hemispheres(r'lh.aparc.a2009s.stats')    ..testcleanup::        >>>os.chdir(cwd)

returnstats_both_hemispheres,column_names

Check warning on line 667 in nibabel/freesurfer/io.py

View check run for this annotation

Codecov/ codecov/patch

nibabel/freesurfer/io.py#L667

Added line #L667 was not covered by tests
Loading

[8]ページ先頭

©2009-2025 Movatter.jp