def test_read_dnd(self): """Test function for read_dnd. """ with pkg_resources.path(testdata, self.path_dict['fname_dnd']) as path: fpath = path # extracting scans from original file raw = loadtxt(fpath, usecols=(0, 16, 17, 18)) index = index_dups(raw[:, 0], 1e-4) raw = delete(raw, index, 0) muref = raw[:, 3] mu = raw[:, 2] fluo = raw[:, 1] for scan in ['mu', 'fluo', None]: # testing with request for mu_ref group = read_dnd(fpath, scan=scan) self.assertIsInstance(group, Group) # group class is returned self.assertIsInstance(group.energy, ndarray) # ndarray type is returned self.assertIsInstance(group.mu_ref, ndarray) # ndarray type is returned self.assertTrue(allclose(group.mu_ref, muref)) # mu_ref is properly retrieved if scan == 'mu': self.assertIsInstance(getattr(group, scan), ndarray) self.assertFalse(hasattr( group, 'fluo')) # instance fluo is not returned self.assertTrue(allclose(group.mu, mu)) # mu_ref is properly retrieved elif scan == 'fluo': self.assertIsInstance(getattr(group, scan), ndarray) self.assertFalse(hasattr(group, 'mu')) # instance mu is not returned self.assertTrue(allclose(group.fluo, fluo)) # fluo is properly retrieved for scan in ['mu', 'fluo']: # testing with no request for mu_ref group = read_dnd(fpath, scan=scan, ref=False) self.assertIsInstance(group, Group) # group class is returned self.assertIsInstance(group.energy, ndarray) # ndarray type is returned self.assertFalse(hasattr( group, 'mu_ref')) # instance mu_ref is not returned if scan == 'mu': self.assertFalse(hasattr( group, 'fluo')) # instance fluo is not returned self.assertTrue(allclose(group.mu, mu)) # mu_ref is properly retrieved elif scan == 'fluo': self.assertFalse(hasattr(group, 'mu')) # instance mu is not returned self.assertTrue(allclose(group.fluo, fluo)) # fluo is properly retrieved
import matplotlib.pyplot as plt from araucaria.testdata import get_testpath from araucaria.io import read_dnd from araucaria.xas import pre_edge, autobk from araucaria.plot import fig_autobk fpath = get_testpath('dnd_testfile1.dat') group = read_dnd(fpath, scan='mu') pre = pre_edge(group, update=True) bkg = autobk(group, update=True) fig, ax = fig_autobk(group, show_window=False) plt.show(block=False)
from araucaria.testdata import get_testpath from araucaria import Group from araucaria.io import read_dnd from araucaria.xas import pre_edge, autobk, xftf, xftr from araucaria.utils import check_objattrs kw = 2 k_range = [2, 10] r_range = [0.5, 2] fpath = get_testpath('dnd_testfile1.dat') group = read_dnd(fpath, scan='mu') # extracting mu and mu_ref scans pre = pre_edge(group, update=True) autbk = autobk(group, update=True) fft = xftf(group, k_range=k_range, kweight=kw, update=True) rft = xftr(group, r_range=r_range, update=True) attrs = ['rwin', 'q', 'chiq', 'chiq_mag', 'chiq_re', 'chiq_im'] check_objattrs(group, Group, attrs) # [True, True, True, True, True, True] # plotting forward FFT signal import matplotlib.pyplot as plt from araucaria.plot import fig_xas_template fig, ax = fig_xas_template(panels='rq', fig_pars={'kweight': kw}) line = ax[0].plot(group.r, group.chir_mag) line = ax[0].plot(group.r, group.rwin, color='firebrick') xlim = ax[0].set_xlim(0, 6) line = ax[1].plot(group.k, group.k**kw * group.chi) line = ax[1].plot(group.q, group.chiq_re) xlim = ax[1].set_xlim(0, 12) fig.tight_layout() plt.show(block=False)
from numpy import allclose from araucaria.testdata import get_testpath from araucaria import Group from araucaria.io import read_dnd from araucaria.xas import deglitch, pre_edge, autobk from araucaria.utils import check_objattrs fpath = get_testpath('dnd_glitchfile.dat') group = read_dnd(fpath, scan='fluo') # extracting fluo and mu_ref scans cgroup = group.copy() degli = deglitch(cgroup, update=True) attrs = ['index_glitches', 'energy_glitches', 'deglitch_pars'] check_objattrs(cgroup, Group, attrs) # [True, True, True] allclose(cgroup.energy_glitches, group.energy[cgroup.index_glitches]) # True print(cgroup.energy_glitches) # [7552.2789 7548.1747 7390.512 7387.2613] # plotting original and deglitched spectrum from araucaria.plot import fig_xas_template import matplotlib.pyplot as plt for g in [group, cgroup]: pre = pre_edge(g, update=True) autbk = autobk(g, update=True) fig, ax = fig_xas_template(panels='xe') line = ax[0].plot(group.energy, group.norm, label='original', color='tab:red') line = ax[0].plot(cgroup.energy, cgroup.norm, label='degliched', color='k') line = ax[1].plot(group.k, group.k**2 * group.chi, color='tab:red') line = ax[1].plot(cgroup.k, cgroup.k**2 * cgroup.chi, color='k') leg = ax[0].legend() fig.tight_layout()