aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2022-08-24 16:23:18 +0200
committerThomas White <taw@physics.org>2022-08-24 16:23:45 +0200
commitcdcb96528b869fee86ac5531dbb45fdf726045b1 (patch)
tree7e5570df32f2c3778288a265c75f8587089e288d /scripts
parent1f7b7c1e0fc7a002eae26b5442469b4cbee3a735 (diff)
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.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/detector-shift57
1 files changed, 34 insertions, 23 deletions
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)