-
Notifications
You must be signed in to change notification settings - Fork 1
/
usrbinmerge.py
39 lines (26 loc) · 1.15 KB
/
usrbinmerge.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
35
36
37
38
39
import argparse
from glob import glob
import pandas
import numpy as np
def merge(input_files, output_file):
first_file = pandas.read_csv(input_files[0], sep=' ', names=('x', 'y', 'z', 'v'))
result = first_file
for file in input_files[1:]:
data = pandas.read_csv(file, sep=' ', names=('x', 'y', 'z', 'v'))
print(np.max(data['x']), np.max(data['y']), np.max(data['z']))
result['v'] += data['v']
result['v'] /= len(input_files)
for axis in ('x', 'y', 'z'):
if np.unique(result[axis]).size == 1:
result.drop(axis, inplace=True, axis=1)
result.to_csv(output_file, sep=' ', header=False, index=False)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('pattern', action='store', nargs='+',
help='input files (list of files or pattern')
parser.add_argument('--outputfile', action='store', default='out_ascii.dat',
help='output file')
args = parser.parse_args()
print("Input files: ", args.pattern)
print("Output file: ", args.outputfile)
merge(input_files=args.pattern, output_file=args.outputfile)