updated examples
This commit is contained in:
parent
4319f4e394
commit
63c07ea3f1
|
@ -18,11 +18,12 @@ from mcutils.xray import id9
|
||||||
#id9 = xray.id9
|
#id9 = xray.id9
|
||||||
|
|
||||||
# use npz files (they can handle more stuff (list of arrays,unicode) than h5py)
|
# use npz files (they can handle more stuff (list of arrays,unicode) than h5py)
|
||||||
id9.default_extension = '.npz'
|
g_default_ext = '.npz'
|
||||||
#id9.default_extension = '.h5'
|
|
||||||
|
|
||||||
|
id9.default_extension = g_default_ext
|
||||||
g_default_mask = '../masks/fesalen1_run8_careful.edf'
|
g_default_mask = '../masks/fesalen1_run8_careful.edf'
|
||||||
g_default_folder = "../fesalen/fesalen1/run%d"
|
g_default_folder = "../fesalen/fesalen1/run%d"
|
||||||
|
|
||||||
runsE = collections.OrderedDict()
|
runsE = collections.OrderedDict()
|
||||||
runsT = collections.OrderedDict()
|
runsT = collections.OrderedDict()
|
||||||
runsE[7] = 60; runsT[7] = 135
|
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):
|
def removeBaseline(folder,qlims=(0.5,2.5),max_iter=30,force=False):
|
||||||
if isinstance(folder,int): folder = g_default_folder%folder
|
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:
|
if not os.path.isfile(fname) or force:
|
||||||
log.info("Calling azav with default parameters")
|
logging.info("Calling azav with default parameters")
|
||||||
data = azav(folder,withBaseline=False)
|
data = azav(folder,withBaseline=True)
|
||||||
# first peak (around 0.6) is weak and requires special care ...
|
# first peak (around 0.6) is weak and requires special care ...
|
||||||
data.q,data.data = xray.utils.removeBackground(data.q,data.data,
|
data.q,data.data = xray.utils.removeBackground(data.q,data.data,
|
||||||
xlims=qlims,max_iter=max_iter,background_regions=[ (0,0.58) ])
|
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,
|
def azav(folder,nQ=3000,force=False,saveChi=True,mask=g_default_mask,
|
||||||
withBaseline=True):
|
withBaseline=True):
|
||||||
|
if isinstance(folder,int): folder = g_default_folder%folder
|
||||||
if withBaseline:
|
if withBaseline:
|
||||||
data=removeBaseline(folder)
|
|
||||||
else:
|
|
||||||
data = id9.doFolder_azav(folder,nQ=nQ,force=force,mask=mask,
|
data = id9.doFolder_azav(folder,nQ=nQ,force=force,mask=mask,
|
||||||
saveChi=saveChi)
|
saveChi=saveChi)
|
||||||
|
else:
|
||||||
|
data=removeBaseline(folder)
|
||||||
return data
|
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,
|
qlims=(0.5,3),withBaseline=False,forceDatared=False,
|
||||||
select=slice(None),**kw):
|
select=slice(None),**kw):
|
||||||
if isinstance(folder,int): folder = g_default_folder%folder
|
if isinstance(folder,int): folder = g_default_folder%folder
|
||||||
data = azav(folder,withBaseline=withBaseline)
|
data = azav(folder,withBaseline=withBaseline)
|
||||||
extension = def_ext if withBaseline else "_nobaseline" + def_ext
|
if withBaseline:
|
||||||
# storage files to use
|
diffFile = folder + "/diffs" + g_default_ext
|
||||||
diffFile = folder + "/diffs" + extension
|
else:
|
||||||
|
diffFile = folder + "/diffs_nobaseline" + g_default_ext
|
||||||
|
|
||||||
if not os.path.isfile(diffFile) or forceDatared:
|
if not os.path.isfile(diffFile) or forceDatared:
|
||||||
data,diffs = id9.doFolder_dataRed(data,monitor=monitor,
|
data,diffs = id9.doFolder_dataRed(data,monitor=monitor,
|
||||||
errMask=errMask,chi2Mask=chi2Mask,qlims=qlims,
|
errMask=errMask,chi2Mask=chi2Mask,qlims=qlims,
|
||||||
outStorageFile=diffFile)
|
outStorageFile=diffFile)
|
||||||
else:
|
else:
|
||||||
data = xray.storage.read(azavFile)
|
|
||||||
diffs = xray.storage.read(diffFile)
|
diffs = xray.storage.read(diffFile)
|
||||||
|
|
||||||
if showPlot:
|
if showPlot:
|
||||||
|
@ -191,11 +193,11 @@ def anaAmplitue(run=12,plot=False,scaleWithE=False,withBaseline=False):
|
||||||
ax[num].set_title("Range %s"%(str(r)))
|
ax[num].set_title("Range %s"%(str(r)))
|
||||||
return diffs.scan,amp
|
return diffs.scan,amp
|
||||||
|
|
||||||
def _getPeakPos(x,y):
|
def _getPeakPos(x,y,e=1):
|
||||||
if y.ndim == 1: y = (y,)
|
if y.ndim == 1: y = (y,)
|
||||||
ret = dict()
|
ret = dict()
|
||||||
for yy in y:
|
for yy,ee in zip(y,e):
|
||||||
res = xray.peaks.fitPeak(x,yy)
|
res = xray.peaks.fitPeak(x,yy,err=ee)
|
||||||
#plt.figure(); res.plot_fit(); input("ok")
|
#plt.figure(); res.plot_fit(); input("ok")
|
||||||
pars = res.params.keys()
|
pars = res.params.keys()
|
||||||
for p in pars:
|
for p in pars:
|
||||||
|
@ -218,7 +220,7 @@ def anaPeakPos(run=12,plot=False,withBaseline=False):
|
||||||
for num,r in enumerate(ranges):
|
for num,r in enumerate(ranges):
|
||||||
idx = (diffs.q>r[0]) & (diffs.q<r[1])
|
idx = (diffs.q>r[0]) & (diffs.q<r[1])
|
||||||
#amplitude = _getAmplitudeFromLinFit( diffs.data[:,idx] )
|
#amplitude = _getAmplitudeFromLinFit( diffs.data[:,idx] )
|
||||||
pars[r] = _getPeakPos( data.q[idx],diffs.dataAsAbs[:,idx] )
|
pars[r] = _getPeakPos( data.q[idx],diffs.dataAsAbs[:,idx],diffs.err[:,idx])
|
||||||
if plot:
|
if plot:
|
||||||
ax[num].axhline( pars[r].center.value[0] )
|
ax[num].axhline( pars[r].center.value[0] )
|
||||||
ax[num].plot(diffs.scan,pars[r].center.value,'-o')
|
ax[num].plot(diffs.scan,pars[r].center.value,'-o')
|
||||||
|
@ -254,8 +256,8 @@ def showBaseline(N=2):
|
||||||
|
|
||||||
def showBaselineStability(N=100):
|
def showBaselineStability(N=100):
|
||||||
# has to be done with cryo on
|
# has to be done with cryo on
|
||||||
data_bs = azav("../fesalen/fesalen1/run15")
|
data_bs = azav("../fesalen/fesalen1/run15",withBaseline=True)
|
||||||
data = removeBaseline("../fesalen/fesalen1/run15")
|
data = azav("../fesalen/fesalen1/run15",withBaseline=False)
|
||||||
fig,ax=plt.subplots(2,2,sharey=True)
|
fig,ax=plt.subplots(2,2,sharey=True)
|
||||||
i = np.arange(data.data.shape[0])
|
i = np.arange(data.data.shape[0])
|
||||||
ax[0,0].pcolormesh(i,data_bs.q,data_bs.data.T)
|
ax[0,0].pcolormesh(i,data_bs.q,data_bs.data.T)
|
||||||
|
@ -333,20 +335,21 @@ def comparePosition2(runs=(11,12,8,9,10),withBaseline=False,useRatio=True,scaleW
|
||||||
plt.subplots_adjust( **subplots_kw )
|
plt.subplots_adjust( **subplots_kw )
|
||||||
plt.rcParams['font.size']=14
|
plt.rcParams['font.size']=14
|
||||||
if scaleWithE and not ratio:
|
if scaleWithE and not ratio:
|
||||||
log.warn("scaleWithE requires useRatio, setting scaleWithE to False")
|
logging.warn("scaleWithE requires useRatio, setting scaleWithE to False")
|
||||||
scaleWithE = Fale
|
scaleWithE = Fale
|
||||||
for run in runs:
|
for run in runs:
|
||||||
t,pos = anaPeakPos(run,plot=False,withBaseline=withBaseline)
|
t,pars = anaPeakPos(run,plot=False,withBaseline=withBaseline)
|
||||||
for k,a in zip(pos.keys(),ax):
|
for k,a in zip(pars.keys(),ax):
|
||||||
label = "run %d %.0f uJ"%(run,runsE[run])
|
label = "run %d %.0f uJ"%(run,runsE[run])
|
||||||
if useRatio:
|
if useRatio:
|
||||||
ratio = pos[k].center.value[1:]/pos[k].center.value[0]
|
ratio = pars[k].center.value[1:]/pars[k].center.value[0]
|
||||||
|
err = pars[k].center.err[1:]/pars[k].center.value[0]
|
||||||
if scaleWithE: ratio = (ratio-1)/runsE[run]+1
|
if scaleWithE: ratio = (ratio-1)/runsE[run]+1
|
||||||
line = a.plot(t[1:],ratio,'-o',label=label)[0]
|
line = a.errorbar(t[1:],ratio,err,fmt='-o',label=label)[0]
|
||||||
else:
|
else:
|
||||||
line = a.plot(t[1:],pos[k].center.value[1:],'-o',label=label)[0]
|
line = a.plot(t[1:],pars[k].center.value[1:],'-o',label=label)[0]
|
||||||
a.axhline(pos[k].center.value[0],color=line.get_color())
|
a.axhline(pars[k].center.value[0],color=line.get_color())
|
||||||
for interval,a in zip(pos.keys(),ax): a.set_title("range %s"%(str(interval)))
|
for interval,a in zip(pars.keys(),ax): a.set_title("range %s"%(str(interval)))
|
||||||
if useRatio:
|
if useRatio:
|
||||||
ax[0].set_ylabel("Peak Position / Peak Position(t=-5ns)")
|
ax[0].set_ylabel("Peak Position / Peak Position(t=-5ns)")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
from __future__ import print_function,division
|
from __future__ import print_function,division
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pylab as plt
|
import pylab as plt
|
||||||
|
import os
|
||||||
import mcutils as mc
|
import mcutils as mc
|
||||||
import mcutils.xray as xray
|
import mcutils.xray as xray
|
||||||
from mcutils.xray import id9
|
from mcutils.xray import id9
|
||||||
id9 = xray.id9
|
id9 = xray.id9
|
||||||
|
|
||||||
|
g_default_ext = '.npz'
|
||||||
# use npz files (they can handle more stuff (list of arrays,unicode) than h5py)
|
# use npz files (they can handle more stuff (list of arrays,unicode) than h5py)
|
||||||
id9.default_extension = '.npz'
|
id9.default_extension = g_default_ext
|
||||||
#id9.default_extension = '.h5'
|
#id9.default_extension = '.h5'
|
||||||
|
|
||||||
def readCalc():
|
def readCalc():
|
||||||
|
@ -25,8 +27,14 @@ calc = readCalc()
|
||||||
def azav(folder,nQ=1500,force=False,saveChi=True,mask='y>470'):
|
def azav(folder,nQ=1500,force=False,saveChi=True,mask='y>470'):
|
||||||
return id9.doFolder_azav(folder,nQ=nQ,force=force,mask=mask,saveChi=saveChi)
|
return id9.doFolder_azav(folder,nQ=nQ,force=force,mask=mask,saveChi=saveChi)
|
||||||
|
|
||||||
def datared(folder,monitor=(1,5),showPlot=True,**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)
|
data,diffs = id9.doFolder_dataRed(folder,monitor=monitor,**kw)
|
||||||
|
else:
|
||||||
|
data = xray.storage.read(azavFile)
|
||||||
|
diffs = xray.storage.read(diffFile)
|
||||||
if showPlot:
|
if showPlot:
|
||||||
xray.utils.plotdiffs(diffs.q,diffs.data,t=diffs.scan,
|
xray.utils.plotdiffs(diffs.q,diffs.data,t=diffs.scan,
|
||||||
absSignal=diffs.dataAbsAvAll,absSignalScale=30)
|
absSignal=diffs.dataAbsAvAll,absSignalScale=30)
|
||||||
|
@ -36,7 +44,7 @@ def datared(folder,monitor=(1,5),showPlot=True,**kw):
|
||||||
|
|
||||||
def doall(folder,force=False):
|
def doall(folder,force=False):
|
||||||
azav(folder,force=force)
|
azav(folder,force=force)
|
||||||
return datared(folder)
|
return datared(folder,forceDatared=force)
|
||||||
|
|
||||||
def anaAmplitue(run=6):
|
def anaAmplitue(run=6):
|
||||||
fname = "../tiox/tiox1/run%d/diffs.npz" % run
|
fname = "../tiox/tiox1/run%d/diffs.npz" % run
|
||||||
|
|
Loading…
Reference in New Issue