/
calvec
executable file
·79 lines (65 loc) · 2.32 KB
/
calvec
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python3
#
# Description: Calculate a calibration-vector for specmon2
#
# Author: Bart Somers PE1RIK
#
import argparse
import array #used for fromfile
import numpy as np
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--infile', type=str, help='Filename with vectors', required=False)
parser.add_argument('-o', '--outfile', type=str, help='Filename where to put output', required=True)
parser.add_argument('-c', '--constant', type=float, help='Constant to use for calculation', required=True)
parser.add_argument('-l', '--length', type=int, help='Vector-length to parse', required=True)
args = parser.parse_args()
constant_array = [args.constant] * args.length
readlist = array.array('f')
# Name: DerdeMethode
# Desc: Create a calibration-vector, based on the inputvector
# Input: readlist, outputfile, contstant
# Output: Calibration vector in outputfile
# Return: -
def DerdeMethode(readlist,outputfile, constant):
testout = array.array('f')
for i in range(len(readlist)):
res = constant - readlist[i]
testout.append(float(res))
#print (testout)
fout = open(outputfile,'wb')
testout.tofile(fout)
fout.close()
if args.infile:
# Input file is defined. Create a calibration outputfile
f=open(args.infile,"rb")
# Skip first few lines
for i in range(20):
readlist.fromfile(f, args.length)
del readlist[:]
## Now read the vector to use
#readlist.fromfile(f, args.length)
#f.close()
# 210927 Test for more vectors
# Base is 5 vectors per second.
# 20 vectors = 4 seconds
# 300 vectors = 1 minute
vecavg = 20
e = np.zeros(args.length)
for i in range(vecavg):
readlist.fromfile(f, args.length)
#print ("len readlist: ", len(readlist), " len e: ", len(e))
e = np.add(e,readlist)
# Now clear the list from file.
del readlist[:]
# Divide by number of vectors
readlist = np.divide(e,vecavg)
f.close()
# Write the vector to file
DerdeMethode(readlist, args.outfile, args.constant)
else:
# Inputfile is not defined. Create a vector with only the constant value
constant_array = array.array('f', [args.constant] * args.length)
fout = open(args.outfile,'wb')
constant_array.tofile(fout)
fout.close()
exit(0)