forked from pyIonControl/IonControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeScans.py
More file actions
50 lines (38 loc) · 1.49 KB
/
MergeScans.py
File metadata and controls
50 lines (38 loc) · 1.49 KB
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
40
41
42
43
44
45
46
47
48
from pathlib import Path
from trace.TraceCollection import TraceCollection
import numpy as np
import argparse
parser = argparse.ArgumentParser(description='Merge multiple scans into single file')
parser.add_argument('filename', type=str, default=None, nargs='+', help='filename of trace scan')
parser.add_argument('--path', action="store", type=str, help="path to files")
parser.add_argument('--new-filename', action="store", type=str, help="name of new file")
args = parser.parse_args()
commonPath = Path(args.path)
filename = args.filename[0]
filename = str(commonPath / filename)
# Trace = TraceCollection()
# Trace.loadTracePlain(filename)
# scanData = Trace
# for otherfilename in args.filename[1:]:
# otherTrace = TraceCollection()
# otherTrace.loadTracePlain(str(commonPath / otherfilename))
# file1 = otherTrace
# for key, value in otherTrace.items():
# scanData[key].extend(value)
#scanData.saveHdf5()
#newfile = commonPath / args.new_filename
#scanData.saveHdf5(newfile)
newtext = Path(filename).read_text()
import csv
for fname in args.filename[1:]:
fname = commonPath / fname
with open(str(fname), 'r') as csvfile:
reader = csv.reader(csvfile, delimiter='\t')
for row in reader:
if '#' not in row[0]:
strrow = ''
for col, items in enumerate(row):
strrow += items + '\t'
newtext += str(strrow) +'\n'
newpath = commonPath / args.new_filename
Path(newpath).write_text(newtext)