コード例 #1
0
def clean_dataset(dataset):
    """
    Clean an ESPEI dataset dictionary.

    Parameters
    ----------
    dataset : dict
        Dictionary of the standard ESPEI dataset.   dataset : dic

    Returns
    -------
    dict
        Modified dataset that has been cleaned

    Notes
    -----
    Assumes a valid, checked dataset. Currently handles
    * Converting expected numeric values to floats

    """
    dataset["conditions"] = {
        k: recursive_map(float, v)
        for k, v in dataset["conditions"].items()
    }

    solver = dataset.get("solver")
    if solver is not None:
        solver["sublattice_site_ratios"] = recursive_map(
            float, solver["sublattice_site_ratios"])
        occupancies = solver.get("sublattice_occupancies")
        if occupancies is not None:
            solver["sublattice_occupancies"] = recursive_map(
                float, occupancies)

    if dataset["output"] == "ZPF":
        values = dataset["values"]
        new_values = []
        for tieline in values:
            new_tieline = []
            for tieline_point in tieline:
                if all([comp is None for comp in tieline_point[2]]):
                    # this is a null tieline point
                    new_tieline.append(tieline_point)
                else:
                    new_tieline.append([
                        tieline_point[0], tieline_point[1],
                        recursive_map(float, tieline_point[2])
                    ])
            new_values.append(new_tieline)
        dataset["values"] = new_values
    else:
        # values should be all numerical
        dataset["values"] = recursive_map(float, dataset["values"])

    return dataset
コード例 #2
0
def test_recursive_map():
    """Test that recursive map function works"""

    strings = [[["1.0"], ["5.5", "8.8"], ["10.7"]]]
    floats = [[[1.0], [5.5, 8.8], [10.7]]]

    assert recursive_map(float, strings) == floats
    assert recursive_map(str, floats) == strings
    assert recursive_map(float, "1.234") == 1.234
    assert recursive_map(int, ["1", "2", "5"]) == [1, 2, 5]
    assert recursive_map(float, ["1.0", ["0.5", "0.5"]]) == [1.0, [0.5, 0.5]]