diff --git a/xray/id9.py b/xray/id9.py index 4bbe6c5..1561045 100644 --- a/xray/id9.py +++ b/xray/id9.py @@ -8,6 +8,7 @@ from . import azav from . import dataReduction from . import utils from . import storage +from . import filters default_extension = ".npz" @@ -18,13 +19,26 @@ def _conv(x): x = np.nan return x +def _readDiagnostic(fname,retry=3): + ntry = 0 + while ntry 0: + data.data = filters.removeZingers(data.data,threshold=zingerFilter) + #data.save(storageFile); it does not save err ? + + +# idx = utils.findSlice(data.q,qlims) +# n = np.nanmean(data.data[:,idx],axis=1) +# data.norm_range = qlims +# data.norm = n +# n = utils.reshapeToBroadcast(n,data.data) +# data.data_norm = data.data/n + + data.save(storageFile) + + + return data + + def doFolder_dataRed(azavStorage,monitor=None,funcForAveraging=np.nanmean, - errMask=5,chi2Mask=2,qlims=None,outStorageFile='auto'): + qlims=None,outStorageFile='auto',reference='min'): """ azavStorage if a DataStorage instance or the filename to read """ if isinstance(azavStorage,storage.DataStorage): @@ -61,22 +101,20 @@ def doFolder_dataRed(azavStorage,monitor=None,funcForAveraging=np.nanmean, azavStorage = folder + "/pyfai_1d" + default_extension data = storage.DataStorage(azavStorage) + #assert data.q.shape[0] == data.data.shape[1] == data.err.shape[1] if qlims is not None: idx = (data.q>qlims[0]) & (data.q0: - diffs = dataReduction.errorMask(diffs,threshold=errMask) - if chi2Mask>0: - diffs = dataReduction.chi2Mask(diffs,threshold=chi2Mask) - diffs = dataReduction.applyMasks(diffs) - + + + # calculate differences + diffs = dataReduction.calcTimeResolvedSignal(data.delays,data.data,err=data.err, + q=data.q,reference=reference,monitor=monitor, + funcForAveraging=funcForAveraging) + # save txt and npz file dataReduction.saveTxt(folder,diffs,info=data.pyfai_info) if outStorageFile == 'auto': @@ -84,3 +122,33 @@ def doFolder_dataRed(azavStorage,monitor=None,funcForAveraging=np.nanmean, diffs.save(outStorageFile) return data,diffs + +def doFolder(folder,azav_kw = dict(), datared_kw = dict(),online=True, retryMax=20): + import matplotlib.pyplot as plt + if folder == "./": folder = os.path.abspath(folder) + fig = plt.figure() + lastNum = None + keepGoing = True + lines = None + retryNum = 0 + if online: print("Press Ctrl+C to stop") + while keepGoing and retryNum < retryMax: + try: + data = doFolder_azav(folder,**azav_kw) + # check if there are new data + if lastNum is None or lastNum