From 71f4e6a5752f6586ec83a8c9606b100f2fe497fb Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 13 Nov 2018 14:14:44 +0100 Subject: Add some new scripts --- scripts/euxfel-train-analysis | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 scripts/euxfel-train-analysis (limited to 'scripts/euxfel-train-analysis') 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 +# + +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") -- cgit v1.2.3