-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmnc_timeaverage.py
More file actions
32 lines (25 loc) · 982 Bytes
/
mnc_timeaverage.py
File metadata and controls
32 lines (25 loc) · 982 Bytes
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
import argparse
import numpy as np
from pyminc.volumes.factory import *
parser = argparse.ArgumentParser(description="Average MINC timeseries across the time dimension")
parser.add_argument('file', help="Input mnc timeseries")
parser.add_argument('-o', '--outfile', help="Output mnc file")
parser.add_argument('-t', '--time_axis', default=4, type=int, help="Dimension along which temporal variation is captured (default 4)")
args = parser.parse_args()
infile = args.file
outfile = args.outfile
invol = volumeFromFile(infile)
timeseries = invol.data
dimnames = invol.dimnames
steps = invol.separations
starts = invol.starts
sizes = list(timeseries.shape)
averaged_volume = np.mean(timeseries, axis=(args.time_axis-1))
dimnames.pop(args.time_axis-1)
steps.pop(args.time_axis-1)
starts.pop(args.time_axis-1)
sizes.pop(args.time_axis-1)
outvol = volumeFromDescription(outfile, dimnames, sizes, starts, steps)
outvol.data = averaged_volume
outvol.writeFile()
outvol.closeVolume()