From 33bf3384dbc8f3b4431ad4c213748c5ce2243289 Mon Sep 17 00:00:00 2001 From: marco cammarata Date: Fri, 3 Mar 2017 23:09:34 +0100 Subject: [PATCH] improved getAI now one can override parameters read from file, convenient for testing different settings --- xray/azav.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/xray/azav.py b/xray/azav.py index f6da4af..515cea4 100644 --- a/xray/azav.py +++ b/xray/azav.py @@ -95,17 +95,17 @@ def do2d(ai, imgs, mask = None, npt_radial = 600, npt_azim=360,method = 'csr',sa out[_i] = i2d return q,azTheta,np.squeeze(out) -def getAI(poni,folder=None): +def getAI(poni=None,folder=None,**kwargs): """ get AzimuthalIntegrator instance: - → if poni is a dictionary use it to define one - → if poni is a string look, it is used as filename to read. + → if poni is a string, it is used as filename to read. in this case if folder is given it is used (together with all its subfolder) as search path (along with ./ and home folder) + → kwargs if present can be used to define (or override) parameters from files, + dist,xcen,ycen,poni1,poni2,rot1,rot2,rot3,pixel1,pixel2,splineFile, + detector,wavelength """ if isinstance(poni,pyFAI.azimuthalIntegrator.AzimuthalIntegrator): ai = poni - elif isinstance(poni,dict): - ai = pyFAI.azimuthalIntegrator.AzimuthalIntegrator(**poni) elif isinstance(poni,str): # look is file exists in cwd if os.path.isfile(poni): @@ -130,6 +130,14 @@ def getAI(poni,folder=None): else: log.debug("Could not poni file %s",fname) ai = pyFAI.load(fname) + else: + ai = pyFAI.azimuthalIntegrator.AzimuthalIntegrator() + for par,value in kwargs.items(): setattr(ai,par,value) + # provide xcen and ycen for convenience (note: xcen changes poni2 + # and ycen changes poni1) + if 'xcen' in kwargs: ai.poni2 = kwargs['xcen'] * ai.pixel2 + if 'ycen' in kwargs: ai.poni1 = kwargs['ycen'] * ai.pixel1 + ai.reset(); # needed in case of overridden parameters return ai g_mask_str = re.compile("(\w)\s*(<|>)\s*(\d+)")