Skip to content

Curves generator

curves_generator

Functions:

get_history

get_history(
    list_expressions: Iterable[str] = (),
    support: ndarray | Iterable[Number] = (),
    nb_points=50,
)

Builds a curve y-values by stacking transformation expressions.

Source code in src\vimseo\utilities\curves_generator.py
51
52
53
54
55
56
57
58
59
60
61
62
63
def get_history(
    list_expressions: Iterable[str] = (),
    support: np.ndarray | Iterable[Number] = (),
    nb_points=50,
):
    """Builds a curve y-values by stacking transformation expressions."""
    if len(support) == 0:
        support = linspace(0.0, 1.0, nb_points)
    hist = support.copy()
    for expression in list_expressions:
        hist = str_to_func(expression)(hist)

    return hist

str_to_func

str_to_func(expression: str)

Create a python function from a string analytical expression.

Source code in src\vimseo\utilities\curves_generator.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def str_to_func(expression: str):
    """Create a python  function from a string analytical expression."""

    def f(x):
        # return eval(expression)

        disc = create_discipline(
            "AnalyticDiscipline", name="analytic", expressions={"y": expression}
        )

        x_array = np.atleast_1d(x)
        y_array = np.zeros(x_array.size)
        for i in range(len(x_array)):
            xx = np.atleast_1d(x_array[i])
            out = disc.execute({"x": xx})
            y_array[i] = out["y"][0]

        return y_array

    return f