import logging log = logging.getLogger(__name__) import os import collections import numpy as np from . import azav from . import dataReduction from . import utils from . import storage default_extension = ".npz" def _conv(x): try: x = float(x) except: x = np.nan return x 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(str) 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='pyfai.poni',storageFile='auto'): """ very small wrapper around azav.doFolder, essentially just reading the diagnostics.log """ diag = dict( delays = readDelayFromDiagnostic(folder) ) if storageFile == 'auto' : storageFile = folder + "/" + "pyfai_1d" + default_extension return azav.doFolder(folder,files="*.edf*",nQ=nQ,force=force,mask=mask, saveChi=saveChi,poni=poni,storageFile=storageFile,diagnostic=diag) def doFolder_dataRed(folder,storageFile='auto',monitor=None, funcForAveraging=np.nanmean,errMask=5,chi2Mask=2,qlims=None): """ storageFile cab the the basename of the file (to look for in folder) or a DataStorage instance """ if storageFile == 'auto' : storageFile = folder + "/" + "pyfai_1d" + default_extension if isinstance(storageFile,storage.DataStorage): data = storageFile else: # read azimuthal averaged curves data = storage.DataStorage(storageFile) if qlims is not None: idx = (data.q>qlims[0]) & (data.q0: diffs = dataReduction.errorMask(diffs,threshold=errMask) if chi2Mask>0: diffs = dataReduction.chi2Mask(diffs,threshold=chi2Mask) diffs = dataReduction.applyMasks(diffs) # save txt and npz file dataReduction.saveTxt(folder,diffs,info=data.pyfai_info) diffs.save(folder + "/" + "diffs" + default_extension) return data,diffs