2017-01-05 19:22:37 +01:00
|
|
|
import logging as log
|
|
|
|
log.basicConfig(level=log.INFO)
|
|
|
|
|
|
|
|
import os
|
|
|
|
import collections
|
|
|
|
import numpy as np
|
2017-01-06 18:06:34 +01:00
|
|
|
from . import azav
|
|
|
|
from . import dataReduction
|
|
|
|
from . import utils
|
2017-01-07 23:53:12 +01:00
|
|
|
from . import storage
|
2017-01-06 15:40:26 +01:00
|
|
|
|
2017-01-07 23:53:12 +01:00
|
|
|
default_extension = ".npz"
|
2017-01-05 19:22:37 +01:00
|
|
|
|
|
|
|
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'])
|
2017-01-06 15:40:26 +01:00
|
|
|
files = data['fname'].astype(str)
|
2017-01-05 19:22:37 +01:00
|
|
|
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,
|
2017-01-10 00:28:29 +01:00
|
|
|
poni='pyfai.poni',storageFile='auto'):
|
2017-01-05 19:22:37 +01:00
|
|
|
""" very small wrapper around azav.doFolder, essentially just reading
|
|
|
|
the diagnostics.log """
|
|
|
|
|
|
|
|
diag = dict( delays = readDelayFromDiagnostic(folder) )
|
2017-01-07 23:53:12 +01:00
|
|
|
if storageFile == 'auto' : storageFile = folder + "/" + "pyfai_1d" + default_extension
|
2017-01-05 19:22:37 +01:00
|
|
|
return azav.doFolder(folder,files="*.edf*",nQ=nQ,force=force,mask=mask,
|
2017-01-06 15:40:26 +01:00
|
|
|
saveChi=saveChi,poni=poni,storageFile=storageFile,diagnostic=diag)
|
|
|
|
|
2017-01-06 18:06:34 +01:00
|
|
|
def doFolder_dataRed(folder,storageFile='auto',monitor=None,
|
2017-01-10 00:28:29 +01:00
|
|
|
funcForAveraging=np.nanmean,errMask=5,chi2Mask=2,qlims=None):
|
2017-01-06 18:06:34 +01:00
|
|
|
|
2017-01-07 23:53:12 +01:00
|
|
|
if storageFile == 'auto' : storageFile = folder + "/" + "pyfai_1d" + default_extension
|
2017-01-06 18:06:34 +01:00
|
|
|
|
|
|
|
# read azimuthal averaged curves
|
2017-01-07 23:53:12 +01:00
|
|
|
data = storage.DataStorage(storageFile)
|
2017-01-06 18:06:34 +01:00
|
|
|
|
2017-01-10 00:28:29 +01:00
|
|
|
if qlims is not None:
|
|
|
|
idx = (data.q>qlims[0]) & (data.q<qlims[1])
|
|
|
|
data.data = data.data[:,idx]
|
|
|
|
data.q = data.q[idx]
|
2017-01-06 18:06:34 +01:00
|
|
|
|
|
|
|
# calculate differences
|
|
|
|
diffs = dataReduction.calcTimeResolvedSignal(data.delays,data.data,q=data.q,\
|
2017-01-10 00:28:29 +01:00
|
|
|
reference="min",monitor=monitor,funcForAveraging=funcForAveraging)
|
2017-01-06 18:06:34 +01:00
|
|
|
|
2017-01-10 00:28:29 +01:00
|
|
|
# mask if asked so
|
|
|
|
if errMask>0:
|
|
|
|
diffs = dataReduction.errorMask(diffs,threshold=errMask)
|
|
|
|
if chi2Mask>0:
|
|
|
|
diffs = dataReduction.chi2Mask(diffs,threshold=chi2Mask)
|
|
|
|
diffs = dataReduction.applyMasks(diffs)
|
2017-01-06 18:06:34 +01:00
|
|
|
|
|
|
|
# save txt and npz file
|
2017-01-06 15:40:26 +01:00
|
|
|
dataReduction.saveTxt(folder,diffs,info=data.pyfai_info)
|
2017-01-07 23:53:12 +01:00
|
|
|
diffs.save(folder + "/" + "diffs" + default_extension)
|
2017-01-06 18:06:34 +01:00
|
|
|
|
|
|
|
return data,diffs
|