from __future__ import print_function,division import os # prepare logging import logging logfname = os.path.splitext(__file__)[0] + ".log" logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', datefmt='%y-%m-%d %H:%M:%S', filename=logfname, filemode='w') import numpy as np import pylab as plt import mcutils as mc import mcutils.xray as xray from mcutils.xray import id9 #id9 = xray.id9 from dualtree import dualtree # use npz files (they can handle more stuff (list of arrays,unicode) than h5py) id9.default_extension = '.npz' #id9.default_extension = '.h5' g_default_mask = '../masks/fesalen1_run8_careful.edf' def prepareLog(): """ It allows printing to terminal on top of logfile """ # define a Handler which writes INFO messages or higher to the sys.stderr console = logging.StreamHandler() console.setLevel(logging.INFO) # set a format which is simpler for console use formatter = logging.Formatter('%(message)s') # tell the handler to use this format console.setFormatter(formatter) # add the handler to the root logger logging.getLogger('').addHandler(console) prepareLog() def findCenter(): files = xray.utils.getEdfFiles("../fesalen/fesalen1/run8/",nFiles=100) img = xray.azav.read(files).mean(axis=0) - 10. xray.azav.find_center(img) def azav(folder,nQ=1500,force=False,saveChi=True,mask=g_default_mask): if isinstance(mask,int): files = xray.utils.getFiles(folder,"*.edf*") img = xray.azav.pyFAIread(files[0]) temp = np.ones_like(img,dtype=bool) temp[:mask] = False mask = temp return id9.doFolder_azav(folder,nQ=nQ,force=force,mask=mask,saveChi=saveChi) def removeBaseline(folder,qlims=(0.6,3),max_iter=30): data = azav(folder) idx = (data.q>qlims[0]) & (data.qr[0]) & (data.q