Commit 99f992dab35e8c83df55d8542dbe642a16d2f475

Authored by Brice COLOMBIER
1 parent 6429772f15
Exists in master

Scale_float_to_uint: Round before converting float to int

Showing 1 changed file with 3 additions and 3 deletions

scale_float_to_uinttype.py View file @ 99f992d
... ... @@ -3,7 +3,7 @@
3 3 import argparse
4 4 import os
5 5  
6   -def scale_float_to_uinttype(traces, uinttype):
  6 +def scale_float_to_uinttype(traces, uinttype='uint8'):
7 7 if uinttype not in ['uint8', 'uint16', 'uint32', 'uint64']:
8 8 raise TypeError ('Cannot rescale to this type, choose an unsigned integer (uintXX) type instead')
9 9 new_max = np.iinfo(uinttype).max
10 10  
... ... @@ -18,14 +18,14 @@
18 18 # print "Achievable new max :", np.iinfo(uinttype).max
19 19 # print "Actual new min :", np.amin(scaled_traces)
20 20 # print "Actual new max :", np.amax(scaled_traces)
21   - return traces.astype(uinttype)
  21 + return np.around(traces).astype(uinttype)
22 22  
23 23 if __name__ == "__main__":
24 24  
25 25 # Parsing arguments
26 26 parser = argparse.ArgumentParser(description='Preprocess traces')
27 27 parser.add_argument("traces_name", type=str)
28   - parser.add_argument("--uinttype", type=str)
  28 + parser.add_argument("--uinttype", type=str, default='uint8')
29 29 args = parser.parse_args()
30 30  
31 31 traces = np.load(args.traces_name)