aboutsummaryrefslogtreecommitdiff
path: root/scripts/sum-peaks
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2017-07-06 17:22:11 +0200
committerThomas White <taw@physics.org>2017-07-06 17:24:59 +0200
commit5292f57d4434c7267e8d945871513d742ff42427 (patch)
treed460aa5cef5a501516876850ef243cfc27313d5a /scripts/sum-peaks
parent48d4a6b8e82cce81222ec58fdfb488ed79ce0bcf (diff)
parentdc3395900fc3ce0d3961757628ff83ad6456be19 (diff)
Merge branch 'master' into taketwo
Diffstat (limited to 'scripts/sum-peaks')
-rwxr-xr-xscripts/sum-peaks47
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()