Exemplo n.º 1
0
def test_get_quant_fluor_data_dict():
    """Tests for 'get_quant_fluor_data_dict': basic tests for consistensy of the returned dictionary"""

    for standard_data in _standard_data_sample:

        quant_fluor_data_dict = get_quant_fluor_data_dict(standard_data,
                                                          incident_energy=12.0)
        # Will raise exception is schema is not satisfied
        jsonschema.validate(instance=quant_fluor_data_dict,
                            schema=_xrf_quant_fluor_schema)

        assert quant_fluor_data_dict["name"] == standard_data[
            "name"], "Dictionary element 'name' is incorrect"

        assert (quant_fluor_data_dict["serial"] == standard_data["serial"]
                ), "Dictionary element 'serial' is incorrect"

        assert (quant_fluor_data_dict["description"] ==
                standard_data["description"]
                ), "Dictionary element 'description' is incorrect"

        eline_set = set()
        # The 'mass' is not actual mass. If elements has multiple emission lines activated, then
        #   the mass (density) of the element will be counted multiple times. There is no
        #   physical meaning in the computed value: it is used to verify the sum of densities in
        #   the 'element_lines' dictionary of emission lines in 'quant_fluor_data_dict'
        mass_sum_expected = 0
        for cmpd, mass in standard_data["compounds"].items():
            em_dict = split_compound_mass(cmpd, mass)
            for el, ms in em_dict.items():
                elines = generate_eline_list([el], incident_energy=12.0)
                n_elines = len(elines)
                if n_elines:
                    mass_sum_expected += n_elines * ms
                    eline_set.update(elines)

        eline_out_list = list(quant_fluor_data_dict["element_lines"].keys())
        assert len(eline_out_list) == len(
            eline_set), "The number of emission lines is not as expected"
        assert (
            set(eline_out_list) == eline_set
        ), "Generated object contains emission lines that are different from expected"

        mass_sum = sum([
            _["density"]
            for _ in quant_fluor_data_dict["element_lines"].values()
        ])
        assert (
            mass_sum == mass_sum_expected
        ), "The total mass (density) of the components is different from expected"
Exemplo n.º 2
0
def test_split_compound_mass(formula, elements, n_atoms):

    mass_total = 10.0

    data = split_compound_mass(formula, mass_total)
    # Basic checks for proper parsing
    assert len(data) == len(
        elements), "The number of parsed elements is incorrect"
    assert set(elements) == set(
        data.keys()), "The set of parsed elements is incorrect"
    # Make sure that the sum of mass of each element equals to total mass
    npt.assert_almost_equal(
        np.sum(list(data.values())),
        mass_total,
        err_msg="The computed mass is not distributed properly among elements")
Exemplo n.º 3
0
def test_split_compound_mass_fail(formula):
    with pytest.raises(RuntimeError,
                       match=f"Invalid chemical formula.*{formula}"):
        split_compound_mass(formula, 10.0)