diff --git a/xray/example_main_salen.py b/xray/example_main_salen.py index cd10fad..afabf5e 100644 --- a/xray/example_main_salen.py +++ b/xray/example_main_salen.py @@ -18,11 +18,12 @@ from mcutils.xray import id9 #id9 = xray.id9 # use npz files (they can handle more stuff (list of arrays,unicode) than h5py) -id9.default_extension = '.npz' -#id9.default_extension = '.h5' +g_default_ext = '.npz' +id9.default_extension = g_default_ext g_default_mask = '../masks/fesalen1_run8_careful.edf' g_default_folder = "../fesalen/fesalen1/run%d" + runsE = collections.OrderedDict() runsT = collections.OrderedDict() runsE[7] = 60; runsT[7] = 135 @@ -100,10 +101,10 @@ def findCenter(cen=(484,479.5),dist=0.251): def removeBaseline(folder,qlims=(0.5,2.5),max_iter=30,force=False): if isinstance(folder,int): folder = g_default_folder%folder - fname = folder + "/pyfai_1d_nobaseline"+id9.default_extension + fname = folder + "/pyfai_1d_nobaseline"+g_default_ext if not os.path.isfile(fname) or force: - log.info("Calling azav with default parameters") - data = azav(folder,withBaseline=False) + logging.info("Calling azav with default parameters") + data = azav(folder,withBaseline=True) # first peak (around 0.6) is weak and requires special care ... data.q,data.data = xray.utils.removeBackground(data.q,data.data, xlims=qlims,max_iter=max_iter,background_regions=[ (0,0.58) ]) @@ -114,28 +115,29 @@ def removeBaseline(folder,qlims=(0.5,2.5),max_iter=30,force=False): def azav(folder,nQ=3000,force=False,saveChi=True,mask=g_default_mask, withBaseline=True): + if isinstance(folder,int): folder = g_default_folder%folder if withBaseline: - data=removeBaseline(folder) - else: data = id9.doFolder_azav(folder,nQ=nQ,force=force,mask=mask, saveChi=saveChi) + else: + data=removeBaseline(folder) return data -def datared(folder,monitor=(0.5,4),showPlot=True,errMask=5,chi2Mask=2, +def datared(folder,monitor=(0.5,4),showPlot=True,errMask=5,chi2Mask=1.5, qlims=(0.5,3),withBaseline=False,forceDatared=False, select=slice(None),**kw): if isinstance(folder,int): folder = g_default_folder%folder data = azav(folder,withBaseline=withBaseline) - extension = def_ext if withBaseline else "_nobaseline" + def_ext - # storage files to use - diffFile = folder + "/diffs" + extension + if withBaseline: + diffFile = folder + "/diffs" + g_default_ext + else: + diffFile = folder + "/diffs_nobaseline" + g_default_ext if not os.path.isfile(diffFile) or forceDatared: data,diffs = id9.doFolder_dataRed(data,monitor=monitor, errMask=errMask,chi2Mask=chi2Mask,qlims=qlims, outStorageFile=diffFile) else: - data = xray.storage.read(azavFile) diffs = xray.storage.read(diffFile) if showPlot: @@ -191,11 +193,11 @@ def anaAmplitue(run=12,plot=False,scaleWithE=False,withBaseline=False): ax[num].set_title("Range %s"%(str(r))) return diffs.scan,amp -def _getPeakPos(x,y): +def _getPeakPos(x,y,e=1): if y.ndim == 1: y = (y,) ret = dict() - for yy in y: - res = xray.peaks.fitPeak(x,yy) + for yy,ee in zip(y,e): + res = xray.peaks.fitPeak(x,yy,err=ee) #plt.figure(); res.plot_fit(); input("ok") pars = res.params.keys() for p in pars: @@ -218,7 +220,7 @@ def anaPeakPos(run=12,plot=False,withBaseline=False): for num,r in enumerate(ranges): idx = (diffs.q>r[0]) & (diffs.q470'): return id9.doFolder_azav(folder,nQ=nQ,force=force,mask=mask,saveChi=saveChi) -def datared(folder,monitor=(1,5),showPlot=True,**kw): - data,diffs = id9.doFolder_dataRed(folder,monitor=monitor,**kw) +def datared(folder,monitor=(1,5),forceDatared=False,showPlot=True,**kw): + azavFile = folder + "/pyfai_1d" + g_default_ext + diffFile = folder + "/diffs" + g_default_ext + if not os.path.isfile(diffFile) or forceDatared: + data,diffs = id9.doFolder_dataRed(folder,monitor=monitor,**kw) + else: + data = xray.storage.read(azavFile) + diffs = xray.storage.read(diffFile) if showPlot: xray.utils.plotdiffs(diffs.q,diffs.data,t=diffs.scan, absSignal=diffs.dataAbsAvAll,absSignalScale=30) @@ -36,7 +44,7 @@ def datared(folder,monitor=(1,5),showPlot=True,**kw): def doall(folder,force=False): azav(folder,force=force) - return datared(folder) + return datared(folder,forceDatared=force) def anaAmplitue(run=6): fname = "../tiox/tiox1/run%d/diffs.npz" % run