From 518fc6175ee806cbe0037c3326d325c59b71da64 Mon Sep 17 00:00:00 2001 From: Marco Cammarata Date: Wed, 4 Jan 2017 14:15:08 +0100 Subject: [PATCH] few more functions: strToTime and pyfai shorthands --- mcutils.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/mcutils.py b/mcutils.py index 17d318f..89d21f7 100644 --- a/mcutils.py +++ b/mcutils.py @@ -469,6 +469,19 @@ def bytesToHuman(bytes,units="auto",fmt="%.2f %s"): value = bytes/1024**u return fmt % (value,units) +def strToTime(s): + """ convert 3us in 3e-6, ... """ + v = float(s[:-2]) + u = s[-2:] + if (u=="ps"): + v*=1e-12 + elif (u=="ns"): + v*=1e-9 + elif (u=="us"): + v*=1e-6 + else: + pass + return v def memAvailable(asHuman=True): import psutil @@ -1207,6 +1220,38 @@ def insertInSortedArray(a,v): a[idx]=v return a +def pyFAI1d(ai, imgs, mask = None, npt_radial = 600, method = 'csr',safe=True,dark=10., polCorr = 1): + """ ai is a pyFAI azimuthal intagrator + it can be defined with pyFAI.load(ponifile) + mask: True are points to be masked out """ + # force float to be sure of type casting for img + if isinstance(dark,int): dark = float(dark); + if imgs.ndim == 2: imgs = (imgs,) + out_i = np.empty( ( len(imgs), npt_radial) ) + out_s = np.empty( ( len(imgs), npt_radial) ) + for _i,img in enumerate(imgs): + q,i, sig = ai.integrate1d(img-dark, npt_radial, mask= mask, safe = safe,\ + unit="q_A^-1", method = method, error_model = "poisson", + polarization_factor = polCorr) + out_i[_i] = i + out_s[_i] = sig + return q,np.squeeze(out_i),np.squeeze(out_s) + +def pyFAI2d(ai, imgs, mask = None, npt_radial = 600, npt_azim=360,method = 'csr',safe=True,dark=10., polCorr = 1): + """ ai is a pyFAI azimuthal intagrator + it can be defined with pyFAI.load(ponifile) + mask: True are points to be masked out """ + # force float to be sure of type casting for img + if isinstance(dark,int): dark = float(dark); + if imgs.ndim == 2: imgs = (imgs,) + out = np.empty( ( len(imgs), npt_azim,npt_radial) ) + for _i,img in enumerate(imgs): + i2d,q,azTheta = ai.integrate2d(img-dark, npt_radial, npt_azim=npt_azim, + mask= mask, safe = safe,unit="q_A^-1", method = method, + polarization_factor = polCorr ) + out[_i] = i2d + return q,azTheta,np.squeeze(out) + ### Objects ###