Skip to content

Conversation

@jackbdoughty
Copy link
Contributor

Found issues with linear fitting whereby the guess function would not work as expected e.g not guessing a straight line and division by zero error. This fixes by instead using the already implemented polynomial guess function and passing 1 as the polynomial degree. Should test by creating an example plan and two blocks to scan against eachother from- use a python script to repeatedly write to one of the blocks to simulate data from scan. See below. Check that initial guess produced in plot window fits the data provided well.

See fitting docs for more info.

Run this separately

def linear(x, m, c):
    return m * x + c

g.set_pv("CS:SB:bob", 1, is_local=True)

while True:

    val = g.get_pv("CS:SB:bob", is_local=True)
    g.set_pv("CS:SB:alice", linear(val, 0, 1),is_local=True)

Use a plan that looks like this

def plan():

    alice = block_r(float, "alice")
    bob = block_rw(float, "bob", write_config=BlockWriteConfig(settle_time_s=0.5))

    lf = LiveFit(Linear.fit(), "alice", "bob")

    fig, ax = plt.subplots()
    
    @subs_decorator(
        [
            LiveTable([bob.name, alice.name]),
            LiveFitPlot(lf, ax=ax, color="r", num_points=1000),
            LivePlot(y=alice.name, x=bob.name, ax=ax, marker="x", linestyle="none"),
        ]
    )
    def _inner() -> Generator[Msg, None, None]:
        yield from ensure_connected(bob, alice)
        yield from bp.scan([alice], bob, -5, 5, num=15)
        logger.blueskylogger.info("Some useful message")
    yield from _inner()

@jackbdoughty jackbdoughty changed the title Fixes issue found with linear fitting guess Fixes issues found with linear fitting guess function Oct 28, 2024
@Tom-Willemsen Tom-Willemsen merged commit 7063ad4 into main Oct 29, 2024
11 checks passed
@Tom-Willemsen Tom-Willemsen deleted the fixes_linear_fitting branch October 29, 2024 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants