From d17b9caa7fbfee84c55f64a8d948007a7e0cf926 Mon Sep 17 00:00:00 2001 From: Marco Cammarata Date: Thu, 9 Mar 2017 23:20:57 +0100 Subject: [PATCH] added id9 log file parser --- xray/__init__.py | 1 + xray/id9.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/xray/__init__.py b/xray/__init__.py index 5ae30d7..e57bba7 100644 --- a/xray/__init__.py +++ b/xray/__init__.py @@ -4,6 +4,7 @@ from . import mask from . import peaks from . import cell from . import filters +from . import id9 try: from . import azav except ImportError: diff --git a/xray/id9.py b/xray/id9.py index 1561045..7c90bef 100644 --- a/xray/id9.py +++ b/xray/id9.py @@ -48,6 +48,49 @@ def readDelayFromDiagnostic(fname): delays = np.round(delays.astype(float),12) return collections.OrderedDict( zip(files,delays) ) +def _findDark(line): + _,value = line.split(":") + return float(value) + +def _delayToNum(delay): + if delay.decode('ascii') == 'off': + delay = -10 + else: + delay=utils.strToTime(delay) + return delay + +def findLogFile(folder): + files = utils.getFiles(folder,basename='*.log') + files.remove(os.path.join(folder,"diagnostics.log")) + logfile = files[0] + if len(files)>1: log.warn("Found more than one *.log file that is not diagnostics.log: %s"%files) + return logfile + +def readLogFile(fnameOrFolder,subtractDark=False): + """ read id9 style logfile """ + if os.path.isdir(fnameOrFolder): + fname = findLogFile(fnameOrFolder) + else: + fname = fnameOrFolder + f = open(fname,"r") + lines = f.readlines() + f.close() + lines = [line.strip() for line in lines] + darks = {} + for line in lines: + if line.find("pd1 dark/sec")>=0: darks['pd1ic'] = _findDark(line) + if line.find("pd2 dark/sec")>=0: darks['pd2ic'] = _findDark(line) + if line.find("pd3 dark/sec")>=0: darks['pd3ic'] = _findDark(line) + if line.find("pd4 dark/sec")>=0: darks['pd4ic'] = _findDark(line) + for iline,line in enumerate(lines): + if line.lstrip()[0] != "#": break + data=np.genfromtxt(fname,skip_header=iline-1,names=True,comments="%",dtype=None,converters = {'delay': lambda s: _delayToNum(s)}) + if subtractDark: + for diode in ['pd1ic','pd2ic','pd3ic','pd4ic']: + if diode in darks: data[diode]=data[diode]-darks[diode]*data['timeic'] + return data + + def doFolder_azav(folder,nQ=1500,files='*.edf*',force=False,mask=None, saveChi=True,poni='pyfai.poni',storageFile='auto',dark=9.9,zingerFilter=30,qlims=(0,10),