diff options
-rwxr-xr-x | scripts/euxfel-train-analysis | 86 | ||||
-rwxr-xr-x | scripts/find-multiples | 58 | ||||
-rwxr-xr-x | scripts/transfer-geom | 91 |
3 files changed, 235 insertions, 0 deletions
diff --git a/scripts/euxfel-train-analysis b/scripts/euxfel-train-analysis new file mode 100755 index 00000000..0d20decd --- /dev/null +++ b/scripts/euxfel-train-analysis @@ -0,0 +1,86 @@ +#!/usr/bin/env python + +# +# Analysis train and pulse IDs +# +# Copyright (c) 2017 Deutsches Elektronen-Synchrotron DESY, +# a research centre of the Helmholtz Association. +# +# Author: +# 2017 Thomas White <taw@physics.org> +# + +import sys +from collections import deque + +f = open(sys.argv[1], 'r') +n_crystals = 0 +n_frames = 0 +crystal = deque() +in_crystal = 0 +trainID = 0 +pulseID = 0 +trains = dict() +while True: + + fline = f.readline() + if not fline: + break + + fline = fline.rstrip("\r\n") + + if fline.find("Image filename") != -1: + filename = fline.split(": ")[1] + + if fline.find("Event") != -1: + event = fline.split(": ")[1] + + if fline.find("End chunk") != -1: + if n_crystals > 0: + if trainID not in trains: + trains[trainID] = [] + frame = dict() + frame['filename'] = filename+" "+event + frame['ncrystals'] = n_crystals + frame['crystals'] = deque(crystal) + frame['pulseID'] = pulseID + trains[trainID].append(frame) + + if fline.find("Begin chunk") != -1: + n_crystals = 0 + filename = "" + event = "" + pulseID = "" + trainID = "" + crystal.clear() + + if fline.find("Begin crystal") != -1: + n_crystals += 1 + + if fline.find("Cell param") != -1: + in_crystal = 1 + + if fline.find("hdf5/instrument/trainID") != -1: + trainID = fline.split(" = ")[1] + + if fline.find("hdf5/instrument/pulseID") != -1: + pulseID = fline.split(" = ")[1] + + if in_crystal: + crystal.append(fline) + + if fline.find("unique_axis") != -1: + in_crystal = 0 + +for trainID in trains: + print("Train: "+trainID) + print("There are "+str(len(trains[trainID]))+" indexed frames in this train") + if len(trains[trainID]) > 1: + for frame in trains[trainID]: + print("\nFrame: "+frame['filename']) + print("Pulse: "+frame['pulseID']) + print("There are "+str(frame['ncrystals'])+" crystals in this frame") + for line in frame['crystals']: + print(line) + print("\n") + print("\n") diff --git a/scripts/find-multiples b/scripts/find-multiples new file mode 100755 index 00000000..6196e83c --- /dev/null +++ b/scripts/find-multiples @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Find multiple crystal hits +# +# Copyright © 2017 Deutsches Elektronen-Synchrotron DESY, +# a research centre of the Helmholtz Association. +# +# Author: +# 2017 Thomas White <taw@physics.org> +# + +import sys +from collections import deque + +f = open(sys.argv[1], 'r') +n_crystals = 0 +crystal = deque() +in_crystal = 0 +while True: + + fline = f.readline() + if not fline: + break + + fline = fline.rstrip("\r\n") + + if fline.find("Image filename") != -1: + filename = fline + + if fline.find("Event") != -1: + event = fline + + if fline.find("End chunk") != -1: + if n_crystals > 1: + print("\nFilename: "+filename) + print("Event: "+event) + for line in crystal: + print(line) + + if fline.find("Begin chunk") != -1: + n_crystals = 0 + filename = "" + event = "" + crystal.clear() + + if fline.find("Begin crystal") != -1: + n_crystals += 1 + + if fline.find("Cell param") != -1: + in_crystal = 1 + + if in_crystal: + crystal.append(fline) + + if fline.find("unique_axis") != -1: + in_crystal = 0 + diff --git a/scripts/transfer-geom b/scripts/transfer-geom new file mode 100755 index 00000000..6109f5ed --- /dev/null +++ b/scripts/transfer-geom @@ -0,0 +1,91 @@ +#!/usr/bin/python3 + +import sys + +corner_x = dict() +corner_y = dict() +fs = dict() +ss = dict() +coffset = dict() + +# Go through "ingeom" and find all corner_{x,y}/fs/ss/coffset lines +with open(sys.argv[1]) as ingeom: + while True: + line = ingeom.readline() + if not line: + break + line = line.rstrip("\r\n") + slash = line.find("/") + if slash != -1: + panel = line[0:slash] + else: + panel = None + if line.find("/corner_x") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + corner_x[panel] = line.split(" = ")[1] + if line.find("/corner_y") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + corner_y[panel] = line.split(" = ")[1] + if line.find("/fs") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + fs[panel] = line.split(" = ")[1] + if line.find("/ss") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + ss[panel] = line.split(" = ")[1] + if line.find("/coffset") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + coffset[panel] = line.split(" = ")[1] + +# Go through "template", and replace all corner_{x,y}/fs/ss lines from memory +out = open(sys.argv[3], "w") +with open(sys.argv[2]) as template: + while True: + line = template.readline() + if not line: + break + line = line.rstrip("\r\n") + slash = line.find("/") + if slash != -1: + panel = line[0:slash] + else: + panel = None + if line.find("/corner_x") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + out.write("%s/corner_x = %s\n" % (panel, corner_x[panel])) + elif line.find("/corner_y") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + out.write("%s/corner_y = %s\n" % (panel, corner_y[panel])) + elif line.find("/fs") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + out.write("%s/fs = %s\n" % (panel, fs[panel])) + elif line.find("/ss") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + out.write("%s/ss = %s\n" % (panel, ss[panel])) + elif line.find("/coffset") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + out.write("%s/coffset = %s\n" % (panel, coffset[panel])) + else: + out.write("%s\n" % line) + +out.close() + |