balthazarneveu / interactive_pipe

create interactive image processing pipeline with friendly sliders
The Unlicense
8 stars 1 forks source link

@interactive decorator could return a filter instance #21

Open balthazarneveu opened 1 year ago

balthazarneveu commented 1 year ago

Right now it returns the original function. By returning a filter instance (with a call method) , this could be transparent to the user. Furthermore, even a simple filter should be "testable" with a graphical interface.

balthazarneveu commented 1 month ago

_private.registered_controls_names = []

def get_curve(frequency=1.):
    x= np.linspace(0, 1, 200)
    return SingleCurve(
        x,
        np.cos(2 * np.pi * frequency * x),
        label=f"cos(2π * {frequency} * x)",
    )

def stack_curves(*curves):
    return Curve([curve for curve in curves], grid=True, title="Curve List", xlim=(0., 1.), ylim=(0., 0.01))

interactive(frequency=(1., [0., 100.]))(get_curve)
get_curve(frequency=2.).show()

This works! function can be called correctly

def pipeline():
    in1 = get_curve()
    out = stack_curves(in1)
    return out

interactive_pipeline(gui="nb")(pipeline)()

This works.

:bug: frequency=5 won't work!

_private.registered_controls_names = []
@interactive(frequency=(1., [0., 100.]))
def get_curve_2(frequency=1.):
    x= np.linspace(0, 1, 200)
    return SingleCurve(
        x,
        np.cos(2 * np.pi * frequency * x),
        label=f"cos(2π * {frequency} * x)",
    )

get_curve_2(frequency=5.).show()