本文整理汇总了Python中larch.Group.kmin方法的典型用法代码示例。如果您正苦于以下问题:Python Group.kmin方法的具体用法?Python Group.kmin怎么用?Python Group.kmin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类larch.Group
的用法示例。
在下文中一共展示了Group.kmin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: autobk
# 需要导入模块: from larch import Group [as 别名]
# 或者: from larch.Group import kmin [as 别名]
def autobk(energy, mu=None, group=None, rbkg=1, nknots=None, e0=None,
edge_step=None, kmin=0, kmax=None, kweight=1, dk=0,
win='hanning', k_std=None, chi_std=None, nfft=2048, kstep=0.05,
pre_edge_kws=None, nclamp=4, clamp_lo=1, clamp_hi=1,
calc_uncertainties=False, _larch=None, **kws):
"""Use Autobk algorithm to remove XAFS background
Parameters:
-----------
energy: 1-d array of x-ray energies, in eV, or group
mu: 1-d array of mu(E)
group: output group (and input group for e0 and edge_step).
rbkg: distance (in Ang) for chi(R) above
which the signal is ignored. Default = 1.
e0: edge energy, in eV. If None, it will be determined.
edge_step: edge step. If None, it will be determined.
pre_edge_kws: keyword arguments to pass to pre_edge()
nknots: number of knots in spline. If None, it will be determined.
kmin: minimum k value [0]
kmax: maximum k value [full data range].
kweight: k weight for FFT. [1]
dk: FFT window window parameter. [0]
win: FFT window function name. ['hanning']
nfft: array size to use for FFT [2048]
kstep: k step size to use for FFT [0.05]
k_std: optional k array for standard chi(k).
chi_std: optional chi array for standard chi(k).
nclamp: number of energy end-points for clamp [2]
clamp_lo: weight of low-energy clamp [1]
clamp_hi: weight of high-energy clamp [1]
calc_uncertaintites: Flag to calculate uncertainties in
mu_0(E) and chi(k) [False]
Output arrays are written to the provided group.
Follows the 'First Argument Group' convention.
"""
msg = _larch.writer.write
if 'kw' in kws:
kweight = kws.pop('kw')
if len(kws) > 0:
msg('Unrecognized a:rguments for autobk():\n')
msg(' %s\n' % (', '.join(kws.keys())))
return
energy, mu, group = parse_group_args(energy, members=('energy', 'mu'),
defaults=(mu,), group=group,
fcn_name='autobk')
energy = remove_dups(energy)
# if e0 or edge_step are not specified, get them, either from the
# passed-in group or from running pre_edge()
group = set_xafsGroup(group, _larch=_larch)
if edge_step is None and isgroup(group, 'edge_step'):
edge_step = group.edge_step
if e0 is None and isgroup(group, 'e0'):
e0 = group.e0
if e0 is None or edge_step is None:
# need to run pre_edge:
pre_kws = dict(nnorm=3, nvict=0, pre1=None,
pre2=-50., norm1=100., norm2=None)
if pre_edge_kws is not None:
pre_kws.update(pre_edge_kws)
pre_edge(energy, mu, group=group, _larch=_larch, **pre_kws)
if e0 is None:
e0 = group.e0
if edge_step is None:
edge_step = group.edge_step
if e0 is None or edge_step is None:
msg('autobk() could not determine e0 or edge_step!: trying running pre_edge first\n')
return
# get array indices for rkbg and e0: irbkg, ie0
ie0 = index_of(energy, e0)
rgrid = np.pi/(kstep*nfft)
if rbkg < 2*rgrid: rbkg = 2*rgrid
irbkg = int(1.01 + rbkg/rgrid)
# save ungridded k (kraw) and grided k (kout)
# and ftwin (*k-weighting) for FT in residual
enpe = energy[ie0:] - e0
kraw = np.sign(enpe)*np.sqrt(ETOK*abs(enpe))
if kmax is None:
kmax = max(kraw)
else:
kmax = max(0, min(max(kraw), kmax))
kout = kstep * np.arange(int(1.01+kmax/kstep), dtype='float64')
iemax = min(len(energy), 2+index_of(energy, e0+kmax*kmax/ETOK)) - 1
# interpolate provided chi(k) onto the kout grid
if chi_std is not None and k_std is not None:
chi_std = np.interp(kout, k_std, chi_std)
# pre-load FT window
ftwin = kout**kweight * ftwindow(kout, xmin=kmin, xmax=kmax,
window=win, dx=dk)
# calc k-value and initial guess for y-values of spline params
nspl = max(4, min(128, 2*int(rbkg*(kmax-kmin)/np.pi) + 1))
spl_y, spl_k, spl_e = np.zeros(nspl), np.zeros(nspl), np.zeros(nspl)
for i in range(nspl):
#.........这里部分代码省略.........
示例2: autobk
# 需要导入模块: from larch import Group [as 别名]
# 或者: from larch.Group import kmin [as 别名]
def autobk(energy, mu=None, group=None, rbkg=1, nknots=None, e0=None,
edge_step=None, kmin=0, kmax=None, kweight=1, dk=0.1,
win='hanning', k_std=None, chi_std=None, nfft=2048, kstep=0.05,
pre_edge_kws=None, nclamp=4, clamp_lo=1, clamp_hi=1,
calc_uncertainties=True, err_sigma=1, _larch=None, **kws):
"""Use Autobk algorithm to remove XAFS background
Parameters:
-----------
energy: 1-d array of x-ray energies, in eV, or group
mu: 1-d array of mu(E)
group: output group (and input group for e0 and edge_step).
rbkg: distance (in Ang) for chi(R) above
which the signal is ignored. Default = 1.
e0: edge energy, in eV. If None, it will be determined.
edge_step: edge step. If None, it will be determined.
pre_edge_kws: keyword arguments to pass to pre_edge()
nknots: number of knots in spline. If None, it will be determined.
kmin: minimum k value [0]
kmax: maximum k value [full data range].
kweight: k weight for FFT. [1]
dk: FFT window window parameter. [0.1]
win: FFT window function name. ['hanning']
nfft: array size to use for FFT [2048]
kstep: k step size to use for FFT [0.05]
k_std: optional k array for standard chi(k).
chi_std: optional chi array for standard chi(k).
nclamp: number of energy end-points for clamp [2]
clamp_lo: weight of low-energy clamp [1]
clamp_hi: weight of high-energy clamp [1]
calc_uncertaintites: Flag to calculate uncertainties in
mu_0(E) and chi(k) [True]
err_sigma: sigma level for uncertainties in mu_0(E) and chi(k) [1]
Output arrays are written to the provided group.
Follows the 'First Argument Group' convention.
"""
msg = sys.stdout
if _larch is not None:
msg = _larch.writer.write
if 'kw' in kws:
kweight = kws.pop('kw')
if len(kws) > 0:
msg('Unrecognized a:rguments for autobk():\n')
msg(' %s\n' % (', '.join(kws.keys())))
return
energy, mu, group = parse_group_args(energy, members=('energy', 'mu'),
defaults=(mu,), group=group,
fcn_name='autobk')
if len(energy.shape) > 1:
energy = energy.squeeze()
if len(mu.shape) > 1:
mu = mu.squeeze()
energy = remove_dups(energy)
# if e0 or edge_step are not specified, get them, either from the
# passed-in group or from running pre_edge()
group = set_xafsGroup(group, _larch=_larch)
if edge_step is None and isgroup(group, 'edge_step'):
edge_step = group.edge_step
if e0 is None and isgroup(group, 'e0'):
e0 = group.e0
if e0 is None or edge_step is None:
# need to run pre_edge:
pre_kws = dict(nnorm=3, nvict=0, pre1=None,
pre2=-50., norm1=100., norm2=None)
if pre_edge_kws is not None:
pre_kws.update(pre_edge_kws)
pre_edge(energy, mu, group=group, _larch=_larch, **pre_kws)
if e0 is None:
e0 = group.e0
if edge_step is None:
edge_step = group.edge_step
if e0 is None or edge_step is None:
msg('autobk() could not determine e0 or edge_step!: trying running pre_edge first\n')
return
# get array indices for rkbg and e0: irbkg, ie0
ie0 = index_of(energy, e0)
rgrid = np.pi/(kstep*nfft)
if rbkg < 2*rgrid: rbkg = 2*rgrid
irbkg = int(1.01 + rbkg/rgrid)
# save ungridded k (kraw) and grided k (kout)
# and ftwin (*k-weighting) for FT in residual
enpe = energy[ie0:] - e0
kraw = np.sign(enpe)*np.sqrt(ETOK*abs(enpe))
if kmax is None:
kmax = max(kraw)
else:
kmax = max(0, min(max(kraw), kmax))
kout = kstep * np.arange(int(1.01+kmax/kstep), dtype='float64')
iemax = min(len(energy), 2+index_of(energy, e0+kmax*kmax/ETOK)) - 1
# interpolate provided chi(k) onto the kout grid
if chi_std is not None and k_std is not None:
chi_std = np.interp(kout, k_std, chi_std)
# pre-load FT window
#.........这里部分代码省略.........