Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions larch/xafs/fluo.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ def fluo_corr(energy, mu, formula, elem, group=None, edge='K', line='Ka', anginp
pre_opts = {'e0': None, 'nnorm': 1, 'nvict': 0,
'pre1': None, 'pre2': -30,
'norm1': 100, 'norm2': None}
if hasattr(group, 'pre_edge_details'):
uopts = getattr(group.pre_edge_details, 'call_args', {})
for attr in pre_opts:
if attr in uopts:
pre_opts[attr] = uopts[attr]
# use the ranges pre_edge() settled on for this group, so that
# norm_corr is normalized the same way as norm
details = getattr(group, 'pre_edge_details', None)
if details is not None:
for attr in ('pre1', 'pre2', 'norm1', 'norm2', 'nnorm'):
if getattr(details, attr, None) is not None:
pre_opts[attr] = getattr(details, attr)
if getattr(group, 'e0', None) is not None:
pre_opts['e0'] = group.e0
pre_opts.update(pre_kws)
pre_opts['step'] = None
pre_opts['nvict'] = 0
Expand Down
29 changes: 29 additions & 0 deletions tests/test_xafs_fluo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from pathlib import Path

import numpy as np
import pytest

from larch.io import read_ascii
from larch.xafs import fluo_corr, pre_edge

basedir = Path(__file__).parent.parent.resolve()


@pytest.mark.parametrize('pre_edge_opts', [
{},
dict(pre1=-100, pre2=-30, norm1=50, norm2=300, nnorm=2),
])
def test_fluo_corr_uses_group_normalization(pre_edge_opts):
"""fluo_corr() normalizes with the ranges pre_edge() used for the group"""
dat = read_ascii(Path(basedir, 'examples', 'xafsdata', 'fe2o3_rt1.xmu'))
pre_edge(dat, **pre_edge_opts)
details = dat.pre_edge_details
explicit = {attr: getattr(details, attr)
for attr in ('pre1', 'pre2', 'norm1', 'norm2', 'nnorm')}

fluo_corr(dat.energy, dat.mu, 'Fe2O3', 'Fe', group=dat, e0=dat.e0, **explicit)
explicit_mu, explicit_norm = dat.mu_corr.copy(), dat.norm_corr.copy()

fluo_corr(dat.energy, dat.mu, 'Fe2O3', 'Fe', group=dat)
np.testing.assert_allclose(dat.mu_corr, explicit_mu)
np.testing.assert_allclose(dat.norm_corr, explicit_norm)
Loading