-
Notifications
You must be signed in to change notification settings - Fork 68
/
sagittal_brain.py
34 lines (25 loc) · 1.38 KB
/
sagittal_brain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
import numpy as np
def run_averages(file_input='brain_sample.csv', file_output='brain_average.csv'):
"""
Calculates the average through the coronal planes
The input file should has as many columns as coronal planes
The rows are intersections of the sagittal/horizontal planes
The result is the average for each sagittal/horizontal plane (rows)
"""
# Open the file to analyse
planes = np.loadtxt(file_input, dtype=int, delimiter=',')
# Calculates the averages through the sagittal/horizontal planes
# and makes it as a row vector
averages = planes.mean(axis=0)[np.newaxis, :]
# write it out on my file
np.savetxt(file_output, averages, fmt='%.1f', delimiter=',')
if __name__ == "__main__":
parser = ArgumentParser(description="Calculates the average for each sagittal-horizontal plane.",
formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('file_input', nargs='?', default="brain_sample.csv",
help="Input CSV file with the results from scikit-brain binning algorithm.")
parser.add_argument('--file_output', '-o', default="brain_average.csv",
help="Name of the output CSV file.")
arguments = parser.parse_args()
run_averages(arguments.file_input, arguments.file_output)