From bff1d54b091ad6a7dfe28fa0ddabdfe823b5fda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=2E=20Armando=20Sol=C3=A9?= Date: Mon, 15 Nov 2021 15:07:51 +0100 Subject: [PATCH] Calculate live time instead of reading it. --- PyMca5/PyMcaIO/specfilewrapper.py | 34 ++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/PyMca5/PyMcaIO/specfilewrapper.py b/PyMca5/PyMcaIO/specfilewrapper.py index 0b92477a9..102375ba2 100644 --- a/PyMca5/PyMcaIO/specfilewrapper.py +++ b/PyMca5/PyMcaIO/specfilewrapper.py @@ -356,8 +356,13 @@ def __init__(self, filename, amptek=None, qxas=None, dta=None): ketek_keys = ["File Version = ", "Livetime = ", "Realtime = ", + "Input Count Rate = ", + "Output Count Rate = ", "= KETEK"] ketek_counter = 0 + icr = None + ocr = None + live_time = None live_time = None real_time = None for line in self.header: @@ -367,18 +372,41 @@ def __init__(self, filename, amptek=None, qxas=None, dta=None): if keylower.startswith("livetime ="): tokens = line.split() if tokens[-1] == "s": - live_time = float(tokens[2] + "." + tokens[3]) + if "." in tokens[2]: + live_time = float(tokens[2]) + else: + live_time = float(tokens[2] + "." + tokens[3]) elif keylower.startswith("realtime ="): tokens = line.split() if tokens[-1] == "s": - real_time = float(tokens[2] + "." + tokens[3]) + if "." in tokens[2]: + real_time = float(tokens[2]) + else: + real_time = float(tokens[2] + "." + tokens[3]) + elif keylower.startswith("input count rate = "): + tokens = line.split(" = ")[-1].split() + if "." in tokens[0]: + icr = float(tokens[0]) + else: + icr = float(tokens[0] + "." + tokens[1]) + elif keylower.startswith("output count rate = "): + tokens = line.split(" = ")[-1].split() + if "." in tokens[0]: + ocr = float(tokens[0]) + else: + ocr = float(tokens[0] + "." + tokens[1]) ketek_counter += 1 break - if ketek_counter == len(ketek_keys): + if ketek_counter >= 4: self.ketek = 1 if real_time and live_time: self._ketekHeader = {} self._ketekHeader['S'] = '#S1 '+ " Unlabelled Spectrum" + if ocr and icr: + live_time = real_time * ocr / icr + _logger.info("Taking live time = real_time * ocr / icr") + else: + _logger.warning("Taking live time from file") self._ketekHeader['@CTIME'] = ['#@CTIME %f %f %f' % (real_time, live_time, real_time)]