From cdcb96528b869fee86ac5531dbb45fdf726045b1 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 24 Aug 2022 16:23:18 +0200 Subject: detector-shift: Better handling of multiple input streams Previously, the only way to process more than one stream was to concatenate them via stdin. Now, you can give '--' followed by a list of streams. The '--' is needed to distinguish from the situation where a geometry file is to be updated. --- scripts/detector-shift | 57 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 23 deletions(-) (limited to 'scripts') diff --git a/scripts/detector-shift b/scripts/detector-shift index c9da3a9a..b16d788b 100755 --- a/scripts/detector-shift +++ b/scripts/detector-shift @@ -18,16 +18,19 @@ import re import numpy as np import matplotlib.pyplot as plt -if sys.argv[1] == "-": - f = sys.stdin -else: - f = open(sys.argv[1], 'r') +infiles = [] -if len(sys.argv) > 2: - geom = sys.argv[2] - have_geom = 1 -else: +if sys.argv[1] == "--": have_geom = 0 + infiles += sys.argv[2:] +else: + if len(sys.argv) > 2: + infiles += [sys.argv[1]] + geom = sys.argv[2] + have_geom = 1 + else: + have_geom = 0 + infiles += sys.argv[1:] # Determine the mean shifts x_shifts = [] @@ -37,25 +40,33 @@ z_shifts = [] prog1 = re.compile("^predict_refine/det_shift\sx\s=\s([0-9\.\-]+)\sy\s=\s([0-9\.\-]+)\smm$") prog2 = re.compile("^predict_refine/clen_shift\s=\s([0-9\.\-]+)\smm$") -while True: +for file in infiles: + + print("Reading "+file) + if file == "-": + f = sys.stdin + else: + f = open(file, 'r') + + while True: - fline = f.readline() - if not fline: - break + fline = f.readline() + if not fline: + break - match = prog1.match(fline) - if match: - xshift = float(match.group(1)) - yshift = float(match.group(2)) - x_shifts.append(xshift) - y_shifts.append(yshift) + match = prog1.match(fline) + if match: + xshift = float(match.group(1)) + yshift = float(match.group(2)) + x_shifts.append(xshift) + y_shifts.append(yshift) - match = prog2.match(fline) - if match: - zshift = float(match.group(1)) - z_shifts.append(zshift) + match = prog2.match(fline) + if match: + zshift = float(match.group(1)) + z_shifts.append(zshift) -f.close() + f.close() mean_x = sum(x_shifts) / len(x_shifts) mean_y = sum(y_shifts) / len(y_shifts) -- cgit v1.2.3