diff options
author | Thomas White <taw@physics.org> | 2017-05-17 16:14:35 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2017-05-17 16:14:35 +0200 |
commit | f31c8cd01d36347e9254b6ff83979af690628975 (patch) | |
tree | 6c74c4295cdc5714e76859d33ebc0ae47e97ae77 | |
parent | 9bf3eaac8d5172868fc0cc85186a872f5644d201 (diff) |
Actually add scripts/sum-peaks
-rwxr-xr-x | scripts/sum-peaks | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/scripts/sum-peaks b/scripts/sum-peaks new file mode 100755 index 00000000..eccb9fc6 --- /dev/null +++ b/scripts/sum-peaks @@ -0,0 +1,47 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Generate "peak powder" from CrystFEL stream +# +# Copyright © 2017 Deutsches Elektronen-Synchrotron DESY, +# a research centre of the Helmholtz Association. +# +# Author: +# 2017 Thomas White <taw@physics.org> +# + +import numpy as np +import h5py +import sys +import re + +f = open(sys.argv[1], 'r') +powder = np.zeros((512,1024), dtype=float) +peaks = [] + +prog1 = re.compile("^\s*([\d\-\.]+)\s+([\d\-\.]+)\s+[\d\-\.]+\s+([\d\-\.]+)\s+\S+$") + +while True: + + fline = f.readline() + if not fline: + break + + if fline == '----- End chunk -----\n': + if len(peaks) > 10: + for p in peaks: + powder[p[1],p[0]] += p[2] + peaks = [] + + match = prog1.match(fline) + if match: + fs = int(float(match.group(1))) + ss = int(float(match.group(2))) + intensity = float(match.group(3)) + peaks.append((fs,ss,intensity)) + +f.close() + +fh = h5py.File("summed-peaks.h5", "w") +fh.create_dataset("/data", (512,1024), data=powder) +fh.close() |