import logging as log log.basicConfig(level=log.INFO) import os import collections import numpy as np from .xray import azav def _conv(x): try: x = float(x) except: x = np.nan return x def getFiles(folder,basename="*.edf*"): files = glob.glob(folder + "/" + basename) files.sort() return files def getEdfFiles(folder): return getFiles(folder,basename="*.edf*") def removeExt(fname): """ special remove extension meant to work with compressed files.edf and .edf.gz files """ if fname[-3:] == ".gz": fname = fname[-3:] return os.path.splitext(fname)[0] def readDelayFromDiagnostic(fname): """ return an ordered dict dictionary of filename; for each key a rounded value of delay is associated """ if os.path.isdir(fname): fname += "/diagnostics.log" data = np.genfromtxt(fname,usecols=(2,3),\ dtype=None,converters={3: lambda x: _conv(x)}, names = ['fname','delay']) files = data['fname'].astype(np.str); # to avoid encoding problems delays = data['delay'] # skip lines that cannot be interpreted as float (like done, etc) idx_ok = np.isfinite( delays ) files = files[idx_ok] delays = delays[idx_ok] delays = np.round(delays.astype(float),12) return collections.OrderedDict( zip(files,delays) ) def doFolder_azav(folder,nQ=1500,force=False,mask=None,saveChi=True, poni='auto',h5File='auto'): """ very small wrapper around azav.doFolder, essentially just reading the diagnostics.log """ if h5File == 'auto': n5File = folder + "/" + "pyfai_1d.h5" diag = dict( delays = readDelayFromDiagnostic(folder) ) return azav.doFolder(folder,files="*.edf*",nQ=nQ,force=force,mask=mask, saveChi=saveChi,poni=poni,h5File=h5File,diagnostic=diag)