diff options
author | Thomas White <taw@physics.org> | 2018-09-16 10:34:27 -0700 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2018-09-16 19:43:33 +0200 |
commit | 3fac406b8977728501e0b5caca35c5feaa5cb1e7 (patch) | |
tree | 6e985df5c3ac1538aabc4ef536541c202b0c84a7 /scripts/sum-peaks | |
parent | 017b070f74af546b4a2611088cfe1203e7aab79c (diff) |
scripts/sum-peaks: Accept - for stdin
Diffstat (limited to 'scripts/sum-peaks')
-rwxr-xr-x | scripts/sum-peaks | 66 |
1 files changed, 35 insertions, 31 deletions
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) |