def test_scofield_limits(self):
     """Check Scofield parametrisation refuses to extrapolate"""
     with self.assertRaises(ValueError):
         get_cross_sections_scofield(0.5, elements=['H'])
     with self.assertRaises(ValueError):
         get_cross_sections_scofield((10, 11, 0.5), elements=['H'])
     with self.assertRaises(ValueError):
         get_cross_sections_scofield(1600, elements=['H'])
     with self.assertRaises(ValueError):
         get_cross_sections_scofield((10, 11, 1600, 12), elements=['H'])
    def test_scofield_ref(self):
        """Check Scofield parametrisation: spot-check vs tables"""

        for el, orb, occ, energy, value in self.ref_values:
            cs = get_cross_sections_scofield(energy, elements=[el])
            # Check error is below 1 percent; small error is due to
            # fitting, not implementation in this part of code!
            self.assertAlmostEqual(cs[el][orb] * occ,
                                   value, delta=(value * 0.01))
Beispiel #3
0
def run(elements, emin=1, emax=10, size=None, output=None, fontsize=10):
    energies = np.linspace(emin, emax, 200)
    cross_sections = get_cross_sections_scofield(energies, elements)

    if size is None:
        fig = plt.figure()
    else:
        size_inches = [float(x) / 2.54 for x in size]
        fig = plt.figure(figsize=size_inches)

    ax = fig.add_subplot(1, 1, 1)

    colors = cycle(('C0', 'C1', 'C2', 'C3', 'C4'))
    markers = cycle(('o', '^', 'D', 'x', '*'))

    for element in elements:
        color, marker = next(colors), next(markers)
        linestyles = cycle((['-', '--', ':', '-.']))

        if 'warning' in cross_sections[element]:
            logging.warning("  {0}: {1}".format(
                element, cross_sections[element]['warning']))

        for orbital in 'spdf':
            if (orbital in cross_sections[element]
                    and cross_sections[element][orbital] is not None):
                ax.plot(energies,
                        cross_sections[element][orbital],
                        color=color,
                        linestyle=next(linestyles),
                        marker=marker,
                        markevery=40,
                        label='{0}-{1}'.format(element, orbital),
                        markersize=5)

    ax.tick_params(labelsize=(fontsize - 2))
    ax.set_xlabel('Photon energy / keV', fontsize=fontsize)
    ax.set_ylabel(r'Photoionization cross-section / barns electron$^{-1}$',
                  fontsize=fontsize)
    ax.set_yscale('log')
    ax.legend(loc='lower right', fontsize=fontsize)
    fig.subplots_adjust(right=0.98, top=0.98)

    if output is None:
        plt.show()
    else:
        fig.savefig(output)