From 3fac406b8977728501e0b5caca35c5feaa5cb1e7 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 16 Sep 2018 10:34:27 -0700 Subject: scripts/sum-peaks: Accept - for stdin --- scripts/sum-peaks | 66 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 31 deletions(-) (limited to 'scripts') diff --git a/scripts/sum-peaks b/scripts/sum-peaks index 5b528661..c239e113 100755 --- a/scripts/sum-peaks +++ b/scripts/sum-peaks @@ -15,37 +15,41 @@ import numpy as np import h5py from os.path import basename, splitext -with open(sys.argv[1], 'r') as stream: - reading_geometry = False - reading_chunks = False - reading_peaks = False - max_fs = -100500 - max_ss = -100500 - for line in stream: - if reading_chunks: - if line.startswith('End of peak list'): - reading_peaks = False - elif line.startswith(' fs/px ss/px (1/d)/nm^-1 Intensity Panel'): - reading_peaks = True - elif reading_peaks: - fs, ss, dump, intensity = [float(i) for i in line.split()[:4]] - powder[int(ss), int(fs)] += intensity - elif line.startswith('----- End geometry file -----'): - reading_geometry = False - powder = np.zeros((max_ss + 1, max_fs + 1)) - elif reading_geometry: - try: - par, val = line.split('=') - if par.split('/')[-1].strip() == 'max_fs' and int(val) > max_fs: - max_fs = int(val) - elif par.split('/')[-1].strip() == 'max_ss' and int(val) > max_ss: - max_ss = int(val) - except ValueError: - pass - elif line.startswith('----- Begin geometry file -----'): - reading_geometry = True - elif line.startswith('----- Begin chunk -----'): - reading_chunks = True +if sys.argv[1] == '-': + stream = sys.stdin +else: + stream = open(sys.argv[1], 'r') + +reading_geometry = False +reading_chunks = False +reading_peaks = False +max_fs = -100500 +max_ss = -100500 +for line in stream: + if reading_chunks: + if line.startswith('End of peak list'): + reading_peaks = False + elif line.startswith(' fs/px ss/px (1/d)/nm^-1 Intensity Panel'): + reading_peaks = True + elif reading_peaks: + fs, ss, dump, intensity = [float(i) for i in line.split()[:4]] + powder[int(ss), int(fs)] += intensity + elif line.startswith('----- End geometry file -----'): + reading_geometry = False + powder = np.zeros((max_ss + 1, max_fs + 1)) + elif reading_geometry: + try: + par, val = line.split('=') + if par.split('/')[-1].strip() == 'max_fs' and int(val) > max_fs: + max_fs = int(val) + elif par.split('/')[-1].strip() == 'max_ss' and int(val) > max_ss: + max_ss = int(val) + except ValueError: + pass + elif line.startswith('----- Begin geometry file -----'): + reading_geometry = True + elif line.startswith('----- Begin chunk -----'): + reading_chunks = True f = h5py.File(splitext(basename(sys.argv[1]))[0]+'-powder.h5', 'w') f.create_dataset('/data/data', data=powder) -- cgit v1.2.3