Skip to content

Commit

Permalink
change feffit reports to gformat with len=10
Browse files Browse the repository at this point in the history
  • Loading branch information
newville committed Sep 21, 2023
1 parent 525b294 commit 0ce39ed
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
9 changes: 4 additions & 5 deletions larch/xafs/feffdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
from larch import Group, isNamedClass
from larch.utils.strutils import fix_varname, b32hash
from larch.fitting import group2params, dict2params, isParameter, param_value
from larch.utils import gformat
from .xafsutils import ETOK, ktoe, set_xafsGroup
from .xafsutils import ETOK, ktoe, set_xafsGroup, gfmt
from .sigma2_models import add_sigma2funcs

SMALL_ENERGY = 1.e-6
Expand Down Expand Up @@ -459,7 +458,7 @@ def report(self):

stderrs = {}
out.append(' {:7s}= {:s}'.format('reff',
gformat(self._feffdat.reff)))
gfmt(self._feffdat.reff)))

for pname in ('degen', 's02', 'e0', 'r',
'deltar', 'sigma2', 'third', 'fourth', 'ei'):
Expand All @@ -482,9 +481,9 @@ def report(self):
std = par.stderr

if std is None or std <= 0:
svalue = gformat(val)
svalue = gfmt(val)
else:
svalue = "{:s} +/-{:s}".format(gformat(val), gformat(std))
svalue = "{:s} +/-{:s}".format(gfmt(val), gfmt(std))
if pname == 's02':
pname = 'n*s02'

Expand Down
42 changes: 21 additions & 21 deletions larch/xafs/feffit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
from lmfit import Parameters, Parameter, Minimizer, fit_report

from larch import Group, isNamedClass
from larch.utils import fix_varname, gformat
from larch.utils import fix_varname
from ..math import index_of, realimag, complex_phase, remove_nans
from ..fitting import (correlated_values, eval_stderr, ParameterGroup,
group2params, params2group, isParameter)

from .xafsutils import set_xafsGroup
from .xafsutils import set_xafsGroup, gfmt
from .xafsft import xftf_fast, xftr_fast, ftwindow
from .feffdat import FeffPathGroup, ff2chi

Expand Down Expand Up @@ -720,11 +720,11 @@ def feffit_report(result, min_correl=0.1, with_paths=True, _larch=None):
out.append(' nvarys, npts = %i, %i' % (result.nvarys,
result.ndata))
out.append(' n_independent = %.3f' % (result.n_independent))
out.append(' chi_square = %s' % gformat(result.chi_square))
out.append(' reduced chi_square = %s' % gformat(result.chi2_reduced))
out.append(' r-factor = %s' % gformat(result.rfactor))
out.append(' Akaike info crit = %s' % gformat(result.aic))
out.append(' Bayesian info crit = %s' % gformat(result.bic))
out.append(' chi_square = %s' % gfmt(result.chi_square))
out.append(' reduced chi_square = %s' % gfmt(result.chi2_reduced))
out.append(' r-factor = %s' % gfmt(result.rfactor))
out.append(' Akaike info crit = %s' % gfmt(result.aic))
out.append(' Bayesian info crit = %s' % gfmt(result.bic))
out.append(' ')

if len(datasets) == 1:
Expand All @@ -741,20 +741,20 @@ def feffit_report(result, min_correl=0.1, with_paths=True, _larch=None):
if isinstance(ds.epsilon_k[0], np.ndarray):
msg = []
for eps in ds.epsilon_k:
msg.append('Array(mean=%s, std=%s)' % (gformat(eps.mean()).strip(),
gformat(eps.std()).strip()))
msg.append('Array(mean=%s, std=%s)' % (gfmt(eps.mean()).strip(),
gfmt(eps.std()).strip()))
eps_k = ', '.join(msg)
else:
eps_k = ', '.join([gformat(eps).strip() for eps in ds.epsilon_k])
eps_r = ', '.join([gformat(eps).strip() for eps in ds.epsilon_r])
eps_k = ', '.join([gfmt(eps).strip() for eps in ds.epsilon_k])
eps_r = ', '.join([gfmt(eps).strip() for eps in ds.epsilon_r])
kweigh = ', '.join(['%i' % kwe for kwe in tr.kweight])
else:
if isinstance(ds.epsilon_k, np.ndarray):
eps_k = 'Array(mean=%s, std=%s)' % (gformat(ds.epsilon_k.mean()).strip(),
gformat(ds.epsilon_k.std()).strip())
eps_k = 'Array(mean=%s, std=%s)' % (gfmt(ds.epsilon_k.mean()).strip(),
gfmt(ds.epsilon_k.std()).strip())
else:
eps_k = gformat(ds.epsilon_k)
eps_r = gformat(ds.epsilon_r).strip()
eps_k = gfmt(ds.epsilon_k)
eps_r = gfmt(ds.epsilon_r).strip()
kweigh = '%i' % tr.kweight
out.append(' fit space = \'%s\'' % (tr.fitspace))
out.append(' r-range = %.3f, %.3f' % (tr.rmin, tr.rmax))
Expand Down Expand Up @@ -782,18 +782,18 @@ def feffit_report(result, min_correl=0.1, with_paths=True, _larch=None):
if par.vary:
stderr = 'unknown'
if par.stderr is not None:
stderr = gformat(par.stderr)
out.append(varformat % (name, gformat(par.value),
stderr, gformat(par.init_value)))
stderr = gfmt(par.stderr)
out.append(varformat % (name, gfmt(par.value),
stderr, gfmt(par.init_value)))

elif par.expr is not None:
stderr = 'unknown'
if par.stderr is not None:
stderr = gformat(par.stderr)
out.append(exprformat % (name, gformat(par.value),
stderr = gfmt(par.stderr)
out.append(exprformat % (name, gfmt(par.value),
stderr, par.expr))
else:
out.append(fixformat % (name, gformat(par.value)))
out.append(fixformat % (name, gfmt(par.value)))

covar_vars = result.var_names
if len(covar_vars) > 0:
Expand Down
6 changes: 5 additions & 1 deletion larch/xafs/xafsutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
import numpy as np
from larch import Group, Journal

from larch.utils import gformat
import scipy.constants as consts
KTOE = 1.e20*consts.hbar**2 / (2*consts.m_e * consts.e) # 3.8099819442818976
ETOK = 1.0/KTOE
Expand All @@ -12,6 +12,10 @@
FT_WINDOWS = ('Kaiser-Bessel', 'Hanning', 'Parzen', 'Welch', 'Gaussian', 'Sine')
FT_WINDOWS_SHORT = tuple([a[:3].lower() for a in FT_WINDOWS])

NUMLEN = 10
def gfmt(x):
return gformat(x, length=NUMLEN)

def etok(energy):
"""convert photo-electron energy to wavenumber"""
if energy < 0: return 0
Expand Down

0 comments on commit 0ce39ed

Please sign in to comment.