aggregate_entropy_stats.py (1277B)
1 #!/usr/bin/env python3 2 ## Copyright (c) 2017, Alliance for Open Media. All rights reserved. 3 ## 4 ## This source code is subject to the terms of the BSD 2 Clause License and 5 ## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 6 ## was not distributed with this source code in the LICENSE file, you can 7 ## obtain it at www.aomedia.org/license/software. If the Alliance for Open 8 ## Media Patent License 1.0 was not distributed with this source code in the 9 ## PATENTS file, you can obtain it at www.aomedia.org/license/patent. 10 ## 11 """Aggregate multiple entropy stats output which is written in 32-bit int. 12 13 python ./aggregate_entropy_stats.py [dir of stats files] [keyword of filenames] 14 [filename of final stats] 15 """ 16 17 __author__ = "yuec@google.com" 18 19 import os 20 import sys 21 import numpy as np 22 23 def main(): 24 dir = sys.argv[1] 25 sum = [] 26 for fn in os.listdir(dir): 27 if sys.argv[2] in fn: 28 stats = np.fromfile(dir + fn, dtype=np.int32) 29 if len(sum) == 0: 30 sum = stats 31 else: 32 sum = np.add(sum, stats) 33 if len(sum) == 0: 34 print("No stats file is found. Double-check directory and keyword?") 35 else: 36 sum.tofile(dir+sys.argv[3]) 37 38 if __name__ == '__main__': 39 main()