Exemple #1
0
def test_photonintensityresultbuilder(builder):
    data = builder.build()

    assert len(data) == 9
    assert pyxray.xray_line(13, "K") in data
    assert pyxray.xray_line(13, "Ka") in data
    assert pyxray.xray_line(13, "L") in data
    assert pyxray.xray_line(13, "Ll,n") in data
Exemple #2
0
    def read(self, fileobj):
        super().read(fileobj)

        self.primary_intensities_1_per_sr_electron.clear()
        self.characteristic_fluorescence_intensities_1_per_sr_electron.clear()
        self.bremsstrahlung_fluorescence_intensities_1_per_sr_electron.clear()
        self.total_fluorescence_intensities_1_per_sr_electron.clear()
        self.total_intensities_1_per_sr_electron.clear()
        self._read_until_line_startswith(fileobj, '# IZ S0 S1  E (eV)')
        for line in fileobj:
            z = int(line[3:5])
            dst = pyxray.atomic_subshell(line[6:8].strip())
            src = pyxray.atomic_subshell(line[9:11].strip())
            xrayline = pyxray.xray_line(z, (src, dst))

            _e, val_p, unc_p, val_c, unc_c, val_b, unc_b, val_tf, unc_tf, val_t, unc_t = self._read_all_values(
                line)
            self.primary_intensities_1_per_sr_electron[xrayline] = ufloat(
                val_p, unc_p / 3)
            self.characteristic_fluorescence_intensities_1_per_sr_electron[
                xrayline] = ufloat(val_c, unc_c / 3)
            self.bremsstrahlung_fluorescence_intensities_1_per_sr_electron[
                xrayline] = ufloat(val_b, unc_b / 3)
            self.total_fluorescence_intensities_1_per_sr_electron[
                xrayline] = ufloat(val_tf, unc_tf / 3)
            self.total_intensities_1_per_sr_electron[xrayline] = ufloat(
                val_t, unc_t / 3)
Exemple #3
0
def convert_xrayline(xrayline):
    if isinstance(xrayline, pyxray.XrayLine):
        return xrayline

    try:
        return pyxray.xray_line(*xrayline)
    except:
        raise ValueError('"{}" is not an XrayLine'.format(xrayline))
Exemple #4
0
def test_lazysimulationparameters_eq(lazysimulationparameters):
    assert lazysimulationparameters == LazySimulationParameters(c1=0.1, c2=0.15)

    assert lazysimulationparameters != LazySimulationParameters()
    assert lazysimulationparameters != LazySimulationParameters(
        pyxray.xray_line(13, "Ka1"), c1=0.1, c2=0.15
    )
    assert lazysimulationparameters != LazySimulationParameters(c1=0.09, c2=0.15)
    assert lazysimulationparameters != LazySimulationParameters(c1=0.1, c2=0.09)
Exemple #5
0
def test_seriesbuilder_format_xrayline(seriesbuilder):
    xrayline = pyxray.xray_line(13, "Ka1")

    seriesbuilder.add_column(xrayline, xrayline, 0.5)
    seriesbuilder.add_column("e", "e", xrayline)

    s = seriesbuilder.build()

    assert xrayline.iupac in s
    assert s[xrayline.iupac] == pytest.approx(0.5, abs=1e-4)
    assert s["e"] == xrayline.iupac
Exemple #6
0
def find_known_xray_lines(zs,
                          minimum_energy_eV=0.0,
                          maximum_energy_eV=float("inf")):
    xray_lines = []

    for z in zs:
        for xraytransition in pyxray.element_xray_transitions(z):
            if xraytransition not in KNOWN_XRAYTRANSITIONS:
                continue

            xray_line = pyxray.xray_line(z, xraytransition)
            if minimum_energy_eV <= xray_line.energy_eV <= maximum_energy_eV:
                xray_lines.append(xray_line)

    return xray_lines
Exemple #7
0
    def _import_analysis_photonintensity(self, analysis, dirpath, errors,
                                         simdata):
        emitted_builder = EmittedPhotonIntensityResultBuilder(analysis)
        intensities = simdata.get_total_xray_intensities_1_esr()

        for z in intensities:
            for line in intensities[z]:
                if line not in LINE_LOOKUP:
                    continue

                transition = LINE_LOOKUP[line]
                xrayline = pyxray.xray_line(z, transition)
                value = intensities[z][line]
                error = 0.0
                emitted_builder.add_intensity(xrayline, value, error)

        return [emitted_builder.build()]
Exemple #8
0
    def _create_extra_transitions(self):
        # Expand data
        element_transition_results = {}
        for xrayline, result in self.data.items():
            element_transition_results.setdefault(
                xrayline.element, {})[xrayline.transition] = result

        newdata = {}
        for element in element_transition_results:
            for extra_transition in self._EXTRA_TRANSITIONS:
                # If the transition already exists, we skip
                if extra_transition in element_transition_results[element]:
                    continue

                # Search for the possible transitions (i.e. expand the extra transition)
                try:
                    possible_transitions = pyxray.element_xray_transitions(
                        element, extra_transition)
                except pyxray.NotFound:
                    continue

                # Find the results
                results = [
                    result for transition, result in
                    element_transition_results[element].items()
                    if transition in possible_transitions
                ]

                # If no results, do nothing
                if not results:
                    continue

                # Add new entry
                try:
                    xrayline = pyxray.xray_line(element, extra_transition)
                except pyxray.NotFound:
                    continue

                newdata[xrayline] = self._sum_results(results)

        return newdata
    def _test_result(self, result):
        self.assertEqual(1, result.detector_index)

        self.assertAlmostEqual(0.0, result.theta1_deg.n, 8)
        self.assertAlmostEqual(0.0, result.theta1_deg.s, 8)
        self.assertAlmostEqual(90.0, result.theta2_deg.n, 8)
        self.assertAlmostEqual(0.0, result.theta2_deg.s, 8)
        self.assertAlmostEqual(0.0, result.phi1_deg.n, 8)
        self.assertAlmostEqual(0.0, result.phi1_deg.s, 8)
        self.assertAlmostEqual(360.0, result.phi2_deg.n, 8)
        self.assertAlmostEqual(0.0, result.phi2_deg.s, 8)

        self.assertEqual(10, len(result.primary_intensities_1_per_sr_electron))
        self.assertEqual(
            10,
            len(result.
                characteristic_fluorescence_intensities_1_per_sr_electron))
        self.assertEqual(
            10,
            len(result.
                bremsstrahlung_fluorescence_intensities_1_per_sr_electron))
        self.assertEqual(
            10, len(result.total_fluorescence_intensities_1_per_sr_electron))
        self.assertEqual(10, len(result.total_intensities_1_per_sr_electron))

        cu_l1_m3 = pyxray.xray_line(29, 'L1-M3')

        intensity = result.primary_intensities_1_per_sr_electron[cu_l1_m3]
        self.assertAlmostEqual(1.518793e-6, intensity.n, 8)
        self.assertAlmostEqual(1.28e-7, intensity.s * 3, 8)

        intensity = result.characteristic_fluorescence_intensities_1_per_sr_electron[
            cu_l1_m3]
        self.assertAlmostEqual(0.0, intensity.n, 8)
        self.assertAlmostEqual(0.0, intensity.s * 3, 8)

        intensity = result.bremsstrahlung_fluorescence_intensities_1_per_sr_electron[
            cu_l1_m3]
        self.assertAlmostEqual(1.683623e-9, intensity.n, 8)
        self.assertAlmostEqual(3.57e-9, intensity.s * 3, 8)

        intensity = result.total_fluorescence_intensities_1_per_sr_electron[
            cu_l1_m3]
        self.assertAlmostEqual(1.683623e-9, intensity.n, 8)
        self.assertAlmostEqual(3.57e-9, intensity.s * 3, 8)

        intensity = result.total_intensities_1_per_sr_electron[cu_l1_m3]
        self.assertAlmostEqual(1.520476e-6, intensity.n, 8)
        self.assertAlmostEqual(1.28e-7, intensity.s * 3, 8)

        cu_k_l3 = pyxray.xray_line(29, 'K-L3')

        intensity = result.primary_intensities_1_per_sr_electron[cu_k_l3]
        self.assertAlmostEqual(1.995294e-5, intensity.n, 8)
        self.assertAlmostEqual(5.28e-7, intensity.s * 3, 8)

        intensity = result.characteristic_fluorescence_intensities_1_per_sr_electron[
            cu_k_l3]
        self.assertAlmostEqual(6.031664e-8, intensity.n, 8)
        self.assertAlmostEqual(2.32e-8, intensity.s * 3, 8)

        intensity = result.bremsstrahlung_fluorescence_intensities_1_per_sr_electron[
            cu_k_l3]
        self.assertAlmostEqual(1.133920e-6, intensity.n, 8)
        self.assertAlmostEqual(9.51e-8, intensity.s * 3, 8)

        intensity = result.total_fluorescence_intensities_1_per_sr_electron[
            cu_k_l3]
        self.assertAlmostEqual(1.194237e-6, intensity.n, 8)
        self.assertAlmostEqual(1.18e-7, intensity.s * 3, 8)

        intensity = result.total_intensities_1_per_sr_electron[cu_k_l3]
        self.assertAlmostEqual(2.114718e-5, intensity.n, 8)
        self.assertAlmostEqual(5.40e-7, intensity.s * 3, 8)
Exemple #10
0
import pyxray

import pytest

# Local modules.
from pymontecarlo.options.xrayline import LazyLowestEnergyXrayLine
from pymontecarlo.options.material import Material
import pymontecarlo.util.testutil as testutil

# Globals and constants variables.


@pytest.mark.parametrize(
    "z,beam_energy_eV,minimum_energy_eV,expected",
    [
        (6, 20e3, 0.0, pyxray.xray_line(6, "Ka1")),
        (13, 20e3, 0.0, pyxray.xray_line(13, "Ll")),
        (13, 20e3, 1e3, pyxray.xray_line(13, "Ka1")),
    ],
)
def test_lazylowestenergyxrayline(options, z, beam_energy_eV,
                                  minimum_energy_eV, expected):
    options.beam.energy_eV = beam_energy_eV
    options.sample.material = Material.pure(z)

    assert LazyLowestEnergyXrayLine(minimum_energy_eV).apply(
        None, options) == expected


@pytest.fixture
def lazylowestenergyxrayline():