few more functions: strToTime and pyfai shorthands

This commit is contained in:
Marco Cammarata 2017-01-04 14:15:08 +01:00
parent bc708b4200
commit 518fc6175e
1 changed files with 45 additions and 0 deletions

View File

@ -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 ###