aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2017-10-18 13:05:05 +0200
committerThomas White <taw@physics.org>2017-10-18 13:08:27 +0200
commit8ea97aa3b3d12d4ccad01373e3ea4782645202ef (patch)
tree075f4e2749668b105915f28b68e1dd6f476c047f
parente18c025df6f5d8e2ecd0b0ac2b827e657fb53415 (diff)
New version of sum-peaks
This version gets the array dimensions automatically. However, it still assumes the data is "slabby".
-rwxr-xr-xscripts/sum-peaks71
1 files changed, 38 insertions, 33 deletions
diff --git a/scripts/sum-peaks b/scripts/sum-peaks
index eccb9fc6..5b528661 100755
--- a/scripts/sum-peaks
+++ b/scripts/sum-peaks
@@ -7,41 +7,46 @@
# a research centre of the Helmholtz Association.
#
# Author:
-# 2017 Thomas White <taw@physics.org>
+# 2017 Alexandra Tolstikova <alexandra.tolstikova@desy.de>
#
+import sys
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))
-
+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
+
+f = h5py.File(splitext(basename(sys.argv[1]))[0]+'-powder.h5', 'w')
+f.create_dataset('/data/data', data=powder)
f.close()
-
-fh = h5py.File("summed-peaks.h5", "w")
-fh.create_dataset("/data", (512,1024), data=powder)
-fh.close()